[OpenLayers-Users] Switching projection on loaded map

Fabian Patzke patzke at geoinformationsdienst.de
Wed Aug 12 08:04:50 EDT 2009


If anyone is interested how I solved my problem, see below.

Fabian Patzke wrote:
> 
> I want to build an option in my OL map app so that a user can switch the
> used
> projection of the map to another.
> For example my map is in EPSG:4326. Than I add some layers to the map and
> the
> user can use the map. If one want it should be possible to switch to
> EPSG:32632
> via a button and the map should be reloaded with the new projection.
> 
> My problem is, that it is not possible to set the map.projection once a
> layer
> has been added. I've tried it and it can only be set with
> map.setOptions(...) as
> long no layer has been loaded.
> 
> Is there an easy way to reload/redraw/recreate the map or do I have to
> destroy
> the map an build it up with a new projection by hand?
> 

I took all necessary information out of the map
map.getProjection();
map.getCenter().lon;
map.getCenter().lat;
map.getZoom();
Destroy the map an then restart it with the transform parameters an new
Projection, new units, and a new resolutionsArray.

No big deal but not everything is solved out of the box with this solution.
For example when you want to have the same layers visible as before the
switch. We do it with saving our visibility and such stuff in a database. I
think for a small map with only a few layers you could simply make another
array an save there state inside.

-- 
View this message in context: http://n2.nabble.com/Switching-projection-on-loaded-map-tp3011928p3430249.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list