admin管理员组文章数量:1310034
I'm trying to show a map with three layers (google maps layers, wms layer and points layer) this is my code:
var map = new OpenLayers.Map({
div: "map",
maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
});
var capaGoogle = new OpenLayers.Layer.Google(
"Google Satellite",
{ type: G_SATELLITE_MAP, sphericalMercator: true, transparent: true }
);
var wmsOverlay = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://localhost:1979/geoserver/wms",
{ layers: 'world:PYCIUDADES', transparent: true }, { isBaseLayer: false });
var vectorLayer = new OpenLayers.Layer.Vector("vector");
vectorLayer.addFeatures([
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-57.635021, -25.276987)
),
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-56.759034, -22.71539)
)
]
);
map.addLayers([wmsOverlay, vectorLayer, capaGoogle]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
var center = new OpenLayers.LonLat(-57.58, -25.27).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
)
map.setCenter(center, 6);
the "vectorLayer" layer must be above of my map, but I get this (my wms layer is in south america, my points have to be also in south america, but they're near africa):
.png
What can I do?
Thanks in advance
I'm trying to show a map with three layers (google maps layers, wms layer and points layer) this is my code:
var map = new OpenLayers.Map({
div: "map",
maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
});
var capaGoogle = new OpenLayers.Layer.Google(
"Google Satellite",
{ type: G_SATELLITE_MAP, sphericalMercator: true, transparent: true }
);
var wmsOverlay = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://localhost:1979/geoserver/wms",
{ layers: 'world:PYCIUDADES', transparent: true }, { isBaseLayer: false });
var vectorLayer = new OpenLayers.Layer.Vector("vector");
vectorLayer.addFeatures([
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-57.635021, -25.276987)
),
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-56.759034, -22.71539)
)
]
);
map.addLayers([wmsOverlay, vectorLayer, capaGoogle]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
var center = new OpenLayers.LonLat(-57.58, -25.27).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
)
map.setCenter(center, 6);
the "vectorLayer" layer must be above of my map, but I get this (my wms layer is in south america, my points have to be also in south america, but they're near africa):
http://i45.tinypic./34y40zk.png
What can I do?
Thanks in advance
Share Improve this question asked May 31, 2012 at 22:40 Naty BizzNaty Bizz 2,3427 gold badges35 silver badges56 bronze badges 1- naty chica, fijate, i would be very wary of using any google mapping interface professionally. they have been steadily clamping down and restricting free use of their API and other resources. i just threw away 6 months of coding because they changed their licensing (again) and wanted to charge me a minimum of 18 thousand US$ per year. there is NO guarantee that whatever tiling you are using will still be free of charge in the near future. i strongly advise you to contact them (in brazil, they are represented by apontador..br) BEFORE investing your time in developing ANYTHING. – tony gil Commented Jun 4, 2012 at 21:17
2 Answers
Reset to default 6You should to transform your point's coordinates:
var epsg4326 = new OpenLayers.Projection('EPSG:4326');
var epsg900913 = new OpenLayers.Projection('EPSG:900913');
vectorLayer.addFeatures([
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-57.635021, -25.276987).transform(epsg4326, epsg900913)
),
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-56.759034, -22.71539).transform(epsg4326, epsg900913)
)
]);
"next to Africa" = longitude 0 latitude 0
when you simply enter Longitude and Latitude, OL considers this a WGS84 projection (standard).
but since you are using a Google layer (CapaGoogle), which is a mercator-referenced projection, you end up using two reference projections (4326 = WGS84 AND 900913 = mercator) simultaneously and the map server disconsiders the location of your markers, since they are "incorrect". therefore, it simply places them at (0,0).
as DrNextGIS said, you must "transform your points coordinates" so that everything on your map uses the same projection.
you would NOT have this problem if you were using a simple OpenLayer map (without Google or OSM).
本文标签: javascriptProjections and OpenLayersGeometryPoint in openlayersStack Overflow
版权声明:本文标题:javascript - Projections and OpenLayers.Geometry.Point in openlayers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741842809a2400603.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论