From 71482163cfa37ae6be062bfb03af4e54880af133 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 8 Jun 2010 21:37:33 +0000 Subject: [PATCH] Making it possible to use a custom SRS identifier for spherical mercator layers. r=bartvde (closes #2665) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10384 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/web-mercator.html | 46 +++++++++++++++++++++++ examples/web-mercator.js | 45 ++++++++++++++++++++++ lib/OpenLayers/Layer/SphericalMercator.js | 2 +- tests/Layer/Google.html | 32 ++++++++++++++++ 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 examples/web-mercator.html create mode 100644 examples/web-mercator.js diff --git a/examples/web-mercator.html b/examples/web-mercator.html new file mode 100644 index 0000000000..f1e602e4fc --- /dev/null +++ b/examples/web-mercator.html @@ -0,0 +1,46 @@ + + + + OpenLayers: Web Mercator + + + + + + + + +

OpenLayers Spherical Mercator Example

+ +
+
+

+ Shows the use of layers in spherical or web mercator using different + EPSG codes to indicate the same projection. +

+
+
+

+ A number of mapping services support the spherical or web + mercator but use different EPSG codes to identify it. ArcGIS + server version 9.3 uses EPSG:102113 to represent the same SRS + that OpenLayers typically refers to by EPSG:900913. +

+ To configure a map with a WMS layer overlaid on a Google layer + where the WMS uses EPSG:102113 to refer to the web mercator + projection, the Google layer must be constructed with this + projection code in its options (it is not sufficient to + construct the map with this projection). +

+ If your application needs to transform coordinates to and from + EPSG:102113, you must add custom transforms as well. +

+ See the web-mercator.js + source for details. +

+
+ + + + + diff --git a/examples/web-mercator.js b/examples/web-mercator.js new file mode 100644 index 0000000000..ab32547ca2 --- /dev/null +++ b/examples/web-mercator.js @@ -0,0 +1,45 @@ +// make map available for easy debugging +var map; + +// if your application transforms coordinates to and from EPSG:102113 then +// you must uncomment the lines below + +// OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:102113", +// OpenLayers.Layer.SphericalMercator.projectForward); +// OpenLayers.Projection.addTransform("EPSG:102113", "EPSG:4326", +// OpenLayers.Layer.SphericalMercator.projectInverse); + +function init() { + + var options = { + projection: new OpenLayers.Projection("EPSG:102113"), + units: "m", + numZoomLevels: 18, + maxResolution: 156543.0339, + maxExtent: new OpenLayers.Bounds(-20037508, -20037508, + 20037508, 20037508.34) + }; + map = new OpenLayers.Map('map', options); + + // create Google layer with EPSG:102113 code + var gsat = new OpenLayers.Layer.Google("Google Imagery", { + type: G_SATELLITE_MAP, + sphericalMercator: true, + projection: "EPSG:102113" + }); + + // create WMS layer + var wms = new OpenLayers.Layer.WMS( + "Highways", + "http://sampleserver1.arcgisonline.com/arcgis/services/Specialty/ESRI_StateCityHighway_USA/MapServer/WMSServer", + {layers: "2", format: "image/gif", transparent: "true"}, + { + isBaseLayer: false, + wrapDateLine: true + } + ); + + map.addLayers([gsat, wms]); + map.addControl(new OpenLayers.Control.LayerSwitcher()); + map.setCenter(new OpenLayers.LonLat(-10723197, 4500612), 3); +} \ No newline at end of file diff --git a/lib/OpenLayers/Layer/SphericalMercator.js b/lib/OpenLayers/Layer/SphericalMercator.js index bb5477aba1..730d8305b1 100644 --- a/lib/OpenLayers/Layer/SphericalMercator.js +++ b/lib/OpenLayers/Layer/SphericalMercator.js @@ -63,7 +63,7 @@ OpenLayers.Layer.SphericalMercator = { this.RESOLUTIONS[zoom] = maxResolution / Math.pow(2, zoom); } this.units = "m"; - this.projection = "EPSG:900913"; + this.projection = this.projection || "EPSG:900913"; }, /** diff --git a/tests/Layer/Google.html b/tests/Layer/Google.html index e2fb1fdbaa..2f205260c3 100644 --- a/tests/Layer/Google.html +++ b/tests/Layer/Google.html @@ -319,6 +319,38 @@ window.location.host); } } + + function test_sphericalMercator(t) { + + t.plan(4); + var map, layer; + + map = new OpenLayers.Map("map"); + layer = new OpenLayers.Layer.Google(); + map.addLayer(layer); + t.ok(!layer.sphericalMercator, "sphericalMercator false by default"); + t.eq(map.getProjection(), "EPSG:4326", "4326 by default without sphericalMercator"); + map.destroy(); + + map = new OpenLayers.Map("map"); + layer = new OpenLayers.Layer.Google(null, { + sphericalMercator: true + }); + map.addLayer(layer); + t.eq(map.getProjection(), "EPSG:900913", "900913 by default with sphericalMercator"); + map.destroy(); + + map = new OpenLayers.Map("map"); + layer = new OpenLayers.Layer.Google(null, { + sphericalMercator: true, + projection: "EPSG:102113" + }); + map.addLayer(layer); + t.eq(map.getProjection(), "EPSG:102113", "custom code respected with sphericalMercator"); + map.destroy(); + + } +