我使用OpenLayers技术绘制多边形并保存坐标。这是我的代码: -
REngine engine = REngine.GetInstance();
rfile = rfile.Replace("\\", "/");
engine.Evaluate("source('" + rfile + "')");
polygonString具有
形式的坐标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 map = new ol.Map({
layers: [raster, vector],
target: 'map',
view: new ol.View({
center: [-11000000, 4600000],
zoom: 4
})
});
var typeSelect = document.getElementById('type');
var draw; // global so we can remove it later
function addInteraction() {
var value = typeSelect.value;
if (value !== 'None') {
draw = new ol.interaction.Draw({
source: source,
type: /** @type {ol.geom.GeometryType} */ (typeSelect.value),
freehand: true
});
draw.on('drawend',function(e){
var polygonString = e.feature.getGeometry().getCoordinates();
//polygonString = polygonString.toString();
//$('#polygonString').val(polygonString);
//$('#myPlot').modal('show');
});
map.addInteraction(draw);
}
}
我想将这些值保存为纬度和经度。我怎么能这样做?
答案 0 :(得分:3)
您需要将几何图形从地图参考系统(EPSG:3857)转换为纬度和经度(EPSG:4326)。
在drawend回调中尝试这个:
var geom = e.feature.getGeometry().transform('EPSG:3857', 'EPSG:4326');
console.log(geom.getCoordinates())