Making sketch handlers work over the dateline by using layer.getLonLatFromViewPortPx instead of map.getLonLatFromPixel. Thanks bartvde for the unit and acceptance tests. r=bartvde (closes #2787)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12346 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-09-08 17:53:44 +00:00
parent 21423cefe2
commit 98be6e313b
10 changed files with 175 additions and 23 deletions

View File

@@ -24,6 +24,13 @@
OpenLayers.Control.EditingToolbar = OpenLayers.Class(
OpenLayers.Control.Panel, {
/**
* APIProperty: citeCompliant
* {Boolean} If set to true, coordinates of features drawn in a map extent
* crossing the date line won't exceed the world bounds. Default is false.
*/
citeCompliant: false,
/**
* Constructor: OpenLayers.Control.EditingToolbar
* Create an editing toolbar for a given layer.
@@ -39,9 +46,18 @@ OpenLayers.Control.EditingToolbar = OpenLayers.Class(
[ new OpenLayers.Control.Navigation() ]
);
var controls = [
new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}),
new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}),
new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})
new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {
displayClass: 'olControlDrawFeaturePoint',
handlerOptions: {citeCompliant: this.citeCompliant}
}),
new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {
displayClass: 'olControlDrawFeaturePath',
handlerOptions: {citeCompliant: this.citeCompliant}
}),
new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {
displayClass: 'olControlDrawFeaturePolygon',
handlerOptions: {citeCompliant: this.citeCompliant}
})
];
this.addControls(controls);
},

View File

@@ -108,7 +108,7 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
* feature.
*/
createFeature: function(pixel) {
var lonlat = this.map.getLonLatFromPixel(pixel);
var lonlat = this.layer.getLonLatFromViewPortPx(pixel);
var geometry = new OpenLayers.Geometry.Point(
lonlat.lon, lonlat.lat
);
@@ -165,7 +165,7 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
*/
addPoint: function(pixel) {
this.layer.removeFeatures([this.point]);
var lonlat = this.control.map.getLonLatFromPixel(pixel);
var lonlat = this.layer.getLonLatFromViewPortPx(pixel);
this.point = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
);
@@ -326,7 +326,7 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
if(!this.line) {
this.createFeature(pixel);
}
var lonlat = this.control.map.getLonLatFromPixel(pixel);
var lonlat = this.layer.getLonLatFromViewPortPx(pixel);
this.point.geometry.x = lonlat.lon;
this.point.geometry.y = lonlat.lat;
this.callback("modify", [this.point.geometry, this.getSketch(), drawing]);

View File

@@ -42,6 +42,13 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
*/
multi: false,
/**
* APIProperty: citeCompliant
* {Boolean} If set to true, coordinates of features drawn in a map extent
* crossing the date line won't exceed the world bounds. Default is false.
*/
citeCompliant: false,
/**
* Property: mouseDown
* {Boolean} The mouse is down
@@ -164,7 +171,8 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
// without this, resolution properties must be specified at the
// map-level for this temporary layer to init its resolutions
// correctly
calculateInRange: OpenLayers.Function.True
calculateInRange: OpenLayers.Function.True,
wrapDateLine: this.citeCompliant
}, this.layerOptions);
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
this.map.addLayer(this.layer);
@@ -179,7 +187,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
* pixel - {<OpenLayers.Pixel>} A pixel location on the map.
*/
createFeature: function(pixel) {
var lonlat = this.map.getLonLatFromPixel(pixel);
var lonlat = this.layer.getLonLatFromViewPortPx(pixel);
var geometry = new OpenLayers.Geometry.Point(
lonlat.lon, lonlat.lat
);
@@ -306,7 +314,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
if(!this.point) {
this.createFeature(pixel);
}
var lonlat = this.map.getLonLatFromPixel(pixel);
var lonlat = this.layer.getLonLatFromViewPortPx(pixel);
this.point.geometry.x = lonlat.lon;
this.point.geometry.y = lonlat.lat;
this.callback("modify", [this.point.geometry, this.point, false]);

View File

@@ -75,7 +75,7 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, {
* feature.
*/
createFeature: function(pixel) {
var lonlat = this.map.getLonLatFromPixel(pixel);
var lonlat = this.layer.getLonLatFromViewPortPx(pixel);
var geometry = new OpenLayers.Geometry.Point(
lonlat.lon, lonlat.lat
);

View File

@@ -83,6 +83,13 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
*/
irregular: false,
/**
* APIProperty: citeCompliant
* {Boolean} If set to true, coordinates of features drawn in a map extent
* crossing the date line won't exceed the world bounds. Default is false.
*/
citeCompliant: false,
/**
* Property: angle
* {Float} The angle from the origin (mouse down) to the current mouse
@@ -174,7 +181,8 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
// without this, resolution properties must be specified at the
// map-level for this temporary layer to init its resolutions
// correctly
calculateInRange: OpenLayers.Function.True
calculateInRange: OpenLayers.Function.True,
wrapDateLine: this.citeCompliant
}, this.layerOptions);
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
this.map.addLayer(this.layer);
@@ -224,7 +232,7 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
*/
down: function(evt) {
this.fixedRadius = !!(this.radius);
var maploc = this.map.getLonLatFromPixel(evt.xy);
var maploc = this.layer.getLonLatFromViewPortPx(evt.xy);
this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
// create the new polygon
if(!this.fixedRadius || this.irregular) {
@@ -250,7 +258,7 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
* evt - {Evt} The move event
*/
move: function(evt) {
var maploc = this.map.getLonLatFromPixel(evt.xy);
var maploc = this.layer.getLonLatFromViewPortPx(evt.xy);
var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
if(this.irregular) {
var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2;