slutske22 / react-esri-leaflet

react components for esri-leaflet
https://codesandbox.io/s/github/slutske22/react-esri-leaflet/tree/master/examples/ts
MIT License
37 stars 5 forks source link

Warning about Identify in esri-leaflet creating multiple callback scripts #10

Closed kevinkdarling closed 2 years ago

kevinkdarling commented 3 years ago

This is not a problem per se with your code, but your code could possibly solve the bug in other code. (Or if you wish, I could take this to the esri-leaflet people.)

What happens is that each time you call identify, esri-leaflet creates a new jsonp callback script element. This continues ad infinitum. A quick solution is to capture the returned script id and immediately remove the element, as shown below. (This is okay, as the initial script include has already fired off the request. Another method is to remove it in your own callback.)

{
        let idInfo = myLayer.current.identify()
          .layers(layerParam)
          .tolerance(16)
          .on(theMap)
          .at(ev.latlng)
        .run(function(error:any, featureCollection:any, response:any)
        {
            if (response != undefined)
            {
                listItems(response.results);
            }
        });

        // delete the callback jsonp script
        if (idInfo && idInfo.id)
            document.getElementById(idInfo.id).remove();
}

This way, the DOM does not get filled up with old identify scripts. Another possiblity might be to somehow capture this method in your code and do the deletion for the user (??).

In any case, your users should be made aware of this, possibly by including a note or code in your examples.

Thanks again! Kev

slutske22 commented 3 years ago

Interesting.

slutske22 commented 3 years ago

Any update on this? Things are busy, so without an example to go off of, if or you're saying this is a problem that happens with vanilla esri-leaflet, I may just close this.

slutske22 commented 2 years ago

No response on this and no working example, closing.