OpenLayers OpenLayers

Ticket #1210 (closed feature: fixed)

Opened 1 year ago

Last modified 1 year ago

methods to transform geometries from epsg:4326 to spherical mercator and back

Reported by: tschaub Assigned to: crschmidt
Priority: minor Milestone: 2.6 Release
Component: Layer.SphericalMercator Version: 2.5
Keywords: Cc:
State: Complete

Description

I fully support the proj work as *the* way to go with client-side transforms. With or without that work, we still have this SphericalMercator layer mixin. This already gives us two API methods to deal with tranforming coordinates into instances of LonLat. This helps for people who want to do things like display mouse position, or set center in one SRS while the map is in the other.

What we don't have - and what we won't have if the proj lib is optional (which we all agree it should be) - are methods to transform geometries to and from Spherical Mercator (using EPSG:4326 as a base). This requires no significant new code - just some handy utility methods that use the existing API methods (forwardMercator and inverseMercator). As long as SpericalMercator is part of the API, I think it makes good sense to allow people to transform geometries correctly.

Attachments

1210.patch (4.8 kB) - added by crschmidt on 12/14/07 10:12:09.
Support for alternative transformation functions in the case of lack of proj4js support
1210.2.patch (10.8 kB) - added by tschaub on 12/14/07 15:28:50.
reworked a bit with tests

Change History

12/13/07 17:55:52 changed by tschaub

  • keywords set to review.

Tests pass in FF, IE6, IE7. Please review.

12/13/07 23:32:54 changed by crschmidt

  • keywords deleted.

I think this is the wrong way to go about it.

Problem statement:

  • Reprojection of geometries is desired from EPSG:4326 to EPSG:900913 and back when SphericalMercator layers are in use.
  • No external dependancies should be required in order to perform this reprojection.

Instead we should:

Modify OpenLayers.Projection to fall back to a locally defined lookup table to determine if a mapping is available for a particular projection if proj4js support is not available. Essentially, this is a modification to the Projection.transform function so that it will first look for proj4js, and if not available, it will look up something like a:

OpenLayers.Projection.projectionTableEPSG:4326?EPSG:900913? = OpenLayers.Layer.SphericalMercator.forwardMercator;

OpenLayers.Projection.projectionTableEPSG:900913?EPSG:4326? = OpenLayers.Layer.SphericalMercator.reverseMercator;

Then the SphericalMercator layer should implement these by default.

I then think that we should concentrate on #1037 to solve the rest of the problem.

Then geometries can transform themselves, and we're hooking into the same support as the rest of the projection system rather than having two competing methods to transform.

Until such a time as we decide this is *not* the right way to go, I'm going to mark this *not* for review, and we can discuss more: if it turns out I'm wrong and others want this in a different way, then we can bring review back, but I think that we're just developing something we're going to end up throwing out. I believe the above uses the built in reprojection support we're going to continue to need, so anyone using SphericalMercator will get it -- and anyone else doesn't need it.

12/13/07 23:33:31 changed by crschmidt

OpenLayers.Projection.projectionTable['EPSG:4326']['EPSG:900913'] = OpenLayers.Layer.SphericalMercator.forwardMercator;
OpenLayers.Projection.projectionTable['EPSG:900913']['EPSG:4326'] = OpenLayers.Layer.SphericalMercator.reverseMercator;

i hate wikitext.

12/14/07 10:00:18 changed by crschmidt

  • owner changed from tschaub to crschmidt.
  • state set to Needs More Work.

12/14/07 10:12:09 changed by crschmidt

  • attachment 1210.patch added.

Support for alternative transformation functions in the case of lack of proj4js support

12/14/07 10:14:15 changed by crschmidt

  • state changed from Needs More Work to Review.

Okay, 1210.patch now implements this: now, even without proj4js support, I can do:

>>> OpenLayers.Projection.transform({'x':-71,y:42}, 
  map.baseLayer.projection, 
  new OpenLayers.Projection("EPSG:900913"))
Object x=-7903683.845222223 y=5160979.443331368
>>> OpenLayers.Projection.transform(OpenLayers.Projection.transform({'x':-71,y:42},
   map.baseLayer.projection, new OpenLayers.Projection("EPSG:900913")), 
   new OpenLayers.Projection("EPSG:900913"), map.baseLayer.projection)
Object x=-71.00000000000001 y=42.00000000000001

I think this is ready for review.

12/14/07 15:28:50 changed by tschaub

  • attachment 1210.2.patch added.

reworked a bit with tests

12/14/07 15:32:40 changed by tschaub

Ok, 1210.2.patch changes a few things. It leaves us with the following API additions:

OpenLayers.Projection.addTransform

and that's it. The OpenLayers.Projection.transforms class property is non-API - should only be modified by the addTransform method. Also, the projectForward and projectInverse methods on that SM mixin are non-API.

I think this is cool. And the tests make it look like it will work.

12/14/07 15:34:33 changed by tschaub

  • state changed from Review to Commit.

12/14/07 15:45:42 changed by crschmidt

  • status changed from new to closed.
  • resolution set to fixed.

(In [5410]) Add support for transformation functions without using proj4js, and make the SphericalMercator mixin register two transformations to/from EPSG:900913, EPSG:4326. Thanks to Tim for the feedback and review. (Closes #1210)

This allows us to transform points to/from SphericalMercator without proj4js support -- and if other projects need similar functionality, they can write their own custom transformation functions rather than modifying proj4js to support some custom projection.

12/14/07 15:57:59 changed by crschmidt

  • state changed from Commit to Complete.

(In [5410]) Add support for transformation functions without using proj4js, and make the SphericalMercator mixin register two transformations to/from EPSG:900913, EPSG:4326. Thanks to Tim for the feedback and review. (Closes #1210)

This allows us to transform points to/from SphericalMercator without proj4js support -- and if other projects need similar functionality, they can write their own custom transformation functions rather than modifying proj4js to support some custom projection.