added 'drawn' property to all tiles. removed redraw() and adapted all draw()s to auto handle redraw. remove getPosition() accessor that noone was using. set generic Tile's moveTo() to auto trigger the clear() and the redraw() (if desired). Update Image and WFS tile classes correspondingly. also update tests

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1198 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-08-12 15:54:51 +00:00
parent 0a04ee3d1b
commit 96c56e9d84
4 changed files with 105 additions and 93 deletions

View File

@@ -32,6 +32,9 @@ OpenLayers.Tile.prototype = {
* @type OpenLayers.Pixel */
position:null,
/** @type Boolean */
drawn: false,
/**
* @constructor
*
@@ -66,36 +69,33 @@ OpenLayers.Tile.prototype = {
/**
*/
draw:function() {
},
redraw: function () {
this.draw();
this.drawn = true;
},
/**
* @param {OpenLayers.Bounds}
* @param {OpenLayers.pixel} position
* @param {Boolean} redraw Redraw tile after moving?
* Default is true
*/
moveTo: function (bounds, position) {
moveTo: function (bounds, position, redraw) {
if (redraw == null) {
redraw = true;
}
this.clear();
this.bounds = bounds.clone();
this.position = position.clone();
this.redraw();
if (redraw) {
this.draw();
}
},
/** Clear the tile of any bounds/position-related data so that it can
* be reused in a new location.
*/
clear: function() {
this.bounds = null;
this.position = null;
},
/**
* @type OpenLayers.Pixel
*/
getPosition: function() {
return this.position;
this.drawn = false;
},
/** @final @type String */

View File

@@ -1,7 +1,9 @@
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
* text of the license. */
// @require: OpenLayers/Tile.js
/**
* @class
*/
@@ -25,6 +27,9 @@ OpenLayers.Tile.Image.prototype =
OpenLayers.Tile.prototype.initialize.apply(this, arguments);
},
/**
*
*/
destroy: function() {
if ((this.imgDiv != null) && (this.imgDiv.parentNode == this.layer.div)) {
this.layer.div.removeChild(this.imgDiv);
@@ -34,46 +39,15 @@ OpenLayers.Tile.Image.prototype =
},
/**
*/
*
*/
draw:function() {
if (this.layer.alpha) {
this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null,
this.position,
this.size,
this.url,
"absolute",
null,
null,
true);
} else {
this.imgDiv = OpenLayers.Util.createImage(null,
this.position,
this.size,
this.url,
"absolute",
null,
true);
OpenLayers.Tile.prototype.draw.apply(this, arguments);
if (this.imgDiv == null) {
this.initImgDiv();
}
this.layer.div.appendChild(this.imgDiv);
},
/** Clear the tile of any bounds/position-related data so that it can
* be reused in a new location.
*/
clear: function() {
this.imgDiv.style.display = "none";
},
/**
* @param {OpenLayers.Bounds}
* @param {OpenLayers.pixel} position
*/
moveTo: function (bounds, position) {
this.url = this.layer.getURL(bounds);
OpenLayers.Tile.prototype.moveTo.apply(this, arguments);
},
redraw: function () {
this.imgDiv.style.display = "none";
if (this.layer.alpha) {
OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv,
@@ -85,6 +59,49 @@ OpenLayers.Tile.Image.prototype =
}
},
/** Clear the tile of any bounds/position-related data so that it can
* be reused in a new location.
*/
clear: function() {
OpenLayers.Tile.prototype.clear.apply(this, arguments);
this.imgDiv.style.display = "none";
},
/**
* @param {OpenLayers.Bounds}
* @param {OpenLayers.pixel} position
* @param {Boolean} redraw
*/
moveTo: function (bounds, position, redraw) {
this.url = this.layer.getURL(bounds);
OpenLayers.Tile.prototype.moveTo.apply(this, arguments);
},
/**
*
*/
initImgDiv: function() {
if (this.layer.alpha) {
this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null,
this.position,
this.size,
null,
"absolute",
null,
null,
true);
} else {
this.imgDiv = OpenLayers.Util.createImage(null,
this.position,
this.size,
null,
"absolute",
null,
true);
}
this.layer.div.appendChild(this.imgDiv);
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Tile.Image"
}

View File

@@ -39,36 +39,29 @@ OpenLayers.Tile.WFS.prototype =
*
*/
destroy: function() {
this.clear();
this.urls = null;
OpenLayers.Tile.prototype.destroy.apply(this, arguments);
this.destroyAllFeatures();
this.features = null;
this.urls = null;
},
/** Clear the tile of any bounds/position-related data so that it can
* be reused in a new location.
*/
clear: function() {
while(this.features.length > 0) {
var feature = this.features.shift();
feature.destroy();
}
OpenLayers.Tile.prototype.clear.apply(this, arguments);
this.destroyAllFeatures();
},
/**
*/
draw:function() {
this.loadFeaturesForRegion(this.requestSuccess);
},
/**
* @param {OpenLayers.Bounds}
* @param {OpenLayers.pixel} position
*
*/
moveTo: function (bounds, position) {
this.loaded = false;
OpenLayers.Tile.prototype.moveTo.apply(this, arguments);
draw:function() {
if (this.drawn) {
this.clear();
}
OpenLayers.Tile.prototype.draw.apply(this, arguments);
this.loadFeaturesForRegion(this.requestSuccess);
},
/** get the full request string from the ds and the tile params
@@ -81,22 +74,13 @@ OpenLayers.Tile.WFS.prototype =
*/
loadFeaturesForRegion:function(success, failure) {
if (!this.loaded) {
if (this.urls != null) {
if (this.urls != null) {
// TODO: Hmmm, this stops multiple loads of the data when a
// result isn't immediately retrieved, but it's hacky.
// Do it better.
this.loaded = true;
for(var i=0; i < this.urls.length; i++) {
var params ={ BBOX:bounds.toBBOX() };
var url = this.urls[i] +
OpenLayers.Util.getParameterString(params);
OpenLayers.loadURL(url, null, this,
success, failure);
}
for(var i=0; i < this.urls.length; i++) {
var params = { BBOX:bounds.toBBOX() };
var url = this.urls[i] +
OpenLayers.Util.getParameterString(params);
OpenLayers.loadURL(url, null, this, success, failure);
}
}
},
@@ -121,14 +105,23 @@ OpenLayers.Tile.WFS.prototype =
* @param {Object} results
*/
addResults: function(results) {
for (var i=0; i < results.length; i++) {
var feature = new this.layer.featureClass(this.layer,
results[i]);
this.features.push(feature);
}
},
/** Iterate through and call destroy() on each feature, removing it from
* the local array
*
* @private
*/
destroyAllFeatures: function() {
while(this.features.length > 0) {
var feature = this.features.shift();
feature.destroy();
}
},
/** @final @type String */

View File

@@ -8,7 +8,9 @@
function test_01_Tile_Image_constructor (t) {
t.plan( 6 );
var layer = new Object(); //bogus layer
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
var position = new OpenLayers.Pixel(20,30);
var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "http://www.openlayers.org/dev/tests/tileimage";
@@ -16,7 +18,7 @@
tile = new OpenLayers.Tile.Image(layer, position, bounds, url, size);
t.ok( tile instanceof OpenLayers.Tile.Image, "new OpenLayers.Tile returns Tile object" );
t.eq( tile.layer, layer, "tile.layer is set correctly");
t.ok( tile.layer == layer, "tile.layer is set correctly");
t.ok( tile.position.equals(position), "tile.position is set correctly");
t.ok( tile.bounds.equals(bounds), "tile.bounds is set correctly");
t.eq( tile.url, url, "tile.url is set correctly");