传单搜索:无法搜索点类型

时间:2018-12-21 06:47:10

标签: javascript google-maps leaflet maps geojson

我关注了这个仓库Leaflet Search

,我想使用多边形,折线和点来组合搜索框。 用于多边形和折线的效果很好。但不是要点。属性名称确实出现,但是当我选择它时没有响应。

error

如您所见,当我找到要点时出现错误

如果我发现其他人喜欢折线或多边形,the results was successfull

<script src="data/us-states.js"></script>
    <script src="data/restaurant.geojson.js"></script>

var map = new L.Map('map', {zoom: 1, center: new L.latLng([37.8, -96]) });

    map.addLayer(new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')); //base layer

    var us_states = new L.GeoJSON(us_states, {
        style: function(feature) {
            return {color: feature.properties.color };
        },
        onEachFeature: function(feature, marker) {
            marker.bindPopup('<h4 style="color:'+feature.properties.color+'">'+ feature.properties.name +'</h4>');
        }
    });

    map.addLayer(us_states);

    var restaurant = new L.GeoJSON(restaurant, {
        style: function(feature) {
            return {color: feature.properties.color };
        },
        onEachFeature: function(feature, marker) {
            marker.bindPopup('<h4 style="color:'+feature.properties.color+'">'+ feature.properties.name +'</h4>');
        }
    });

    map.addLayer(restaurant);

    var searchControl = new L.Control.Search({
        layer: L.featureGroup([us_states,restaurant]),
        propertyName: 'name',
        marker: false,
        moveToLocation: function(latlng, title, map) {
            var zoom = map.getBoundsZoom(latlng.layer.getBounds());
            map.setView(latlng, zoom); 
        }
    });

    searchControl.on('search:locationfound', function(e) {
        e.layer.setStyle({fillColor: '#3f0', color: '#0f0'});
        if(e.layer._popup)
            e.layer.openPopup();

    }).on('search:collapsed', function(e) {

        featuresLayer.eachLayer(function(layer) {
            featuresLayer.resetStyle(layer);
        }); 
    });

    map.addControl( searchControl );  

也许有人可以帮助我吗?

此错误通知:

  

未捕获的TypeError:latlng.layer.getBounds不是位于的函数   e.moveToLocation [as _moveToLocation](geojson-layer.html:63)位于   位于e._handleSubmit的e.showLocation(leaflet-search.js:893)   (leaflet-search.js:856),网址为e。 (leaflet-search.js:398)在   HTMLLIElement.r(leaflet.js:5)

0 个答案:

没有答案