Changeset 10554


Ignore:
Timestamp:
Jul 29, 2010 10:23:10 AM (6 years ago)
Author:
tschaub
Message:

Making it so layers that use the SphericalMercator mixin call getLonLatFromViewPortPx and getViewPortPxFromLonLat on the Layer prototype instead of relying on the underlying map object for pixel to map location translations. This allows the Google (and other SM) layers to be used as a base layer but not be visible (with allOverlays set true on the map). r=ahocevar (closes #2759)

Location:
trunk/openlayers
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/openlayers/lib/OpenLayers/Layer/Google.js

    r10550 r10554  
    6969     */
    7070    type: null,
     71
     72    /**
     73     * APIProperty: wrapDateLine
     74     * {Boolean} Allow user to pan forever east/west.  Default is true. 
     75     *     Setting this to false only restricts panning if
     76     *     <sphericalMercator> is true.
     77     */
     78    wrapDateLine: true,
    7179
    7280    /**
  • trunk/openlayers/lib/OpenLayers/Layer/SphericalMercator.js

    r10384 r10554  
    4949        }
    5050        return extent;
     51    },
     52
     53    /**
     54     * Method: getLonLatFromViewPortPx
     55     * Get a map location from a pixel location
     56     *
     57     * Parameters:
     58     * viewPortPx - {<OpenLayers.Pixel>}
     59     *
     60     * Returns:
     61     *  {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in view
     62     *  port OpenLayers.Pixel, translated into lon/lat by map lib
     63     *  If the map lib is not loaded or not centered, returns null
     64     */
     65    getLonLatFromViewPortPx: function (viewPortPx) {
     66        return OpenLayers.Layer.prototype.getLonLatFromViewPortPx.apply(this, arguments);
     67    },
     68   
     69    /**
     70     * Method: getViewPortPxFromLonLat
     71     * Get a pixel location from a map location
     72     *
     73     * Parameters:
     74     * lonlat - {<OpenLayers.LonLat>}
     75     *
     76     * Returns:
     77     * {<OpenLayers.Pixel>} An OpenLayers.Pixel which is the passed-in
     78     * OpenLayers.LonLat, translated into view port pixels by map lib
     79     * If map lib is not loaded or not centered, returns null
     80     */
     81    getViewPortPxFromLonLat: function (lonlat) {
     82        return OpenLayers.Layer.prototype.getViewPortPxFromLonLat.apply(this, arguments);
    5183    },
    5284
  • trunk/openlayers/lib/OpenLayers/Layer/VirtualEarth.js

    r10103 r10554  
    6767
    6868    /**
     69     * APIProperty: wrapDateLine
     70     * {Boolean} Allow user to pan forever east/west.  Default is true. 
     71     *     Setting this to false only restricts panning if
     72     *     <sphericalMercator> is true.
     73     */
     74    wrapDateLine: true,
     75
     76    /**
    6977     * APIProperty: sphericalMercator
    7078     * {Boolean} Should the map act as a mercator-projected map? This will
  • trunk/openlayers/lib/OpenLayers/Layer/Yahoo.js

    r9679 r10554  
    6565   
    6666    /**
     67     * APIProperty: wrapDateLine
     68     * {Boolean} Allow user to pan forever east/west.  Default is true. 
     69     *     Setting this to false only restricts panning if
     70     *     <sphericalMercator> is true.
     71     */
     72    wrapDateLine: true,
     73
     74    /**
    6775     * APIProperty: sphericalMercator
    6876     * {Boolean} Should the map act as a mercator-projected map? This will
  • trunk/openlayers/tests/Layer/Google/v3.html

    r10480 r10554  
    261261
    262262     }
     263     
     264     function test_allOverlays_pan(t) {
     265
     266         t.plan(8);
     267
     268         var map = new OpenLayers.Map('map', {allOverlays: true});
     269
     270         var gmap = new OpenLayers.Layer.Google("Google Streets");
     271         var osm = new OpenLayers.Layer.OSM();
     272         map.addLayers([gmap, osm]);
     273
     274         var origin = new OpenLayers.LonLat(1000000, 6000000);
     275         map.setCenter(origin, 4);
     276         var resolution = map.getResolution();
     277         
     278         var dx, dy, center, expectedX, expectedY;
     279
     280         // confirm that panning works with Google visible
     281         dx = 100, dy = -100;
     282         map.pan(dx, dy, {animate: false});
     283         center = map.getCenter();
     284         expectedX = origin.lon + (resolution * dx);
     285         expectedY = origin.lat - (resolution * dy);
     286         t.eq(center.lon, expectedX, "x panning with Google visible " + dx + ", " + dy);
     287         t.eq(center.lat, expectedY, "y panning with Google visible " + dx + ", " + dy);
     288         map.pan(-dx, -dy, {animate: false});
     289         center = map.getCenter();
     290         t.eq(center.lon, origin.lon, "x panning with Google visible " + (-dx) + ", " + (-dy));
     291         t.eq(center.lat, origin.lat, "y panning with Google visible " + (-dx) + ", " + (-dy));
     292
     293         // confirm that panning works with Google invisible
     294         gmap.setVisibility(false);
     295         dx = 100, dy = -100;
     296         map.pan(dx, dy, {animate: false});
     297         center = map.getCenter();
     298         expectedX = origin.lon + (resolution * dx);
     299         expectedY = origin.lat - (resolution * dy);
     300         t.eq(center.lon, expectedX, "x panning with Google invisible " + dx + ", " + dy);
     301         t.eq(center.lat, expectedY, "y panning with Google invisible " + dx + ", " + dy);
     302         map.pan(-dx, -dy, {animate: false});
     303         center = map.getCenter();
     304         t.eq(center.lon, origin.lon, "x panning with Google invisible " + (-dx) + ", " + (-dy));
     305         t.eq(center.lat, origin.lat, "y panning with Google invisible " + (-dx) + ", " + (-dy));
     306         
     307         map.destroy();
     308
     309     }
     310     
     311     function test_wrapDateLine(t) {
     312         t.plan(2);
     313
     314         var map = new OpenLayers.Map("map");
     315
     316         var gmap = new OpenLayers.Layer.Google("Google Streets");
     317         map.addLayer(gmap);
     318         map.setCenter(new OpenLayers.LonLat(0, 0), 1);
     319         
     320         var center;
     321         
     322         // pan to the edge of the world
     323         map.pan(256, 0, {animate: false});
     324         center = map.getCenter();
     325         t.eq(center.lon, 20037508.3392, "edge of the world");
     326         // pan off the edge of the world
     327         map.pan(100, 0, {animate: false});
     328         center = map.getCenter();
     329         t.eq(center.lon, -12210356.6442, "magically back in the western hemisphere");
     330         
     331         map.destroy();
     332         
     333     }
     334
     335     function test_respectDateLine(t) {
     336         t.plan(2);
     337
     338         var map = new OpenLayers.Map("map");
     339
     340         var gmap = new OpenLayers.Layer.Google("Google Streets", {wrapDateLine: false});
     341         map.addLayer(gmap);
     342         map.setCenter(new OpenLayers.LonLat(0, 0), 1);
     343         
     344         var center;
     345         
     346         // pan to the edge of the world
     347         map.pan(256, 0, {animate: false});
     348         center = map.getCenter();
     349         t.eq(center.lon, 20037508.3392, "edge of the world");
     350         // pan off the edge of the world
     351         map.pan(100, 0, {animate: false});
     352         center = map.getCenter();
     353         t.eq(center.lon, 20037508.3392, "whew, still on the edge");
     354         
     355         map.destroy();
     356         
     357     }
    263358
    264359  </script>
Note: See TracChangeset for help on using the changeset viewer.