new calculateFeatureDx method which is used by both Canvas and Elements renderers.

This commit is contained in:
ahocevar
2011-10-08 12:26:19 -04:00
parent f2fcb5a95c
commit 281ae3dfe7
2 changed files with 30 additions and 28 deletions

View File

@@ -76,12 +76,8 @@ OpenLayers.Renderer = OpenLayers.Class({
/**
* Property: featureDx
* {Number} Feature offset in x direction. Will be calculated for and
* applied to the current feature while rendering. Looking at the center of
* the feature bounds and the renderer extent, we calculate how many world
* widths the two are away from each other. This value is used to shift the
* feature as close as possible to the center of the current renderer
* extent. This ensures that the feature is visible in the current
* viewport.
* applied to the current feature while rendering (see
* <calculateFeatureDx>).
*/
/**
@@ -206,15 +202,7 @@ OpenLayers.Renderer = OpenLayers.Class({
if (!bounds.intersectsBounds(this.extent, {worldBounds: worldBounds})) {
style = {display: "none"};
} else {
this.featureDx = 0;
if (worldBounds) {
bounds = feature.geometry.getBounds();
var worldWidth = worldBounds.getWidth(),
rendererCenterX = (this.extent.left + this.extent.right) / 2,
featureCenterX = (bounds.left + bounds.right) / 2,
worldsAway = Math.round((featureCenterX - rendererCenterX) / worldWidth);
this.featureDx = worldsAway * worldWidth;
}
this.calculateFeatureDx(bounds, worldBounds);
}
var rendered = this.drawGeometry(feature.geometry, style, feature.id);
if(style.display != "none" && style.label && rendered !== false) {
@@ -235,6 +223,29 @@ OpenLayers.Renderer = OpenLayers.Class({
}
},
/**
* Method: calculateFeatureDx
* {Number} Calculates the feature offset in x direction. Looking at the
* center of the feature bounds and the renderer extent, we calculate how
* many world widths the two are away from each other. This distance is
* used to shift the feature as close as possible to the center of the
* current enderer extent, which ensures that the feature is visible in the
* current viewport.
*
* Parameters:
* bounds - {<OpenLayers.Bounds>} Bounds of the feature
* worldBounds - {<OpenLayers.Bounds>} Bounds of the world
*/
calculateFeatureDx: function(bounds, worldBounds) {
this.featureDx = 0;
if (worldBounds) {
var worldWidth = worldBounds.getWidth(),
rendererCenterX = (this.extent.left + this.extent.right) / 2,
featureCenterX = (bounds.left + bounds.right) / 2,
worldsAway = Math.round((featureCenterX - rendererCenterX) / worldWidth);
this.featureDx = worldsAway * worldWidth;
}
},
/**
* Method: drawGeometry