0

I've been fighting a bug in an ESRI leaflet map for days and I am hoping for some ideas. I have a geosearch that searches dynamicMapLayers. I pull a latlng from the results and pass it to a .identify() as the argument in the .at(). This works fine if I am at a zoom level of 15 of greater. However if I am at a zoom level less than 15 the .identify() returns a different feature than what is found by the geosearch. It seems that the smaller the zoom is when the search is initiated, the larger the error (might be two parcels away instead of simply adjacent).
Confoundingly, I have a map.on("click", function) that also takes the latlng from the click event and passes it to the same function the geosearch does but it works at any zoom level.
I have found a hack to resolve the problem but can't be sure it will for all cases. If I initiate a .flyTo() and pass it the latlng and a zoom level of 16 and delay the .identify() using a map.once("moveend zoomend", ...) I seem to get the correct feature. Landing on the zoom of 16 was trial and error. A Zoom of 15 works for most cases but I found at least 1 where the latlng is close to the edge and required a 16 to get the correct feature.
I don't understand what is causing the issue. I don't know if it is an issue with the image tiles being in transition loading when the .identify() is triggered? Or if it something to do with the crs and on-the-fly projections (data is in EPSG 2914)? Or something else entirely?
Any ideas for what is going on and is there a more elegant solution than my hack?
Here are excerpts of the original code for reference:

var searchControl = L.esri.Geocoding.geosearch({
    providers: [addrSearch, taxlotSearch], // will geocode via addressParcel Mapserver.
    placeholder: "house number, address, or maptaxlot",
    zoomToResult: false,
    searchBounds: searchBounds,
  }).addTo(map);

  searchControl.on("results", function (e) {
    goToFeature(e, tableElems, map, parcels, address, rebuild, sales, damage);
  });
  map.on("click", function (e) {
    goToFeature(e, tableElems, map, parcels, address, rebuild, sales, damage);
  });
  function activatePane(map, identifiedFeature) {
    //shrink map to allow panel to fit
    $("#map").css({ width: "65%", "border-radius": "0 0 0 1em" });
    //allow for map center to be based on new map frame
    map.invalidateSize();
    //display the panel
    $("#selectedFeatures").css("display", "flex");
    //center map on selected feature
    map.flyToBounds(identifiedFeature.getBounds());
}
  function goToFeature( //e=event
  e,
  tableElems,
  map,
  parcels,
  address,
  rebuild,
  sales,
  damage
) {
    
  //identify the feature clicked/searched in parcels
  parcels
    .identify()
    .layers("all:0") // just the counties sublayer
    .on(map)
    .at(e.latlng)
    .run(function (error, featureCollection) {
      if (error) {
        console.log("error", error);
        return;
      }

      // make sure at least one feature was identified.
      if (featureCollection.features.length > 0) {
        
        //add a feature to highlight the selected feature
        let identifiedFeature = L.geoJSON(featureCollection.features[0]).addTo(
          map
        );
        //open pane and zoom to feature
        activatePane(map, identifiedFeature);

This is the hack for the search control:

searchControl.on("results", function (e) {
    map.flyTo(e.latlng, 16);
    map.once("moveend zoomend", function () {
      goToFeature(
        e,
        tableElems,
        map,
        parcels,
        address,
        rebuild,
        sales,
        damage
      );
    });
  });

Of course there is much more code to this project that could be causing the issue and so it may be best viewed on github in the add_search branch: https://github.com/TjBruhn/holidayfarm_leaflet.git
Or the site: https://tjbruhn.github.io/holidayfarm_leaflet/

2
  • Your first paragraph, which I think contains your question, is really hard to absorb. What is the issue exactly? That clicking on a parcel yields a different identify result than searching for it? And that when passing the results of search into identify gives different results based on map zoom? There is an interesting question here, but I'm struggling to understand what it is Commented Aug 17, 2022 at 0:05
  • Sorry I'm having a hard time explaining it. Yes, when you click on a parcel identify gives you the correct parcel. When you pass the search results into identify whether you get the correct result depends on the zoom level. At smaller number zoom levels the results are more inaccurate. At higher zoom levels the results become more accurate until at some zoom you can reliably get the correct result.
    – TreverB
    Commented Aug 17, 2022 at 17:35

0

Browse other questions tagged or ask your own question.