How do I use base layer of two different projection Spherical Mercator and WGS84? – www.scriptscoop.net

How do I add baselayer with two different projection? I have added overlayer with a different projection(EPSG:4326), but I need to add base layer with various projection I can see everything is fine with google map but when I switch base layer to EPSG:4326 layer everything is white. One possible work around is to use a cascading WMS like GeoServer to reproject one of the base layers from one to the other projection. Set up your WMS layer with out any reference to 900913 (assuming your data is in 4326). Then when you add the layer to OpenLayers make sure that you have set the projection of the map to 900913 (or just make sure to add Google Maps first). Then when you add the WMS layer, OpenLayers will request the data in the map projection (900913) and GeoServer will reproject from 4326 to 900913 on the fly. there is something as your question here, How to reproject base layers in OpenLayers? and you get some information about transformation, you should look this, Creating Spherical Mercator Raster Images. One of the reasons that the Spherical Mercator projection is so important is that it is the only projection which will allow for overlaying image data on top of commercial layers like Google Maps correctly. When using raster images, in the browser, it is not possible to reproject the images in the same way it might be in a ‘thick’ GIS client. Instead, all images must be in the same projection. How to create Spherical Mercator projected tiles depends on the software you are using to generate your images. Sorry to revive this old thread, but as I've been looking into this recently, and this is one of the top search results, I figured i'd add some breadcrumbs for those who come later of my research and experimentation. The 2.X line of Open Layers does not support this. The Map, it's properties such as center, resolution and extents are set by the INITIAL base layer of the map. Change to another base layer DOES NOT adjust these properties, so the outcome is unknown. Often, you get a center point/bounds that are not valid for the base layer you are changing to, so you see white tiles. But that is not ALWAYS the outcome (for example, switching from 4326 to 900913 will bring you to a point close to 0degN,0degE). Some patches were written against open layers that attempt to patch this for the map and many of the layers (see [1]). This comes from a bug filed over 6 (6!!!) years ago [2]. While you'd have to host your own version of OL and patch it by hand (the patch will not apply cleanly to the latest versions, so you have to manually do the edit), this will get you mostly where you want to be. Very nasty, and doesn't handle everything, but overall, gets someone who NEEDS multiple baselayers with different projections on their feet. One example is the base layer/overlay dichotomy. It is often a challenge to know how and where to set resolutions, maxExtent, etc. for the map. Projection handling between map and layers and the interplay between projection and properties like maxExtent and center are complicated at best. The Map object in 2.X relied too heavily on the base layer, and that is going to change going forward. So, if you can hold out until late 2013, there may be a pre-made solution for you to use. [1] http://trac.osgeo.org/openlayers/attachment/ticket/1249/NEW.Reproject.patch [2] http://trac.osgeo.org/openlayers/ticket/1249 [3] http://openlayers.org/blog/2012/11/14/why-are-we-building-openlayers-3/ You basically want to set some control points (reference points) using gdal_translate then warp the image using gdalwarp. So for a rough projection you could simply use the corner cordinates to set 4 control points like so. (These examples are using EPSG:4326, but you can use EPSG:900913. The above is saying that pixel x=0 and y=0 is equal to '-89.38939600 30.39282800' pixel x=1024 and y=0 is -87.00029400 30.01043900 and so forth. If you want to transform between some other projections, then you will have to use the Proj4js library. Note that transform() changes the actual object, so if you need the orignal object for something, remember to clone it. Source.


Яндекс.Метрика Рейтинг@Mail.ru Free Web Counter
page counter
Last Modified: April 18, 2016 @ 3:05 am