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

View File

@@ -169,14 +169,13 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
this.lastXy = evt.xy;
}
var newHtml = this.formatOutput(lonLat);
var layers = this.findLayers();
if (layers.length > 0) {
var layer;
for (var i=0, len=layers.length; i<len; i++) {
layer = layers[i];
var info = layer.getTileInfo( lonLat );
//MP TODO make function
if (this.debugElement) {
var debug = "<ul>";
debug += "<li>i :" + info.i + "</li>";
@@ -192,7 +191,7 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
}
var tile = info.tile;
/*
TODO Sanity checks
MP TODO Sanity checks
if ((Math.floor(info.i) >= tileSize) ||
(Math.floor(info.j) >= tileSize)) alert("TOO BIG");
*/
@@ -217,6 +216,7 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
/**
* Method: callback
* MP TODO
* Takes the attrs and does somethings with them
* 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
* Internal method to get the layers, independent of whether we are
* inspecting the map or using a client-provided array
* MP TODO respect list of user-supplied candidates
*/
findLayers: function() {
var candidates = this.layers || this.map.layers;

View File

@@ -9,7 +9,7 @@
/**
* Class: OpenLayers.Layer.UTFGrid
* TODO
* MP TODO
*
* Inherits from:
* - <OpenLayers.Layer.Grid>
@@ -26,7 +26,8 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
* APIProperty: sphericalMecator
* Whether the tile extents should be set to the defaults for
* 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,
@@ -143,7 +144,9 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
* loc - {<OpenLayers.LonLat} A location in map coordinates.
*
* 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
* i and j values are the number of pixels to the left and top
* (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
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?
var gridColOffset =
(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];
return {
globalCol: globalCol,
globalRow: globalRow,
@@ -195,7 +197,7 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
/**
* APIProperty: tileClass
* {<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,
@@ -216,9 +218,10 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
var y = Math.round((this.maxExtent.top - bounds.top) /
(res * this.tileSize.h));
var resolutions = this.serverResolutions || this.resolutions;
var z = this.zoomOffset == 0 ?
OpenLayers.Util.indexOf(resolutions, res) :
this.getServerZoom() + this.zoomOffset;
var z = this.getServerZoom();
if (this.zoomOffset > 0) {
z += this.zoomOffset;
}
var limit = Math.pow(2, z);
if (this.wrapDateLine)

View File

@@ -11,7 +11,9 @@
/**
* Class: OpenLayers.Tile.UTFGrid
* 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.
*
* Inherits from:
@@ -69,6 +71,7 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
* MP TODO what do we need to clear for the utfgrid implementation?
*/
destroy: function() {
if (this.imgDiv) {
@@ -90,6 +93,7 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
*/
draw: function() {
var drawn = OpenLayers.Tile.prototype.draw.apply(this, arguments);
console.log(drawn);
if (drawn) {
if (this.isLoading) {
//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) {
console.log(e);
@@ -122,9 +126,7 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, {
var res = ols.read();
console.log(res.priv);
*/
this.positionTile();
//this.renderTile();
} else {
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
* 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
* MP TODO remove the json from the DOM!
* Remove the tile from the DOM, clear it of any image related data so that
* it can be reused in a new location.
*/