我已阅读@ghybs页面提供的有用答案:“update properties of geojson to use it with leaflet”
但是我仍然坚持使用引导弹出窗口使用它从用户收集数据并将其保存在feature.properties之后我将从多个标记收集多个数据,多边形折线转换为geojson。 我可以从弹出窗口收集数据,但数据对于我创建的每个标记都显示相同。每个标记的feature.properties应该不同。
pelase审查我的代码:
ignorecase = true
[remote "origin"]
url = https://github.com/NrkSensors/Android.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch]
autosetuprebase = always
[branch "master"]
rebase = true
remote = origin
merge = refs/heads/master
[remote "github"]
url = https://github.com/Muuddz/AndroidApp.git
fetch = +refs/heads/*:refs/remotes/github/*
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, {
maxZoom: 18,
attribution: osmAttrib
});
map = L.map('map', {
layers: [osm],
center: [31.9500, 35.9333],
zoom: 15
});
var editableLayers = L.geoJson().addTo(map);
map.addControl(new L.Control.Draw({
edit: {
featureGroup: editableLayers
}
}));
map.on('draw:created', function (e) {
var layer = e.layer,
feature = layer.feature = layer.feature || {};
feature.type = feature.type || "Feature";
var props = feature.properties = feature.properties || {};
//layer.feature = {properties: {}}; // No need to convert to GeoJSON.
//var props = layer.feature.properties;
props.action = null;
editableLayers.addLayer(layer);
addPopup(layer);
});
function addPopup(layer) {
var content = document.getElementById('action');
layer.feature.properties.action = content;
/* content.addEventListener("keyup", function () {
layer.feature.properties.action = content;
});*/
/* layer.on("popupopen", function () {
content.value = layer.feature.properties.desc;
content.focus();
});
layer.bindPopup(content).openPopup();*/
layer.on('click', function() {
$('#action').val(layer.feature.properties.action);
//content.value = layer.feature.properties.action;
$('#attributes').modal({'show' : true, backdrop:'static', keyboard:false});
$('#action').val(layer.feature.properties.action);
});
}
document.getElementById("convert").addEventListener("click", function () {
console.log(JSON.stringify(editableLayers.toGeoJSON(), null, 2));
});
#map {
height: 500px;
}