stefanocudini / leaflet-search

Search stuff in a Leaflet map
https://opengeo.tech/maps/leaflet-search/
MIT License
773 stars 335 forks source link

leaflet-search 2.9.9 not working #265

Closed benesche1 closed 3 years ago

benesche1 commented 3 years ago

Expected Behavior

After typing something in the search box:

NOTE: This works in my Setup with leaflet-search 2.9.8

Current Behavior

If I type something in the Search Box nothing happens. When i press enter "Location not found" is displayed

Steps to Reproduce

  1. npm install leaflet-search
  2. my code:

    map.addControl( new L.Control.Search({ url: 'https://nominatim.openstreetmap.org/search?format=json&q={s}', jsonpParam: 'json_callback', propertyName: 'display_name', propertyLoc: ['lat','lon'], marker: L.marker([0,0]), autoCollapse: true, autoType: false, minLength: 2, }) );

Context (Environment)

I build an nodejs express application. Leaflet-serach is "imported" through require and then everything is translated through browserify. It worked on my first test 3 weeks ago (version 2.9.8) and now I started over and installed the latest version of leaflet-search (2.9.9). I suspected my code is broken (i switched from no template engine to handlebarsjs) but then I forced installing the previous version and everything worked fine. So I suspect the version is somehow flawed.

Edit: I use leaflet 1.7.1

Detailed Description

Through my debugging process I compared the behavior of version 2.9.9 vs 2.9.8 and I observed that both choose different paths at the first if-statement in the '_fillRecordsCache' function (Line 760). 2.9.9 jumps into the if part an 2.9.8 into the else one


I'm sorry if everything is not that detailed. I'm new to the JavaScript world and don't really know which information is useful. So pls ask if there is anything missing.

ppete2 commented 3 years ago

I can confirm this problem. Since some weeks this Leaflet plugin is not working anymore. I used it as Geocoder for Nominatim.

The problem can be reproduced:

In contrast - if you open the same example at Stefano's site https://opengeo.tech/maps/leaflet-search/examples/geocoding-nominatim.html and enter somthing in the search field you'll notice that it works on his site.

ppete2 commented 3 years ago

I think I found the reason why the easyblog.it site is working and the github example not. There's 1 code line different:

Within "/src/leaflet-search.js" line 755 has to be changed from if(this._layer) to if(this.options.layer)

The same should be done within the distribution files "/dist/leaflet-search.min.js" and "/dist/leaflet-search.src.js"

stefanocudini commented 3 years ago

solved from version 3.0.0 just published on npm

cheers!