Supplement local data for geocoder using Mapbox GL

2019-07-16 12:00发布

问题:

I am running a map of the location of a few facilities with their name and coordinate data. I want the geocoder to be able to search for the name of the facility.

Mapbox has a great example of this, but their example shows a use case where the dataset is loaded INTO the actual code. My dataset is much larger and it is currently located on a .geojson file in the project folder.

How can I transform this code to work for my example?

I tried to call back my dataset into the geocoder code by using

  var myData =getSource('BRdata');

then calling

 for (var i = 0; i < myData.features.length; i++) {
    var feature = myData.features[I];

// handle queries with different capitalization than the source data by calling toLowerCase()
     if (feature.properties.HandlerId.toLowerCase().search(query.toLowerCase()) !== -1) {

     feature['place_name'] = '