[OpenLayers-Commits] r2296 - in sandbox/emanuel/animatedZooming/lib/OpenLayers: . Control Layer Layer/WMS
commits at openlayers.org
commits at openlayers.org
Fri Mar 2 09:53:35 EST 2007
Author: emanuel
Date: 2007-03-02 09:53:32 -0500 (Fri, 02 Mar 2007)
New Revision: 2296
Modified:
sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseDefaults.js
sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseToolbar.js
sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js
sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js
sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Image.js
sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/WMS/Untiled.js
sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js
sandbox/emanuel/animatedZooming/lib/OpenLayers/Util.js
Log:
round scale values; zoom image layer fixed; zoomanimationActive with dblclick and zoombox
Modified: sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseDefaults.js
===================================================================
--- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseDefaults.js 2007-03-02 11:00:20 UTC (rev 2295)
+++ sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseDefaults.js 2007-03-02 14:53:32 UTC (rev 2296)
@@ -68,22 +68,21 @@
* @param {Event} evt
*/
defaultDblClick: function (evt) {
- //var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
- //this.map.setCenter(newCenter, this.map.zoom + 1);
+ if (!this.map.zoomanimationActive){
+ // convert the (old) center of the map in pixel
+ var centerPx = this.map.getPixelFromLonLat(this.map.getCenter());
+
+ // pan to new center
+ var deltaX = evt.xy.x - centerPx.x;
+ var deltaY = evt.xy.y - centerPx.y;
+ this.map.pan(deltaX, deltaY,true);
- // convert the (old) center of the map in pixel
- var centerPx = this.map.getPixelFromLonLat(this.map.getCenter());
-
- // pan to new center
- var deltaX = evt.xy.x - centerPx.x;
- var deltaY = evt.xy.y - centerPx.y;
- this.map.pan(deltaX, deltaY,true);
+ // zoom to new level
+ this.map.zoomIn();
- // zoom to new level
- this.map.zoomIn();
-
- OpenLayers.Event.stop(evt);
- return false;
+ OpenLayers.Event.stop(evt);
+ return false;
+ }
},
/**
@@ -242,23 +241,30 @@
*/
zoomBoxEnd: function(evt) {
if (this.mouseDragStart != null) {
- if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
- Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
- var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
- var end = this.map.getLonLatFromViewPortPx( evt.xy );
- var top = Math.max(start.lat, end.lat);
- var bottom = Math.min(start.lat, end.lat);
- var left = Math.min(start.lon, end.lon);
- var right = Math.max(start.lon, end.lon);
- var bounds = new OpenLayers.Bounds(left, bottom, right, top);
- this.map.zoomToExtent(bounds);
- } else {
- var end = this.map.getLonLatFromViewPortPx( evt.xy );
- this.map.setCenter(new OpenLayers.LonLat(
- (end.lon),
- (end.lat)
- ), this.map.getZoom() + 1);
- }
+ if (!this.map.zoomanimationActive) {
+ if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
+ Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
+ var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
+ var end = this.map.getLonLatFromViewPortPx( evt.xy );
+ var top = Math.max(start.lat, end.lat);
+ var bottom = Math.min(start.lat, end.lat);
+ var left = Math.min(start.lon, end.lon);
+ var right = Math.max(start.lon, end.lon);
+ var bounds = new OpenLayers.Bounds(left, bottom, right, top);
+ if (!this.map.zoomanimationActive)
+ this.map.zoomToExtent(bounds);
+ } else {
+ // convert the (old) center of the map in pixel
+ var centerPx = this.map.getPixelFromLonLat(this.map.getCenter())
+ // pan to new center
+ var deltaX = evt.xy.x - centerPx.x;
+ var deltaY = evt.xy.y - centerPx.y;
+ this.map.pan(deltaX, deltaY,true);
+
+ // zoom to new level
+ this.map.zoomIn();
+ }
+ }
this.removeZoomBox();
}
},
Modified: sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseToolbar.js
===================================================================
--- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseToolbar.js 2007-03-02 11:00:20 UTC (rev 2295)
+++ sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseToolbar.js 2007-03-02 14:53:32 UTC (rev 2296)
@@ -109,22 +109,24 @@
* @param {Event} evt
*/
defaultDblClick: function (evt) {
- this.switchModeTo("pan");
- this.performedDrag = false;
+ if (!this.map.zoomanimationActive){
+ this.switchModeTo("pan");
+ this.performedDrag = false;
- // convert the (old) center of the map in pixel
- var centerPx = this.map.getPixelFromLonLat(this.map.getCenter());
-
- // pan to new center
- var deltaX = evt.xy.x - centerPx.x;
- var deltaY = evt.xy.y - centerPx.y;
- this.map.pan(deltaX, deltaY,true);
+ // convert the (old) center of the map in pixel
+ var centerPx = this.map.getPixelFromLonLat(this.map.getCenter());
+
+ // pan to new center
+ var deltaX = evt.xy.x - centerPx.x;
+ var deltaY = evt.xy.y - centerPx.y;
+ this.map.pan(deltaX, deltaY,true);
- // zoom to new level
- this.map.zoomIn();
+ // zoom to new level
+ this.map.zoomIn();
- OpenLayers.Event.stop(evt);
- return false;
+ OpenLayers.Event.stop(evt);
+ return false;
+ }
},
/**
Modified: sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js
===================================================================
--- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js 2007-03-02 11:00:20 UTC (rev 2295)
+++ sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js 2007-03-02 14:53:32 UTC (rev 2296)
@@ -600,16 +600,16 @@
//set new left position
var newLeftPos = parseInt(centerTile.imgDiv.style.left)
+ deltaCol * newTileSize.w ;
- tile.imgDiv.style.left = newLeftPos + "px";
+ tile.imgDiv.style.left = Math.round(newLeftPos) + "px";
//set new top position
var newTopPos = parseInt(centerTile.imgDiv.style.top)
+ deltaRow * newTileSize.h ;
- tile.imgDiv.style.top = newTopPos + "px";
+ tile.imgDiv.style.top = Math.round(newTopPos) + "px";
//set new width and height
- tile.imgDiv.style.width = newTileSize.w + "px";
- tile.imgDiv.style.height = newTileSize.h + "px";
+ tile.imgDiv.style.width = Math.round(newTileSize.w) + "px";
+ tile.imgDiv.style.height = Math.round(newTileSize.h) + "px";
}
}
}
Modified: sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Image.js
===================================================================
--- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Image.js 2007-03-02 11:00:20 UTC (rev 2295)
+++ sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Image.js 2007-03-02 14:53:32 UTC (rev 2296)
@@ -134,7 +134,20 @@
this.tile.size = tileSize.clone();
this.tile.position = ulPx.clone();
}
+
+ // fire loadstart event
+ this.events.triggerEvent("loadstart");
+ this.doneLoading = false;
+
this.tile.draw();
+
+ var onload = function() {
+ this.doneLoading = true;
+ this.events.triggerEvent("loadend");
+ }
+
+ OpenLayers.Event.observe(this.tile.imgDiv, 'load',
+ onload.bindAsEventListener(this));
}
},
@@ -166,24 +179,54 @@
/**
- * gets tile (image) size
+ * Gets tile (image) size.
*
- * @returns the image size
+ * @returns the image size if tile exists; otherwise
+ * null
+ * @type {OpenLayers.Size}
*/
getTileSize:function() {
- return this.tile.size;
+ if (this.tile)
+ return this.tile.size;
+ else
+ return null;
},
/**
- *
+ * Gets the tile of this image layer.
+ *
* @returns the only tile of the layer
* @type {OpenLayers.Tile}
*/
getCenterTile:function() {
- return this.tile;
+ if (this.tile)
+ return this.tile;
+ else
+ return null;
},
+ /**
+ * Clones layerContainer for "smooth tile update".
+ * So, it gets no blank map while map is loading in new zoomlevel.
+ *
+ * @returns true after layerContainer is cloned
+ * @type Boolean
+ */
+ cloneLayerContainer:function() {
+ // share clone algorithm with other baselayers
+ this.cloneLayerContainer_share();
+ // remove the old imgDiv tile
+ // (so it doesn't becomes complicate with the same imgDiv of the
+ // cloned layerContainerDiv)
+ if (this.tile)
+ this.div.removeChild(this.tile.imgDiv);
+
+ this.tile = null;
+
+ return true;
+ },
+
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.Image"
});
Modified: sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/WMS/Untiled.js
===================================================================
--- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/WMS/Untiled.js 2007-03-02 11:00:20 UTC (rev 2295)
+++ sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/WMS/Untiled.js 2007-03-02 14:53:32 UTC (rev 2296)
@@ -258,21 +258,31 @@
/**
- * gets tile size
+ * Gets tile size.
*
- * @returns the current map tile size
+ * @returns the current map tile size if tile exists; otherwise
+ * null
+ * @type {OpenLayers.Size}
*/
getTileSize:function() {
- return this.tile.size; //getTileSize();
+ if (this.tile)
+ return this.tile.size;
+ else
+ return null;
},
/**
- *
- * @returns the only tile of the layer
+ * Gets the center tile.
+ *
+ * @returns the only tile of the layer if tile exists; otherwise
+ * null
* @type {OpenLayers.Tile}
*/
getCenterTile:function() {
- return this.tile;
+ if (this.tile)
+ return this.tile;
+ else
+ return null;
},
/**
@@ -309,7 +319,8 @@
// remove the old imgDiv tile
// (so it doesn't becomes complicate with the same imgDiv of the
// cloned layerContainerDiv)
- this.div.removeChild(this.tile.imgDiv);
+ if (this.tile)
+ this.div.removeChild(this.tile.imgDiv);
this.tile = null;
Modified: sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js
===================================================================
--- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js 2007-03-02 11:00:20 UTC (rev 2295)
+++ sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js 2007-03-02 14:53:32 UTC (rev 2296)
@@ -690,7 +690,6 @@
*
*/
cloneLayerContainer_share:function() {
-
// function for map only; not for overviewmap!
if (this.map.div.id == "map") {
// 1. clone layerContainerDiv with all childs (replace, if already exist)
@@ -700,10 +699,12 @@
}
this.map.layerContainerDivClone = this.map.layerContainerDiv.cloneNode(true);
this.map.layerContainerDivClone.id = "map_OpenLayers_Container_clone";
+
// 2. append layerContainerDivClone to viewPortDiv
// (now the cloned div is above the original; it hides the original)
this.map.viewPortDiv.appendChild(this.map.layerContainerDivClone);
-
+
+ // 3. set original div invisible during the tiles are loading
this.map.layerContainerDiv.style.display= "none";
}
},
@@ -723,15 +724,15 @@
if (this.map.baseLayer.zoomOutTile){
this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none";
}
- // set cloned layerDiv invisibile -> original div is visible
+ // set cloned layerDiv invisibile and original div visible
if (this.map.layerContainerDivClone){
- this.map.layerContainerDivClone.style.display= "none";
this.map.layerContainerDiv.style.display= "block";
-
+ this.map.layerContainerDivClone.style.display= "none";
}
-
-
}
+
+ // set flag that zoom animation finished
+ this.map.zoomanimationActive = false;
},
/**
@@ -773,7 +774,7 @@
leftOffset = Math.round(leftOffset);
var newLeftPos = centerPx.x - leftOffset
- parseInt(this.map.layerContainerDiv.style.left);
- tile.imgDiv.style.left = newLeftPos + "px";
+ tile.imgDiv.style.left = Math.round(newLeftPos) + "px";
// set real start position of centerTile
var startPosY = (tile.position.y +
@@ -784,11 +785,11 @@
topOffset = Math.round(topOffset);
var newTopPos = centerPx.y - topOffset
- parseInt(this.map.layerContainerDiv.style.top);
- tile.imgDiv.style.top = newTopPos + "px";
+ tile.imgDiv.style.top = Math.round(newTopPos) + "px";
//set new width and height
- tile.imgDiv.style.width = newTileSize.w + "px";
- tile.imgDiv.style.height = newTileSize.h + "px";
+ tile.imgDiv.style.width = Math.round(newTileSize.w) + "px";
+ tile.imgDiv.style.height = Math.round(newTileSize.h) + "px";
return true;
}
@@ -850,10 +851,10 @@
var centerPx = this.map.getPixelFromLonLat(this.map.getCenter());
//set new size (width and height)
- this.zoomOutTile.imgDiv.style.width = this.map.tileSize.w
- * Math.pow(2, newZoomlevel) + "px";
- this.zoomOutTile.imgDiv.style.height = this.map.tileSize.h
- * Math.pow(2, newZoomlevel) + "px";
+ this.zoomOutTile.imgDiv.style.width =
+ Math.round(this.map.tileSize.w * Math.pow(2, newZoomlevel)) + "px";
+ this.zoomOutTile.imgDiv.style.height =
+ Math.round(this.map.tileSize.h * Math.pow(2, newZoomlevel)) + "px";
//set new position (top and left)
var bounds = this.zoomOutTile.bounds;
@@ -863,27 +864,22 @@
var resolution = this.map.getMaxResolution();
var centerLonLat = extent.getCenterLonLat();
- /* if( bounds.containsLonLat(centerLonLat)
- && !(extent.equals(maxExtent))) {*/
- var offsetlon = bounds.left - centerLonLat.lon;
- var offsetlat = -bounds.top + centerLonLat.lat;
-
- var offsetx = offsetlon / newResolution
- - parseInt(this.map.layerContainerDiv.style.left);
- var offsety = offsetlat / newResolution
- - parseInt(this.map.layerContainerDiv.style.top);
-
- this.zoomOutTile.imgDiv.style.left = centerPx.x + offsetx + "px";
- this.zoomOutTile.imgDiv.style.top = centerPx.y + offsety + "px";
-
- // set zoomOutTile visible if viewport < map bounds
- /* if ( (bounds.left < extent.left) || (bounds.right >
- * extent.right) )*/
- this.map.baseLayer.zoomOutTile.imgDiv.style.display = "block";
-/* else
- this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none";
-// }*/
+ var offsetlon = bounds.left - centerLonLat.lon;
+ var offsetlat = -bounds.top + centerLonLat.lat;
+ var offsetx = offsetlon / newResolution
+ - parseInt(this.map.layerContainerDiv.style.left);
+ var offsety = offsetlat / newResolution
+ - parseInt(this.map.layerContainerDiv.style.top);
+
+ this.zoomOutTile.imgDiv.style.left =
+ Math.round(centerPx.x + offsetx) + "px";
+ this.zoomOutTile.imgDiv.style.top =
+ Math.round(centerPx.y + offsety) + "px";
+
+
+ this.map.baseLayer.zoomOutTile.imgDiv.style.display = "block";
+
return true;
},
Modified: sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js
===================================================================
--- sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js 2007-03-02 11:00:20 UTC (rev 2295)
+++ sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js 2007-03-02 14:53:32 UTC (rev 2296)
@@ -139,7 +139,7 @@
/** steps in the slide
*
* @type int */
- slideSteps: 7,
+ slideSteps: 4,
/** millisecondss between each step
*
@@ -1385,8 +1385,14 @@
if (this.isValidZoomLevel(finalZoomlevel))
this.setCenter(null, finalZoomlevel);
- // end zoom animation -> set flag
- this.zoomanimationActive = false;
+ // set zoomanimation flag to false _manually_
+ // (only for image baselayer, because there is no onimageload event);
+ // for all other layers it calls automatically from
+ // loadendevent in layers.js
+ if (this.baseLayer.CLASS_NAME == "OpenLayers.Layer.Image"){
+ this.zoomanimationActive = false;
+ }
+
},
Modified: sandbox/emanuel/animatedZooming/lib/OpenLayers/Util.js
===================================================================
--- sandbox/emanuel/animatedZooming/lib/OpenLayers/Util.js 2007-03-02 11:00:20 UTC (rev 2295)
+++ sandbox/emanuel/animatedZooming/lib/OpenLayers/Util.js 2007-03-02 14:53:32 UTC (rev 2296)
@@ -229,19 +229,11 @@
// therefore this tile does not need to be displayed (so we do not execute
// this code that turns its display on).
//
- var request;
- if (!this.viewRequestID)
- request = true;
-
- if (this.map) {
- if (this.viewRequestID == this.map.viewRequestID)
- request = true;
- }
-
- if (request) {
- this.style.backgroundColor = null;
- this.style.display = "";
- }
+ if (!this.viewRequestID ||
+ (this.map && this.viewRequestID == this.map.viewRequestID)) {
+ this.style.backgroundColor = null;
+ this.style.display = "";
+ }
};
OpenLayers.Util.onImageLoadErrorColor = "pink";
More information about the Commits
mailing list