[OpenLayers-Users] Spatial Reference
Tim Schaub
tschaub at opengeo.org
Thu Mar 19 19:42:58 EDT 2009
Hey-
jcon... at gmail.com wrote:
> Hi Tim,
>
> I noticed one of your responses in a string to someone about spatial reference here http://preview.tinyurl.com/d2552v
>
> I'm attempting to make a change to map I have with a KML over Yahoo maps and I'm having a heck of a time figuring out where I can place your suggested script. I'm rather new to scripting and i'm curious if there is a way to manipulate the spatial reference without changing something inside the JS library. My question might be a little pedestrian, but I'm very much only taking baby steps at the moment. Any help is appreciated.
>
Hope it is ok to forward your request here. This is a common problem,
and something we'll try to better address with future OpenLayers releases.
Your KML data is in a geographic projection. Yahoo's tiles are in a
projection we call Spherical Mercator.
To properly overlay features derived from your KML on Yahoo's tiles, you
need to transform coordinates from geographic to spherical mercator.
Take a look at the following example:
http://openlayers.org/dev/examples/sundials-spherical-mercator.html
This is pretty similar to what you want to do.
If you look at the source of that example, you'll see that the map is
created with a couple projection related options. First, "projection"
is set to a new projection referenced with the code "EPSG:900913".
Next, the "displayProjection" property is set to a projection referenced
by the code "EPSG:4326". The first is Spherical Mercator and the second
is a geographic projection.
Note that you don't need to set the "displayProjection", it just
transforms the output coordinates for things like the MousePosition
control. In this example, setting the "displayProjection" has no effect
- but the property is used later.
The important part to notice is that the maxExtent coordinates are in
the same projection as the map. Below, you'll see that in calling
map.zoomToExtent, a bounds is passed in the map projection as well
(transformed from a geographic projection).
You'll want to create a Yahoo layer that is similar to the Google layer
on this example. The key part here is to set the sphericalMercator
option to true.
Finally, the KML is loaded by the sundials layer. The data is loaded
once (Fixed strategy) and comes from a URL relative to the example
(kml/sundials.kml). Data requested in this way has to come from the
same origin as the page.
The projection on the KML layer is set to geographic (referenced by
"EPSG:4326"). Because the layer is in a different projection than the
map, the strategy will do the right thing and transform the geometries
of any features before they are passed to the layer (for rendering).
So, that's a fair bit to get right. Write back with any more questions.
Also, make sure to read over the following:
http://docs.openlayers.org/library/spherical_mercator.html
Tim
> Thanks again,
>
> Conor Stinson
--
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.
More information about the Users
mailing list