0
我使用OpenLayers在地图上创建,显示和编辑功能。功能在Django中保存为JSONField。后保存我添加一个关键字django_pk到JSON。我怎样才能直接从该功能得到这个djanog_pk?阅读GeoJSON的键值和na来自Openlayers的功能
我需要这样做,所以当功能编辑时,我知道什么功能在Django更新。
我的JS代码如下:
<script>
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var source = new ol.source.Vector({wrapX: false});
var vector = new ol.layer.Vector({
source: source
});
var format = new ol.format.GeoJSON();
var select = new ol.interaction.Select({
wrapX: false
});
var modify = new ol.interaction.Modify({
features: select.getFeatures()
});
var map = new ol.Map({
interactions: ol.interaction.defaults().extend([select, modify]),
layers: [raster, vector],
target: 'map',
view: new ol.View({
center: [-11000000, 4600000],
zoom: 4
})
});
var features = new ol.source.Vector({
projection: 'EPSG:4326'
});
{% for polygon in polygons.0.gates %}
console.log(format.readFeature({{ polygon|safe }}).getProperties()))
{% endfor %}
features.addFeature(format.readFeature({{ polygons.0.protected_area|safe }}));
{% for polygon in polygons.0.gates %}
features.addFeature(format.readFeature({{ polygon|safe }}));
console.log(format.readFeature({{ polygon|safe }}))
{% endfor %}
var featureOverlay = new ol.layer.Vector({
source: features,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: '#ff78d1',
width: 2
}),
image: new ol.style.Circle({
radius: 6,
fill: new ol.style.Fill({
color: '#4ca6b6'
}),
})
})
});
featureOverlay.setMap(map);
</script>
我尝试这样做:Buyt它只返回几何:
select.on( '选择',函数(E){ 的console.log( e.selected [0] .getProperties()) });
的JSONField在Django看起来是这样的:
{
"geometry":{
"type":"Polygon",
"coordinates":[
[
[
-11156543.033928039,
6698655.0485978
],
[
-11410925.464061106,
5896371.999716589
],
[
-9972686.33984723,
5084305.011214877
],
[
-9512841.177683609,
6649735.350495286
],
[
-10090093.61529326,
6972605.357971871
],
[
-11156543.033928039,
6698655.0485978
]
]
]
},
"type":"Feature",
"properties":null,
"django_pk":10
}
所以我需要编辑它时,它选择它,OT删除它找到一个特征django_pk。
不知道如何获取此信息