0
votes

I have a GeoJSON dataset of about 30,000 polygons each of which has a name and address attached. I have uploaded this to Mapbox as a tileset.

Is it possible to create a 'search by attribute' box using Mapbox GL JS, where the user can start typing and the search box provides results based on the name and address for the user to choose from? Along the lines of this Mango example:

enter image description here

Is this possible in Mapbox? I could do it by running something like SELECT * FROM tiles WHERE name LIKE '%venet%' or address LIKE '%venet%' against the tileset, and then wiring up the results to my own dropdown, but I don't know if Mapbox JS supports that kind of Ajax query. or whether Mapbox JS provides a widget for doing this.

I've done this before in Carto.JS using custom code and a SQL LIKE query, but I don't know if it's possible with Mapbox.

2

2 Answers

0
votes

Per the documentation for the datasets API, there is no operation that allows you to search by attribute at this time.

0
votes

Although Lucas is correct that you can't do this with datasets you said you uploaded the data as a tileset.

The Mapbox-GL-JS querySourceFeatures may do what you want:

Returns an array of GeoJSON Feature objects representing features within the specified vector tile or GeoJSON source that satisfy the query parameters.

It doesn't support partial matching (ie, %venet%), but you could probably use it to fetch all features within the viewport, then filter them yourself. There's a good example of this here: https://www.mapbox.com/mapbox-gl-js/example/filter-features-within-map-view/