-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a query parameter to enable modifying url of VectorTileLayer to filter features #263
base: VectorTileLayer
Are you sure you want to change the base?
Conversation
Known issue that should be resolved Update: the issue seems to be resolved in my third commit, but I am not sure if the code follows the best practice and whether it will lead to other unseen issues |
I just made one more commit to add setStyle method, which can update the style dictionary or function used for a vector tile layer. I give an example of changing the attribute to display in a callback function.
Maybe using this method to un-display certain features (e.g., set stroke and fill to false) in lieu of url filter that I wrote earlier in this PR is better, since setStyle does not require re-transmission of updated tiles. Ideally it will be great if we could have a real hideout property in the context, but I do not know how to update the properties stored in the context |
I just made 5th commit to resolve a bug related to update the style of the layer to perform filtering. Previously layer is not redrawn after layer.setStyle method is applied, and I suggest that the layer style typically is updated automatically. I discover that there is a case in which the above assumption is not true:
In my 5th commit, I add a property to track the zoom value when the style is changed, and redraw the layer if the zoom values is different between current and previous zoom. If the zoom level is the same between two style updates, I have not observed any issue so far. Redraw probably should be avoided when possible for vector tile layer since it will re-request tiles from the tile server. Update the style of a vector tile layer itself does not seem to make duplicate requests of tiles, although new tiles will be requested when panning the map or zoom in and out of the map |
Why is this feature needed?
Why is current version not suitable for the needs?
With the new changes, how to do the filter then?
The vector tile server needs to support CQL in order to perform filtering by passing different URL. Here I use TiPG for testing the functionality.
Note in the above code, the url ends with
?{q}
, this format must be strictly followed if you want to perform filtering. If you do not expect to use filtering functionality, you can choose to specify the url without?{q}
at the end.Additionally, to perform filtering, the
query
parameter needs to be specified. This parameter assumes a dictionary-like object. In this example,"properties": "res,comind,geometry"
means to select those three columns from the PostGIS table."filter-lang": "cql2-text"
specifies the filter language, and"filter": "res IS NULL AND comind IS NULL"
is like a SQL where clause that selects only features with both res and comind fields having null values. Note that those specific query parameters are tile server dependent and please consult the documentation of the tile server that you are using. I also want to mention that TiPG seems to assume column names to be all lower case.