Replies: 12 comments 4 replies
-
Hi @liskaole! You should add a vector source with: {
type: 'vector',
url: 'http://localhost:3000/rpc/public.function_source.json?param1=param1'
} And then, you can access Eg. CREATE OR REPLACE FUNCTION public.function_source(z integer, x integer, y integer, query_params json) RETURNS bytea AS $$
DECLARE
bounds geometry;
mvt bytea;
BEGIN
SELECT INTO bounds TileBBox(z, x, y, 3857);
SELECT INTO mvt ST_AsMVT(tile, 'public.function_source', 4096, 'geom') FROM (
SELECT
ST_AsMVTGeom(geom, bounds, 4096, 64, true) AS geom
FROM public.table_source
WHERE geom && bounds
AND param1 = query_params->>'param1' -- filter records
) as tile WHERE geom IS NOT NULL;
RETURN mvt;
END
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; |
Beta Was this translation helpful? Give feedback.
-
@stepankuzmin this is still not clear, where does this postgis function lives ?!! |
Beta Was this translation helpful? Give feedback.
-
Hey @mapsgeek! What do you mean by "lives"? It's just a user-defined PostgreSQL function |
Beta Was this translation helpful? Give feedback.
-
@stepankuzmin i need to make sql like queries for tables to generate the tiles for the matching criteria only, i thought that this function is required to be on the server side somehow but i understand now what is it mean, it's on the database level but i still don't understand where does it get the |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
so in my case i need to repeat the same function for each table i want to query, is there away to implement sql like queries without the need to these functions ? |
Beta Was this translation helpful? Give feedback.
-
You can pass your table as an argument into query_params and use it to query your tables |
Beta Was this translation helpful? Give feedback.
-
@stepankuzmin can you please help ? |
Beta Was this translation helpful? Give feedback.
-
Hey @mapsgeek! Could you please provide more info on this? You can enable debug mode and share logs here. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@mapsgeek if you're copy/pasting from the example in the documentation, you have to remember to manually load the TileBBox to your database. |
Beta Was this translation helpful? Give feedback.
-
In the Martin docs (https://maplibre.org/martin/sources-pg-functions.html), there is still the remark "TODO: Modify this example to actually use the query parameters.". I can't help because I'm also searching for answers. |
Beta Was this translation helpful? Give feedback.
-
How can I pass query_params in Function Source Tiles from tile source url MapBox?
source: { type: 'vector', url: 'http://localhost:3000/rpc/public.function_source.json?param1=param1' // doesn't work for me }
And how do I need to use query_params here? I want to filter my table by condition from query_params.
CREATE OR REPLACE FUNCTION public.function_source_test(z integer, x integer, y integer, query_params json) RETURNS bytea AS ...
Beta Was this translation helpful? Give feedback.
All reactions