gpt4 book ai didi

javascript - OpenLayers 保存特征

转载 作者:行者123 更新时间:2023-12-02 19:43:15 25 4
gpt4 key购买 nike

我正在创建一条可以使用以下代码进行编辑的行:

    var line_points = Array();
var lineLayer = new OpenLayers.Layer.Vector(label);
this.map.addLayer(lineLayer);
this.map.addControl(new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path));

for ( x in points ) {
var point = points[x].split(',');
var lat = parseFloat( point[0] );
var lon = parseFloat( point[1] );
line_points[x] = new OpenLayers.Geometry.Point(this.Lon2Merc(lon), this.Lat2Merc(lat));
}

var line = new OpenLayers.Geometry.LineString(line_points);
var lineFeature = new OpenLayers.Feature.Vector(line, null, style);

lineLayer.addFeatures([lineFeature]);

每当移动或创建一个点以更新 HTML 表单(然后用于保存该数据)时,我都会尝试从此功能中提取纬度和经度。我听说过协议(protocol)之类的东西,但认为这不适合我。

有人能给我指出正确的方向吗?

编辑:我尝试直接从 HTML 获取详细信息:

    var x = 0;
var y = 0;
$.each(document.getElementById("OpenLayers.Geometry.LineString_195").getAttribute("points").split(','), function(index, value) {
if(index%2){
y = value;
console.log(MercatorToLatLon(x,y).Lat + "," + MercatorToLatLon(x,y).Lon);
} else {
x = value;
}
//console.log(value);
});

但这似乎没有给出任何有用的值,并且没有特定的顺序,我觉得很奇怪。

最佳答案

您可以使用getVertices操作来检索要素中所有点的最新纬度和经度。

因此,每当您想要更新 html 时,请调用以下命令。

console.log(lineFeature.geometry.getVertices());

每条评论更新:

function report(event) {
console.log(event.feature.geometry.getVertices());
console.log(event.type, event.feature ? event.feature.id : event.components);
}
lineLayer.events.on({
"beforefeaturemodified": report,
"featuremodified": report,
"afterfeaturemodified": report,
"vertexmodified": report,
"sketchmodified": report,
"sketchstarted": report,
"sketchcomplete": report
});

关于javascript - OpenLayers 保存特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10139372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com