new calculateFeatureDx method which is used by both Canvas and Elements renderers.
This commit is contained in:
+26
-15
@@ -76,12 +76,8 @@ OpenLayers.Renderer = OpenLayers.Class({
|
|||||||
/**
|
/**
|
||||||
* Property: featureDx
|
* Property: featureDx
|
||||||
* {Number} Feature offset in x direction. Will be calculated for and
|
* {Number} Feature offset in x direction. Will be calculated for and
|
||||||
* applied to the current feature while rendering. Looking at the center of
|
* applied to the current feature while rendering (see
|
||||||
* the feature bounds and the renderer extent, we calculate how many world
|
* <calculateFeatureDx>).
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,15 +202,7 @@ OpenLayers.Renderer = OpenLayers.Class({
|
|||||||
if (!bounds.intersectsBounds(this.extent, {worldBounds: worldBounds})) {
|
if (!bounds.intersectsBounds(this.extent, {worldBounds: worldBounds})) {
|
||||||
style = {display: "none"};
|
style = {display: "none"};
|
||||||
} else {
|
} else {
|
||||||
this.featureDx = 0;
|
this.calculateFeatureDx(bounds, worldBounds);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var rendered = this.drawGeometry(feature.geometry, style, feature.id);
|
var rendered = this.drawGeometry(feature.geometry, style, feature.id);
|
||||||
if(style.display != "none" && style.label && rendered !== false) {
|
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
|
* Method: drawGeometry
|
||||||
|
|||||||
@@ -685,24 +685,15 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
|
|||||||
this.hitContext.clearRect(0, 0, width, height);
|
this.hitContext.clearRect(0, 0, width, height);
|
||||||
}
|
}
|
||||||
var labelMap = [];
|
var labelMap = [];
|
||||||
var feature, style, bounds;
|
var feature, geometry, style;
|
||||||
var worldBounds = (this.map.baseLayer && this.map.baseLayer.wrapDateLine) && this.map.getMaxExtent();
|
var worldBounds = (this.map.baseLayer && this.map.baseLayer.wrapDateLine) && this.map.getMaxExtent();
|
||||||
for (var id in this.features) {
|
for (var id in this.features) {
|
||||||
if (!this.features.hasOwnProperty(id)) { continue; }
|
if (!this.features.hasOwnProperty(id)) { continue; }
|
||||||
feature = this.features[id][0];
|
feature = this.features[id][0];
|
||||||
|
geometry = feature.geometry;
|
||||||
this.featureDx = 0;
|
this.calculateFeatureDx(geometry.getBounds(), worldBounds);
|
||||||
if (worldBounds) {
|
|
||||||
bounds = feature.geometry.getBounds();
|
|
||||||
var worldWidth = worldBounds.getWidth();
|
|
||||||
var rendererCenterX = (this.extent.left + this.extent.right) / 2;
|
|
||||||
var featureCenterX = (bounds.left + bounds.right) / 2;
|
|
||||||
var worldsAway = Math.round((featureCenterX - rendererCenterX) / worldWidth);
|
|
||||||
this.featureDx = worldsAway * worldWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
style = this.features[id][1];
|
style = this.features[id][1];
|
||||||
this.drawGeometry(feature.geometry, style, feature.id);
|
this.drawGeometry(geometry, style, feature.id);
|
||||||
if(style.label) {
|
if(style.label) {
|
||||||
labelMap.push([feature, style]);
|
labelMap.push([feature, style]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user