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)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10554 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-07-29 17:23:10 +00:00
parent f2247ae079
commit 9fd7463680
5 changed files with 151 additions and 0 deletions

View File

@@ -69,6 +69,14 @@ OpenLayers.Layer.Google = OpenLayers.Class(
*/
type: null,
/**
* APIProperty: wrapDateLine
* {Boolean} Allow user to pan forever east/west. Default is true.
* Setting this to false only restricts panning if
* <sphericalMercator> is true.
*/
wrapDateLine: true,
/**
* APIProperty: sphericalMercator
* {Boolean} Should the map act as a mercator-projected map? This will

View File

@@ -50,6 +50,38 @@ OpenLayers.Layer.SphericalMercator = {
return extent;
},
/**
* Method: getLonLatFromViewPortPx
* Get a map location from a pixel location
*
* Parameters:
* viewPortPx - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in view
* port OpenLayers.Pixel, translated into lon/lat by map lib
* If the map lib is not loaded or not centered, returns null
*/
getLonLatFromViewPortPx: function (viewPortPx) {
return OpenLayers.Layer.prototype.getLonLatFromViewPortPx.apply(this, arguments);
},
/**
* Method: getViewPortPxFromLonLat
* Get a pixel location from a map location
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
*
* Returns:
* {<OpenLayers.Pixel>} An OpenLayers.Pixel which is the passed-in
* OpenLayers.LonLat, translated into view port pixels by map lib
* If map lib is not loaded or not centered, returns null
*/
getViewPortPxFromLonLat: function (lonlat) {
return OpenLayers.Layer.prototype.getViewPortPxFromLonLat.apply(this, arguments);
},
/**
* Method: initMercatorParameters
* Set up the mercator parameters on the layer: resolutions,

View File

@@ -65,6 +65,14 @@ OpenLayers.Layer.VirtualEarth = OpenLayers.Class(
*/
type: null,
/**
* APIProperty: wrapDateLine
* {Boolean} Allow user to pan forever east/west. Default is true.
* Setting this to false only restricts panning if
* <sphericalMercator> is true.
*/
wrapDateLine: true,
/**
* APIProperty: sphericalMercator
* {Boolean} Should the map act as a mercator-projected map? This will

View File

@@ -63,6 +63,14 @@ OpenLayers.Layer.Yahoo = OpenLayers.Class(
*/
type: null,
/**
* APIProperty: wrapDateLine
* {Boolean} Allow user to pan forever east/west. Default is true.
* Setting this to false only restricts panning if
* <sphericalMercator> is true.
*/
wrapDateLine: true,
/**
* APIProperty: sphericalMercator
* {Boolean} Should the map act as a mercator-projected map? This will

View File

@@ -261,6 +261,101 @@
}
function test_allOverlays_pan(t) {
t.plan(8);
var map = new OpenLayers.Map('map', {allOverlays: true});
var gmap = new OpenLayers.Layer.Google("Google Streets");
var osm = new OpenLayers.Layer.OSM();
map.addLayers([gmap, osm]);
var origin = new OpenLayers.LonLat(1000000, 6000000);
map.setCenter(origin, 4);
var resolution = map.getResolution();
var dx, dy, center, expectedX, expectedY;
// confirm that panning works with Google visible
dx = 100, dy = -100;
map.pan(dx, dy, {animate: false});
center = map.getCenter();
expectedX = origin.lon + (resolution * dx);
expectedY = origin.lat - (resolution * dy);
t.eq(center.lon, expectedX, "x panning with Google visible " + dx + ", " + dy);
t.eq(center.lat, expectedY, "y panning with Google visible " + dx + ", " + dy);
map.pan(-dx, -dy, {animate: false});
center = map.getCenter();
t.eq(center.lon, origin.lon, "x panning with Google visible " + (-dx) + ", " + (-dy));
t.eq(center.lat, origin.lat, "y panning with Google visible " + (-dx) + ", " + (-dy));
// confirm that panning works with Google invisible
gmap.setVisibility(false);
dx = 100, dy = -100;
map.pan(dx, dy, {animate: false});
center = map.getCenter();
expectedX = origin.lon + (resolution * dx);
expectedY = origin.lat - (resolution * dy);
t.eq(center.lon, expectedX, "x panning with Google invisible " + dx + ", " + dy);
t.eq(center.lat, expectedY, "y panning with Google invisible " + dx + ", " + dy);
map.pan(-dx, -dy, {animate: false});
center = map.getCenter();
t.eq(center.lon, origin.lon, "x panning with Google invisible " + (-dx) + ", " + (-dy));
t.eq(center.lat, origin.lat, "y panning with Google invisible " + (-dx) + ", " + (-dy));
map.destroy();
}
function test_wrapDateLine(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
var gmap = new OpenLayers.Layer.Google("Google Streets");
map.addLayer(gmap);
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
var center;
// pan to the edge of the world
map.pan(256, 0, {animate: false});
center = map.getCenter();
t.eq(center.lon, 20037508.3392, "edge of the world");
// pan off the edge of the world
map.pan(100, 0, {animate: false});
center = map.getCenter();
t.eq(center.lon, -12210356.6442, "magically back in the western hemisphere");
map.destroy();
}
function test_respectDateLine(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
var gmap = new OpenLayers.Layer.Google("Google Streets", {wrapDateLine: false});
map.addLayer(gmap);
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
var center;
// pan to the edge of the world
map.pan(256, 0, {animate: false});
center = map.getCenter();
t.eq(center.lon, 20037508.3392, "edge of the world");
// pan off the edge of the world
map.pan(100, 0, {animate: false});
center = map.getCenter();
t.eq(center.lon, 20037508.3392, "whew, still on the edge");
map.destroy();
}
</script>
</head>
<body>