patch for #487 -- dateline wrapping
git-svn-id: http://svn.openlayers.org/trunk/openlayers@3323 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
61
examples/wrapDateLine.html
Normal file
61
examples/wrapDateLine.html
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<style type="text/css">
|
||||||
|
#map {
|
||||||
|
width: 800px;
|
||||||
|
height: 475px;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
<!--
|
||||||
|
var map;
|
||||||
|
function init(){
|
||||||
|
map = new OpenLayers.Map( 'map', {maxResolution: 1.40625} );
|
||||||
|
var mapserv = new OpenLayers.Layer.MapServer( "OpenLayers Basic",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0",
|
||||||
|
{layers: 'basic'},
|
||||||
|
{wrapDateLine: true} );
|
||||||
|
|
||||||
|
var kamap = new OpenLayers.Layer.KaMap( "Blue Marble NG",
|
||||||
|
"http://www.openlayers.org/world/index.php",
|
||||||
|
{g: "satellite", map: "world"},
|
||||||
|
{wrapDateLine: true} );
|
||||||
|
|
||||||
|
var wms = new OpenLayers.Layer.WMS( "DM Solutions Demo",
|
||||||
|
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
|
||||||
|
{layers: "bathymetry,land_fn,park,drain_fn,drainage," +
|
||||||
|
"prov_bound,fedlimit,rail,road,popplace",
|
||||||
|
transparent: "true", format: "image/png"},
|
||||||
|
{wrapDateLine: true, reproject: false});
|
||||||
|
|
||||||
|
/* TMS is broken, too */
|
||||||
|
tms = new OpenLayers.Layer.TMS( "OpenStreetMap",
|
||||||
|
"http://labs.metacarta.com/wms-c/Basic.py/",
|
||||||
|
{layername: 'osm-map', type:'png', wrapDateLine: true} );
|
||||||
|
|
||||||
|
/* WW doesn't quite work yet */
|
||||||
|
ww = new OpenLayers.Layer.WorldWind( "LANDSAT",
|
||||||
|
"http://worldwind25.arc.nasa.gov/tile/tile.aspx", 2.25, 4,
|
||||||
|
{T:"105"},
|
||||||
|
{'maxResolution': .28125,
|
||||||
|
tileSize: new OpenLayers.Size(512, 512),
|
||||||
|
wrapDateLine: true});
|
||||||
|
|
||||||
|
map.addLayers([mapserv, kamap, wms]);
|
||||||
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
|
map.addControl(new OpenLayers.Control.MousePosition());
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
}
|
||||||
|
// -->
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="init()">
|
||||||
|
<div id="map"></div>
|
||||||
|
<div id="docs">
|
||||||
|
This is an example that shows wrapping the date line. Wrapping the
|
||||||
|
date line is an option on the layer.
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -299,6 +299,32 @@ OpenLayers.LonLat.prototype = {
|
|||||||
return equals;
|
return equals;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenLayers.Bounds} maxExtent
|
||||||
|
*
|
||||||
|
* @returns A copy of this lonlat, but wrapped around the "dateline" (as
|
||||||
|
* specified by the borders of maxExtent)
|
||||||
|
* @type OpenLayers.LonLat
|
||||||
|
*/
|
||||||
|
wrapDateLine: function(maxExtent) {
|
||||||
|
|
||||||
|
var newLonLat = this.clone();
|
||||||
|
|
||||||
|
if (maxExtent) {
|
||||||
|
//shift right?
|
||||||
|
while (newLonLat.lon < maxExtent.left) {
|
||||||
|
newLonLat.lon += maxExtent.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
//shift left?
|
||||||
|
while (newLonLat.lon > maxExtent.right) {
|
||||||
|
newLonLat.lon -= maxExtent.getWidth();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newLonLat;
|
||||||
|
},
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
CLASS_NAME: "OpenLayers.LonLat"
|
CLASS_NAME: "OpenLayers.LonLat"
|
||||||
};
|
};
|
||||||
@@ -666,6 +692,50 @@ OpenLayers.Bounds.prototype = {
|
|||||||
return quadrant;
|
return quadrant;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenLayers.Bounds} maxExtent
|
||||||
|
* @param {Object} options
|
||||||
|
* @option {float} leftTolerance Allow for a margin of error with the
|
||||||
|
* 'left' value of this bound.
|
||||||
|
* Default is 0
|
||||||
|
* @option {float} rightTolerance Allow for a margin of error with the
|
||||||
|
* 'right' value of this bound.
|
||||||
|
* Default is 0
|
||||||
|
*
|
||||||
|
* @returns A copy of this bounds, but wrapped around the "dateline" (as
|
||||||
|
* specified by the borders of maxExtent). Note that this
|
||||||
|
* function only returns a different bounds value if this bounds
|
||||||
|
* is *entirely* outside of the maxExtent. If this bounds
|
||||||
|
* straddles the dateline (is part in/part out of maxExtent),
|
||||||
|
* the returned bounds will be merely a copy of this one.
|
||||||
|
* @type OpenLayers.Bounds
|
||||||
|
*/
|
||||||
|
wrapDateLine: function(maxExtent, options) {
|
||||||
|
options = options || new Object();
|
||||||
|
|
||||||
|
var leftTolerance = options.leftTolerance || 0;
|
||||||
|
var rightTolerance = options.rightTolerance || 0;
|
||||||
|
|
||||||
|
var newBounds = this.clone();
|
||||||
|
|
||||||
|
if (maxExtent) {
|
||||||
|
|
||||||
|
//shift right?
|
||||||
|
while ( newBounds.left < maxExtent.left &&
|
||||||
|
(newBounds.right - rightTolerance) <= maxExtent.left ) {
|
||||||
|
newBounds = newBounds.add(maxExtent.getWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//shift left?
|
||||||
|
while ( (newBounds.left + leftTolerance) >= maxExtent.right &&
|
||||||
|
newBounds.right > maxExtent.right ) {
|
||||||
|
newBounds = newBounds.add(-maxExtent.getWidth(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newBounds;
|
||||||
|
},
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
CLASS_NAME: "OpenLayers.Bounds"
|
CLASS_NAME: "OpenLayers.Bounds"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -140,6 +140,12 @@ OpenLayers.Layer.prototype = {
|
|||||||
/** @type Boolean */
|
/** @type Boolean */
|
||||||
displayOutsideMaxExtent: false,
|
displayOutsideMaxExtent: false,
|
||||||
|
|
||||||
|
/** wrapDateLine -- #487 for more info.
|
||||||
|
*
|
||||||
|
* @type @Boolean
|
||||||
|
*/
|
||||||
|
wrapDateLine: false,
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -165,6 +171,10 @@ OpenLayers.Layer.prototype = {
|
|||||||
this.events = new OpenLayers.Events(this, this.div,
|
this.events = new OpenLayers.Events(this, this.div,
|
||||||
this.EVENT_TYPES);
|
this.EVENT_TYPES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.wrapDateLine) {
|
||||||
|
this.displayOutsideMaxExtent = true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -616,6 +626,10 @@ OpenLayers.Layer.prototype = {
|
|||||||
|
|
||||||
lonlat = new OpenLayers.LonLat(center.lon + delta_x * res ,
|
lonlat = new OpenLayers.LonLat(center.lon + delta_x * res ,
|
||||||
center.lat - delta_y * res);
|
center.lat - delta_y * res);
|
||||||
|
|
||||||
|
if (this.wrapDateLine) {
|
||||||
|
lonlat = lonlat.wrapDateLine(this.maxExtent);
|
||||||
|
}
|
||||||
} // else { DEBUG STATEMENT }
|
} // else { DEBUG STATEMENT }
|
||||||
}
|
}
|
||||||
return lonlat;
|
return lonlat;
|
||||||
@@ -641,23 +655,6 @@ OpenLayers.Layer.prototype = {
|
|||||||
return px;
|
return px;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Adjusts the extent of a bounds in map units by the layer's gutter
|
|
||||||
* in pixels.
|
|
||||||
*
|
|
||||||
* @param {OpenLayers.Bounds} bounds
|
|
||||||
* @type OpenLayers.Bounds
|
|
||||||
* @return A bounds adjusted in height and width by the gutter
|
|
||||||
*/
|
|
||||||
adjustBoundsByGutter: function(bounds) {
|
|
||||||
var mapGutter = this.gutter * this.map.getResolution();
|
|
||||||
bounds = new OpenLayers.Bounds(bounds.left - mapGutter,
|
|
||||||
bounds.bottom - mapGutter,
|
|
||||||
bounds.right + mapGutter,
|
|
||||||
bounds.top + mapGutter);
|
|
||||||
return bounds;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the opacity for the entire layer (all images)
|
* Sets the opacity for the entire layer (all images)
|
||||||
* @param {Float} opacity
|
* @param {Float} opacity
|
||||||
@@ -681,6 +678,38 @@ OpenLayers.Layer.prototype = {
|
|||||||
this.div.style.zIndex = zIdx;
|
this.div.style.zIndex = zIdx;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will take a bounds, and if wrapDateLine option is set
|
||||||
|
* on the layer, it will return a bounds which is wrapped around the world.
|
||||||
|
* We do not wrap for bounds which *cross* the maxExtent.left/right, only
|
||||||
|
* bounds which are entirely to the left or entirely to the right.
|
||||||
|
*
|
||||||
|
* @param {OpenLayers.Bounds} bounds
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
adjustBounds: function (bounds) {
|
||||||
|
|
||||||
|
if (this.gutter) {
|
||||||
|
// Adjust the extent of a bounds in map units by the
|
||||||
|
// layer's gutter in pixels.
|
||||||
|
var mapGutter = this.gutter * this.map.getResolution();
|
||||||
|
bounds = new OpenLayers.Bounds(bounds.left - mapGutter,
|
||||||
|
bounds.bottom - mapGutter,
|
||||||
|
bounds.right + mapGutter,
|
||||||
|
bounds.top + mapGutter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.wrapDateLine) {
|
||||||
|
// wrap around the date line, within the limits of rounding error
|
||||||
|
var wrappingOptions = {
|
||||||
|
'rightTolerance':this.getResolution()
|
||||||
|
};
|
||||||
|
bounds = bounds.wrapDateLine(this.maxExtent, wrappingOptions);
|
||||||
|
|
||||||
|
}
|
||||||
|
return bounds;
|
||||||
|
},
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
CLASS_NAME: "OpenLayers.Layer"
|
CLASS_NAME: "OpenLayers.Layer"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ OpenLayers.Layer.KaMap.prototype =
|
|||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
getURL: function (bounds) {
|
getURL: function (bounds) {
|
||||||
|
bounds = this.adjustBounds(bounds);
|
||||||
var mapRes = this.map.getResolution();
|
var mapRes = this.map.getResolution();
|
||||||
var scale = Math.round((this.map.getScale() * 10000)) / 10000;
|
var scale = Math.round((this.map.getScale() * 10000)) / 10000;
|
||||||
var pX = Math.round(bounds.left / mapRes);
|
var pX = Math.round(bounds.left / mapRes);
|
||||||
|
|||||||
@@ -87,9 +87,7 @@ OpenLayers.Layer.MapServer.prototype =
|
|||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
getURL: function (bounds) {
|
getURL: function (bounds) {
|
||||||
if(this.gutter) {
|
bounds = this.adjustBounds(bounds);
|
||||||
bounds = this.adjustBoundsByGutter(bounds);
|
|
||||||
}
|
|
||||||
// Make a list, so that getFullRequestString uses literal ","
|
// Make a list, so that getFullRequestString uses literal ","
|
||||||
var extent = [bounds.left, bounds. bottom, bounds.right, bounds.top];
|
var extent = [bounds.left, bounds. bottom, bounds.right, bounds.top];
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ OpenLayers.Layer.TMS.prototype =
|
|||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
getURL: function (bounds) {
|
getURL: function (bounds) {
|
||||||
|
bounds = this.adjustBounds(bounds);
|
||||||
var res = this.map.getResolution();
|
var res = this.map.getResolution();
|
||||||
var x = (bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w);
|
var x = (bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w);
|
||||||
var y = (bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h);
|
var y = (bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h);
|
||||||
|
|||||||
@@ -94,9 +94,7 @@ OpenLayers.Layer.WMS.prototype =
|
|||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
getURL: function (bounds) {
|
getURL: function (bounds) {
|
||||||
if(this.gutter) {
|
bounds = this.adjustBounds(bounds);
|
||||||
bounds = this.adjustBoundsByGutter(bounds);
|
|
||||||
}
|
|
||||||
return this.getFullRequestString(
|
return this.getFullRequestString(
|
||||||
{BBOX:bounds.toBBOX(),
|
{BBOX:bounds.toBBOX(),
|
||||||
WIDTH:this.imageSize.w,
|
WIDTH:this.imageSize.w,
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ OpenLayers.Layer.WorldWind.prototype =
|
|||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
getURL: function (bounds) {
|
getURL: function (bounds) {
|
||||||
|
bounds = this.adjustBounds(bounds);
|
||||||
var zoom = this.getZoom();
|
var zoom = this.getZoom();
|
||||||
var extent = this.map.getMaxExtent();
|
var extent = this.map.getMaxExtent();
|
||||||
var deg = this.lzd/Math.pow(2,this.getZoom());
|
var deg = this.lzd/Math.pow(2,this.getZoom());
|
||||||
|
|||||||
@@ -1168,8 +1168,30 @@ OpenLayers.Map.prototype = {
|
|||||||
* @param {OpenLayers.Bounds} bounds
|
* @param {OpenLayers.Bounds} bounds
|
||||||
*/
|
*/
|
||||||
zoomToExtent: function(bounds) {
|
zoomToExtent: function(bounds) {
|
||||||
this.setCenter(bounds.getCenterLonLat(),
|
var center = bounds.getCenterLonLat();
|
||||||
this.getZoomForExtent(bounds));
|
if (this.baseLayer.wrapDateLine) {
|
||||||
|
var maxExtent = this.getMaxExtent();
|
||||||
|
|
||||||
|
//fix straddling bounds (in the case of a bbox that straddles the
|
||||||
|
// dateline, it's left and right boundaries will appear backwards.
|
||||||
|
// we fix this by allowing a right value that is greater than the
|
||||||
|
// max value at the dateline -- this allows us to pass a valid
|
||||||
|
// bounds to calculate zoom)
|
||||||
|
//
|
||||||
|
bounds = bounds.clone();
|
||||||
|
while (bounds.right < bounds.left) {
|
||||||
|
bounds.right += maxExtent.getWidth();
|
||||||
|
}
|
||||||
|
//if the bounds was straddling (see above), then the center point
|
||||||
|
// we got from it was wrong. So we take our new bounds and ask it
|
||||||
|
// for the center. Because our new bounds is at least partially
|
||||||
|
// outside the bounds of maxExtent, the new calculated center
|
||||||
|
// might also be. We don't want to pass a bad center value to
|
||||||
|
// setCenter, so we have it wrap itself across the date line.
|
||||||
|
//
|
||||||
|
center = bounds.getCenterLonLat().wrapDateLine(maxExtent);
|
||||||
|
}
|
||||||
|
this.setCenter(center, this.getZoomForExtent(bounds));
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Zoom to the full extent and recenter.
|
/** Zoom to the full extent and recenter.
|
||||||
|
|||||||
@@ -380,6 +380,98 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function test_16_Bounds_wrapDateLine(t) {
|
||||||
|
t.plan( 13 );
|
||||||
|
|
||||||
|
var testBounds, wrappedBounds, desiredBounds;
|
||||||
|
|
||||||
|
var maxExtent = new OpenLayers.Bounds(-10,-10,10,10);
|
||||||
|
var exactBounds = maxExtent.clone();
|
||||||
|
var simpleBounds = new OpenLayers.Bounds( -5,-5,5,5);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//bad maxextent
|
||||||
|
testBounds = simpleBounds.clone();
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(null);
|
||||||
|
t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds with a bad maxextent does nothing");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//exactly inside
|
||||||
|
testBounds = exactBounds.clone();
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(exactBounds), "wrapping a bounds precisely within (equal to) maxextent does nothing");
|
||||||
|
|
||||||
|
|
||||||
|
//inside
|
||||||
|
testBounds = simpleBounds.clone();
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds within maxextent does nothing");
|
||||||
|
|
||||||
|
// LEFT //
|
||||||
|
|
||||||
|
//straddling left
|
||||||
|
testBounds = simpleBounds.add(-10,0);
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(testBounds), "wrapping a bounds that straddles the left of maxextent does nothing");
|
||||||
|
|
||||||
|
//left rightTolerance
|
||||||
|
testBounds = simpleBounds.add(-14,0);
|
||||||
|
wrappedBounds =
|
||||||
|
testBounds.wrapDateLine(maxExtent, {'rightTolerance': 1} );
|
||||||
|
desiredBounds = simpleBounds.add(6,0);
|
||||||
|
t.ok(wrappedBounds.equals(desiredBounds), "wrapping a bounds rightTolerance left of maxextent works");
|
||||||
|
|
||||||
|
//exactly left
|
||||||
|
testBounds = exactBounds.add(-20,0);
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(exactBounds), "wrapping an exact bounds once left of maxextent works");
|
||||||
|
|
||||||
|
//left
|
||||||
|
testBounds = simpleBounds.add(-20,0);
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds once left of maxextent works");
|
||||||
|
|
||||||
|
//way left
|
||||||
|
testBounds = simpleBounds.add(-200,0);
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds way left of maxextent works");
|
||||||
|
|
||||||
|
// RIGHT //
|
||||||
|
|
||||||
|
//straddling right
|
||||||
|
testBounds = simpleBounds.add(10,0);
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(testBounds), "wrapping a bounds that straddles the right of maxextent does nothing");
|
||||||
|
|
||||||
|
//right leftTolerance
|
||||||
|
testBounds = simpleBounds.add(14,0);
|
||||||
|
wrappedBounds =
|
||||||
|
testBounds.wrapDateLine(maxExtent, {'leftTolerance': 1} );
|
||||||
|
desiredBounds = simpleBounds.add(-6,0);
|
||||||
|
t.ok(wrappedBounds.equals(desiredBounds), "wrapping a bounds leftTolerance right of maxextent works");
|
||||||
|
|
||||||
|
//exactly right
|
||||||
|
testBounds = exactBounds.add(20,0);
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(exactBounds), "wrapping an exact bounds once right of maxextent works");
|
||||||
|
|
||||||
|
//right
|
||||||
|
testBounds = simpleBounds.add(20,0);
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds once right of maxextent works");
|
||||||
|
|
||||||
|
//way right
|
||||||
|
testBounds = simpleBounds.add(200,0);
|
||||||
|
wrappedBounds = testBounds.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds way right of maxextent works");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// -->
|
// -->
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -88,6 +88,50 @@
|
|||||||
t.ok( lonlat.equals(ll), "lonlat is set correctly");
|
t.ok( lonlat.equals(ll), "lonlat is set correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_08_LonLat_wrapDateLine(t) {
|
||||||
|
t.plan( 6 );
|
||||||
|
|
||||||
|
var goodLL = new OpenLayers.LonLat(0,0);
|
||||||
|
var testLL, wrappedLL;
|
||||||
|
|
||||||
|
//bad maxextent
|
||||||
|
var maxExtent = null;
|
||||||
|
|
||||||
|
testLL = goodLL.clone();
|
||||||
|
wrappedLL = testLL.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedLL.equals(goodLL), "wrapping a ll with a bad maxextent does nothing");
|
||||||
|
|
||||||
|
|
||||||
|
//good maxextent
|
||||||
|
maxExtent = new OpenLayers.Bounds(-10,-10,10,10);
|
||||||
|
|
||||||
|
//inside
|
||||||
|
testLL = goodLL.clone();
|
||||||
|
wrappedLL = testLL.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedLL.equals(goodLL), "wrapping a ll within the maxextent does nothing");
|
||||||
|
|
||||||
|
//left
|
||||||
|
testLL = goodLL.add(-20,0);
|
||||||
|
wrappedLL = testLL.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedLL.equals(goodLL), "wrapping a ll once left of maxextent works");
|
||||||
|
|
||||||
|
//way left
|
||||||
|
testLL = goodLL.add(-200,0);
|
||||||
|
wrappedLL = testLL.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedLL.equals(goodLL), "wrapping a ll way left of maxextent works");
|
||||||
|
|
||||||
|
//right
|
||||||
|
testLL = goodLL.add(20,0);
|
||||||
|
wrappedLL = testLL.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedLL.equals(goodLL), "wrapping a ll once right of maxextent works");
|
||||||
|
|
||||||
|
//way right
|
||||||
|
testLL = goodLL.add(200,0);
|
||||||
|
wrappedLL = testLL.wrapDateLine(maxExtent);
|
||||||
|
t.ok(wrappedLL.equals(goodLL), "wrapping a ll way right of maxextent works");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// -->
|
// -->
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
176
tests/Layer/test_WrapDateLine.html
Normal file
176
tests/Layer/test_WrapDateLine.html
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript"><!--
|
||||||
|
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
||||||
|
var layer;
|
||||||
|
|
||||||
|
var name = 'Test Layer';
|
||||||
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
||||||
|
var params = { map: '/mapdata/vmap_wms.map',
|
||||||
|
layers: 'basic',
|
||||||
|
format: 'image/png'};
|
||||||
|
|
||||||
|
|
||||||
|
function test_Layer_WrapDateLine_adjustBounds(t) {
|
||||||
|
t.plan(10);
|
||||||
|
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
|
||||||
|
map.addLayer(layer);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
var bounds = layer.adjustBounds(new OpenLayers.Bounds(-270,-90,-180,0));
|
||||||
|
t.ok( bounds.equals(new OpenLayers.Bounds(90,-90,180,0)), "-270,-90,-180,0 wraps to 90,-90,180,0");
|
||||||
|
bounds = layer.adjustBounds(new OpenLayers.Bounds(180,-90,270,0));
|
||||||
|
t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,-90,0)), "180,-90,270,0 wraps to -180,-90,-90,0");
|
||||||
|
bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-90,0,0));
|
||||||
|
t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,0,0)), "-180,-90,0,0 doesn't wrap");
|
||||||
|
bounds = layer.adjustBounds(new OpenLayers.Bounds(-181,-90,-179,0));
|
||||||
|
t.ok( bounds.equals(new OpenLayers.Bounds(-181,-90,-179,0)), "-181,-90,-179,0 doesn't wrap, because it straddles the dateline");
|
||||||
|
bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-180,-90,-90));
|
||||||
|
t.ok( bounds.equals(new OpenLayers.Bounds(-180,-180,-90,-90)), "-180,-180,-90,-90 doesn't wrap, because we don't wrap lats.");
|
||||||
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
||||||
|
map.addLayer(layer);
|
||||||
|
var testBounds = null;
|
||||||
|
var outBounds = null;
|
||||||
|
var testList = [
|
||||||
|
new OpenLayers.Bounds(-270,-90,-180,0),
|
||||||
|
new OpenLayers.Bounds(180,-90,270,0),
|
||||||
|
new OpenLayers.Bounds(-180,-90,0,0),
|
||||||
|
new OpenLayers.Bounds(-181,-90,-179,0),
|
||||||
|
new OpenLayers.Bounds(-180,-180,-90,-90)
|
||||||
|
];
|
||||||
|
for (var i = 0; i < testList.length; i++) {
|
||||||
|
outBounds = layer.adjustBounds(testList[i]);
|
||||||
|
t.ok( outBounds.equals(testList[i]), testList[i]+" doesn't wrap in non-wrapping layer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function test_Layer_WrapDateLine_getLonLat(t) {
|
||||||
|
t.plan(12);
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
|
||||||
|
map.addLayer(layer);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
var testLonLats = [
|
||||||
|
new OpenLayers.LonLat(-185,5),
|
||||||
|
new OpenLayers.LonLat(-180,-95),
|
||||||
|
new OpenLayers.LonLat(-180,95),
|
||||||
|
new OpenLayers.LonLat(180,-95),
|
||||||
|
new OpenLayers.LonLat(180,95),
|
||||||
|
new OpenLayers.LonLat(185,5)
|
||||||
|
];
|
||||||
|
var outLonLats = [
|
||||||
|
new OpenLayers.LonLat(175,5),
|
||||||
|
new OpenLayers.LonLat(-180,-95),
|
||||||
|
new OpenLayers.LonLat(-180,95),
|
||||||
|
new OpenLayers.LonLat(180,-95),
|
||||||
|
new OpenLayers.LonLat(180,95),
|
||||||
|
new OpenLayers.LonLat(-175,5)
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var i = 0; i < testLonLats.length; i++) {
|
||||||
|
var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]);
|
||||||
|
var lonlat = layer.getLonLatFromViewPortPx(pixel);
|
||||||
|
lonlat.lon = Math.round(lonlat.lon);
|
||||||
|
lonlat.lat = Math.round(lonlat.lat);
|
||||||
|
t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
||||||
|
map.addLayer(layer);
|
||||||
|
var outLonLats = [
|
||||||
|
new OpenLayers.LonLat(-185,5),
|
||||||
|
new OpenLayers.LonLat(-180,-95),
|
||||||
|
new OpenLayers.LonLat(-180,95),
|
||||||
|
new OpenLayers.LonLat(180,-95),
|
||||||
|
new OpenLayers.LonLat(180,95),
|
||||||
|
new OpenLayers.LonLat(185,5)
|
||||||
|
];
|
||||||
|
for (var i = 0; i < testLonLats.length; i++) {
|
||||||
|
var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]);
|
||||||
|
var lonlat = layer.getLonLatFromViewPortPx(pixel);
|
||||||
|
lonlat.lon = Math.round(lonlat.lon);
|
||||||
|
lonlat.lat = Math.round(lonlat.lat);
|
||||||
|
t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function test_Layer_WrapDateLine_ZoomToExtent (t) {
|
||||||
|
t.plan( 4 );
|
||||||
|
|
||||||
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
||||||
|
layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
|
||||||
|
var m = new OpenLayers.Map('map');
|
||||||
|
m.addLayer(layer);
|
||||||
|
m.setCenter = function(myCenter) { this.center = myCenter; }
|
||||||
|
var testBounds = [
|
||||||
|
new OpenLayers.Bounds(-185,-90,-175,-85),
|
||||||
|
new OpenLayers.Bounds(0,-90,-170,-85),
|
||||||
|
new OpenLayers.Bounds(-270,-90,-180,-85),
|
||||||
|
new OpenLayers.Bounds(0,0,45,45)
|
||||||
|
];
|
||||||
|
var outCenters = [
|
||||||
|
new OpenLayers.LonLat(-180,-87.5),
|
||||||
|
new OpenLayers.LonLat(95,-87.5),
|
||||||
|
new OpenLayers.LonLat(135,-87.5),
|
||||||
|
new OpenLayers.LonLat(22.5,22.5)
|
||||||
|
];
|
||||||
|
for (var i = 0; i < testBounds.length; i++) {
|
||||||
|
m.zoomToExtent(testBounds[i]);
|
||||||
|
t.ok(m.center.equals(outCenters[i]), "Map center from bounds " + testBounds[i] + " should be " + outCenters[i] + ", got " + m.center);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
function test_Layer_WrapDateLine_WMS (t) {
|
||||||
|
t.plan( 3 );
|
||||||
|
|
||||||
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
||||||
|
layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
|
||||||
|
var m = new OpenLayers.Map('map');
|
||||||
|
m.addLayer(layer);
|
||||||
|
m.zoomToMaxExtent();
|
||||||
|
t.eq(layer.grid[3][0].url, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=%2Fmapdata%2Fvmap_wms.map&LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "cell [3][0] is wrapped around the world.");
|
||||||
|
t.eq(layer.grid[0][0].url, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=%2Fmapdata%2Fvmap_wms.map&LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C450%2C180%2C630&WIDTH=256&HEIGHT=256", "cell [0][0] is wrapped around the world lon, but not lat");
|
||||||
|
t.eq(layer.grid[0][3].url, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=%2Fmapdata%2Fvmap_wms.map&LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-180%2C450%2C0%2C630&WIDTH=256&HEIGHT=256", "cell [3][0] is not wrapped at all.");
|
||||||
|
|
||||||
|
}
|
||||||
|
function test_Layer_WrapDateLine_KaMap (t) {
|
||||||
|
t.plan( 3 );
|
||||||
|
|
||||||
|
var layer = new OpenLayers.Layer.KaMap( "Blue Marble NG",
|
||||||
|
"http://www.openlayers.org/world/index.php",
|
||||||
|
{g: "satellite", map: "world"},
|
||||||
|
{wrapDateLine: true} );
|
||||||
|
var m = new OpenLayers.Map('map');
|
||||||
|
m.addLayer(layer);
|
||||||
|
m.zoomToMaxExtent();
|
||||||
|
t.eq(layer.grid[0][0].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-768&l=0&s=221471921.25", "grid[0][0] kamap is okay");
|
||||||
|
t.eq(layer.grid[0][3].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-768&l=-256&s=221471921.25", "grid[0][3] kamap is okay");
|
||||||
|
t.eq(layer.grid[3][0].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=0&s=221471921.25", "grid[3][0] is okay");
|
||||||
|
}
|
||||||
|
function test_Layer_WrapDateLine_WMS_Overlay (t) {
|
||||||
|
t.plan( 3 );
|
||||||
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
||||||
|
baselayer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
|
||||||
|
var layer = new OpenLayers.Layer.WMS( "DM Solutions Demo",
|
||||||
|
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
|
||||||
|
{layers: "bathymetry,land_fn,park,drain_fn,drainage," +
|
||||||
|
"prov_bound,fedlimit,rail,road,popplace",
|
||||||
|
transparent: "true", format: "image/png"},
|
||||||
|
{wrapDateLine: true, reproject: false});
|
||||||
|
var m = new OpenLayers.Map('map');
|
||||||
|
m.addLayers([baselayer,layer]);
|
||||||
|
m.zoomToMaxExtent();
|
||||||
|
t.eq(layer.grid[0][0].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C450%2C180%2C630&WIDTH=256&HEIGHT=256", "grid[0][0] wms overlay is okay");
|
||||||
|
t.eq(layer.grid[0][3].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-180%2C450%2C0%2C630&WIDTH=256&HEIGHT=256", "grid[0][3] wms overlay is okay");
|
||||||
|
t.eq(layer.grid[3][0].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "grid[3][0] wms overlay okay");
|
||||||
|
}
|
||||||
|
// -->
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="map" style="width:1000px;height:550px"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
<li>Layer/test_TMS.html</li>
|
<li>Layer/test_TMS.html</li>
|
||||||
<li>Layer/test_Vector.html</li>
|
<li>Layer/test_Vector.html</li>
|
||||||
<li>Layer/test_GML.html</li>
|
<li>Layer/test_GML.html</li>
|
||||||
|
<li>Layer/test_WrapDateLine.html</li>
|
||||||
<li>test_Tile.html</li>
|
<li>test_Tile.html</li>
|
||||||
<li>Tile/test_Image.html</li>
|
<li>Tile/test_Image.html</li>
|
||||||
<li>test_Control.html</li>
|
<li>test_Control.html</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user