我正在创建一个可以使用此代码编辑的行:
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 表单时,我都会尝试从该功能中提取纬度和经度。我听说过协议和东西,但不认为这对我来说是正确的。
有人可以指出我正确的方向吗?
编辑:我尝试直接从 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);
});
但这似乎并没有给出任何有用的价值,而且没有特别的顺序,我觉得很奇怪。