Fix a problem determining zoom levels. Updated some docs.

This commit is contained in:
Matthew Perry
2012-02-06 09:06:49 -08:00
parent 6ff3b895c9
commit 8aaaecc9ee
3 changed files with 23 additions and 59 deletions
+4 -21
View File
@@ -169,14 +169,13 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
this.lastXy = evt.xy; this.lastXy = evt.xy;
} }
var newHtml = this.formatOutput(lonLat);
var layers = this.findLayers(); var layers = this.findLayers();
if (layers.length > 0) { if (layers.length > 0) {
var layer; var layer;
for (var i=0, len=layers.length; i<len; i++) { for (var i=0, len=layers.length; i<len; i++) {
layer = layers[i]; layer = layers[i];
var info = layer.getTileInfo( lonLat ); var info = layer.getTileInfo( lonLat );
//MP TODO make function
if (this.debugElement) { if (this.debugElement) {
var debug = "<ul>"; var debug = "<ul>";
debug += "<li>i :" + info.i + "</li>"; debug += "<li>i :" + info.i + "</li>";
@@ -192,7 +191,7 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
} }
var tile = info.tile; var tile = info.tile;
/* /*
TODO Sanity checks MP TODO Sanity checks
if ((Math.floor(info.i) >= tileSize) || if ((Math.floor(info.i) >= tileSize) ||
(Math.floor(info.j) >= tileSize)) alert("TOO BIG"); (Math.floor(info.j) >= tileSize)) alert("TOO BIG");
*/ */
@@ -217,6 +216,7 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
/** /**
* Method: callback * Method: callback
* MP TODO
* Takes the attrs and does somethings with them * Takes the attrs and does somethings with them
* this is a default (intended to be overridden) * this is a default (intended to be overridden)
*/ */
@@ -259,28 +259,11 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
} }
}, },
/**
* Method: formatOutput
* Override to provide custom display output
*
* Parameters:
* lonLat - {<OpenLayers.LonLat>} Location to display
*/
formatOutput: function(lonLat) {
var digits = parseInt(this.numDigits);
var newHtml =
this.prefix +
lonLat.lon.toFixed(digits) +
this.separator +
lonLat.lat.toFixed(digits) +
this.suffix;
return newHtml;
},
/** /**
* Method: findLayers * Method: findLayers
* Internal method to get the layers, independent of whether we are * Internal method to get the layers, independent of whether we are
* inspecting the map or using a client-provided array * inspecting the map or using a client-provided array
* MP TODO respect list of user-supplied candidates
*/ */
findLayers: function() { findLayers: function() {
var candidates = this.layers || this.map.layers; var candidates = this.layers || this.map.layers;
+12 -9
View File
@@ -9,7 +9,7 @@
/** /**
* Class: OpenLayers.Layer.UTFGrid * Class: OpenLayers.Layer.UTFGrid
* TODO * MP TODO
* *
* Inherits from: * Inherits from:
* - <OpenLayers.Layer.Grid> * - <OpenLayers.Layer.Grid>
@@ -26,7 +26,8 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
* APIProperty: sphericalMecator * APIProperty: sphericalMecator
* Whether the tile extents should be set to the defaults for * Whether the tile extents should be set to the defaults for
* spherical mercator. Useful for things like OpenStreetMap. * spherical mercator. Useful for things like OpenStreetMap.
* Default is false, except for the OSM subclass. * Default is true as most (all?) utfgrid implementations assume
* sperical mercator.
*/ */
sphericalMercator: false, sphericalMercator: false,
@@ -143,7 +144,9 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
* loc - {<OpenLayers.LonLat} A location in map coordinates. * loc - {<OpenLayers.LonLat} A location in map coordinates.
* *
* Returns: * Returns:
* {Object} An object with "col", "row", "i", and "j" properties. The col * {Object} An object with
* MP TODO
* "col", "row", "i", and "j" properties. The col
* and row values are zero based tile indexes from the top left. The * and row values are zero based tile indexes from the top left. The
* i and j values are the number of pixels to the left and top * i and j values are the number of pixels to the left and top
* (respectively) of the given location within the target tile. * (respectively) of the given location within the target tile.
@@ -159,7 +162,7 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
// Get the current grid offset // Get the current grid offset
var gridOrigin = this.grid[0][0].bounds; var gridOrigin = this.grid[0][0].bounds;
// TODO rounding errors can cause intermittent problems (4.9999 should be 5) // MP TODO rounding errors can cause intermittent problems (4.9999 should be 5)
// flooring will cause big problems (4.999 becomes 4)... do round or toFixed later? // flooring will cause big problems (4.999 becomes 4)... do round or toFixed later?
var gridColOffset = var gridColOffset =
(gridOrigin.left - this.tileOrigin.lon) / (res * this.tileSize.w); (gridOrigin.left - this.tileOrigin.lon) / (res * this.tileSize.w);
@@ -177,7 +180,6 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
var tile = this.grid[gridRow][gridCol]; var tile = this.grid[gridRow][gridCol];
return { return {
globalCol: globalCol, globalCol: globalCol,
globalRow: globalRow, globalRow: globalRow,
@@ -195,7 +197,7 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
/** /**
* APIProperty: tileClass * APIProperty: tileClass
* {<OpenLayers.Tile>} The tile class to use for this layer. * {<OpenLayers.Tile>} The tile class to use for this layer.
* Defaults is OpenLayers.Tile (not Tile.Image) * Defaults is OpenLayers.Tile.UTFGrid (not Tile.Image)
*/ */
tileClass: OpenLayers.Tile.UTFGrid, tileClass: OpenLayers.Tile.UTFGrid,
@@ -216,9 +218,10 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
var y = Math.round((this.maxExtent.top - bounds.top) / var y = Math.round((this.maxExtent.top - bounds.top) /
(res * this.tileSize.h)); (res * this.tileSize.h));
var resolutions = this.serverResolutions || this.resolutions; var resolutions = this.serverResolutions || this.resolutions;
var z = this.zoomOffset == 0 ? var z = this.getServerZoom();
OpenLayers.Util.indexOf(resolutions, res) : if (this.zoomOffset > 0) {
this.getServerZoom() + this.zoomOffset; z += this.zoomOffset;
}
var limit = Math.pow(2, z); var limit = Math.pow(2, z);
if (this.wrapDateLine) if (this.wrapDateLine)
+7 -29
View File
@@ -11,7 +11,9 @@
/** /**
* Class: OpenLayers.Tile.UTFGrid * Class: OpenLayers.Tile.UTFGrid
* Instances of OpenLayers.Tile.UTFGrid are used to manage the image tiles * Instances of OpenLayers.Tile.UTFGrid are used to manage the image tiles
* TODO * MP TODO
* IMPORTANT - remove all traces of IMAGES
*
* <OpenLayers.Tile.UTFGrid> constructor. * <OpenLayers.Tile.UTFGrid> constructor.
* *
* Inherits from: * Inherits from:
@@ -69,6 +71,7 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
/** /**
* APIMethod: destroy * APIMethod: destroy
* nullify references to prevent circular references and memory leaks * nullify references to prevent circular references and memory leaks
* MP TODO what do we need to clear for the utfgrid implementation?
*/ */
destroy: function() { destroy: function() {
if (this.imgDiv) { if (this.imgDiv) {
@@ -90,6 +93,7 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
*/ */
draw: function() { draw: function() {
var drawn = OpenLayers.Tile.prototype.draw.apply(this, arguments); var drawn = OpenLayers.Tile.prototype.draw.apply(this, arguments);
console.log(drawn);
if (drawn) { if (drawn) {
if (this.isLoading) { if (this.isLoading) {
//if we're already loading, send 'reload' instead of 'loadstart'. //if we're already loading, send 'reload' instead of 'loadstart'.
@@ -108,7 +112,7 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
}); });
/* /*
* TODO Investigate JSONP method to avoid xbrowser polucy * MP TODO Investigate JSONP method to avoid xbrowser polucy
* *
grid = function(e) { grid = function(e) {
console.log(e); console.log(e);
@@ -122,9 +126,7 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
var res = ols.read(); var res = ols.read();
console.log(res.priv); console.log(res.priv);
*/ */
this.positionTile(); this.positionTile();
//this.renderTile();
} else { } else {
this.unload(); this.unload();
} }
@@ -145,31 +147,6 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
} }
}, },
/**
* Method: renderTile
* Internal function to actually initialize the image tile,
* position it correctly, and set its url.
*/
renderTile: function() {
this.layer.div.appendChild(this.getTile());
if (this.layer.async) {
// Asynchronous image requests call the asynchronous getURL method
// on the layer to fetch an image that covers 'this.bounds', in the scope of
// 'this', setting the 'url' property of the layer itself, and running
// the callback 'initImage' when the image request returns.
var myId = this.asyncRequestId = (this.asyncRequestId || 0) + 1;
this.layer.getURLasync(this.bounds, this, "url", function() {
if (myId == this.asyncRequestId) {
this.initImage();
}
});
} else {
// synchronous image requests get the url immediately.
this.url = this.layer.getURL(this.bounds);
this.initImage();
}
},
/** /**
* Method: positionTile * Method: positionTile
* Using the properties currenty set on the layer, position the tile correctly. * Using the properties currenty set on the layer, position the tile correctly.
@@ -186,6 +163,7 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
/** /**
* Method: clear * Method: clear
* MP TODO remove the json from the DOM!
* Remove the tile from the DOM, clear it of any image related data so that * Remove the tile from the DOM, clear it of any image related data so that
* it can be reused in a new location. * it can be reused in a new location.
*/ */