首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拖动标记并更新Turf.js缓冲区

拖动标记并更新Turf.js缓冲区
EN

Stack Overflow用户
提问于 2015-04-16 00:49:27
回答 1查看 548关注 0票数 0

我正在尝试创建一个地图,其中一个标记是可拖动的,并且它可以缓冲移动。与这个question处理的内容非常相似(几乎相同),但在我的例子中,我使用的不是Mapbox.js,而是普通的leaflet。我当前的代码是:

代码语言:javascript
复制
 //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函数,所以我猜这可能是原因。

EN

回答 1

Stack Overflow用户

发布于 2015-04-16 01:32:44

所以看起来问题出在buff = turf.featurecollection([buffered]); one中,我改成了buff = L.geoJson(buffered); everything works。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29656147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档