我尝试在Mapbox中加载geoJson数据并使用插件Leaflet.Draw对其进行编辑 当我点击编辑按钮时,我有一个错误: 无法设置未定义的属性“原始”
图层在地图上,但我无法编辑。
以下是代码:
var map = L.map('map').setView( [40, 40], 2);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: '*******'
}).addTo(map);
// Initialise the FeatureGroup to store editable layers
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
L.geoJson(<%=RGeo::GeoJSON.encode(@field.shape).to_json.html_safe%>,
{
onEachFeature: function (feature, layer) {
drawnItems.addLayer(layer);
}
}).addTo(map);
// Initialise the draw control and pass it the FeatureGroup of editable layers
var drawControl = new L.Control.Draw({
draw : {
position : 'topleft',
polygon : true,
polyline : false,
rectangle : false,
circle : false,
marker: false
},
edit: {
featureGroup: drawnItems
},
}).addTo(map);
答案 0 :(得分:0)
所以,我找到了答案。 我试图编辑多面,但是leaflet.draw不支持它们。
我切换到leaflet.editable