【发布时间】:2016-08-26 20:13:48
【问题描述】:
我在初始化Leaflet.draw toolbar 时遇到了困难。我尝试使用各种示例中的代码,但仍然无法在我的地图上显示工具栏。我的代码存在于它自己的 .js 文件中,如下所示:
function main() {
// create a map in the "map" div, set the view to a given place and zoom
var map = L.map('map', {
drawControl: true
}).setView([35.110756 , -120.591667], 14);
// add an OpenStreetMap tile layer
L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v9/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoiemFjaHJvYmluc29uIiwiYSI6IjZXWDh0enMifQ.P_x5U3esb8BJM9apOhn4Kg', {
attribution: '© Mapbox © OpenStreetMap © DigitalGlobe'
}).addTo(map);
// Initialise the FeatureGroup to store editable layers
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
// Initialise the draw control and pass it the FeatureGroup of editable layers
var drawControl = new L.Control.Draw({
position: 'topleft',
draw: {
marker: true
},
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
map.on('draw:created', function(e){
var type = e.layerType,
layer = e.layer;
if (type === 'marker'){
layer.bindPopup('A popup!');
}
drawnItems.addLayer(layer);
});
}
window.onload = main;
【问题讨论】:
标签: javascript leaflet gis