stefanocudini / leaflet-search

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

Multiple layer search (lineString & point) #175

Closed frolody closed 7 years ago

frolody commented 7 years ago
                        var myStyle = {
                    "color": "#ff7800",
                    "weight": 5,
                    "opacity": 0
                };

                var roadLayer = L.geoJson(false, {
                    style:myStyle
                }); 

                var locLayer = L.geoJson(false, {
                    style:myStyle
                });                 

                $.getJSON("roads.json", function (data) {
                    roadLayer.addData(data);
                });

                $.getJSON("lokasi.php", function (data) {
                    locLayer.addData(data);
                });

                var allLayer = L.layerGroup([roadLayer, locLayer]);
                            var controlSearch = new L.Control.Search({
                position:'topleft',        
                layer: allLayer,
                initial: false,
                zoom: 17,
                marker: false,
                propertyName : 'name'
            });

Show error : Uncaught TypeError: a.getLatLng is not a function at leaflet-search.min.js:17 at eachLayer (leaflet.js:7) at e. (leaflet-search.min.js:17) at eachLayer (leaflet.js:7) at e._recordsFromLayer (leaflet-search.min.js:17) at e._fillRecordsCache (leaflet-search.min.js:17) at leaflet-search.min.js:17

stefanocudini commented 7 years ago

don't use minfized version to debugging.. try to use expanded version of plugin: /src/leaflet-search.js

frolody commented 7 years ago

@stefanocudini now error like this :

Uncaught TypeError: m.getLatLng is not a function at leaflet-search.js:578 at eachLayer (leaflet.js:7) at e. (leaflet-search.js:577) at eachLayer (leaflet.js:7) at e._recordsFromLayer (leaflet-search.js:529) at e._fillRecordsCache (leaflet-search.js:722) at leaflet-search.js:684 (anonymous) @ leaflet-search.js:578 eachLayer @ leaflet.js:7 (anonymous) @ leaflet-search.js:577 eachLayer @ leaflet.js:7 _recordsFromLayer @ leaflet-search.js:529 _fillRecordsCache @ leaflet-search.js:722 (anonymous) @ leaflet-search.js:684 setTimeout (async) _handleKeypress @ leaflet-search.js:682 h @ leaflet.js:6

if just use one geojson file, search control is work. if i combine both, error show like above.

stefanocudini commented 7 years ago

this error is caused from you old version of plugin.. try to upgrade to te the last version: https://github.com/stefanocudini/leaflet-search/blob/master/src/leaflet-search.js#L578

frolody commented 7 years ago

@stefanocudini Thanks sir, works like a charm

stefanocudini commented 7 years ago

hi @frolody you can try mny new platform http://keplerjs.io/ ;-)