[OpenLayers-Users] need help with projection issues

Christopher Schmidt crschmidt at metacarta.com
Mon Jan 14 11:14:56 EST 2008


On Mon, Jan 14, 2008 at 05:06:44PM +0100, O. Baum wrote:
> Hello list,
> 
> I am new to OpenLayers and made my first attempts in using the
> JavaScript API of Google Maps and OpenLayers 2.5 these days.
> 
> I want to draw vector graphics into the OpenLayers map. I have read
> and understood basically that I have to follow
> http://trac.openlayers.org/wiki/SphericalMercator when I am using
> Google Maps in OpenLayers together with a Vector layer. If I do so,
> all coordinates I am going to use (including the one displayed by
> OpenLayers.Control.MousePosition()) are not in Geo-Lat/Long format any
> more, but in some other format (much bigger numbers) - these seems to
> be the "projected coordinates" mentioned in
> http://trac.openlayers.org/wiki/RFC/ProjectionSupport.
> 
> What do I have to do to be able to use Geo-Lat/Long coordinates for
> drawing on the Vector layer when I am using a Google Maps layer?

There are two parts to this.
 
  1. You'll almost definitely want to be using trunk, since it has
      projection support, and 2.5 doesn't. 

  2. It's not clear to me what 'use Geo-Lat/Long coordinates for
     drawing" means, so it depends what stage you want to use them in.

When you're actually drawing in the map, the coordinates shouldn't
matter. (I hope!) Using the digitization tools means that you're
interacting with the map, not the coordinates.

If you mean "How can I create features programatically using data in
geographic coordinates", the answer is that you will (in trunk) create
them, then, once your features are created, call
feature.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new
OpenLayers.Projection("EPSG:900913")), before you add your features to
the map.

If you mean, "How can I take features that I've drawn and programatically
convert them", do the oposite of the above for each feature. 
 

If you mean "How can I draw features using the digitizing tools, and
then get out a serialized representation of them as geographic, like
GeoJSON or GML", you would want to create a Format class with the
internal and external projection set:

f = new OpenLayers.Format.GeoJSON({'internalProjection':
map.getProjectionObject(), 'externalProjection': new
OpenLayers.Projection("EPSG:4326"));
f.write(map.layers[1].features);

There are other options, but specifying what you mean here is useful.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list