[OpenLayers-Users] Newbie Projection Troubles

Paul Spencer pagameba at gmail.com
Wed Jun 18 21:14:53 EDT 2008


Hi,

unfortunately you cannot overlay 4326 tiles on a spherical mercator  
basemap.  OpenLayers does not reproject your tiles.  If your basemap  
is using spherical mercator (as is the case with the commercial  
services) then your overlay layers (i.e. your WMS) need to support the  
spherical mercator projection.  If it doesn't, then you will not be  
able to put them on the spherical mercator map.

You have a couple of choices at this point.  If you control the WMS,  
then you can probably modify it to add support for the spherical  
mercator projection.  If you know who does run it then you can contact  
them to see if they will do it.  Finally, if you can't change the WMS  
then you could set up a mapping server as a WMS Server and WMS Client  
where the WMS client ingests the WMS layer in 4326 and republishes it  
in 900913 - but you need a mapping server that can reproject (warp)  
rasters on the fly, such as MapServer.

Probably not good news for you, but I hope that helps.

Cheers

Paul

On 18-Jun-08, at 5:44 PM, bmcbride wrote:

>
> Hello,
> I'm working with the spherical-mercator example and trying to add a  
> WMS
> layer, which is in EPSG:4326.  The WMS (NYC Imagery) layer will not  
> render
> on the map and I'm sure it has to do with either projection,  
> maxResolution,
> or maxExtent variables, but I cannot figure it out.  Any help would be
> greatly appreciated.  The code is below:
>
> // make map available for easy debugging
>        var map;
>
>        // avoid pink tiles
>        OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
>        OpenLayers.Util.onImageLoadErrorColor = "transparent";
>
>        function init(){
>            var options = {
>                projection: new OpenLayers.Projection("EPSG:900913"),
>                displayProjection: new OpenLayers.Projection("EPSG: 
> 4326"),
>                units: "m",
>                maxResolution: 156543.0339,
>                maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
>                                                 20037508, 20037508.34)
>            };
>            map = new OpenLayers.Map('map', options);
>
>            // create Google Mercator layers
>            var gmap = new OpenLayers.Layer.Google(
>                "Google Streets",
>                {'sphericalMercator': true}
>            );
>            var gsat = new OpenLayers.Layer.Google(
>                "Google Satellite",
>                {type: G_SATELLITE_MAP, 'sphericalMercator': true}
>            );
>            var ghyb = new OpenLayers.Layer.Google(
>                "Google Hybrid",
>                {type: G_HYBRID_MAP, 'sphericalMercator': true}
>            );
> 			
>
>            // create Virtual Earth layers
>            var veroad = new OpenLayers.Layer.VirtualEarth(
>                "Virtual Earth Roads",
>                {'type': VEMapStyle.Road, 'sphericalMercator': true}
>            );
>            var veaer = new OpenLayers.Layer.VirtualEarth(
>                "Virtual Earth Aerial",
>                {'type': VEMapStyle.Aerial, 'sphericalMercator': true}
>            );
>            var vehyb = new OpenLayers.Layer.VirtualEarth(
>                "Virtual Earth Hybrid",
>                {'type': VEMapStyle.Hybrid, 'sphericalMercator': true}
>            );
>
>            // create Yahoo layer
>            var yahoo = new OpenLayers.Layer.Yahoo(
>                "Yahoo Street",
>                {'sphericalMercator': true}
>            );
>            var yahoosat = new OpenLayers.Layer.Yahoo(
>                "Yahoo Satellite",
>                {'type': YAHOO_MAP_SAT, 'sphericalMercator': true}
>            );
>            var yahoohyb = new OpenLayers.Layer.Yahoo(
>                "Yahoo Hybrid",
>                {'type': YAHOO_MAP_HYB, 'sphericalMercator': true}
>            );
>
>            // create OSM layer
>            var mapnik = new OpenLayers.Layer.TMS(
>                "OpenStreetMap (Mapnik)",
>                "http://tile.openstreetmap.org/",
>                {
>                    type: 'png', getURL: osm_getTileURL,
>                    displayOutsideMaxExtent: true,
>                    attribution: ' http://www.openstreetmap.org/
> OpenStreetMap '
>                }
>            );
>
>            // create OSM layer
>            var osmarender = new OpenLayers.Layer.TMS(
>                "OpenStreetMap (Tiles at Home)",
>                "http://tah.openstreetmap.org/Tiles/tile.php/",
>                {
>                    type: 'png', getURL: osm_getTileURL,
>                    displayOutsideMaxExtent: true,
>                    attribution: ' http://www.openstreetmap.org/
> OpenStreetMap '
>                }
>            );
>
>
>            // create WMS layer
>            var wms = new OpenLayers.Layer.WMS(
>                "World Map",
>                "http://world.freemap.in/tiles/",
>                {'layers': 'factbook-overlay', 'format':'png'},
>                {
>                    'opacity': 0.4,
>                    'isBaseLayer': false,'wrapDateLine': true
>                }
>            );
> 			
> 			var nysdop = new OpenLayers.Layer.WMS(
>                "NYSDOP",
>
> "http://imsortho.cr.usgs.gov/servlet/com.esri.wms.Esrimap/USGS_EDC_Ortho_NYSDOP_Grid? 
> ",
>                {'layers': "NY_NYC_2006_2FT_NC"},{projection:"EPSG: 
> 4326"}
>            );
>
>            // create a vector layer for drawing
>            var vector = new OpenLayers.Layer.Vector("Editable  
> Vectors");
>
>            map.addLayers([gmap, gsat, ghyb, nysdop, veroad, veaer,  
> vehyb,
>                           yahoo, yahoosat, yahoohyb, mapnik,  
> osmarender,
>                           wms, vector]);
>            map.addControl(new OpenLayers.Control.LayerSwitcher());
>            map.addControl(new  
> OpenLayers.Control.EditingToolbar(vector));
>            map.addControl(new OpenLayers.Control.Permalink());
>            map.addControl(new OpenLayers.Control.MousePosition());
>            if (!map.getCenter()) {map.zoomToMaxExtent()}
>        }
>
>        function osm_getTileURL(bounds) {
>            var res = this.map.getResolution();
>            var x = Math.round((bounds.left - this.maxExtent.left) /  
> (res *
> this.tileSize.w));
>            var y = Math.round((this.maxExtent.top - bounds.top) /  
> (res *
> this.tileSize.h));
>            var z = this.map.getZoom();
>            var limit = Math.pow(2, z);
>
>            if (y < 0 || y >= limit) {
>                return OpenLayers.Util.getImagesLocation() + "404.png";
>            } else {
>                x = ((x % limit) + limit) % limit;
>                return this.url + z + "/" + x + "/" + y + "." +  
> this.type;
>            }
>        }
>
> The following example works fine, but I need the commercial imagery  
> and OSM
> mapnik data available...
>
> var map = null;
>
>        function init(){
>
>            map = new OpenLayers.Map('map');
>
>            var ol_wms = new OpenLayers.Layer.WMS(
>                "OpenLayers WMS",
>                "http://labs.metacarta.com/wms/vmap0",
>                {layers: 'basic'}
>            );
>
>            var nysdop = new OpenLayers.Layer.WMS(
>                "NYSDOP",
>
> "http://imsortho.cr.usgs.gov/servlet/com.esri.wms.Esrimap/USGS_EDC_Ortho_NYSDOP_Grid? 
> ",
>                {layers: "NY_NYC_2006_2FT_NC"}
>            );
>
>            map.addLayers([ol_wms, nysdop]);
>            map.addControl(new OpenLayers.Control.LayerSwitcher());
>            map.zoomToMaxExtent();
>        }
>
> -- 
> View this message in context: http://www.nabble.com/Newbie-Projection-Troubles-tp17157211p17157211.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list