[OpenLayers-Commits] r11503 - in trunk/openlayers: examples lib/OpenLayers/Layer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Feb 25 09:27:56 EST 2011


Author: ahocevar
Date: 2011-02-25 06:27:54 -0800 (Fri, 25 Feb 2011)
New Revision: 11503

Modified:
   trunk/openlayers/examples/bing.html
   trunk/openlayers/examples/spherical-mercator.html
   trunk/openlayers/lib/OpenLayers/Layer/VirtualEarth.js
Log:
documenting that Layer.VirtualEarth requires restrictedExtent to be set, and changing the examples accordingly. p=marcjansen (closes #3123)

Modified: trunk/openlayers/examples/bing.html
===================================================================
--- trunk/openlayers/examples/bing.html	2011-02-25 14:20:48 UTC (rev 11502)
+++ trunk/openlayers/examples/bing.html	2011-02-25 14:27:54 UTC (rev 11503)
@@ -12,9 +12,18 @@
     <script>
 
         var map;
-
+ 
         function init(){
-            map = new OpenLayers.Map("map");
+            // setting restrictedExtent so that we can use the 
+            // VirtualEarth-layers, see e.g. 
+            // http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/VirtualEarth-js.html
+            var restrictedExtent = new OpenLayers.Bounds(-20037508, -20037508, 
+                20037508, 20037508);
+            
+            map = new OpenLayers.Map("map", {
+                restrictedExtent: restrictedExtent
+            });
+            
             map.addControl(new OpenLayers.Control.LayerSwitcher());
 
             var shaded = new OpenLayers.Layer.VirtualEarth("Shaded", {

Modified: trunk/openlayers/examples/spherical-mercator.html
===================================================================
--- trunk/openlayers/examples/spherical-mercator.html	2011-02-25 14:20:48 UTC (rev 11502)
+++ trunk/openlayers/examples/spherical-mercator.html	2011-02-25 14:27:54 UTC (rev 11503)
@@ -24,107 +24,111 @@
     <script src="../lib/OpenLayers.js"></script>
     <script type="text/javascript">
 
-        // make map available for easy debugging
-        var map;
+// make map available for easy debugging
+var map;
 
-        // increase reload attempts 
-        OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
+// increase reload attempts 
+OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
 
-        function init(){
-            var options = {
-                projection: new OpenLayers.Projection("EPSG:900913"),
-                displayProjection: new OpenLayers.Projection("EPSG:4326"),
-                units: "m",
-                numZoomLevels: 18,
-                maxResolution: 156543.0339,
-                maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
-                                                 20037508, 20037508.34)
-            };
-            map = new OpenLayers.Map('map', options);
+function init(){
+    var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508),
+        restrictedExtent = maxExtent.clone(-20037508, -20037508, 20037508, 20037508),
+        maxResolution = 156543.0339;
+    
+    var options = {
+        projection: new OpenLayers.Projection("EPSG:900913"),
+        displayProjection: new OpenLayers.Projection("EPSG:4326"),
+        units: "m",
+        numZoomLevels: 18,
+        maxResolution: maxResolution,
+        maxExtent: maxExtent,
+        restrictedExtent: restrictedExtent
+    };
+    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, numZoomLevels: 22}
-            );
-            var ghyb = new OpenLayers.Layer.Google(
-                "Google Hybrid",
-                {type: G_HYBRID_MAP, 'sphericalMercator': true}
-            );
+    // 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, numZoomLevels: 22}
+    );
+    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 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 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.OSM();
-            // create OAM layer
-            var oam = new OpenLayers.Layer.XYZ(
-                "OpenAerialMap",
-                "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/${z}/${x}/${y}.png",
-                {
-                    sphericalMercator: true
-                }
-            );
+    // create OSM layer
+    var mapnik = new OpenLayers.Layer.OSM();
+    // create OAM layer
+    var oam = new OpenLayers.Layer.XYZ(
+        "OpenAerialMap",
+        "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/${z}/${x}/${y}.png",
+        {
+            sphericalMercator: true
+        }
+    );
 
-            // create OSM layer
-            var osmarender = new OpenLayers.Layer.OSM(
-                "OpenStreetMap (Tiles at Home)",
-                "http://tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"
-            );
+    // create OSM layer
+    var osmarender = new OpenLayers.Layer.OSM(
+        "OpenStreetMap (Tiles at Home)",
+        "http://tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"
+    );
 
 
-            // create WMS layer
-            var wms = new OpenLayers.Layer.WMS(
-                "World Map",
-                "http://world.freemap.in/tiles/",
-                {'layers': 'factbook-overlay', 'format':'png'},
-                {
-                    'opacity': 0.4, visibility: false,
-                    'isBaseLayer': false,'wrapDateLine': true
-                }
-            );
+    // create WMS layer
+    var wms = new OpenLayers.Layer.WMS(
+        "World Map",
+        "http://world.freemap.in/tiles/",
+        {'layers': 'factbook-overlay', 'format':'png'},
+        {
+            'opacity': 0.4, visibility: false,
+            'isBaseLayer': false,'wrapDateLine': true
+        }
+    );
 
-            // create a vector layer for drawing
-            var vector = new OpenLayers.Layer.Vector("Editable Vectors");
+    // create a vector layer for drawing
+    var vector = new OpenLayers.Layer.Vector("Editable Vectors");
 
-            map.addLayers([gmap, gsat, ghyb, veroad, veaer, vehyb,
-                           yahoo, yahoosat, yahoohyb, oam, 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()}
-        }
+    map.addLayers([gmap, gsat, ghyb, veroad, veaer, vehyb,
+                   yahoo, yahoosat, yahoohyb, oam, 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()}
+}
 
     </script>
   </head>

Modified: trunk/openlayers/lib/OpenLayers/Layer/VirtualEarth.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/VirtualEarth.js	2011-02-25 14:20:48 UTC (rev 11502)
+++ trunk/openlayers/lib/OpenLayers/Layer/VirtualEarth.js	2011-02-25 14:27:54 UTC (rev 11503)
@@ -13,7 +13,11 @@
 
 /**
  * Class: OpenLayers.Layer.VirtualEarth
- * 
+ * Instances of OpenLayers.Layer.VirtualEarth are used to display the data from
+ *     the Bing Maps AJAX Control (see e.g. 
+ *     http://msdn.microsoft.com/library/bb429619.aspx). Create a VirtualEarth 
+ *     layer with the <OpenLayers.Layer.VirtualEarth> constructor.
+ *     
  * Inherits from:
  *  - <OpenLayers.Layer.EventPane>
  *  - <OpenLayers.Layer.FixedZoomLevels>
@@ -94,7 +98,23 @@
 
     /** 
      * Constructor: OpenLayers.Layer.VirtualEarth
+     * Creates a new instance of a OpenLayers.Layer.VirtualEarth. If you use an
+     *     instance of OpenLayers.Layer.VirtualEarth in you map, you should set 
+     *     the <OpenLayers.Map> option restrictedExtent to a meaningful value,
+     *     e.g.:
+     * (code)
+     * var map = new OpenLayers.Map( 'map', {
+     *     // other map options
+     *     restrictedExtent : OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508)
+     * } );
      * 
+     * var veLayer = new OpenLayers.Layer.VirtualEarth (
+     *     "Virtual Earth Layer"
+     * );
+     * 
+     * map.addLayer( veLayer );
+     * (end)
+     * 
      * Parameters:
      * name - {String}
      * options - {Object}



More information about the Commits mailing list