我在使用 Leaflet Control Search 时遇到问题,我正在使用 Laravel 5.2 在 C9.io 上进行测试,我正在尝试搜索 L.geojson 层,但它出现的只是“找不到位置”并且控制台给出了错误: “无法读取未定义的属性‘调用’”
我有一个保存地图、L.geojson 图层和图块的全局变量。
var map, allcalls, mapquest;
mapquest = new L.TileLayer("http://{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png", {
maxZoom: 18,
subdomains: ["otile1", "otile2", "otile3", "otile4"],
});
map = new L.Map('map', {
center: new L.LatLng(39.90973623453719, -93.69140625),
zoom: 3,
layers: [mapquest]
});
var promise = $.getJSON("leaflet_php/get_users.php");
promise.then(function(data) {
allcalls = L.geoJson(data, {
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.fn + '<br>' +feature.properties.gender + '<br>' + feature.properties.addr + '<br>'+ feature.properties.city );
}
});
map.fitBounds(allcalls.getBounds(), {
padding: [20, 20]
});
allcalls.addTo(map);
});
然后我启动 L.control.search,它显示在地图上,但是当我搜索时我没有得到任何结果,加载程序 gif 永远不会停止,并且我得到控制台错误“无法读取未定义的属性'调用'”
var controlSearch = new L.Control.Search({
layer: allcalls,
position:'topleft',
propertyName: 'city',
});
map.addControl( controlSearch );
我正在使用https://github.com/bmcbride/PHP-Database-GeoJSON生成 json 。我的 Json 至少有 1000 个特征,每个特征有 30 个属性。所以这是一个精简版。这是我得到的 json 样本:
{"type":"FeatureCollection","features":[{"type":"Feature","geometry": {"type":"Point","coordinates":[-80.191626,26.339826]},"properties":{"id":1,"fn":"SAMUEL","mi":null,"ln":"STANTON","name_pre":"MR","addr":"9 HONEYSUCKLE DR","apt":null,"city":"AMELIA","st":"OH","zip":45102,"z4":9722,"dpc":99,"fips_cty":25,"latitude":26.339826,"longitude":-80.191626,}},
任何帮助是极大的赞赏。提前致谢。