我已经使用 geojson api 加载了点数据
var incidences = new L.GeoJSON.AJAX("http://127.0.0.1:8000/incidence_data/",{
onEachFeature: function(feature,layer){
//console.log(feature.properties);
layer.bindPopup(feature.properties.name.toString())
}
});
incidences.addTo(map);
现在我正在尝试在地图上创建一个按钮,当我单击该按钮时,事件会缓冲一英里。
html
<div id="map2" class="col-md-4 well">
<p>GeoDjango is da bomb</p>
<button id="buffer" class="form-control btn-warning">Buffer</button>
</div>
JS
var bufferLayer;
var incidences2 = incidences.toGeoJSON();
$("#buffer").click(function(){
if ($("#buffer").html()=='Buffer'){
var buff=turf.buffer(incidences2,1,'miles');
bufferLayer=L.geoJSON(buff).addTo(map);
$("#buffer").html("Remove Buffer");
} else{
map.removeLayer(bufferLayer);
$("#buffer").html("Buffer");
}
});
然后当我单击按钮时出现此错误
turf.min.js:1 Uncaught Error: options must be an object
at Object.t.buffer (turf.min.js:1)
at HTMLButtonElement.<anonymous> (js.js:112)
at HTMLButtonElement.dispatch (jquery-3.3.1.slim.min.js:2)
at HTMLButtonElement.v.handle (jquery-3.3.1.slim.min.js:2)