CodeForPittsburgh / food-access-map-data

Data for the food access map
MIT License
8 stars 18 forks source link

Search Filter appears to be truncated by map extents #200

Closed ajaxlex closed 2 years ago

ajaxlex commented 2 years ago

Observed Behavior: When entering a search term, the results in the dropdown change based upon the map extents Expected Behavior: When entering a search term, results will represent any records in the dataset that meet the search parameters

The primary map script ( script.js ) includes the following code to add the search to the map

var search = new L.esri.BootstrapGeocoder.search({
  inputTag: 'searchInput',
  placeholder: 'ex. Bloomfield',
}).addTo(map);

bootstrap-geocoder.js defines the following code at line 70 which is a clue to the behavior issue. I believe this code is responsible for navigating to the selected item on the suggested results, but it points to some inner workings that I think are relevant

            h.DomEvent.addListener(this._suggestions, "mousedown", function(e) {
                var t = e.target || e.srcElement;
                this._geosearchCore._geocode(t.innerHTML, t["data-magic-key"], t.provider),
                this.clear()
            }, this),

GeosearchCore.js defines the following code at line 110 that populates the suggested items

    for (var i = 0; i < this._providers.length; i++) {
      var provider = this._providers[i];
      var request = provider.suggestions(text, this._searchBounds(), createCallback(text, provider));
      this._pendingSuggestions.push(request);
    }

This code references this.searchBounds(), which among other things relies on an options object to make a decision about what to return.

I suspect if we can set the GeosearchCore this.options.useMapBounds to false, the system will search across the breadth of the dataset - although I could be wrong-o! It has happened before :D

ajaxlex commented 2 years ago

followup is to review the constructor for that object or read an manual for the library or something of that nature for the correctest way to set the options for the search

ajaxlex commented 2 years ago

search function library found here https://github.com/jgravois/bootstrap-geocoder

references api from here http://esri.github.io/esri-leaflet/api-reference/controls/geosearch.html

Options indicated as passed in as arg to constructor - just have to add useMapBounds to object passed in in script.js

ajaxlex commented 2 years ago

OK. I am sooooooooo wrong.

I thought the search function was searching our data, but it is searching addresses and locations in the region. We will need some kind of filter so we dont, for example, get a list of Giant Eagles from Sudan.

Unfortunately, the nature of the option provided is either on or off, although you can make that conditional depending on the zoom level. This is not really what we want.

It may be possible to modify the provider to only return results from within 10 miles of Pittsburgh, for example.

ajaxlex commented 2 years ago

Hey cool the searchBounds option seems to do what we want.

ajaxlex commented 2 years ago

var nwBoundsCorner = L.latLng(40.507486, -80.063847); var seBoundsCorner = L.latLng(40.385017, -79.837699); var mapBounds = L.latLngBounds(nwBoundsCorner, seBoundsCorner);