,我發現這個代碼在這個網站,這是link繪製多邊形的OpenLayers與WGS84座標
var options = {
div: "map",
zoom: 13,
center: [-9075004.4955698, 5028040.5259088],
layers: [
new OpenLayers.Layer.OSM()
]
},
source = [
[{x: -9075004, y: 5028040}, {x:-9079132, y: 5025403}, {x: -9072673, y: 5023568}],
[{x: -9074004, y: 5026040}, {x:-9073132, y: 5027403}, {x: -9074673, y: 5026568}],
[{x: -9073004, y: 5027040}, {x:-9072132, y: 5029403}, {x: -9075673, y: 5028568}]
],
polygonList = [],
multuPolygonGeometry,
multiPolygonFeature,
vector = new OpenLayers.Layer.Vector('multiPolygon'),
map = new OpenLayers.Map(options);
for (var i=0; i<source.length; i+=1) {
var pointList = [];
for (var j=0; j<source[i].length; j+=1) {
var point = new OpenLayers.Geometry.Point(source[i][j].x, source[i][j].y);
pointList.push(point);
}
var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
var polygon = new OpenLayers.Geometry.Polygon([linearRing]);
polygonList.push(polygon);
}
multuPolygonGeometry = new OpenLayers.Geometry.MultiPolygon(polygonList);
multiPolygonFeature = new OpenLayers.Feature.Vector(multuPolygonGeometry);
vector.addFeatures(multiPolygonFeature);
map.addLayer(vector);
我需要的是能夠把座標緯度/經度表達。我讀過它的WGS84轉換。我也讀過this answer,但我不知道如何使第一代碼與WGS84座標一起工作。
我使用Proj4來做這些類型的座標轉換。儘管如此,Proj4很難與之合作,雖然它非常強大。 http://trac.osgeo.org/proj/ –
非常感謝您的快速回答。我會嘗試。 –
對不起,我沒有更多的細節。我沒有我的Proj4代碼在我面前。如果您有任何疑問可以再次找到我,我會發現我使用Proj4。 –