Merge remote-tracking branch 'upstream/master' into utfgrid

This commit is contained in:
Matthew Perry
2012-02-04 17:03:25 -08:00
29 changed files with 281 additions and 232 deletions

View File

@@ -5,6 +5,10 @@ OpenLayers.Renderer.symbol.church = [4, 0, 6, 0, 6, 4, 10, 4, 10, 6, 6, 6, 6, 14
var map;
function init(){
// allow testing of specific renderers via "?renderer=Canvas", etc
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
map = new OpenLayers.Map('map', {
controls: []
});
@@ -46,7 +50,8 @@ function init(){
// Create a vector layer and give it your style map.
var layer = new OpenLayers.Layer.Vector("Graphics", {
styleMap: styles,
isBaseLayer: true
isBaseLayer: true,
renderers: renderer
});
layer.addFeatures(features);
map.addLayer(layer);

View File

@@ -14,30 +14,6 @@
function init(){
map = new OpenLayers.Map('map', {allOverlays: true});
// context for appropriate scale/resize cursors
var cursors = ["sw-resize", "s-resize", "se-resize",
"e-resize", "ne-resize", "n-resize", "nw-resize", "w-resize"];
var context = {
getCursor: function(feature){
var i = OpenLayers.Util.indexOf(control.handles, feature);
var cursor = "inherit";
if(i !== -1) {
i = (i + 8 + Math.round(control.rotation / 90) * 2) % 8;
cursor = cursors[i];
}
return cursor;
}
};
// a nice style for the transformation box
var style = new OpenLayers.Style({
cursor: "${getCursor}",
pointRadius: 5,
fillColor: "white",
fillOpacity: 1,
strokeColor: "black"
}, {context: context});
// allow testing of specific renderers via "?renderer=Canvas", etc
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
@@ -45,7 +21,36 @@
// the layer that we want to transform features on
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
styleMap: new OpenLayers.StyleMap({
"transform": style
// a nice style for the transformation box
"transform": new OpenLayers.Style({
display: "${getDisplay}",
cursor: "${role}",
pointRadius: 5,
fillColor: "white",
fillOpacity: 1,
strokeColor: "black"
}, {
context: {
getDisplay: function(feature) {
// hide the resize handle at the south-east corner
return feature.attributes.role === "se-resize" ? "none" : "";
}
}
}),
"rotate": new OpenLayers.Style({
display: "${getDisplay}",
pointRadius: 10,
fillColor: "#ddd",
fillOpacity: 1,
strokeColor: "black"
}, {
context: {
getDisplay: function(feature) {
// only display the rotate handle at the south-east corner
return feature.attributes.role === "se-rotate" ? "" : "none";
}
}
})
}),
renderers: renderer
});
@@ -53,7 +58,8 @@
// create the TransformFeature control, using the renderIntent
// from above
control = new OpenLayers.Control.TransformFeature(vectorLayer, {
renderIntent: "transform"
renderIntent: "transform",
rotationHandleSymbolizer: "rotate"
});
map.addControl(control);
@@ -101,13 +107,15 @@
<div id="docs">
<p>This example shows transformation of vector features with a
tranformation box. Grab one of the handles to resize the feature.
Holding the SHIFT key will preserve the aspect ratio. Position the
mouse right outside one of the corner handles to rotate the feature,
and hold the SHIFT key to only rotate in 45° increments.</p>
<p>In this example, the transformation box has been set on the left
Holding the SHIFT key will preserve the aspect ratio. Use the gray
handle to rotate the feature and hold the SHIFT key to only rotate
in 45° increments.
</p>
<p>In this example, the transformation box has been set on the left
feature, with a rotation preset of 45°. Clicking on the right feature
will set it for transformation, starting with an unrotated box.
Dragging a feature or the box edges will move it around.</p>
Dragging a feature or the box edges will move it around.
</p>
</div>
</body>

View File

@@ -359,7 +359,8 @@ OpenLayers.Bounds = OpenLayers.Class({
* APIMethod: containsLonLat
*
* Parameters:
* ll - {<OpenLayers.LonLat>}
* ll - {<OpenLayers.LonLat>|Object} OpenLayers.LonLat or an
* object with a 'lon' and 'lat' properties.
* options - {Object} Optional parameters
*
* Acceptable options:
@@ -382,13 +383,12 @@ OpenLayers.Bounds = OpenLayers.Class({
worldBounds = options.worldBounds;
if (worldBounds && !contains) {
var worldWidth = worldBounds.getWidth();
ll = ll.clone();
var worldCenterX = (worldBounds.left + worldBounds.right) / 2;
var worldsAway = Math.round((ll.lon - worldCenterX) / worldWidth);
ll.lon -= (worldsAway * worldWidth);
contains = this.containsLonLat(
ll, {inclusive: options.inclusive}
);
contains = this.containsLonLat({
lon: ll.lon - worldsAway * worldWidth,
lat: ll.lat
}, {inclusive: options.inclusive});
}
return contains;
},

View File

@@ -62,6 +62,7 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
* evt - {Event}
*/
defaultKeyPress: function (evt) {
var size;
switch(evt.keyCode) {
case OpenLayers.Event.KEY_LEFT:
this.map.pan(-this.slideFactor, 0);
@@ -77,19 +78,19 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
break;
case 33: // Page Up. Same in all browsers.
var size = this.map.getSize();
size = this.map.getSize();
this.map.pan(0, -0.75*size.h);
break;
case 34: // Page Down. Same in all browsers.
var size = this.map.getSize();
size = this.map.getSize();
this.map.pan(0, 0.75*size.h);
break;
case 35: // End. Same in all browsers.
var size = this.map.getSize();
size = this.map.getSize();
this.map.pan(0.75*size.w, 0);
break;
case 36: // Home. Same in all browsers.
var size = this.map.getSize();
size = this.map.getSize();
this.map.pan(-0.75*size.w, 0);
break;

View File

@@ -628,12 +628,14 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* translated into pixel bounds for the overview map
*/
getRectBoundsFromMapBounds: function(lonLatBounds) {
var leftBottomLonLat = new OpenLayers.LonLat(lonLatBounds.left,
lonLatBounds.bottom);
var rightTopLonLat = new OpenLayers.LonLat(lonLatBounds.right,
lonLatBounds.top);
var leftBottomPx = this.getOverviewPxFromLonLat(leftBottomLonLat);
var rightTopPx = this.getOverviewPxFromLonLat(rightTopLonLat);
var leftBottomPx = this.getOverviewPxFromLonLat({
lon: lonLatBounds.left,
lat: lonLatBounds.bottom
});
var rightTopPx = this.getOverviewPxFromLonLat({
lon: lonLatBounds.right,
lat: lonLatBounds.top
});
var bounds = null;
if (leftBottomPx && rightTopPx) {
bounds = new OpenLayers.Bounds(leftBottomPx.x, leftBottomPx.y,
@@ -699,7 +701,8 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* Get a pixel location from a map location
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
* lonlat - {<OpenLayers.LonLat>|Object} OpenLayers.LonLat or an
* object with a 'lon' and 'lat' properties.
*
* Returns:
* {Object} Location which is the passed-in OpenLayers.LonLat,

View File

@@ -232,9 +232,6 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
this.dragControl.deactivate();
deactivated = true;
}
if (deactivated) {
this.unsetFeature();
}
return deactivated;
},
@@ -335,7 +332,7 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
var control = this;
this.center = new OpenLayers.Geometry.Point(0, 0);
var box = new OpenLayers.Feature.Vector(
this.box = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(-1, -1),
new OpenLayers.Geometry.Point(0, -1),
@@ -351,7 +348,7 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
);
// Override for box move - make sure that the center gets updated
box.geometry.move = function(x, y) {
this.box.geometry.move = function(x, y) {
control._moving = true;
OpenLayers.Geometry.LineString.prototype.move.apply(this, arguments);
control.center.move(x, y);
@@ -468,14 +465,17 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
var handles = new Array(8);
var rotationHandles = new Array(4);
var geom, handle, rotationHandle;
var positions = ["sw", "s", "se", "e", "ne", "n", "nw", "w"];
for(var i=0; i<8; ++i) {
geom = box.geometry.components[i];
handle = new OpenLayers.Feature.Vector(geom.clone(), null,
typeof this.renderIntent == "string" ? null :
geom = this.box.geometry.components[i];
handle = new OpenLayers.Feature.Vector(geom.clone(), {
role: positions[i] + "-resize"
}, typeof this.renderIntent == "string" ? null :
this.renderIntent);
if(i % 2 == 0) {
rotationHandle = new OpenLayers.Feature.Vector(geom.clone(),
null, typeof this.rotationHandleSymbolizer == "string" ?
rotationHandle = new OpenLayers.Feature.Vector(geom.clone(), {
role: positions[i] + "-rotate"
}, typeof this.rotationHandleSymbolizer == "string" ?
null : this.rotationHandleSymbolizer);
rotationHandle.geometry.move = rotationHandleMoveFn;
geom._rotationHandle = rotationHandle;
@@ -489,7 +489,6 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
handles[i] = handle;
}
this.box = box;
this.rotationHandles = rotationHandles;
this.handles = handles;
},
@@ -514,7 +513,6 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
onDrag: function(feature, pixel) {
if(feature === control.box) {
control.transformFeature({center: control.center});
control.drawHandles();
}
},
// set a new feature
@@ -600,10 +598,16 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
geom._rotationHandle && geom._rotationHandle.destroy();
geom._rotationHandle = null;
}
this.center = null;
this.feature = null;
this.handles = null;
this.rotationHandleSymbolizer = null;
this.rotationHandles = null;
this.box.destroy();
this.box = null;
this.layer = null;
this.dragControl.destroy();
this.dragControl = null;
OpenLayers.Control.prototype.destroy.apply(this, arguments);
},

View File

@@ -25,7 +25,7 @@
OpenLayers.Events.buttonclick = OpenLayers.Class({
/**
* APIProperty: target
* Property: target
* {<OpenLayers.Events>} The events instance that the buttonclick event will
* be triggered on.
*/
@@ -141,4 +141,4 @@ OpenLayers.Events.buttonclick = OpenLayers.Class({
return propagate;
}
});
});

View File

@@ -267,7 +267,8 @@ OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
* Determins whether the feature intersects with the specified location.
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
* lonlat - {<OpenLayers.LonLat>|Object} OpenLayers.LonLat or an
* object with a 'lon' and 'lat' properties.
* toleranceLon - {float} Optional tolerance in Geometric Coords
* toleranceLat - {float} Optional tolerance in Geographic Coords
*

View File

@@ -255,7 +255,7 @@ OpenLayers.Format.CSWGetRecords.v2_0_2 = OpenLayers.Class(OpenLayers.Format.XML,
"*": function(node, obj) {
var name = node.localName || node.nodeName.split(":").pop();
if (!(OpenLayers.Util.isArray(obj[name]))) {
obj[name] = new Array();
obj[name] = [];
}
var dc_element = {};
var attrs = node.attributes;
@@ -273,7 +273,7 @@ OpenLayers.Format.CSWGetRecords.v2_0_2 = OpenLayers.Class(OpenLayers.Format.XML,
"*": function(node, obj) {
var name = node.localName || node.nodeName.split(":").pop();
if (!(OpenLayers.Util.isArray(obj[name]))) {
obj[name] = new Array();
obj[name] = [];
}
obj[name].push(this.getChildValue(node));
}

View File

@@ -228,7 +228,7 @@ OpenLayers.Format.XLS.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
}
});
if (address.freeFormAddress) {
this.writeNode("freeFormAddess", address.freeFormAddress, node);
this.writeNode("freeFormAddress", address.freeFormAddress, node);
} else {
if (address.street) {
this.writeNode("StreetAddress", address, node);

View File

@@ -176,7 +176,8 @@ OpenLayers.Geometry = OpenLayers.Class({
* geometry.
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
* lonlat - {<OpenLayers.LonLat>|Object} OpenLayers.LonLat or an
* object with a 'lon' and 'lat' properties.
* toleranceLon - {float} Optional tolerance in Geometric Coords
* toleranceLat - {float} Optional tolerance in Geographic Coords
*

View File

@@ -205,12 +205,10 @@ OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
* Parameters:
* bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the
* request.
* scope - {Object} The scope of the callback method.
* prop - {String} The name of the property in the scoped object to
* recieve the image url.
* callback - {Function} Function to call when image url is retrieved.
* scope - {Object} The scope of the callback method.
*/
getURLasync: function(bounds, scope, prop, callback) {
getURLasync: function(bounds, callback, scope) {
bounds = this.adjustBounds(bounds);
// create an arcxml request to generate the image
@@ -239,11 +237,7 @@ OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
var axlResp = new OpenLayers.Format.ArcXML();
var arcxml = axlResp.read(doc);
scope[prop] = this.getUrlOrImage(arcxml.image.output);
// call the callback function to recieve the updated property on the
// scoped object
callback.apply(scope);
callback.call(scope, this.getUrlOrImage(arcxml.image.output));
},
scope: this
});

View File

@@ -25,9 +25,6 @@ OpenLayers.Layer.Boxes = OpenLayers.Class(OpenLayers.Layer.Markers, {
* name - {String}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function (name, options) {
OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments);
},
/**
* Method: drawMarker

View File

@@ -77,7 +77,7 @@ OpenLayers.Layer.FixedZoomLevels = OpenLayers.Class({
*/
initResolutions: function() {
var props = new Array('minZoomLevel', 'maxZoomLevel', 'numZoomLevels');
var props = ['minZoomLevel', 'maxZoomLevel', 'numZoomLevels'];
for(var i=0, len=props.length; i<len; i++) {
var property = props[i];

View File

@@ -677,8 +677,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
* Generate parameters for the grid layout.
*
* Parameters:
* bounds - {<OpenLayers.Bound>}
* origin - {<OpenLayers.LonLat>}
* bounds - {<OpenLayers.Bound>|Object} OpenLayers.Bounds or an
* object with a 'left' and 'top' properties.
* origin - {<OpenLayers.LonLat>|Object} OpenLayers.LonLat or an
* object with a 'lon' and 'lat' properties.
* resolution - {Number}
*
* Returns:
@@ -686,8 +688,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
* tileoffsetlat, tileoffsetx, tileoffsety
*/
calculateGridLayout: function(bounds, origin, resolution) {
bounds = bounds.clone();
var tilelon = resolution * this.tileSize.w;
var tilelat = resolution * this.tileSize.h;

View File

@@ -39,9 +39,7 @@ OpenLayers.Layer.MapServer = OpenLayers.Class(OpenLayers.Layer.Grid, {
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, url, params, options) {
var newArguments = [];
newArguments.push(name, url, params, options);
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
OpenLayers.Layer.Grid.prototype.initialize.apply(this, arguments);
this.params = OpenLayers.Util.applyDefaults(
this.params, this.DEFAULT_PARAMS

View File

@@ -44,9 +44,6 @@ OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, {
* options - {Object} Optional object with properties to tag onto the
* instance.
*/
initialize: function(name, options) {
OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments);
},
/**
* APIMethod: addNodes

View File

@@ -80,7 +80,7 @@ OpenLayers.Layer.Text = OpenLayers.Class(OpenLayers.Layer.Markers, {
*/
initialize: function(name, options) {
OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments);
this.features = new Array();
this.features = [];
},
/**

View File

@@ -21,12 +21,6 @@
*/
OpenLayers.Layer.Zoomify = OpenLayers.Class(OpenLayers.Layer.Grid, {
/**
* Property: url
* {String} URL for root directory with TileGroupX subdirectories.
*/
url: null,
/**
* Property: size
* {<OpenLayers.Size>} The Zoomify image size in pixels.

View File

@@ -1161,6 +1161,11 @@ OpenLayers.Map = OpenLayers.Class({
if(!this.allOverlays || this.baseLayer.visibility) {
this.baseLayer.setVisibility(true);
// Layer may previously have been visible but not in range.
// In this case we need to redraw it to make it visible.
if (this.baseLayer.inRange === false) {
this.baseLayer.redraw();
}
}
// recenter the map

View File

@@ -38,6 +38,30 @@ OpenLayers.Tile = OpenLayers.Class({
*/
events: null,
/**
* APIProperty: eventListeners
* {Object} If set as an option at construction, the eventListeners
* object will be registered with <OpenLayers.Events.on>. Object
* structure must be a listeners object as shown in the example for
* the events.on method.
*
* This options can be set in the ``tileOptions`` option from
* <OpenLayers.Layer.Grid>. For example, to be notified of the
* ``loadend`` event of each tiles:
* (code)
* new OpenLayers.Layer.OSM('osm', 'http://tile.openstreetmap.org/${z}/${x}/${y}.png', {
* tileOptions: {
* eventListeners: {
* 'loadend': function(evt) {
* // do something on loadend
* }
* }
* }
* });
* (end)
*/
eventListeners: null,
/**
* Property: id
* {String} null
@@ -109,10 +133,13 @@ OpenLayers.Tile = OpenLayers.Class({
//give the tile a unique id based on its BBOX.
this.id = OpenLayers.Util.createUniqueID("Tile_");
this.events = new OpenLayers.Events(this);
OpenLayers.Util.extend(this, options);
this.events = new OpenLayers.Events(this);
if (this.eventListeners instanceof Object) {
this.events.on(this.eventListeners);
}
},
/**
@@ -139,7 +166,11 @@ OpenLayers.Tile = OpenLayers.Class({
this.size = null;
this.position = null;
if (this.eventListeners) {
this.events.un(this.eventListeners);
}
this.events.destroy();
this.eventListeners = null;
this.events = null;
},

View File

@@ -168,15 +168,14 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
this.layer.div.appendChild(this.getTile());
if (this.layer.async) {
// Asynchronous image requests call the asynchronous getURL method
// on the layer to fetch an image that covers 'this.bounds', in the scope of
// 'this', setting the 'url' property of the layer itself, and running
// the callback 'initImage' when the image request returns.
var myId = this.asyncRequestId = (this.asyncRequestId || 0) + 1;
this.layer.getURLasync(this.bounds, this, "url", function() {
if (myId == this.asyncRequestId) {
// on the layer to fetch an image that covers 'this.bounds'.
var id = this.asyncRequestId = (this.asyncRequestId || 0) + 1;
this.layer.getURLasync(this.bounds, function(url) {
if (id == this.asyncRequestId) {
this.url = url;
this.initImage();
}
});
}, this);
} else {
// synchronous image requests get the url immediately.
this.url = this.layer.getURL(this.bounds);

View File

@@ -86,6 +86,10 @@ If you were previously using the `OpenLayers.Layer.SphericalMercator.forwardMerc
`OpenLayers.Protocol.HTTP` no longer requires `OpenLayers.Format.QueryStringFilter`. It you need this, make sure it is included in your build config file.
## Changes in getURLasync
The internal `OpenLayers.Layer.getURLasync` function now take a bound, a callback and a scope. The function no longer needs update the passed property but simply to return to url.
## Deprecated Components
A number of properties, methods, and constructors have been marked as deprecated for multiple releases in the 2.x series. For the 2.12 release this deprecated functionality has been moved to a separate deprecated.js file. If you use any of the constructors or methods below, you will have to explicitly include the deprecated.js file in your build (or add it in a separate `<script>` tag after OpenLayers.js).

View File

@@ -47,132 +47,121 @@
* http://unixpapa.com/js/key.html
*/
function test_Control_KeyboardDefaults_KeyDownEvent (t) {
t.plan( 16 );
t.plan( 25 );
var evt = {which: 1}, pans = [], zoomIns = 0, zoomOuts = 0;
var evt = {which: 1};
map = new OpenLayers.Map('map');
// mock "pan", "zoomIn" and "zoomOut"
map.pan = function(dx, dy) {
pans.push({dx: dx, dy: dy});
};
map.zoomIn = function() {
zoomIns++;
};
map.zoomOut = function() {
zoomOuts++;
};
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(layer);
control = new OpenLayers.Control.KeyboardDefaults();
var control = new OpenLayers.Control.KeyboardDefaults({
slideFactor: 100
});
map.addControl(control);
var STARTING_ZOOM_LEVEL = 4;
var DELAY = 2;
var centerLL = new OpenLayers.LonLat(0,0);
map.setCenter(centerLL, STARTING_ZOOM_LEVEL);
map.setCenter(new OpenLayers.LonLat(0, 0), 4);
// Start new test.
evt.keyCode = OpenLayers.Event.KEY_LEFT;
control.defaultKeyPress(evt);
t.delay_call(
DELAY, function() {
t.ok( map.getCenter().lon < centerLL.lon, "key left works correctly" );
// Start new test.
evt.keyCode = OpenLayers.Event.KEY_RIGHT;
control.defaultKeyPress(evt);
},
DELAY, function() {
t.eq( map.getCenter().lon, centerLL.lon, "key right works correctly" );
// Start new test.
evt.keyCode = OpenLayers.Event.KEY_UP;
control.defaultKeyPress(evt);
},
DELAY, function() {
t.ok( map.getCenter().lat > centerLL.lat, "key up works correctly" );
// Start new test.
evt.keyCode = OpenLayers.Event.KEY_DOWN;
control.defaultKeyPress(evt);
},
DELAY, function() {
t.ok( map.getCenter().lat == centerLL.lat, "key down works correctly" );
// Start new test.
evt.keyCode = 33; //page up
control.defaultKeyPress(evt);
},
DELAY, function() {
t.ok( map.getCenter().lat > centerLL.lat, "key page up works correctly" );
// Start new test.
evt.keyCode = 34; //page down
control.defaultKeyPress(evt);
},
DELAY, function() {
t.ok( map.getCenter().lat == centerLL.lat, "key page down works correctly" );
// Start new test.
evt.keyCode = 35; //end
control.defaultKeyPress(evt);
},
DELAY, function() {
t.ok( map.getCenter().lon > centerLL.lon, "key end works correctly" );
// Start new test.
evt.keyCode = 36; //home
control.defaultKeyPress(evt);
},
DELAY, function() {
t.ok( map.getCenter().lon == centerLL.lon, "key home works correctly");
// Start new test.
evt.keyCode = 43; //+
control.defaultKeyPress(evt);
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 1, "key code 43 works correctly: +/= key (ASCII), keypad + (ASCII, Opera)" );
// Start new test.
evt.keyCode = 61;
control.defaultKeyPress(evt);
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 2, "key code 61 works correctly: +/= key (Mozilla, Opera, some ASCII)");
// Start new test.
evt.keyCode = 187;
control.defaultKeyPress(evt);
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 3, "key code 187 works correctly: +/= key (IE)");
// Start new test.
evt.keyCode = 107;
control.defaultKeyPress(evt);
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 4, "key code 107 works correctly: keypad + (IE, Mozilla)");
// Start new test.
// set zoomanimation flag manually,
// reason: loadend event in layers.js will not achieved in unittests
map.zoomanimationActive = false;
evt.keyCode = 45;
control.defaultKeyPress(evt);
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 3, "key code 45 works correctly: -/_ key (ASCII, Opera), keypad - (ASCII, Opera)");
// Start new test.
// set zoomanimation flag manually,
// reason: loadend event in layers.js will not achieved in unittests
map.zoomanimationActive = false;
evt.keyCode = 109;
control.defaultKeyPress(evt);
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 2, "key code 109 works correctly: -/_ key (Mozilla), keypad - (Mozilla, IE)");
// Start new test.
// set zoomanimation flag manually,
// reason: loadend event in layers.js will not achieved in unittests
map.zoomanimationActive = false;
evt.keyCode = 189;
control.defaultKeyPress(evt);
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 1, "key code 189 works correctly: -/_ key (IE)");
// Start new test.
// set zoomanimation flag manually,
// reason: loadend event in layers.js will not achieved in unittests
map.zoomanimationActive = false;
evt.keyCode = 95;
control.defaultKeyPress(evt);
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL, "key code 95 works correctly: -/_ key (some ASCII)");
}
);
t.eq(pans.length, 1, '[KEY_LEFT] pan called once');
t.eq(pans[0], {dx: -100, dy: 0},
'[KEY LEFT] pan called with expected args');
evt.keyCode = OpenLayers.Event.KEY_RIGHT;
control.defaultKeyPress(evt);
t.eq(pans.length, 2, '[KEY_RIGHT] pan called once');
t.eq(pans[1], {dx: 100, dy: 0},
'[KEY RIGHT] pan called with expected args');
evt.keyCode = OpenLayers.Event.KEY_UP;
control.defaultKeyPress(evt);
t.eq(pans.length, 3, '[KEY_UP] pan called once');
t.eq(pans[2], {dx: 0, dy: -100},
'[KEY UP] pan called with expected args');
evt.keyCode = OpenLayers.Event.KEY_DOWN;
control.defaultKeyPress(evt);
t.eq(pans.length, 4, '[KEY_DOWN] pan called once');
t.eq(pans[3], {dx: 0, dy: 100},
'[KEY DOWN] pan called with expected args');
evt.keyCode = 33;
control.defaultKeyPress(evt);
t.eq(pans.length, 5, '[33] pan called once');
t.eq(pans[4], {dx: 0, dy: -384},
'[33] pan called with expected args');
evt.keyCode = 34;
control.defaultKeyPress(evt);
t.eq(pans.length, 6, '[34] pan called once');
t.eq(pans[5], {dx: 0, dy: 384},
'[34] pan called with expected args');
evt.keyCode = 35;
control.defaultKeyPress(evt);
t.eq(pans.length, 7, '[35] pan called once');
t.eq(pans[6], {dx: 768, dy: 0},
'[35] pan called with expected args');
evt.keyCode = 36;
control.defaultKeyPress(evt);
t.eq(pans.length, 8, '[36] pan called once');
t.eq(pans[7], {dx: -768, dy: 0},
'[36] pan called with expected args');
evt.keyCode = 43;
control.defaultKeyPress(evt);
t.eq(zoomIns, 1, '[43] zoomIn called once');
evt.keyCode = 61;
control.defaultKeyPress(evt);
t.eq(zoomIns, 2, '[61] zoomIn called once');
evt.keyCode = 187;
control.defaultKeyPress(evt);
t.eq(zoomIns, 3, '[187] zoomIn called once');
evt.keyCode = 107;
control.defaultKeyPress(evt);
t.eq(zoomIns, 4, '[107] zoomIn called once');
evt.keyCode = 107;
control.defaultKeyPress(evt);
t.eq(zoomIns, 5, '[107] zoomIn called once');
evt.keyCode = 45;
control.defaultKeyPress(evt);
t.eq(zoomOuts, 1, '[45] zoomOut called once');
evt.keyCode = 109;
control.defaultKeyPress(evt);
t.eq(zoomOuts, 2, '[109] zoomOut called once');
evt.keyCode = 189;
control.defaultKeyPress(evt);
t.eq(zoomOuts, 3, '[189] zoomOut called once');
evt.keyCode = 95;
control.defaultKeyPress(evt);
t.eq(zoomOuts, 4, '[95] zoomOut called once');
map.destroy();
}

View File

@@ -70,7 +70,7 @@
}
function test_Handler_Drag_deactivate(t) {
function test_Handler_Keyboard_deactivate(t) {
t.plan(8);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();

View File

@@ -763,7 +763,7 @@
}
function test_Map_setBaseLayer(t) {
t.plan( 4 );
t.plan( 6 );
map = new OpenLayers.Map('map');
@@ -791,6 +791,20 @@
t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property");
map.destroy();
var l1 = new OpenLayers.Layer(),
l2 = new OpenLayers.Layer(null, {maxResolution: 1.4});
map = new OpenLayers.Map({
div: 'map',
allOverlays: true,
layers: [l1, l2],
zoom: 0,
center: [0, 0]
});
t.eq(l2.div.style.display, "none", "Layer invisible because not in range");
map.raiseLayer(l1, 1);
t.eq(l2.div.style.display, "block", "Layer visible after base layer change because in range now");
map.destroy();
}
function test_Map_removeLayer(t) {
@@ -1276,10 +1290,10 @@
t.eq(res, null, "getResolutionForZoom returns null for no base layer");
map.fractionalZoom = true;
var layer = new OpenLayers.Layer("test", {isBaseLayer: true});
map.addLayer(layer);
layer.getResolutionForZoom = function() {
t.ok(true, "getResolutionForZoom calls base layer getResolutionForZoom");
}
map.addLayer(layer);
var res = map.getResolutionForZoom();
layer.destroy();
map.destroy();
@@ -2006,7 +2020,6 @@
map.moveTo([16, 48], 0);
t.eq(map.getCenter().toShortString(), "0, 0", "no panning when moveTo is called with invalid zoom");
}
</script>
</head>
<body>

View File

@@ -80,7 +80,7 @@
strategy.update({force: true});
var from = map.getProjectionObject();
var to = layer.projection;
t.ok(strategy.bounds.equals(map.getExtent().transform(from, to)), "[force update different proj] bounds transformed");
t.eq(strategy.bounds.toString(), map.getExtent().transform(from, to).toString(), "[force update different proj] bounds transformed");
}

View File

@@ -22,7 +22,7 @@
function test_Tile_constructor (t) {
t.plan( 12 );
t.plan( 13 );
setUp();
@@ -33,7 +33,11 @@
var url = "bobob";
var size = new OpenLayers.Size(5,6);
tile = new OpenLayers.Tile(layer, position, bounds, url, size);
tile = new OpenLayers.Tile(layer, position, bounds, url, size, {
eventListeners: {
loadstart: OpenLayers.Function.False
}
});
t.ok(tile instanceof OpenLayers.Tile, "new OpenLayers.Tile returns Tile object");
t.ok(tile.layer === layer, "tile.layer set correctly");
@@ -48,7 +52,9 @@
t.ok(tile.id != null, "tile is given an id");
t.ok(OpenLayers.String.startsWith(tile.id, "Tile_"),
"tile's id starts correctly");
t.ok(tile.events != null, "tile's events intitialized");
t.ok(tile.events != null, "tile's events initialized");
t.ok(tile.events.listeners.loadstart.length == 1,
"tile's events initialized from eventListeners option");
tearDown();

View File

@@ -85,9 +85,8 @@
var layer = new OpenLayers.Layer.WMS(
"Name",
"http://labs.metacarta.com/TESTURL?",
{layers: 'basic'}, {async: true, getURLasync: function(bounds, scope, url, callback) {
scope.url = this.getURL(bounds);
callback.call(scope);
{layers: 'basic'}, {async: true, getURLasync: function(bounds, callback, scope) {
callback.call(scope, this.getURL(bounds));
}}
);
map.addLayer(layer);