[OpenLayers-Users] reprojection of vector layer from wgs84 to
sphericalmercator
Jachym Cepicky
jachym.cepicky at gmail.com
Mon Jan 14 08:11:09 EST 2008
Hi,
I would like to display GML vector layer in epsg:4326 on top of WMS
Layer in epsg:900913.
The map is initialized like
var options = {
maxExtent: new OpenLayers.Bounds(1150000, 6100000, 2500000, 6600000),
maxResolution: "auto",
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
};
map = new OpenLayers.Map("map", options);
var topo = new OpenLayers.Layer.WMS( "Topo",
http://www.bnhelp.cz/cgi-bin/crtopo2",
{layers:'doprava',format:"image/gif"},
{group:"base",sphericalMercator:true});
// the vector map definition
var vector = new OpenLayers.Layer.GML("Vector","gml.xml");
When I try to initialize the map, the vector layer is not drawed, because of the coordinates are in different projection.
Q1: Is there some option, which would force the vector layer, that it's feature will be
recalculated from wgs84 to sphericalmercator, if the base layer would be in spherical mercator ?
----
Then I tried to redefine preFeatureInsert method of OpenLayers.Layer.Vector, to get coordinates
for all features in epsg:900913
preFeatureInsert = function(feature) {
for (var i = 0; i < feature.geometry.components.length; i++) {
var x = feature.geometry.components[i].x;
var y = feature.geometry.components[i].y;
var ll = kolo.forwardMercator(x,y);
x = x * 20037508.34 / 180;
y = Math.log(Math.tan((90 + y) * Math.PI / 360)) / (Math.PI / 180);
y = y * 20037508.34 / 180;
feature.geometry.components[i].x = x;
feature.geometry.components[i].y = y;
}
};
// the vector map definition
var vector = new OpenLayers.Layer.GML("Vector","gml.xml",
{preFeatureInsert:preFeatureInsert});
When I then redraw the map, no vector features are displayed. But when I check the "vector" layer object
with Firebug, the vector features do have coordinates in epsg:900913 and the values do look
reasonable.
Q2: What do I wrong? Is there some better method, how to reproject vector features from wgs84
to epsg:900913?
Thanks
Jachym
--
Jachym Cepicky
e-mail: jachym.cepicky at gmail.com
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Toto je =?UTF-8?Q?digit=C3=A1ln=C4=9B?=
=?ISO-8859-1?Q?_podepsan=E1?= =?UTF-8?Q?_=C4=8D=C3=A1st?=
=?ISO-8859-1?Q?_zpr=E1vy?=
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080114/61e71f2f/attachment.bin
More information about the Users
mailing list