[OpenLayers-Users] reprojection of vector layer from wgs84 to sphericalmercator

Jachym Cepicky jachym.cepicky at gmail.com
Mon Jan 14 10:17:53 EST 2008


Nice one, I heard about proj4js, thought never used it

Thanks for this hint

Jachym

Mike Adair píše v Po 14. 01. 2008 v 10:09 -0500:
> Note that this should work too, and allows you to handle points in 
> coordinate systems other than EPSG:4326:
> 
> - include proj4js in your app via the <script> tag
> 
> - then:
> 
> preFeatureInsert = function(feature) {
>     var src = new OpenLayers.Projection('EPSG:4326');
>     var dest = new OpenLayers.Projection('EPSG:900913');
>     for (var i = 0; i < feature.geometry.components.length; i++) {
> 	OpenLayers.Projection.transform(feature.geometry.components[i], src, dest);
>    }
> };
> 
> You may need to skip transforming the last point in the components if it is a repeat of the first point (for polygons).
> 
> Mike
> 
> 
> 
> Jachym Cepicky wrote:
> > Hi,
> >
> > Jachym Cepicky píše v Po 14. 01. 2008 v 14:11 +0100:
> >   
> >> [...]
> >>
> >> 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});
> >>
> >>     
> > this works. the error was somewhere else
> >
> > j
> >   
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
> >   
-- 
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/541879f0/attachment.bin


More information about the Users mailing list