diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index f3cda155a4..e394c0a660 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -217,6 +217,12 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { * {Boolean} Whether the Vector Layer features have been drawn yet. */ drawn: false, + + /** + * APIProperty: ratio + * {Float} This specifies the ratio of the size of the visiblity of the Vector Layer features to the size of the map. + */ + ratio: 1, /** * Constructor: OpenLayers.Layer.Vector @@ -365,7 +371,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { displayError: function() { if (this.reportError) { OpenLayers.Console.userError(OpenLayers.i18n("browserNotSupported", - {'renderers':this.renderers.join("\n")})); + {renderers: this. renderers.join('\n')})); } }, @@ -386,7 +392,11 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { this.map.removeLayer(this); } else { this.renderer.map = this.map; - this.renderer.setSize(this.map.getSize()); + + var newSize = this.map.getSize(); + newSize.w = newSize.w * this.ratio; + newSize.h = newSize.h * this.ratio; + this.renderer.setSize(newSize); } }, @@ -435,7 +445,11 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { */ onMapResize: function() { OpenLayers.Layer.prototype.onMapResize.apply(this, arguments); - this.renderer.setSize(this.map.getSize()); + + var newSize = this.map.getSize(); + newSize.w = newSize.w * this.ratio; + newSize.h = newSize.h * this.ratio; + this.renderer.setSize(newSize); }, /** @@ -463,14 +477,25 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { var coordSysUnchanged = true; if (!dragging) { - this.renderer.root.style.visibility = "hidden"; - - this.div.style.left = -parseInt(this.map.layerContainerDiv.style.left) + "px"; - this.div.style.top = -parseInt(this.map.layerContainerDiv.style.top) + "px"; - var extent = this.map.getExtent(); + this.renderer.root.style.visibility = 'hidden'; + + var viewSize = this.map.getSize(), + viewWidth = viewSize.w, + viewHeight = viewSize.h, + offsetLeft = (viewWidth / 2 * this.ratio) - viewWidth / 2, + offsetTop = (viewHeight / 2 * this.ratio) - viewHeight / 2; + offsetLeft += parseInt(this.map.layerContainerDiv.style.left, 10); + offsetLeft = -Math.round(offsetLeft); + offsetTop += parseInt(this.map.layerContainerDiv.style.top, 10); + offsetTop = -Math.round(offsetTop); + + this.div.style.left = offsetLeft + 'px'; + this.div.style.top = offsetTop + 'px'; + + var extent = this.map.getExtent().scale(this.ratio); coordSysUnchanged = this.renderer.setExtent(extent, zoomChanged); - - this.renderer.root.style.visibility = "visible"; + + this.renderer.root.style.visibility = 'visible'; // Force a reflow on gecko based browsers to prevent jump/flicker. // This seems to happen on only certain configurations; it was originally @@ -995,4 +1020,4 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { }, CLASS_NAME: "OpenLayers.Layer.Vector" -}); +}); \ No newline at end of file diff --git a/lib/OpenLayers/Renderer.js b/lib/OpenLayers/Renderer.js index bc4ac12cdb..68d48c898e 100644 --- a/lib/OpenLayers/Renderer.js +++ b/lib/OpenLayers/Renderer.js @@ -139,7 +139,9 @@ OpenLayers.Renderer = OpenLayers.Class({ setExtent: function(extent, resolutionChanged) { this.extent = extent.clone(); if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) { - this.extent = extent.wrapDateLine(this.map.getMaxExtent()); + var ratio = extent.getWidth() / this.map.getExtent().getWidth(), + extent = extent.scale(1 / ratio); + this.extent = extent.wrapDateLine(this.map.getMaxExtent()).scale(ratio); } if (resolutionChanged) { this.resolution = null; diff --git a/lib/OpenLayers/Renderer/Elements.js b/lib/OpenLayers/Renderer/Elements.js index 72f5ca659e..9ebab760fc 100644 --- a/lib/OpenLayers/Renderer/Elements.js +++ b/lib/OpenLayers/Renderer/Elements.js @@ -498,8 +498,9 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, { var coordSysUnchanged = OpenLayers.Renderer.prototype.setExtent.apply(this, arguments); var resolution = this.getResolution(); if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) { - coordSysUnchanged = this.featureDx === 0; var rightOfDateLine, + ratio = extent.getWidth() / this.map.getExtent().getWidth(), + extent = extent.scale(1 / ratio), world = this.map.getMaxExtent(); if (world.right > extent.left && world.right < extent.right) { rightOfDateLine = true; diff --git a/tests/Renderer/Elements.html b/tests/Renderer/Elements.html index 0fe940e204..53590e2d60 100644 --- a/tests/Renderer/Elements.html +++ b/tests/Renderer/Elements.html @@ -614,6 +614,9 @@ getMaxExtent: function() { return new OpenLayers.Bounds(-180,-90,180,90); }, + getExtent: function() { + return r.extent; + }, getResolution: function() { return resolution; },