我正在使用 OpenLayers3 并希望拥有用户可以绘制 1 个或多个点的地图。我已经实现了。但是,我还想保存每个点的坐标。
但我真的不知道该怎么做,因为 OpenLayers3 相当新,而且我很难在网上找到示例。
这是我到目前为止所拥有的:
var modeSelect = document.getElementById('type');
var draw; // global so we can remove it later
//modify
var featureOverlay = new ol.FeatureOverlay({
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: '#ffcc33',
width: 2
}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
});
featureOverlay.setMap(map);
// modify end
function addInteraction() {
var value = modeSelect.value;
if (value == 'Point') {
draw = new ol.interaction.Draw({
//source: source,
features: featureOverlay.getFeatures(),
type: /** @type {ol.geom.GeometryType} */ (value)
});
map.addInteraction(draw);
}
// modify
if (value == 'Modify') {
var modify = new ol.interaction.Modify({
features: featureOverlay.getFeatures(),
// the SHIFT key must be pressed to delete vertices, so
// that new vertices can be drawn at the same position
// of existing vertices
deleteCondition: function(event) {
return ol.events.condition.shiftKeyOnly(event) &&
ol.events.condition.singleClick(event);
}
});
map.addInteraction(modify);
}
}
addInteraction();