Merge branch 'master' into multiple-builds

This commit is contained in:
Matt Priour
2012-03-11 20:49:47 -05:00
92 changed files with 2362 additions and 109 deletions

View File

@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers Grayscale OSM Example</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, layer;
function init() {
if (!OpenLayers.CANVAS_SUPPORTED) {
var unsupported = OpenLayers.Util.getElement('unsupported');
unsupported.innerHTML = 'Your browser does not support canvas, nothing to see here !';
}
layer = new OpenLayers.Layer.OSM('Simple OSM Map', null, {
eventListeners: {
tileloaded: function(evt) {
var ctx = evt.tile.getCanvasContext();
if (ctx) {
var imgd = ctx.getImageData(0, 0, evt.tile.size.w, evt.tile.size.h);
var pix = imgd.data;
for (var i = 0, n = pix.length; i < n; i += 4) {
pix[i] = pix[i + 1] = pix[i + 2] = (3 * pix[i] + 4 * pix[i + 1] + pix[i + 2]) / 8;
}
ctx.putImageData(imgd, 0, 0);
evt.tile.imgDiv.removeAttribute("crossorigin");
evt.tile.imgDiv.src = ctx.canvas.toDataURL();
}
}
}
});
// If you get a security error because the tile are not
// from the same domain as this page, a simple Apache
// proxy can be created to workaround this issue:
//
// <Proxy *>
// Order deny,allow
// Allow from localhost
// </Proxy>
// ProxyPass /osm http://tile.openstreetmap.org/
//
// Then, in the layer definition above, replace null with '/osm/${z}/${x}/${y}.png'
map = new OpenLayers.Map('map', {
layers: [layer],
zoom: 3,
center: [-1081125, 6212801]
});
}
</script>
</head>
<body onload="init()">
<h1 id="title">Grayscale OSM Example</h1>
<div id="tags">
openstreetmap canvas grayscale
</div>
<div id="shortdesc">Show an OSM Map in grayscale</div>
<div id="map" class="smallmap"></div>
<div id="docs">
<p>This example shows an OSM layer where the tiles were
converted to grayscale
with <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html">canvas</a>.</p>
<p style="color:red;" id="unsupported"></p>
</div>
</body>
</html>

View File

@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers UTFGrid Geography Class</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
<style>
#flag {
position: relative;
z-index: 999;
height: 0px;
width: 0px;
-moz-transition: all 0.1s linear;
-webkit-transition: all 0.1s linear;
}
#flag img {
position: absolute;
width: 80px;
-moz-box-shadow: 2px 2px 1px 1px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 2px 2px 1px 1px rgba(0, 0, 0, 0.3);
box-shadow: 2px 2px 1px 1px rgba(0, 0, 0, 0.3);
}
.olControlAttribution {
bottom: 5px;
font-size: 9px;
}
</style>
</head>
<body>
<h1 id="title">OpenLayers UTFGrid Geography Class Example</h1>
<div id="shortdesc">
This page demonstrates the use of the OpenLayers UTFGrid Controls.
</div>
<div id="map" class="smallmap">
<div id="flag"></div>
</div>
<p>Point to a country and try to guess the name before it shows up: <strong id="output">&nbsp;</strong>
<div id="docs">
<p>
See the <a href="utfgrid-geography-class.js" target="_blank">utfgrid-geography-class.js</a> source for
detail on using UTFGrids in OpenLayers.
</p>
</div>
<script src="../lib/OpenLayers.js"></script>
<script src="utfgrid-geography-class.js"></script>
</body>
</html>

View File

@@ -0,0 +1,62 @@
var osm = new OpenLayers.Layer.XYZ(
"MapQuest OSM",
[
"http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
"http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
"http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png",
"http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png"
],
{transitionEffect: "resize", wrapDateLine: true}
);
var utfgrid = new OpenLayers.Layer.UTFGrid({
url: "utfgrid/geography-class/${z}/${x}/${y}.grid.json",
utfgridResolution: 4, // default is 2
displayInLayerSwitcher: false
});
var map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
numZoomLevels: 3,
layers: [osm, utfgrid],
controls: [
new OpenLayers.Control.Navigation({
dragPanOptions: {
enableKinetic: true
}
}),
new OpenLayers.Control.Zoom()
],
center: [0, 0],
zoom: 1
});
var output = document.getElementById("output");
var flag = document.getElementById("flag");
var callback = function(infoLookup, loc, pixel) {
var msg = "";
if (infoLookup) {
var info;
for (var idx in infoLookup) {
// idx can be used to retrieve layer from map.layers[idx]
info = infoLookup[idx];
if (info && info.data) {
output.innerHTML = info.data.admin;
flag.innerHTML = "<img src='data:image/png;base64," + info.data.flag_png + "'>";
flag.style.left = (pixel.x + 15) + "px";
flag.style.top = (pixel.y + 15) + "px";
} else {
output.innerHTML = flag.innerHTML = "&nbsp;";
}
}
}
};
var control = new OpenLayers.Control.UTFGrid({
callback: callback,
handlerMode: "move"
});
map.addControl(control);

64
examples/utfgrid.html Normal file
View File

@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers UTFGrid Demo</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
<style>
#attrs {
height: 1.5em;
}
#controlToggle li { list-style: none; }
</style>
</head>
<body>
<h1 id="title">OpenLayers UTFGrid Demo</h1>
<div>
<div id="shortdesc">
This page demonstrates the use of the OpenLayers UTFGrid Controls.
</div>
<div id="map" class="smallmap"></div>
<p>
When the selected event is triggered, the underlying feature
attributes are shown below.
</p>
<div id="attrs">&nbsp;</div>
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="move" id="moveHandler"
onclick="toggleControl(this);" checked="checked" />
<label for="moveHandler">Move</label>
</li>
<li>
<input type="radio" name="type" value="hover" id="hoverHandler"
onclick="toggleControl(this);" />
<label for="hoverHandler">Hover</label>
</li>
<li>
<input type="radio" name="type" value="click" id="clickHandler"
onclick="toggleControl(this);" />
<label for="clickHandler">Click</label>
</li>
</ul>
</div>
<div id="docs">
<p>UTFGrids can be used to output highly optimized feature "hit grids."
The UTFGrid encoding scheme encodes interactivity data for a tile in a
space efficient manner. It is designed to be used in browsers for
interactive features like displaying tooltips without having to hit the
server for an "info query."
</p>
<p>
See the <a href="utfgrid.js" target="_blank">utfgrid.js source</a> for
detail on using UTFGrids in OpenLayers. For more info, view the
<a href="https://github.com/mapbox/utfgrid-spec">UTFGrid Specification</a>.
</p>
</div>
<script src="../lib/OpenLayers.js"></script>
<script src="utfgrid.js"></script>
</body>
</html>

61
examples/utfgrid.js Normal file
View File

@@ -0,0 +1,61 @@
var osm = new OpenLayers.Layer.OSM();
var utfgrid = new OpenLayers.Layer.UTFGrid({
url: "utfgrid/world_utfgrid/${z}/${x}/${y}.json",
utfgridResolution: 4, // default is 2
displayInLayerSwitcher: false
});
var map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
controls: [],
layers: [osm, utfgrid],
center: [0, 0],
zoom: 1
});
var callback = function(infoLookup) {
var msg = "";
if (infoLookup) {
var info;
for (var idx in infoLookup) {
// idx can be used to retrieve layer from map.layers[idx]
info = infoLookup[idx];
if (info && info.data) {
msg += "[" + info.id + "] <strong>In 2005, " +
info.data.NAME + " had a population of " +
info.data.POP2005 + " people.</strong> ";
}
}
}
document.getElementById("attrs").innerHTML = msg;
};
var controls = {
move: new OpenLayers.Control.UTFGrid({
callback: callback,
handlerMode: "move"
}),
hover: new OpenLayers.Control.UTFGrid({
callback: callback,
handlerMode: "hover"
}),
click: new OpenLayers.Control.UTFGrid({
callback: callback,
handlerMode: "click"
})
};
for (var key in controls) {
map.addControl(controls[key]);
}
function toggleControl(el) {
for (var c in controls) {
controls[c].deactivate();
}
controls[el.value].activate();
}
// activate the control that responds to mousemove
toggleControl({value: "move"});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers Multiple UTFGrid Demo</title>
<link rel="stylesheet" href="style.css" type="text/css">
<style>
#controlToggle li { list-style: none; }
</style>
</head>
<body>
<h1 id="title">OpenLayers Multiple UTFGrid Demo</h1>
<div id="shortdesc">
This page demonstrates the use of the OpenLayers UTFGrid Controls with
more than one UTFGrid Layer.
</div>
<div id="map" class="smallmap"></div>
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="move_pop" id="moveHandler"
onclick="toggleControl(this);" checked="checked" />
<label for="moveHandler">View population stats</label>
</li>
<li>
<input type="radio" name="type" value="move_bio" id="hoverHandler"
onclick="toggleControl(this);" />
<label for="hoverHandler">View bioregion stats</label>
</li>
<li>
<input type="radio" name="type" value="move_both" id="clickHandler"
onclick="toggleControl(this);" />
<label for="clickHandler">View all stats</label>
</li>
</ul>
<div id="docs">
<p>
This example demonstrates the use of two separate UTFGrid layers.
See the <a href="utfgrid_twogrids.js">utfgrid_twogrids.js source</a>
for detail on how this is done.
</p>
</div>
<div id="attrsdiv"></div>
<script src="../lib/OpenLayers.js"></script>
<script src="utfgrid_twogrids.js"></script>
<script>
</script>
</body>
</html>

View File

@@ -0,0 +1,70 @@
var osm = new OpenLayers.Layer.OSM();
var population = new OpenLayers.Layer.UTFGrid({
name: "World Population",
url: "utfgrid/world_utfgrid/${z}/${x}/${y}.json",
utfgridResolution: 4 // default is 2
});
var bioregions = new OpenLayers.Layer.UTFGrid({
name: "World Bioregions",
url: "utfgrid/bio_utfgrid/${z}/${x}/${y}.json",
utfgridResolution: 4 // default is 2
});
var map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
controls: [],
layers: [osm, population, bioregions],
center: [0, 0],
zoom: 1
});
var callback = function(infoLookup) {
var msg = "";
if (infoLookup) {
var layer, info;
for (var idx in infoLookup) {
layer = map.layers[idx];
info = infoLookup[idx];
if (info && info.data) {
msg += "<strong>" + layer.name + "</strong><br>";
msg += "feature id: " + info.id + "<br>";
for (var key in info.data) {
msg += key + ": " + info.data[key] + "<br>";
}
}
}
}
document.getElementById("attrsdiv").innerHTML = msg;
};
var controls = {
move_pop: new OpenLayers.Control.UTFGrid({
callback: callback,
layers: [population],
handlerMode: "move"
}),
move_bio: new OpenLayers.Control.UTFGrid({
callback: callback,
layers: [bioregions],
handlerMode: "move"
}),
move_both: new OpenLayers.Control.UTFGrid({
callback: callback,
layers: null, // same as all map.layers
handlerMode: "move"
})
};
for (var key in controls) {
map.addControl(controls[key]);
}
function toggleControl(el) {
for (var c in controls) {
controls[c].deactivate();
}
controls[el.value].activate();
}
toggleControl({value: "move_pop"});

View File

@@ -79,7 +79,42 @@
}
}
return (function() { return l; });
})()
})(),
/**
* APIProperty: ImgPath
* {String} Set this to the path where control images are stored, a path
* given here must end with a slash. If set to '' (which is the default)
* OpenLayers will use its script location + "img/".
*
* You will need to set this property when you have a singlefile build of
* OpenLayers that either is not named "OpenLayers.js" or if you move
* the file in a way such that the image directory cannot be derived from
* the script location.
*
* If your custom OpenLayers build is named "my-custom-ol.js" and the images
* of OpenLayers are in a folder "/resources/external/images/ol" a correct
* way of including OpenLayers in your HTML would be:
*
* (code)
* <script src="/path/to/my-custom-ol.js" type="text/javascript"></script>
* <script type="text/javascript">
* // tell OpenLayers where the control images are
* // remember the trailing slash
* OpenLayers.ImgPath = "/resources/external/images/ol/";
* </script>
* (end code)
*
* Please remember that when your OpenLayers script is not named
* "OpenLayers.js" you will have to make sure that the default theme is
* loaded into the page by including an appropriate <link>-tag,
* e.g.:
*
* (code)
* <link rel="stylesheet" href="/path/to/default/style.css" type="text/css">
* (end code)
*/
ImgPath : ''
};
/**
@@ -124,6 +159,7 @@
"OpenLayers/Tile.js",
"OpenLayers/Tile/Image.js",
"OpenLayers/Tile/Image/IFrame.js",
"OpenLayers/Tile/UTFGrid.js",
"OpenLayers/Layer/Image.js",
"OpenLayers/Layer/SphericalMercator.js",
"OpenLayers/Layer/EventPane.js",
@@ -146,6 +182,7 @@
"OpenLayers/Layer/GeoRSS.js",
"OpenLayers/Layer/Boxes.js",
"OpenLayers/Layer/XYZ.js",
"OpenLayers/Layer/UTFGrid.js",
"OpenLayers/Layer/OSM.js",
"OpenLayers/Layer/Bing.js",
"OpenLayers/Layer/TMS.js",
@@ -203,6 +240,7 @@
"OpenLayers/Control/WMTSGetFeatureInfo.js",
"OpenLayers/Control/Graticule.js",
"OpenLayers/Control/TransformFeature.js",
"OpenLayers/Control/UTFGrid.js",
"OpenLayers/Control/SLDSelect.js",
"OpenLayers/Control/Zoom.js",
"OpenLayers/Geometry.js",

View File

@@ -56,15 +56,19 @@ OpenLayers.Bounds = OpenLayers.Class({
/**
* Constructor: OpenLayers.Bounds
* Construct a new bounds object.
* Construct a new bounds object. Coordinates can either be passed as four
* arguments, or as a single argument.
*
* Parameters:
* Parameters (four arguments):
* left - {Number} The left bounds of the box. Note that for width
* calculations, this is assumed to be less than the right value.
* bottom - {Number} The bottom bounds of the box. Note that for height
* calculations, this is assumed to be more than the top value.
* right - {Number} The right bounds.
* top - {Number} The top bounds.
*
* Parameters (single argument):
* bounds - {Array(Number)} [left, bottom, right, top]
*/
initialize: function(left, bottom, right, top) {
if (OpenLayers.Util.isArray(left)) {

View File

@@ -27,15 +27,19 @@ OpenLayers.LonLat = OpenLayers.Class({
/**
* Constructor: OpenLayers.LonLat
* Create a new map location.
* Create a new map location. Coordinates can be passed either as two
* arguments, or as a single argument.
*
* Parameters:
* Parameters (two arguments):
* lon - {Number} The x-axis coordinate in map units. If your map is in
* a geographic projection, this will be the Longitude. Otherwise,
* it will be the x coordinate of the map location in your map units.
* lat - {Number} The y-axis coordinate in map units. If your map is in
* a geographic projection, this will be the Latitude. Otherwise,
* it will be the y coordinate of the map location in your map units.
*
* Parameters (single argument):
* location - {Array(Float)} [lon, lat]
*/
initialize: function(lon, lat) {
if (OpenLayers.Util.isArray(lon)) {

View File

@@ -6,6 +6,9 @@
/**
* @requires OpenLayers/Control.js
* @requires OpenLayers/Lang.js
* @requires OpenLayers/Rule.js
* @requires OpenLayers/StyleMap.js
* @requires OpenLayers/Layer/Vector.js
*/
/**

View File

@@ -0,0 +1,240 @@
/* Copyright (c) 2006-2012 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Control.js
* @requires OpenLayers/Handler/Hover.js
* @requires OpenLayers/Handler/Click.js
*/
/**
* Class: OpenLayers.Control.UTFGrid
*
* This Control provides behavior associated with UTFGrid Layers.
* These 'hit grids' provide underlying feature attributes without
* calling the server (again). This control allows Mousemove, Hovering
* and Click events to trigger callbacks that use the attributes in
* whatever way you need.
*
* The most common example may be a UTFGrid layer containing feature
* attributes that are displayed in a div as you mouseover.
*
* Example Code:
*
* (start code)
* var world_utfgrid = new OpenLayers.Layer.UTFGrid(
* 'UTFGrid Layer',
* "http://tiles/world_utfgrid/${z}/${x}/${y}.json"
* );
* map.addLayer(world_utfgrid);
*
* var control = new OpenLayers.Control.UTFGrid({
* layers: [world_utfgrid],
* handlerMode: 'move',
* callback: function(infoLookup) {
* // do something with returned data
*
* }
* })
* (end code)
*
*
* Inherits from:
* - <OpenLayers.Control>
*/
OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
/**
* APIProperty: autoActivate
* {Boolean} Activate the control when it is added to a map. Default is
* true.
*/
autoActivate: true,
/**
* APIProperty: Layers
* List of layers to consider. Must be Layer.UTFGrids
* `null` is the default indicating all UTFGrid Layers are queried.
* {Array} <OpenLayers.Layer.UTFGrid>
*/
layers: null,
/* Property: defaultHandlerOptions
* The default opts passed to the handler constructors
*/
defaultHandlerOptions: {
'delay': 300,
'pixelTolerance': 4,
'stopMove': false,
'single': true,
'double': false,
'stopSingle': false,
'stopDouble': false
},
/* APIProperty: handlerMode
* Defaults to 'click'. Can be 'hover' or 'move'.
*/
handlerMode: 'click',
/**
* APIMethod: setHandler
* sets this.handlerMode and calls resetHandler()
*
* Parameters:
* hm - {String} Handler Mode string; 'click', 'hover' or 'move'.
*/
setHandler: function(hm) {
this.handlerMode = hm;
this.resetHandler();
},
/**
* Method: resetHandler
* Deactivates the old hanlder and creates a new
* <OpenLayers.Handler> based on the mode specified in
* this.handlerMode
*
*/
resetHandler: function() {
if (this.handler) {
this.handler.deactivate();
this.handler.destroy();
this.handler = null;
}
if (this.handlerMode == 'hover') {
// Handle this event on hover
this.handler = new OpenLayers.Handler.Hover(
this,
{'pause': this.handleEvent, 'move': this.reset},
this.handlerOptions
);
} else if (this.handlerMode == 'click') {
// Handle this event on click
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.handleEvent
}, this.handlerOptions
);
} else if (this.handlerMode == 'move') {
this.handler = new OpenLayers.Handler.Hover(
this,
// Handle this event while hovering OR moving
{'pause': this.handleEvent, 'move': this.handleEvent},
this.handlerOptions
);
}
if (this.handler) {
return true;
} else {
return false;
}
},
/**
* Constructor: <OpenLayers.Control.UTFGrid>
*
* Parameters:
* options - {Object}
*/
initialize: function(options) {
options = options || {};
options.handlerOptions = options.handlerOptions || this.defaultHandlerOptions;
OpenLayers.Control.prototype.initialize.apply(this, [options]);
this.resetHandler();
},
/**
* Method: handleEvent
* Internal method called when specified event is triggered.
*
* This method does several things:
*
* Gets the lonLat of the event.
*
* Loops through the appropriate hit grid layers and gathers the attributes.
*
* Passes the attributes to the callback
*
* Parameters:
* evt - {<OpenLayers.Event>}
*/
handleEvent: function(evt) {
if (evt == null) {
this.reset();
return;
}
var lonLat = this.map.getLonLatFromPixel(evt.xy);
if (!lonLat) {
return;
}
var layers = this.findLayers();
if (layers.length > 0) {
var infoLookup = {};
var layer, idx;
for (var i=0, len=layers.length; i<len; i++) {
layer = layers[i];
idx = OpenLayers.Util.indexOf(this.map.layers, layer);
infoLookup[idx] = layer.getFeatureInfo(lonLat);
}
this.callback(infoLookup, lonLat, evt.xy);
}
},
/**
* APIMethod: callback
* Function to be called when a mouse event corresponds with a location that
* includes data in one of the configured UTFGrid layers.
*
* Parameters:
* infoLookup - {Object} Keys of this object are layer indexes and can be
* used to resolve a layer in the map.layers array. The structure of
* the property values depend on the data included in the underlying
* UTFGrid and may be any valid JSON type.
*/
callback: function(infoLookup) {
// to be provided in the constructor
},
/**
* Method: reset
* Calls the callback with null.
*/
reset: function(evt) {
this.callback(null);
},
/**
* Method: findLayers
* Internal method to get the layers, independent of whether we are
* inspecting the map or using a client-provided array
*
* The default value of this.layers is null; this causes the
* findLayers method to return ALL UTFGrid layers encountered.
*
* Parameters:
* None
*
* Returns:
* {Array} Layers to handle on each event
*/
findLayers: function() {
var candidates = this.layers || this.map.layers;
var layers = [];
var layer;
for (var i=candidates.length-1; i>=0; --i) {
layer = candidates[i];
if (layer instanceof OpenLayers.Layer.UTFGrid ) {
layers.push(layer);
}
}
return layers;
},
CLASS_NAME: "OpenLayers.Control.UTFGrid"
});

View File

@@ -87,7 +87,7 @@ OpenLayers.Format.SLD.v1_0_0_GeoServer = OpenLayers.Class(
"TextSymbolizer": function(symbolizer) {
var writers = OpenLayers.Format.SLD.v1_0_0.prototype.writers;
var node = writers["sld"]["TextSymbolizer"].apply(this, arguments);
if (symbolizer.externalGraphic || symbolizer.graphicName) {
if (symbolizer.graphic !== false && (symbolizer.externalGraphic || symbolizer.graphicName)) {
this.writeNode("Graphic", symbolizer, node);
}
if ("priority" in symbolizer) {

View File

@@ -88,7 +88,6 @@ OpenLayers.Layer = OpenLayers.Class({
* Supported map event types:
* loadstart - Triggered when layer loading starts.
* loadend - Triggered when layer loading ends.
* loadcancel - Triggered when layer loading is canceled.
* visibilitychanged - Triggered when layer visibility is changed.
* move - Triggered when layer moves (triggered with every mousemove
* during a drag).
@@ -229,7 +228,11 @@ OpenLayers.Layer = OpenLayers.Class({
/**
* APIProperty: maxExtent
* {<OpenLayers.Bounds>} The center of these bounds will not stray outside
* {<OpenLayers.Bounds>|Array} If provided as an array, the array
* should consist of four values (left, bottom, right, top).
* The maximum extent for the layer. Defaults to null.
*
* The center of these bounds will not stray outside
* of the viewport extent during panning. In addition, if
* <displayOutsideMaxExtent> is set to false, data will not be
* requested that falls completely outside of these bounds.
@@ -238,7 +241,9 @@ OpenLayers.Layer = OpenLayers.Class({
/**
* APIProperty: minExtent
* {<OpenLayers.Bounds>}
* {<OpenLayers.Bounds>|Array} If provided as an array, the array
* should consist of four values (left, bottom, right, top).
* The minimum extent for the layer. Defaults to null.
*/
minExtent: null,

View File

@@ -196,6 +196,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
* element - {DOMElement} A reference to layer.events.element.
*
* Supported event types:
* tileloadstart - Triggered when a tile starts loading. Listeners receive
* an object as first argument, which has a tile property that
* references the tile that starts loading.
* tileloaded - Triggered when each new tile is
* loaded, as a means of progress update to listeners.
* listeners can access 'numLoadingTiles' if they wish to keep
@@ -416,6 +419,64 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
}
}
},
/**
* Method: getTileData
* Given a map location, retrieve a tile and the pixel offset within that
* tile corresponding to the location. If there is not an existing
* tile in the grid that covers the given location, null will be
* returned.
*
* Parameters:
* loc - {<OpenLayers.LonLat>} map location
*
* Returns:
* {Object} Object with the following properties: tile ({<OpenLayers.Tile>}),
* i ({Number} x-pixel offset from top left), and j ({Integer} y-pixel
* offset from top left).
*/
getTileData: function(loc) {
var data = null,
x = loc.lon,
y = loc.lat,
numRows = this.grid.length;
if (this.map && numRows) {
var res = this.map.getResolution(),
tileWidth = this.tileSize.w,
tileHeight = this.tileSize.h,
bounds = this.grid[0][0].bounds,
left = bounds.left,
top = bounds.top;
if (x < left) {
// deal with multiple worlds
if (this.map.baseLayer.wrapDateLine) {
var worldWidth = this.map.getMaxExtent().getWidth();
var worldsAway = Math.ceil((left - x) / worldWidth);
x += worldWidth * worldsAway;
}
}
// tile distance to location (fractional number of tiles);
var dtx = (x - left) / (res * tileWidth);
var dty = (top - y) / (res * tileHeight);
// index of tile in grid
var col = Math.floor(dtx);
var row = Math.floor(dty);
if (row >= 0 && row < numRows) {
var tile = this.grid[row][col];
if (tile) {
data = {
tile: tile,
// pixel index within tile
i: Math.floor((dtx - col) * tileWidth),
j: Math.floor((dty - row) * tileHeight)
};
}
}
}
return data;
},
/**
* Method: queueTileDraw
@@ -718,15 +779,36 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
//determine new tile bounds
var center = bounds.getCenterLonLat();
var tileWidth = bounds.getWidth() * this.ratio;
var tileHeight = bounds.getHeight() * this.ratio;
var tileBounds =
new OpenLayers.Bounds(center.lon - (tileWidth/2),
center.lat - (tileHeight/2),
center.lon + (tileWidth/2),
center.lat + (tileHeight/2));
// adjust tile bounds so they do not exceed maxExtent, except when the
// layer's maxExtent equals the world bounds or displayOutsideMaxExtent
// is set to true
var ignoreMaxExtent =
(this.map.baseLayer.wrapDateLine &&
this.maxExtent.equals(this.map.getMaxExtent())) ||
this.displayOutsideMaxExtent;
if(!ignoreMaxExtent) {
tileBounds.bottom = Math.max(this.maxExtent.bottom, tileBounds.bottom);
tileBounds.top = Math.min(this.maxExtent.top, tileBounds.top);
tileBounds.left = Math.max(this.maxExtent.left, tileBounds.left);
tileBounds.right = Math.min(this.maxExtent.right, tileBounds.right);
tileWidth = tileBounds.getWidth();
tileHeight = tileBounds.getHeight();
}
var resolution = this.map.getResolution(),
size = this.tileSize;
size.w = (tileWidth / resolution) | 0;
size.h = (tileHeight / resolution) | 0;
var px = this.map.getLayerPxFromLonLat({
lon: tileBounds.left,
lat: tileBounds.top
@@ -971,6 +1053,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
if (this.numLoadingTiles == 0) {
this.events.triggerEvent("loadstart");
}
this.events.triggerEvent("tileloadstart", {tile: tile});
this.numLoadingTiles++;
};

View File

@@ -0,0 +1,178 @@
/* Copyright (c) 2006-2012 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Layer/XYZ.js
* @requires OpenLayers/Tile/UTFGrid.js
*/
/**
* Class: OpenLayers.Layer.UTFGrid
* This Layer reads from UTFGrid tiled data sources. Since UTFGrids are
* essentially JSON-based ASCII art with attached attributes, they are not
* visibly rendered. In order to use them in the map, you must add a
* <OpenLayers.Control.UTFGrid> ontrol as well.
*
* Example:
*
* (start code)
* var world_utfgrid = new OpenLayers.Layer.UTFGrid({
* url: "/tiles/world_utfgrid/${z}/${x}/${y}.json",
* utfgridResolution: 4,
* displayInLayerSwitcher: false
* );
* map.addLayer(world_utfgrid);
*
* var control = new OpenLayers.Control.UTFGrid({
* layers: [world_utfgrid],
* handlerMode: 'move',
* callback: function(dataLookup) {
* // do something with returned data
* }
* })
* (end code)
*
*
* Inherits from:
* - <OpenLayers.Layer.XYZ>
*/
OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.XYZ, {
/**
* APIProperty: isBaseLayer
* Default is true, as this is designed to be a base tile source.
*/
isBaseLayer: false,
/**
* APIProperty: projection
* {<OpenLayers.Projection>}
* Source projection for the UTFGrids. Default is "EPSG:900913".
*/
projection: new OpenLayers.Projection("EPSG:900913"),
/**
* Property: useJSONP
* {Boolean}
* Should we use a JSONP script approach instead of a standard AJAX call?
*
* Set to true for using utfgrids from another server.
* Avoids same-domain policy restrictions.
* Note that this only works if the server accepts
* the callback GET parameter and dynamically
* wraps the returned json in a function call.
*
* Default is false
*/
useJSONP: false,
/**
* APIProperty: url
* {String}
* URL tempate for UTFGrid tiles. Include x, y, and z parameters.
* E.g. "/tiles/${z}/${x}/${y}.json"
*/
/**
* APIProperty: utfgridResolution
* {Number}
* Ratio of the pixel width to the width of a UTFGrid data point. If an
* entry in the grid represents a 4x4 block of pixels, the
* utfgridResolution would be 4. Default is 2 (specified in
* <OpenLayers.Tile.UTFGrid>).
*/
/**
* Property: tileClass
* {<OpenLayers.Tile>} The tile class to use for this layer.
* Defaults is <OpenLayers.Tile.UTFGrid>.
*/
tileClass: OpenLayers.Tile.UTFGrid,
/**
* Constructor: OpenLayers.Layer.UTFGrid
* Create a new UTFGrid layer.
*
* Parameters:
* config - {Object} Configuration properties for the layer.
*
* Required configuration properties:
* url - {String} The url template for UTFGrid tiles. See the <url> property.
*/
initialize: function(options) {
OpenLayers.Layer.Grid.prototype.initialize.apply(
this, [options.name, options.url, {}, options]
);
this.tileOptions = OpenLayers.Util.extend({
utfgridResolution: this.utfgridResolution
}, this.tileOptions);
},
/**
* APIMethod: clone
* Create a clone of this layer
*
* Parameters:
* obj - {Object} Only used by a subclass of this layer.
*
* Returns:
* {<OpenLayers.Layer.UTFGrid>} An exact clone of this OpenLayers.Layer.UTFGrid
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer.UTFGrid(this.getOptions());
}
// get all additions from superclasses
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
return obj;
},
/**
* APIProperty: getFeatureInfo
* Get details about a feature associated with a map location. The object
* returned will have id and data properties. If the given location
* doesn't correspond to a feature, null will be returned.
*
* Parameters:
* location - {<OpenLayers.LonLat>} map location
*
* Returns:
* {Object} Object representing the feature id and UTFGrid data
* corresponding to the given map location. Returns null if the given
* location doesn't hit a feature.
*/
getFeatureInfo: function(location) {
var info = null;
var tileInfo = this.getTileData(location);
if (tileInfo.tile) {
info = tileInfo.tile.getFeatureInfo(tileInfo.i, tileInfo.j);
}
return info;
},
/**
* APIMethod: getFeatureId
* Get the identifier for the feature associated with a map location.
*
* Parameters:
* location - {<OpenLayers.LonLat>} map location
*
* Returns:
* {String} The feature identifier corresponding to the given map location.
* Returns null if the location doesn't hit a feature.
*/
getFeatureId: function(location) {
var id = null;
var info = this.getTileData(location);
if (info.tile) {
id = info.tile.getFeatureId(info.i, info.j);
}
return id;
},
CLASS_NAME: "OpenLayers.Layer.UTFGrid"
});

View File

@@ -537,6 +537,9 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
if (OpenLayers.Renderer.NG && this.renderer instanceof OpenLayers.Renderer.NG) {
this.drawn = false;
}
this.resolution = null; // this is to force Layer.redraw set
// zoomChanged to true in the moveTo
// call
return OpenLayers.Layer.prototype.redraw.apply(this, arguments);
},
@@ -1023,4 +1026,4 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
},
CLASS_NAME: "OpenLayers.Layer.Vector"
});
});

View File

@@ -307,7 +307,9 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIProperty: maxExtent
* {<OpenLayers.Bounds>} The maximum extent for the map. Defaults to the
* {<OpenLayers.Bounds>|Array} If provided as an array, the array
* should consist of four values (left, bottom, right, top).
* The maximum extent for the map. Defaults to the
* whole world in decimal degrees (-180, -90, 180, 90). Specify a
* different extent in the map options if you are not using a geographic
* projection and displaying the whole world. To restrict user panning
@@ -318,13 +320,17 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIProperty: minExtent
* {<OpenLayers.Bounds>}
* {<OpenLayers.Bounds>|Array} If provided as an array, the array
* should consist of four values (left, bottom, right, top).
* The minimum extent for the map. Defaults to null.
*/
minExtent: null,
/**
* APIProperty: restrictedExtent
* {<OpenLayers.Bounds>} Limit map navigation to this extent where possible.
* {<OpenLayers.Bounds>|Array} If provided as an array, the array
* should consist of four values (left, bottom, right, top).
* Limit map navigation to this extent where possible.
* If a non-null restrictedExtent is set, panning will be restricted
* to the given bounds. In addition, zooming to a resolution that
* displays more than the restricted extent will center the map
@@ -436,6 +442,24 @@ OpenLayers.Map = OpenLayers.Class({
* provided or if you intend to call the <render> method later.
* options - {Object} Optional object with properties to tag onto the map.
*
* Valid options (in addition to the listed API properties):
* center - {<OpenLayers.LonLat>|Array} The default initial center of the map.
* If provided as array, the first value is the x coordinate,
* and the 2nd value is the y coordinate.
* Only specify if <layers> is provided.
* Note that if an ArgParser/Permalink control is present,
* and the querystring contains coordinates, center will be set
* by that, and this option will be ignored.
* zoom - {Number} The initial zoom level for the map. Only specify if
* <layers> is provided.
* Note that if an ArgParser/Permalink control is present,
* and the querystring contains a zoom level, zoom will be set
* by that, and this option will be ignored.
* extent - {<OpenLayers.Bounds>|Array} The initial extent of the map.
* If provided as an array, the array should consist of
* four values (left, bottom, right, top).
* Only specify if <center> and <zoom> are not provided.
*
* Examples:
* (code)
* // create a map with default options in an element with the id "map1"
@@ -443,28 +467,26 @@ OpenLayers.Map = OpenLayers.Class({
*
* // create a map with non-default options in an element with id "map2"
* var options = {
* projection: "EPSG:3857",
* maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000),
* maxResolution: 156543,
* units: 'm',
* projection: "EPSG:41001"
* center: new OpenLayers.LonLat(-12356463.476333, 5621521.4854095)
* };
* var map = new OpenLayers.Map("map2", options);
*
* // map with non-default options - same as above but with a single argument
* // map with non-default options - same as above but with a single argument,
* // a restricted extent, and using arrays for bounds and center
* var map = new OpenLayers.Map({
* div: "map_id",
* maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000),
* maxResolution: 156543,
* units: 'm',
* projection: "EPSG:41001"
* projection: "EPSG:3857",
* maxExtent: [-18924313.432222, -15538711.094146, 18924313.432222, 15538711.094146],
* restrictedExtent: [-13358338.893333, -9608371.5085962, 13358338.893333, 9608371.5085962],
* center: [-12356463.476333, 5621521.4854095]
* });
*
* // create a map without a reference to a container - call render later
* var map = new OpenLayers.Map({
* maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000),
* maxResolution: 156543,
* units: 'm',
* projection: "EPSG:41001"
* projection: "EPSG:3857",
* maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000)
* });
* (end)
*/
@@ -500,6 +522,9 @@ OpenLayers.Map = OpenLayers.Class({
if (this.maxExtent && !(this.maxExtent instanceof OpenLayers.Bounds)) {
this.maxExtent = new OpenLayers.Bounds(this.maxExtent);
}
if (this.minExtent && !(this.minExtent instanceof OpenLayers.Bounds)) {
this.minExtent = new OpenLayers.Bounds(this.minExtent);
}
if (this.restrictedExtent && !(this.restrictedExtent instanceof OpenLayers.Bounds)) {
this.restrictedExtent = new OpenLayers.Bounds(this.restrictedExtent);
}
@@ -625,7 +650,7 @@ OpenLayers.Map = OpenLayers.Class({
if (options && options.layers) {
/**
* If you have set options.center, the map center property will be
* set at this point. However, since setCenter has not been caleld,
* set at this point. However, since setCenter has not been called,
* addLayers gets confused. So we delete the map center in this
* case. Because the check below uses options.center, it will
* be properly set below.
@@ -1662,7 +1687,9 @@ OpenLayers.Map = OpenLayers.Class({
* Set the map center (and optionally, the zoom level).
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>} The new center location.
* lonlat - {<OpenLayers.LonLat>|Array} The new center location.
* If provided as array, the first value is the x coordinate,
* and the 2nd value is the y coordinate.
* zoom - {Integer} Optional zoom level.
* dragging - {Boolean} Specifies whether or not to trigger
* movestart/end events
@@ -2282,7 +2309,8 @@ OpenLayers.Map = OpenLayers.Class({
* Zoom to the passed in bounds, recenter
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* bounds - {<OpenLayers.Bounds>|Array} If provided as an array, the array
* should consist of four values (left, bottom, right, top).
* closest - {Boolean} Find the zoom level that most closely fits the
* specified bounds. Note that this may result in a zoom that does
* not exactly contain the entire extent.

View File

@@ -39,5 +39,40 @@ var OpenLayers = {
}
}
return (function() { return l; });
})()
})(),
/**
* Property: ImgPath
* {String} Set this to the path where control images are stored, a path
* given here must end with a slash. If set to '' (which is the default)
* OpenLayers will use its script location + "img/".
*
* You will need to set this property when you have a singlefile build of
* OpenLayers that either is not named "OpenLayers.js" or if you move
* the file in a way such that the image directory cannot be derived from
* the script location.
*
* If your custom OpenLayers build is named "my-custom-ol.js" and the images
* of OpenLayers are in a folder "/resources/external/images/ol" a correct
* way of including OpenLayers in your HTML would be:
*
* (code)
* <script src="/path/to/my-custom-ol.js" type="text/javascript"></script>
* <script type="text/javascript">
* // tell OpenLayers where the control images are
* // remember the trailing slash
* OpenLayers.ImgPath = "/resources/external/images/ol/";
* </script>
* (end code)
*
* Please remember that when your OpenLayers script is not named
* "OpenLayers.js" you will have to make sure that the default theme is
* loaded into the page by including an appropriate <link>-tag,
* e.g.:
*
* (code)
* <link rel="stylesheet" href="/path/to/default/style.css" type="text/css">
* (end code)
*/
ImgPath : ''
};

View File

@@ -21,9 +21,9 @@
OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
/**
* Property: url
* APIProperty: url
* {String} The URL of the image being requested. No default. Filled in by
* layer.getURL() function.
* layer.getURL() function. May be modified by loadstart listeners.
*/
url: null,
@@ -166,10 +166,10 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
}
if (this.isLoading) {
//if we're already loading, send 'reload' instead of 'loadstart'.
this.events.triggerEvent("reload");
this._loadEvent = "reload";
} else {
this.isLoading = true;
this.events.triggerEvent("loadstart");
this._loadEvent = "loadstart";
}
this.positionTile();
this.renderTile();
@@ -287,6 +287,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
* Creates the content for the frame on the tile.
*/
initImage: function() {
this.events.triggerEvent(this._loadEvent);
var img = this.getImage();
if (this.url && img.getAttribute("src") == this.url) {
this.onImageLoad();
@@ -315,8 +316,8 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
} else {
OpenLayers.Event.observe(img, "load", load);
OpenLayers.Event.observe(img, "error", load);
if (img.crossOrigin) {
img.crossOrigin = null;
if (this.crossOriginKeyword) {
img.removeAttribute("crossorigin");
}
img.src = this.blankImageUrl;
}
@@ -336,8 +337,12 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
img.style.opacity = 0;
if (url) {
// don't set crossOrigin if the url is a data URL
if (this.crossOriginKeyword && url.substr(0, 5 !== 'data:')) {
img.crossOrigin = this.crossOriginKeyword;
if (this.crossOriginKeyword) {
if (url.substr(0, 5) !== 'data:') {
img.setAttribute("crossorigin", this.crossOriginKeyword);
} else {
img.removeAttribute("crossorigin");
}
}
img.src = url;
}

View File

@@ -0,0 +1,251 @@
/* Copyright (c) 2006-2012 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Tile.js
* @requires OpenLayers/Format/JSON.js
*/
/**
* Class: OpenLayers.Tile.UTFGrid
* Instances of OpenLayers.Tile.UTFGrid are used to manage
* UTFGrids. This is an unusual tile type in that it doesn't have a
* rendered image; only a 'hit grid' that can be used to
* look up feature attributes.
*
* See the <OpenLayers.Tile.UTFGrid> constructor for details on constructing a
* new instance.
*
* Inherits from:
* - <OpenLayers.Tile>
*/
OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
/**
* Property: url
* {String}
* The URL of the UTFGrid file being requested. Provided by the <getURL>
* method.
*/
url: null,
/**
* Property: utfgridResolution
* {Number}
* Ratio of the pixel width to the width of a UTFGrid data point. If an
* entry in the grid represents a 4x4 block of pixels, the
* utfgridResolution would be 4. Default is 2.
*/
utfgridResolution: 2,
/**
* Property: json
* {Object}
* Stores the parsed JSON tile data structure.
*/
json: null,
/**
* Property: format
* {OpenLayers.Format.JSON}
* Parser instance used to parse JSON for cross browser support. The native
* JSON.parse method will be used where available (all except IE<8).
*/
format: null,
/**
* Constructor: OpenLayers.Tile.UTFGrid
* Constructor for a new <OpenLayers.Tile.UTFGrid> instance.
*
* Parameters:
* layer - {<OpenLayers.Layer>} layer that the tile will go in.
* position - {<OpenLayers.Pixel>}
* bounds - {<OpenLayers.Bounds>}
* url - {<String>} Deprecated. Remove me in 3.0.
* size - {<OpenLayers.Size>}
* options - {Object}
*/
/**
* APIMethod: destroy
* Clean up.
*/
destroy: function() {
this.clear();
OpenLayers.Tile.prototype.destroy.apply(this, arguments);
},
/**
* Method: draw
* Check that a tile should be drawn, and draw it.
* In the case of UTFGrids, "drawing" it means fetching and
* parsing the json.
*
* Returns:
* {Boolean} Was a tile drawn?
*/
draw: function() {
var drawn = OpenLayers.Tile.prototype.draw.apply(this, arguments);
if (drawn) {
if (this.isLoading) {
this.abortLoading();
//if we're already loading, send 'reload' instead of 'loadstart'.
this.events.triggerEvent("reload");
} else {
this.isLoading = true;
this.events.triggerEvent("loadstart");
}
this.url = this.layer.getURL(this.bounds);
if (this.layer.useJSONP) {
// Use JSONP method to avoid xbrowser policy
var ols = new OpenLayers.Protocol.Script({
url: this.url,
callback: function(response) {
this.isLoading = false;
this.events.triggerEvent("loadend");
this.json = response.data;
},
scope: this
});
ols.read();
this.request = ols;
} else {
// Use standard XHR
this.request = OpenLayers.Request.GET({
url: this.url,
callback: function(response) {
this.isLoading = false;
this.events.triggerEvent("loadend");
if (response.status === 200) {
this.parseData(response.responseText);
}
},
scope: this
});
}
} else {
this.unload();
}
return drawn;
},
/**
* Method: abortLoading
* Cancel a pending request.
*/
abortLoading: function() {
if (this.request) {
this.request.abort();
delete this.request;
}
this.isLoading = false;
},
/**
* Method: getFeatureInfo
* Get feature information associated with a pixel offset. If the pixel
* offset corresponds to a feature, the returned object will have id
* and data properties. Otherwise, null will be returned.
*
*
* Parameters:
* i - {Number} X-axis pixel offset (from top left of tile)
* j - {Number} Y-axis pixel offset (from top left of tile)
*
* Returns:
* {Object} Object with feature id and data properties corresponding to the
* given pixel offset.
*/
getFeatureInfo: function(i, j) {
var info = null;
if (this.json) {
var id = this.getFeatureId(i, j);
if (id !== null) {
info = {id: id, data: this.json.data[id]};
}
}
return info;
},
/**
* Method: getFeatureId
* Get the identifier for the feature associated with a pixel offset.
*
* Parameters:
* i - {Number} X-axis pixel offset (from top left of tile)
* j - {Number} Y-axis pixel offset (from top left of tile)
*
* Returns:
* {Object} The feature identifier corresponding to the given pixel offset.
* Returns null if pixel doesn't correspond to a feature.
*/
getFeatureId: function(i, j) {
var id = null;
if (this.json) {
var resolution = this.utfgridResolution;
var row = Math.floor(j / resolution);
var col = Math.floor(i / resolution);
var charCode = this.json.grid[row].charCodeAt(col);
var index = this.indexFromCharCode(charCode);
var keys = this.json.keys;
if (!isNaN(index) && (index in keys)) {
id = keys[index];
}
}
return id;
},
/**
* Method: indexFromCharCode
* Given a character code for one of the UTFGrid "grid" characters,
* resolve the integer index for the feature id in the UTFGrid "keys"
* array.
*
* Parameters:
* charCode - {Integer}
*
* Returns:
* {Integer} Index for the feature id from the keys array.
*/
indexFromCharCode: function(charCode) {
if (charCode >= 93) {
charCode--;
}
if (charCode >= 35) {
charCode --;
}
return charCode - 32;
},
/**
* Method: parseData
* Parse the JSON from a request
*
* Parameters:
* str - {String} UTFGrid as a JSON string.
*
* Returns:
* {Object} parsed javascript data
*/
parseData: function(str) {
if (!this.format) {
this.format = new OpenLayers.Format.JSON();
}
this.json = this.format.read(str);
},
/**
* Method: clear
* Delete data stored with this tile.
*/
clear: function() {
this.json = null;
},
CLASS_NAME: "OpenLayers.Tile.UTFGrid"
});

View File

@@ -559,14 +559,6 @@ OpenLayers.Util.urlAppend = function(url, paramStr) {
return newUrl;
};
/**
* APIProperty: ImgPath
* {String} Set this to the path where control images are stored.
* If set to '' OpenLayers will use script location + "img/"
* Default is ''.
*/
OpenLayers.ImgPath = '';
/**
* Function: getImagesLocation
*

View File

@@ -1,4 +1,9 @@
# Major enhancements
# Major enhancements and additions
## Zoom Control
A simple control to add zoom in/out buttons on the map that can be entirely styled using CSS.
See it live in this [example](http://openlayers.org/dev/examples/zoom.html).
## Tile animation
@@ -20,6 +25,67 @@ People can override this rule to use other transition settings. To remove tile a
transition: none;
}
## Builds
This version of OpenLayers ships with three builds:
* `OpenLayers.js`
* `OpenLayers.light.js`
* `OpenLayers.mobile.js`
See the README.md file and the docs on docs.openlayers.org for more information.
## Sensible projection defaults
The geographic and web mercator projections define default values for the maxExtent, and units. This simplifies the map and layer configuration.
For example, a map that used to be created with this:
map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
units: "m",
maxExtent: new OpenLayers.Bounds(
-20037508.34, -20037508.34, 20037508.34, 20037508.34
)
});
can now be created with this:
map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913"
});
## Tile Queue
The tiling code has been overhauled so grid layers now work with tile queues.
The tile queue gives more control on the tile requests sent to the tiling
services. Tile requests that become useless can be aborted.
## Tile Canvas
Image tiles expose an `getCanvasContext` function that can be used for various
things, like changing the image pixels, save the image using the File API, etc.
See the [osm-grayscale
example](http://openlayers.org/dev/examples/osm-grayscale.html).
## Backbuffer Overhaul
The backbuffer code (behind `transitionEffect:resize`) has been redesigned and
rewritten. This overhaul yields better performance and code simplifications.
## Continous zooming
Tile layers can now be displayed at resolutions not supported by their tiling
services. This works by requesting tiles at higher resolutions and stretching
the layer div as appropriate. With this change fractionalZoom:true will work
for single tile layers as well as for tiled layers.
See the [client zoom
example](http://openlayers.org/dev/examples/clientzoom.html).
# Behavior Changes from Past Releases
## GPX API change

View File

@@ -43,8 +43,19 @@
function test_Control_PanZoom_control_events (t) {
if ( !window.document.createEvent || OpenLayers.BROWSER_NAME == "opera" || !t.open_window) {
//ie can't simulate mouseclicks
// IE 9+ does support the standard document.createEvent,
// event.initMouseEvent, and elem.dispatchEvent calls, so it
// should be possible to simulate clicks in this browser.
// For example it looks like jQuery UI does simulate events
// using document.createElement in IE 9+. See
// https://github.com/jquery/jquery-ui/blob/master/tests/jquery.simulate.js.
// I haven't been able to make it work though.
if ( !window.document.createEvent ||
OpenLayers.BROWSER_NAME == "msie" ||
OpenLayers.BROWSER_NAME == "opera" ||
!t.open_window) {
t.plan(0);
t.debug_print("FIXME: This browser does not support the PanZoom test at this time.");
} else {

119
tests/Control/UTFGrid.html Normal file
View File

@@ -0,0 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
/**
* Because browsers that implement requestAnimationFrame may not execute
* animation functions while a window is not displayed (e.g. in a hidden
* iframe as in these tests), we mask the native implementations here. The
* native requestAnimationFrame functionality is tested in Util.html and
* in PanZoom.html (where a popup is opened before panning). The panTo tests
* here will test the fallback setTimeout implementation for animation.
*/
window.requestAnimationFrame =
window.webkitRequestAnimationFrame =
window.mozRequestAnimationFrame =
window.oRequestAnimationFrame =
window.msRequestAnimationFrame = null;
</script>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var map, layer, control;
var log;
function setUp() {
layer = new OpenLayers.Layer.UTFGrid({
url: "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json",
isBaseLayer: true,
utfgridResolution: 4
});
map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
layers: [layer],
center: [0, 0],
zoom: 1
});
log = [];
control = new OpenLayers.Control.UTFGrid({
callback: function(infoLookup, loc, pixel) {
log.push([infoLookup, loc, pixel]);
}
});
map.addControl(control);
}
function tearDown() {
map.destroy();
map = null;
layer = null;
control = null;
log = [];
}
function test_constructor(t) {
t.plan(2);
var control = new OpenLayers.Control.UTFGrid();
t.ok(control instanceof OpenLayers.Control.UTFGrid, "utfgrid instance");
t.eq(control.handlerMode, "click", "control mode");
control.destroy();
}
function test_handleEvent(t) {
setUp();
var cases = [{
evt: {xy: {x: 100, y: 70}},
lookup: {
"0": {
id: "207",
data: {
NAME: "United States",
POP2005: 299846449
}
}
}
}, {
evt: {xy: {x: 350, y: 20}},
lookup: {
"0": {
id: "245",
data: {
NAME: "Russia",
POP2005: 143953092
}
}
}
}];
var len = cases.length;
t.plan(4*len);
// wait for tile loading to finish
t.delay_call(0.5, function() {
var c, arg;
for (var i=0; i<len; ++i) {
c = cases[i];
t.eq(log.length, i, i + ": log length before");
control.handleEvent(c.evt);
t.eq(log.length, i+1, i + ": log length after");
t.eq(log[i][0], c.lookup, i + ": callback infoLookup");
t.eq(log[i][2], c.evt.xy, i + ": callback pixel");
}
tearDown();
});
}
</script>
</head>
<body>
<div id="map" style="height: 256px; width: 512px"></div>
</body>
</html>

View File

@@ -14,7 +14,7 @@
"poly_label.sld"
];
var len = cases.length;
t.plan(len);
t.plan(len+1);
var format = new OpenLayers.Format.SLD({
profile: "GeoServer",
@@ -31,7 +31,11 @@
out = format.write(data);
t.xml_eq(out, doc.documentElement, "round-tripped " + c);
}
doc = readXML("poly_label.sld");
data = format.read(doc);
data.namedLayers[0].userStyles[0].rules[0].symbolizers[1].graphic = false;
out = format.write(data);
t.xml_eq(out, readXML("poly_label_nographic.sld").documentElement, "If graphic is false no Graphic is outputted");
}
</script>
@@ -110,5 +114,65 @@
</NamedLayer>
</StyledLayerDescriptor>
--></div>
<div id="poly_label_nographic.sld"><!--
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>Polygon with styled label</Name>
<UserStyle>
<Title>SLD Cook Book: Polygon with styled label</Title>
<FeatureTypeStyle>
<Rule>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#40FF40</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#FFFFFF</CssParameter>
<CssParameter name="stroke-width">2</CssParameter>
</Stroke>
</PolygonSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>name</ogc:PropertyName>
</Label>
<Font>
<CssParameter name="font-family">Arial</CssParameter>
<CssParameter name="font-size">11</CssParameter>
<CssParameter name="font-weight">bold</CssParameter>
<CssParameter name="font-style">normal</CssParameter>
</Font>
<Fill>
<CssParameter name="fill">#000000</CssParameter>
<CssParameter name="fill-opacity">0.5</CssParameter>
</Fill>
<Priority>
<ogc:PropertyName>population</ogc:PropertyName>
</Priority>
<VendorOption name="autoWrap">60</VendorOption>
<VendorOption name="followLine">true</VendorOption>
<VendorOption name="repeat">300</VendorOption>
<VendorOption name="maxDisplacement">150</VendorOption>
<VendorOption name="forceLeftToRight">false</VendorOption>
<VendorOption name="graphic-margin">3</VendorOption>
<VendorOption name="graphic-resize">stretch</VendorOption>
<VendorOption name="group">yes</VendorOption>
<VendorOption name="spaceAround">10</VendorOption>
<VendorOption name="labelAllGroup">true</VendorOption>
<VendorOption name="maxAngleDelta">15</VendorOption>
<VendorOption name="conflictResolution">false</VendorOption>
<VendorOption name="goodnessOfFit">0.3</VendorOption>
<VendorOption name="polygonAlign">mbr</VendorOption>
</TextSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
--></div>
</body>
</html>

View File

@@ -230,17 +230,17 @@
layer.deferMoveGriddedTiles = function() {
log.push("deferMoveGriddedTiles");
origDeferMoveGriddedTiles.apply(this, arguments);
}
};
layer.moveGriddedTiles = function() {
log.push("moveGriddedTiles");
OpenLayers.Layer.WMS.prototype.moveGriddedTiles.apply(this, arguments);
}
};
map.moveTo([5, 0]);
t.eq(log[0], "moveGriddedTiles", "deferred after moveTo");
map.moveTo([0, 0]);
t.eq(log[1], "moveGriddedTiles", "deferred again after another moveTo");
t.eq(log.length, 2, "no tiles loaded yet");
t.delay_call(0.1, function() {
t.delay_call(1, function() {
t.eq(log[2], "deferMoveGriddedTiles", "tiles moved after tileLoadingDelay");
});
@@ -449,7 +449,7 @@
}
function test_Layer_Grid_initSingleTile(t) {
t.plan( 11 );
t.plan( 24 );
layer = new OpenLayers.Layer.Grid(name, url, params, {
singleTile: true,
@@ -462,14 +462,17 @@
var desiredUL = new OpenLayers.LonLat(-40,145);
translatedPX = {};
layer.tileSize = new OpenLayers.Size();
layer.map = {
baseLayer: {wrapDateLine: true},
getMaxExtent: function() { return new OpenLayers.Bounds(-180,-90,180,90); },
getLayerPxFromLonLat: function(ul) {
t.ok(ul.lon === desiredUL.lon && ul.lat === desiredUL.lat, "correct ul passed to translation");
return translatedPX;
},
getResolution: function() {
}
}
getResolution:function(){return 1;}
};
layer.maxExtent = layer.map.getMaxExtent();
var newTile = {
draw: function() {
@@ -499,14 +502,62 @@
t.ok(tileBounds.equals(desiredTileBounds), "correct tile bounds passed to tile.moveTo()");
t.ok(px == translatedPX, "correct tile px passed to tile.moveTo()");
}
};
};
layer.grid = [[ tile ]];
layer.initSingleTile(bounds);
layer.initSingleTile(bounds);
//test maxExtent restrictions
//reset grid
layer.grid = [];
//more useful mocks
layer.map = {
baseLayer: {wrapDateLine: false},
getMaxExtent: function() { return new OpenLayers.Bounds(-180,-90,180,90); },
getLayerPxFromLonLat: function(ul) {
return {
x:ul.lon,
y:ul.lat
};
},
getResolution: function(){return 1;}
};
layer.addTile = function(tileBounds, px) {
t.ok(tileBounds.equals(desiredTileBounds), "correct tile bounds passed to addTile to create new tile");
t.ok(px.x == translatedPX.x && px.y == translatedPX.y, "correct tile px passed to addTile to create new tile");
return newTile;
};
tile = {
moveTo: function(tileBounds, px) {
t.ok(tileBounds.equals(desiredTileBounds), "correct tile bounds passed to tile.moveTo()");
t.ok(px.x == translatedPX.x && px.y == translatedPX.y, "correct tile px passed to tile.moveTo()");
}
};
//test bound fully contains the maxExtent
//tile bounds -10,10,50,100 -> apply ratio -40,-35,80,145
layer.maxExtent = new OpenLayers.Bounds(0,20,40,90);
desiredTileBounds = new OpenLayers.Bounds(0,20,40,90);
translatedPX = {x:0,y:90};
layer.initSingleTile(bounds);
//test bound overlaps the maxExtent
bounds = new OpenLayers.Bounds(-10,10,50,100);
//with ratio applied tile bounds are -40,-35,80,145
layer.maxExtent = new OpenLayers.Bounds(-50,20,40,150);
desiredTileBounds = new OpenLayers.Bounds(-40,20,40,145);
translatedPX = {x:-40,y:145};
layer.grid = [[ tile ]];
layer.initSingleTile(bounds);
t.ok(layer.tileSize.equals(new OpenLayers.Size(80, 125)), "tileSize correct.");
//test bounds where ratio will be applied on all edges
layer.displayOutsideMaxExtent = true;
desiredTileBounds = new OpenLayers.Bounds(-40,-35,80,145);
layer.initSingleTile(bounds);
t.ok(layer.tileSize.equals(new OpenLayers.Size(120, 180)), "tileSize correct.")
}
function test_Layer_Grid_addTileMonitoringHooks(t) {
t.plan(17);
t.plan(18);
layer = new OpenLayers.Layer.Grid();
layer.events = {
@@ -546,10 +597,11 @@
t.eq(g_events[0][0], "loadstart", "loadstart event triggered when numLoadingTiles is 0");
t.eq(layer.numLoadingTiles, 1, "numLoadingTiles incremented");
t.eq(g_events[1][0], "tileloadstart", "tileloadstart event triggered");
g_events = [];
tile.onLoadStart.apply(layer);
t.eq(g_events.length, 0, "loadstart event not triggered when numLoadingTiles is not 0");
t.eq(g_events.length, 1, "tileloadstart, but not loadstart triggered when numLoadingTiles is not 0");
t.eq(layer.numLoadingTiles, 2, "numLoadingTiles incremented");
@@ -1365,6 +1417,132 @@
map.destroy();
});
}
function test_getGridData(t) {
t.plan(12);
var layer = new OpenLayers.Layer.Grid(null, null, null, {
isBaseLayer: true, getURL: function() {
return "/bogus/path/to/tile";
}
});
var map = new OpenLayers.Map({
div: "map",
layers: [layer],
controls: [],
center: [0, 0],
zoom: 1
});
// get tile data for [0, 0]
var data = layer.getTileData({lon: 0, lat: 0});
t.ok(data && data.tile, "[0, 0]: got tile data");
t.eq(data.i, 0, "[0, 0]: i");
t.eq(data.j, 128, "[0, 0]: j");
t.ok(
data.tile.bounds.equals({left: 0, bottom: -90, right: 180, top: 90}),
"[0, 0]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [-110, 45]
data = layer.getTileData({lon: -110, lat: 45});
t.ok(data && data.tile, "[-110, 45]: got tile data");
t.eq(data.i, 99, "[-110, 45]: i");
t.eq(data.j, 64, "[-110, 45]: j");
t.ok(
data.tile.bounds.equals({left: -180, bottom: -90, right: 0, top: 90}),
"[-110, 45]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [0, 300] (north of grid)
data = layer.getTileData({lon: 0, lat: 300})
t.eq(data, null, "[0, 300]: north of grid");
// get tile data for [400, 0] (east of grid)
data = layer.getTileData({lon: 400, lat: 0})
t.eq(data, null, "[400, 0]: east of grid");
// get tile data for [0, -500] (south of grid)
data = layer.getTileData({lon: 0, lat: -500})
t.eq(data, null, "[0, -500]: south of grid");
// get tile data for [-200, 0] (west of grid)
data = layer.getTileData({lon: -200, lat: 0})
t.eq(data, null, "[-200, 0]: west of grid");
map.destroy();
}
function test_getGridData_wrapped(t) {
t.plan(18);
var layer = new OpenLayers.Layer.Grid(null, null, null, {
isBaseLayer: true, getURL: function() {
return "/bogus/path/to/tile";
},
wrapDateLine: true
});
var map = new OpenLayers.Map({
div: "map",
layers: [layer],
controls: [],
center: [-50, 0],
zoom: 1
});
// get tile data for [0, 0]
var data = layer.getTileData({lon: 0, lat: 0});
t.ok(data && data.tile, "[0, 0]: got tile data");
t.eq(data.i, 0, "[0, 0]: i");
t.eq(data.j, 128, "[0, 0]: j");
t.ok(
data.tile.bounds.equals({left: 0, bottom: -90, right: 180, top: 90}),
"[0, 0]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [-110, 45]
data = layer.getTileData({lon: -110, lat: 45});
t.ok(data && data.tile, "[-110, 45]: got tile data");
t.eq(data.i, 99, "[-110, 45]: i");
t.eq(data.j, 64, "[-110, 45]: j");
t.ok(
data.tile.bounds.equals({left: -180, bottom: -90, right: 0, top: 90}),
"[-110, 45]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [0, 300] (north of grid)
data = layer.getTileData({lon: 0, lat: 300})
t.eq(data, null, "[0, 300]: north of grid");
// get tile data for [400, 0] (equivalent to [40, 0] and visible on map)
data = layer.getTileData({lon: 400, lat: 0})
t.ok(data && data.tile, "[400, 0]: got tile data");
t.eq(data.i, 56, "[400, 0]: i");
t.eq(data.j, 128, "[400, 0]: j");
t.ok(
data.tile.bounds.equals({left: 0, bottom: -90, right: 180, top: 90}),
"[400, 0]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [0, -500] (south of grid)
data = layer.getTileData({lon: 0, lat: -500})
t.eq(data, null, "[0, -500]: south of grid");
// get tile data for [-200, 0] (equivalent to [160, 0] and wrapped to west side map)
data = layer.getTileData({lon: -200, lat: 0})
t.ok(data && data.tile, "[-200, 0]: got tile data");
t.eq(data.i, 227, "[-200, 0]: i");
t.eq(data.j, 128, "[-200, 0]: j");
t.ok(
data.tile.bounds.equals({left: 0, bottom: -90, right: 180, top: 90}),
"[-200, 0]: tile bounds " + data.tile.bounds.toString()
);
map.destroy();
}
</script>
</head>
<body>

115
tests/Layer/UTFGrid.html Normal file
View File

@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
/**
* Because browsers that implement requestAnimationFrame may not execute
* animation functions while a window is not displayed (e.g. in a hidden
* iframe as in these tests), we mask the native implementations here. The
* native requestAnimationFrame functionality is tested in Util.html and
* in PanZoom.html (where a popup is opened before panning). The panTo tests
* here will test the fallback setTimeout implementation for animation.
*/
window.requestAnimationFrame =
window.webkitRequestAnimationFrame =
window.mozRequestAnimationFrame =
window.oRequestAnimationFrame =
window.msRequestAnimationFrame = null;
</script>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var map, layer;
function setUp() {
layer = new OpenLayers.Layer.UTFGrid({
url: "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json",
isBaseLayer: true,
utfgridResolution: 4
});
map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
layers: [layer],
center: [0, 0],
zoom: 1
});
}
function tearDown() {
map.destroy();
map = null;
layer = null;
}
function test_constructor(t) {
t.plan(4);
var layer = new OpenLayers.Layer.UTFGrid({
name: "foo",
url: "path/to/tiles/${z}/${x}/${y}",
utfgridResolution: 8
});
t.ok(layer instanceof OpenLayers.Layer.UTFGrid, "utfgrid instance");
t.eq(layer.name, "foo", "layer name");
t.eq(layer.url, "path/to/tiles/${z}/${x}/${y}", "layer url");
t.eq(layer.utfgridResolution, 8, "layer utfgridResolution");
layer.destroy();
}
function test_clone(t) {
t.plan(3);
setUp();
var clone = layer.clone();
t.ok(layer instanceof OpenLayers.Layer.UTFGrid, "utfgrid instance");
t.eq(layer.url, "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json", "layer url");
t.eq(layer.utfgridResolution, 4, "layer utfgridResolution");
clone.destroy();
tearDown();
}
function test_getFeatureInfo(t) {
t.plan(2);
setUp();
// wait for tile loading to finish
t.delay_call(0.5, function() {
var loc = new OpenLayers.LonLat(-110, 45).transform("EPSG:4326", "EPSG:900913");
var info = layer.getFeatureInfo(loc);
t.eq(info.id, "207", "feature id");
t.eq(info.data, {POP2005: 299846449, NAME: "United States"}, "feature data");
tearDown();
});
}
function test_getFeatureId(t) {
t.plan(2);
setUp();
// wait for tile loading to finish
t.delay_call(0.5, function() {
var ca = new OpenLayers.LonLat(-110, 55).transform("EPSG:4326", "EPSG:900913");
var ru = new OpenLayers.LonLat(90, 75).transform("EPSG:4326", "EPSG:900913");
t.eq(layer.getFeatureId(ca), "24", "feature id for ca");
t.eq(layer.getFeatureId(ru), "245", "feature id for ru");
tearDown();
});
}
</script>
</head>
<body>
<div id="map" style="height: 256px; width: 512px"></div>
</body>
</html>

View File

@@ -917,7 +917,32 @@
"featuresadded event received expected number of features");
}
function test_redraw(t) {
t.plan(2);
// test that when redraw is called on a vector layer then
// moveTo gets called on the layer and receives zoomChanged
// true
var log = [];
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.Vector("vector", {isBaseLayer: true});
map.addLayer(layer);
map.setCenter([0, 0], 5);
layer.moveTo = function(extent, zoomChanged) {
log.push(zoomChanged);
};
layer.redraw();
t.eq(log.length, 1, "redraw makes moveTo be called once");
if (log.length == 1) {
t.eq(log[0], true, "redraw makes moveTo be called with zoomChanged true");
}
map.destroy();
}
</script>
</head>

View File

@@ -3,11 +3,13 @@
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_OpenLayers(t) {
t.plan(1);
var script = document.getElementById("script");
t.plan(3);
t.eq(OpenLayers._getScriptLocation(), "../", "Script location correctly detected.");
t.ok(OpenLayers.ImgPath !== undefined, "An ImgPath property exists.");
t.eq(OpenLayers.ImgPath, '', "The default for OpenLayers.ImgPath is the empty string.");
}
</script>
</head>

View File

@@ -6,7 +6,7 @@
var geometry = null, node = null;
function test_VML_constructor(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -17,7 +17,7 @@
}
function test_VML_destroy(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -43,7 +43,7 @@
}
function test_VML_setextent(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -80,7 +80,7 @@
}
function test_VML_setsize(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -99,7 +99,7 @@
}
function test_VML_drawText(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -128,7 +128,7 @@
}
function test_VML_drawpoint(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -149,7 +149,7 @@
}
function test_VML_drawcircle(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -177,7 +177,7 @@
}
function test_VML_drawGraphic(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -219,7 +219,7 @@
}
function test_VML_drawlinestring(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -239,7 +239,7 @@
}
function test_VML_drawlinearring(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -259,7 +259,7 @@
}
function test_VML_drawline(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -300,7 +300,7 @@
}
function test_VML_drawpolygon(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -331,7 +331,7 @@
}
function test_VML_drawrectangle(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -360,7 +360,7 @@
}
function test_vml_getnodetype(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -376,7 +376,7 @@
}
function test_vml_importsymbol(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -405,7 +405,7 @@
}
function test_vml_dashstyle(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}
@@ -422,7 +422,7 @@
}
function test_vml_moveRoot(t) {
if (!OpenLayers.Renderer.VML.prototype.supported()) {
if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
t.plan(0);
return;
}

View File

@@ -50,7 +50,7 @@
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
"../../img/blank.gif", {layers: 'basic'});
map.addLayer(layer);
var position = new OpenLayers.Pixel(20,30);
@@ -87,7 +87,7 @@
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS(
"Name",
"http://labs.metacarta.com/TESTURL?",
"../../img/blank.gif",
{layers: 'basic'}, {async: true, getURLasync: function(bounds, callback, scope) {
callback.call(scope, this.getURL(bounds));
}}
@@ -99,7 +99,9 @@
tile = layer.addTile(bounds, position);
tile.renderTile();
t.delay_call(0.1, function() {
t.eq(tile.imgDiv.src, layer.getURL(bounds), "image src correct for async request");
var expected = new Image();
expected.src = layer.getURL(bounds);
t.eq(tile.imgDiv.src, expected.src, "image src correct for async request");
t.eq(tile.asyncRequestId, 1, "asyncRequestId correct after renderTile");
tile.renderTile();
});
@@ -118,7 +120,7 @@
var size = new OpenLayers.Size(5,6);
layer = new OpenLayers.Layer.WMS("Name",
"http://labs.metacarta.com/TESTURL",
"../../img/blank.gif",
null,
{tileSize: size});
map.addLayer(layer);
@@ -154,10 +156,10 @@
SRS: "EPSG:4326", BBOX: [1,2,3,4],
WIDTH: String(size.w), HEIGHT: String(size.h)
};
var expected = new Image();
expected.src = "../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams)
t.delay_call(0.1, function() {
t.eq( img.src,
"http://labs.metacarta.com/TESTURL?" + OpenLayers.Util.getParameterString(tParams),
"tile.draw creates an image");
t.eq( img.src, expected.src, "tile.draw creates an image");
});
t.eq( tile.imgDiv.style.width, "5%", "Image width is correct" );
t.eq( tile.imgDiv.style.height, "6%", "Image height is correct" );
@@ -176,7 +178,7 @@
var size = new OpenLayers.Size(5,6);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {reproject:false, encodeBBOX: true});
"../../img/blank.gif", {layers: 'basic'}, {reproject:false, encodeBBOX: true});
map.addLayer(layer);
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-185,-90,-180,90), url, size);
tile.draw()
@@ -191,31 +193,31 @@
WIDTH: "256", HEIGHT: "256"
};
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Images over edges of maxextent do load");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-181,-90,180,90), url, size);
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-181,-90,180,90"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Images over edges of maxextent do load");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-180,-90,180,90), url, size);
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-180,-90,180,90"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Image covering all of extent loads");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-80,-45,80,45), url, size);
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-80,-45,80,45"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Image covering small part of extent loads");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-185,-95,185,95), url, size);
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-185,-95,185,95"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Image covering more than all of extent loads");
layer.displayOutsideMaxExtent=1;
@@ -223,31 +225,31 @@
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-185,-90,-180,90"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Images against side of maxextent do load with displayOutsideMaxExtent");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-181,-90,180,90), url, size);
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-181,-90,180,90"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Images over edges of maxextent do load with displayOutsideMaxExtent set");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-180,-90,180,90), url, size);
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-180,-90,180,90"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Image covering all of extent loads with display outside max extent");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-80,-45,80,45), url, size);
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-80,-45,80,45"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Image covering small part of extent loads with display outside max extent");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-185,-95,185,95), url, size);
tile.draw()
tParams = OpenLayers.Util.extend(tParams, {BBOX: "-185,-95,185,95"});
t.eq(tile.url,
"http://labs.metacarta.com/wms/vmap0?" + OpenLayers.Util.getParameterString(tParams),
"../../img/blank.gif?" + OpenLayers.Util.getParameterString(tParams),
"Image covering more than all of extent loads");
}
function test_Tile_Image_Display_After_Move(t) {
@@ -258,7 +260,7 @@
var size = new OpenLayers.Size(5,6);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
"../../img/blank.gif", {layers: 'basic'});
map.addLayer(layer);
map.zoomToMaxExtent();
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-90,-85,-90,85), url, size);
@@ -266,7 +268,7 @@
tile.moveTo(new OpenLayers.Bounds(-185,-90,-180,-80), new OpenLayers.Pixel(-180,-85), true);
t.delay_call( 1, function() { t.eq(tile.imgDiv.style.visibility, "hidden", "Tile image is invisible.") } );
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {'alpha':true});
"../../img/blank.gif", {layers: 'basic'}, {'alpha':true});
map.addLayer(layer);
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-90,-85,-90,85), url, size);
tile.draw();
@@ -326,7 +328,7 @@
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
"../../img/blank.gif", {layers: 'basic'});
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
var tile = layer.grid[0][0];
@@ -351,7 +353,7 @@
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {opacity: 0.5});
"../../img/blank.gif", {layers: 'basic'}, {opacity: 0.5});
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
@@ -378,7 +380,7 @@
t.plan(6);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS("invalid", "", {layers: 'basic'});
var layer = new OpenLayers.Layer.WMS("invalid", "foo", {layers: 'basic'});
map.addLayer(layer);
var size = new OpenLayers.Size(5, 6);
@@ -426,8 +428,8 @@
t.plan(1);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
var layer = new OpenLayers.Layer.WMS("blank",
"../../img/blank.gif", {layers: 'fake'});
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0, 0), 5);

305
tests/Tile/UTFGrid.html Normal file
View File

@@ -0,0 +1,305 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
/**
* Because browsers that implement requestAnimationFrame may not execute
* animation functions while a window is not displayed (e.g. in a hidden
* iframe as in these tests), we mask the native implementations here. The
* native requestAnimationFrame functionality is tested in Util.html and
* in PanZoom.html (where a popup is opened before panning). The panTo tests
* here will test the fallback setTimeout implementation for animation.
*/
window.requestAnimationFrame =
window.webkitRequestAnimationFrame =
window.mozRequestAnimationFrame =
window.oRequestAnimationFrame =
window.msRequestAnimationFrame = null;
</script>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var map, layer;
function setUp() {
layer = new OpenLayers.Layer.UTFGrid({
url: "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json",
isBaseLayer: true,
utfgridResolution: 4
});
map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
layers: [layer],
center: [0, 0],
zoom: 1
});
}
function tearDown() {
map.destroy();
map = null;
layer = null;
}
function test_constructor(t) {
t.plan(7);
setUp();
var position = new OpenLayers.Pixel(20, 30);
var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
var url = "http://example.com/";
var size = new OpenLayers.Size(5, 6);
var tile = new OpenLayers.Tile.UTFGrid(layer, position, bounds, url, size);
t.ok(tile instanceof OpenLayers.Tile, "tile instance");
t.ok(tile instanceof OpenLayers.Tile.UTFGrid, "UTFGrid tile instance");
t.ok(tile.layer === layer, "layer set");
t.ok(tile.position.equals(position), "position set");
t.ok(tile.bounds.equals(bounds), "bounds set");
t.eq(tile.url, url, "url set");
t.ok(tile.size.equals(size), "size set");
tearDown();
}
function test_parseData(t) {
t.plan(2);
setUp();
var tile = layer.grid[0][0];
tile.parseData('{"foo": "bar"}');
t.eq(tile.json, {foo: "bar"}, "valid json parsed");
var err, obj;
try {
obj = tile.parseData('foo bar');
} catch (e) {
err = e;
}
// The JSON format doesn't actually throw on IE6, so we also check
// for undefined here.
t.ok(err instanceof Error || obj === undefined, "throws on invalid json");
tearDown();
}
function test_draw(t) {
t.plan(7);
setUp();
var position = new OpenLayers.Pixel(20, 30);
var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
var url = "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json";
var size = new OpenLayers.Size(256, 256);
var tile = new OpenLayers.Tile.UTFGrid(layer, position, bounds, url, size);
var log = [];
function logger(event) {
log.push(event);
}
tile.events.on({
loadstart: logger,
reload: logger,
loadend: logger
});
t.eq(log.length, 0, "no events logged");
// start tile loading
tile.draw();
t.eq(log.length, 1, "[first draw] one event");
t.eq(log[0].type, "loadstart", "[first draw] loadstart");
// restart tile loading
log.length = 0;
tile.draw();
t.eq(log.length, 1, "[second draw] first event");
t.eq(log[0].type, "reload", "[second draw] reload");
// wait for tile loading to finish
t.delay_call(1, function() {
t.eq(log.length, 2, "[second draw] second event");
t.eq(log[1].type, "loadend", "[second draw] loadend");
tearDown();
});
}
function test_abortLoading(t) {
t.plan(7);
setUp();
var position = new OpenLayers.Pixel(20, 30);
var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
var url = "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json";
var size = new OpenLayers.Size(256, 256);
var tile = new OpenLayers.Tile.UTFGrid(layer, position, bounds, url, size);
var log = [];
function logger(event) {
log.push(event);
}
tile.events.on({
loadstart: logger,
reload: logger,
loadend: logger
});
t.eq(log.length, 0, "no events logged");
// start tile loading
tile.draw();
t.eq(log.length, 1, "[first draw] one event");
t.eq(log[0].type, "loadstart", "[first draw] loadstart");
// abort tile loading
log.length = 0;
tile.abortLoading();
t.eq(log.length, 0, "[first abort] no events logged"); // TODO: does anybody need an abort event?
// abort again for the heck of it
var err;
try {
tile.abortLoading();
} catch (e) {
err = e;
}
t.ok(!err, "[second abort] no trouble");
t.eq(log.length, 0, "[second abort] no events");
// wait to confirm tile loading doesn't happen after abort
t.delay_call(1, function() {
t.eq(log.length, 0, "[wait] no events");
tearDown();
});
}
function test_getFeatureId(t) {
t.plan(3);
setUp();
var tile = layer.grid[1][1];
t.delay_call(0.5, function() {
var id = tile.getFeatureId(16, 60);
t.eq(id, "238", "feature 238 at 16, 60");
t.eq(tile.getFeatureId(18, 63), id, "same feature at 18, 63");
t.eq(tile.getFeatureId(300, 10), null, "null id outside tile");
tearDown();
});
}
function test_getFeatureInfo(t) {
t.plan(3);
setUp();
var tile = layer.grid[1][1];
t.delay_call(0.5, function() {
var info = tile.getFeatureInfo(16, 60);
var exp = {
id: "238",
data: {
NAME: "Svalbard",
POP2005: 0
}
};
t.eq(info, exp, "feature info at 16, 60");
t.eq(tile.getFeatureInfo(17, 62), exp, "same feature at 17, 62");
t.eq(tile.getFeatureInfo(300, 10), null, "undefined outside tile");
tearDown();
});
}
// While I dislike committing tests that aren't run, I'd like to make an
// exception here. This test (or something like it) should pass. When
// https://github.com/mapbox/utfgrid-spec/issues/1 is resolved, we should
// either modify this or update demo.json and enable the test.
function xtest_getFeatureId_demo(t) {
/**
* The UTFGrid 1.2 spec (https://github.com/mapbox/utfgrid-spec/blob/master/1.2/utfgrid.md)
* links to a demo.json to be used for testing implementations. This
* file is constructed with 256x256 data points. Each data point maps
* to a "feature id" using this heuristic:
*
* // x and y are pixel offsets from top left of 256x256 tile
* if (y < 255 || x < 222) {
* id = (y * 256) + x
* } else {
* id = 65501; // max number of ids that can be encoded
* }
*/
t.plan(1);
setUp();
// look at this beauty of a constructor
var tile = new OpenLayers.Tile.UTFGrid(
layer, // layer
new OpenLayers.Pixel(0, 0), // position
new OpenLayers.Bounds(0, 0, 256, 256), // bounds
"../data/utfgrid/demo-1.1.json", // url
new OpenLayers.Size(256, 256), // size
{utfgridResolution: 1} // options
);
var err;
var request = new OpenLayers.Request.GET({
url: tile.url,
success: function(req) {
try {
tile.parseData(req.responseText);
} catch (e) {
err = e;
}
},
failure: function(req) {
err = new Error("Failed to fetch json. Status: " + req.status);
}
});
// wait for response and parsing, then make assertions
t.delay_call(1, function() {
if (err) {
t.fail(err);
} else {
var got, exp, failure;
outer: for (var y=0; y<256; ++y) {
for (var x=0; x<256; ++x) {
if (y<255 || x<222) {
exp = String((y * 256) + x);
} else {
exp = "65501";
}
got = tile.getFeatureId(x, y);
if (got !== exp) {
failure = "Failed to get id for (" + x + ", " + y + "): " +
"got " + got + " but expected " + exp;
break outer;
}
}
}
if (!failure) {
t.ok(true, "resolved feature ids for all data points");
} else {
t.fail(failure);
}
}
tearDown();
});
}
</script>
</head>
<body>
<div id="map" style="height:550px;width:500px"></div>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -0,0 +1 @@
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}

View File

@@ -41,6 +41,7 @@
<li>Control/Split.html</li>
<li>Control/TouchNavigation.html</li>
<li>Control/TransformFeature.html</li>
<li>Control/UTFGrid.html</li>
<li>Control/WMSGetFeatureInfo.html</li>
<li>Control/WMTSGetFeatureInfo.html</li>
<li>Control/PanPanel.html</li>
@@ -165,6 +166,7 @@
<li>Layer/Text.html</li>
<li>Layer/TileCache.html</li>
<li>Layer/TMS.html</li>
<li>Layer/UTFGrid.html</li>
<li>Layer/Vector.html</li>
<li>Layer/Vector/RootContainer.html</li>
<li>Layer/WMS.html</li>
@@ -220,6 +222,7 @@
<li>Tile.html</li>
<li>Tile/Image.html</li>
<li>Tile/Image/IFrame.html</li>
<li>Tile/UTFGrid.html</li>
<li>Tween.html</li>
<li>Kinetic.html</li>
<li>Util.html</li>