0

我正在尝试创建一个标记可拖动的地图,并且它可以缓冲移动。与这个问题所处理的非常相似(几乎相同),在我的情况下,我没有使用 Mapbox.js 只使用普通传单。我目前的代码是:

 //add marker that is draggable
 var marker = L.marker(new L.LatLng(39.75621, -104.99404), {
                      draggable: true});

 //add marker popup
 marker.bindPopup('This marker is draggable! Move it around to see what locales are in your "area of walkability".');
 marker.addTo(map);

 //remove old buffers (used when marker is dragged)
 function removeBuff() {
     map.removeLayer(buff);
 };

 //create buffer (used when the marker is dragged)
 function updateBuffer() {
     //Make the marker a feature
     var pointMarker = marker.toGeoJSON();
     //buffer the marker geoJSON feature
     var buffered = turf.buffer(pointMarker, 1, 'miles');
     //add buffer to the map. Note: no "var" before "buff" makes it a global variable and usable within the removeBuff() function. 
     buff = turf.featurecollection([buffered]);
     L.geoJson(buff).addTo(map);
 };

 marker.on('drag', function () {
     removeBuff(), updateBuffer()
 });
 updateBuffer();

这给了我一个缓冲区并允许我拖动点和缓冲区,但是,所有以前的缓冲区都保留在地图中。

我做了一些更改以替换该问题中的 mapbox.js 函数,所以我的猜测是这可能是原因。

4

1 回答 1

0

所以看来问题出在buff = turf.featurecollection([buffered]);我改成buff = L.geoJson(buffered);一切正常的问题上。

于 2015-04-15T17:32:44.413 回答