Merge pull request #137 from fredj/simple-objects

Replace Size and Pixel instances with simple objects. r=elemoine,probins,tschaub
This commit is contained in:
Frédéric Junod
2012-01-18 04:12:02 -08:00
23 changed files with 222 additions and 167 deletions

View File

@@ -294,17 +294,20 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
* Callback from the handlers.box set up when <box> selection is on
*
* Parameters:
* position - {<OpenLayers.Bounds>}
* position - {<OpenLayers.Bounds>|Object} An OpenLayers.Bounds or
* an object with a 'left', 'bottom', 'right' and 'top' properties.
*/
selectBox: function(position) {
var bounds;
if (position instanceof OpenLayers.Bounds) {
var minXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.left, position.bottom)
);
var maxXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.right, position.top)
);
var minXY = this.map.getLonLatFromPixel({
x: position.left,
y: position.bottom
});
var maxXY = this.map.getLonLatFromPixel({
x: position.right,
y: position.top
});
bounds = new OpenLayers.Bounds(
minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
);

View File

@@ -234,8 +234,8 @@ OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, {
for (var i=0; i<this.intervals.length; ++i) {
llInterval = this.intervals[i]; //could do this for both x and y??
var delta = llInterval/2;
var p1 = mapCenterLL.offset(new OpenLayers.Pixel(-delta, -delta)); //test coords in EPSG:4326 space
var p2 = mapCenterLL.offset(new OpenLayers.Pixel( delta, delta));
var p1 = mapCenterLL.offset({x: -delta, y: -delta}); //test coords in EPSG:4326 space
var p2 = mapCenterLL.offset({x: delta, y: delta});
OpenLayers.Projection.transform(p1, llProj, mapProj); // convert them back to map projection
OpenLayers.Projection.transform(p2, llProj, mapProj);
var distSq = (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y);
@@ -261,13 +261,13 @@ OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, {
var newPoint = mapCenterLL.clone();
var mapXY;
do {
newPoint = newPoint.offset(new OpenLayers.Pixel(0,llInterval));
newPoint = newPoint.offset({x: 0, y: llInterval});
mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj);
centerLonPoints.unshift(newPoint);
} while (mapBounds.containsPixel(mapXY) && ++iter<1000);
newPoint = mapCenterLL.clone();
do {
newPoint = newPoint.offset(new OpenLayers.Pixel(0,-llInterval));
newPoint = newPoint.offset({x: 0, y: -llInterval});
mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj);
centerLonPoints.push(newPoint);
} while (mapBounds.containsPixel(mapXY) && ++iter<1000);
@@ -277,13 +277,13 @@ OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, {
var centerLatPoints = [mapCenterLL.clone()];
newPoint = mapCenterLL.clone();
do {
newPoint = newPoint.offset(new OpenLayers.Pixel(-llInterval, 0));
newPoint = newPoint.offset({x: -llInterval, y: 0});
mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj);
centerLatPoints.unshift(newPoint);
} while (mapBounds.containsPixel(mapXY) && ++iter<1000);
newPoint = mapCenterLL.clone();
do {
newPoint = newPoint.offset(new OpenLayers.Pixel(llInterval, 0));
newPoint = newPoint.offset({x: llInterval, y: 0});
mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj);
centerLatPoints.push(newPoint);
} while (mapBounds.containsPixel(mapXY) && ++iter<1000);

View File

@@ -41,7 +41,7 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* class name olControlOverviewMapElement) may have padding or other style
* attributes added via CSS.
*/
size: new OpenLayers.Size(180, 90),
size: {w: 180, h: 90},
/**
* APIProperty: layers
@@ -659,12 +659,14 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* translated into lon/lat bounds for the overview map
*/
getMapBoundsFromRectBounds: function(pxBounds) {
var leftBottomPx = new OpenLayers.Pixel(pxBounds.left,
pxBounds.bottom);
var rightTopPx = new OpenLayers.Pixel(pxBounds.right,
pxBounds.top);
var leftBottomLonLat = this.getLonLatFromOverviewPx(leftBottomPx);
var rightTopLonLat = this.getLonLatFromOverviewPx(rightTopPx);
var leftBottomLonLat = this.getLonLatFromOverviewPx({
x: pxBounds.left,
y: pxBounds.bottom
});
var rightTopLonLat = this.getLonLatFromOverviewPx({
x: pxBounds.right,
y: pxBounds.top
});
return new OpenLayers.Bounds(leftBottomLonLat.lon, leftBottomLonLat.lat,
rightTopLonLat.lon, rightTopLonLat.lat);
},
@@ -674,22 +676,27 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* Get a map location from a pixel location
*
* Parameters:
* overviewMapPx - {<OpenLayers.Pixel>}
* overviewMapPx - {<OpenLayers.Pixel>|Object} OpenLayers.Pixel or
* an object with a
* 'x' and 'y' properties.
*
* Returns:
* {<OpenLayers.LonLat>} Location which is the passed-in overview map
* OpenLayers.Pixel, translated into lon/lat by the overview map
* {Object} Location which is the passed-in overview map
* OpenLayers.Pixel, translated into lon/lat by the overview
* map. An object with a 'lon' and 'lat' properties.
*/
getLonLatFromOverviewPx: function(overviewMapPx) {
var size = this.ovmap.size;
var res = this.ovmap.getResolution();
var center = this.ovmap.getExtent().getCenterLonLat();
var delta_x = overviewMapPx.x - (size.w / 2);
var delta_y = overviewMapPx.y - (size.h / 2);
return new OpenLayers.LonLat(center.lon + delta_x * res ,
center.lat - delta_y * res);
var deltaX = overviewMapPx.x - (size.w / 2);
var deltaY = overviewMapPx.y - (size.h / 2);
return {
lon: center.lon + deltaX * res,
lat: center.lat - deltaY * res
};
},
/**
@@ -700,19 +707,18 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* lonlat - {<OpenLayers.LonLat>}
*
* Returns:
* {<OpenLayers.Pixel>} Location which is the passed-in OpenLayers.LonLat,
* {Object} Location which is the passed-in OpenLayers.LonLat,
* translated into overview map pixels
*/
getOverviewPxFromLonLat: function(lonlat) {
var res = this.ovmap.getResolution();
var res = this.ovmap.getResolution();
var extent = this.ovmap.getExtent();
var px = null;
if (extent) {
px = new OpenLayers.Pixel(
Math.round(1/res * (lonlat.lon - extent.left)),
Math.round(1/res * (extent.top - lonlat.lat)));
return {
x: Math.round(1/res * (lonlat.lon - extent.left)),
y: Math.round(1/res * (extent.top - lonlat.lat))
};
}
return px;
},
CLASS_NAME: 'OpenLayers.Control.OverviewMap'

View File

@@ -87,7 +87,7 @@ OpenLayers.Control.PanZoom = OpenLayers.Class(OpenLayers.Control, {
// place the controls
this.buttons = [];
var sz = new OpenLayers.Size(18,18);
var sz = {w: 18, h: 18};
var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y);
this._addButton("panup", "north-mini.png", centered, sz);

View File

@@ -151,7 +151,7 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
// place the controls
this.buttons = [];
var sz = new OpenLayers.Size(18,18);
var sz = {w: 18, h: 18};
if (this.panIcons) {
var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y);
var wposition = sz.w;
@@ -198,7 +198,7 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
var zoomsToEnd = this.map.getNumZoomLevels() - 1 - this.map.getZoom();
var slider = OpenLayers.Util.createAlphaImageDiv(id,
centered.add(-1, zoomsToEnd * this.zoomStopHeight),
new OpenLayers.Size(20,9),
{w: 20, h: 9},
imgLocation,
"absolute");
slider.style.cursor = "move";
@@ -217,17 +217,17 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
"click": this.doubleClick
});
var sz = new OpenLayers.Size();
sz.h = this.zoomStopHeight * this.map.getNumZoomLevels();
sz.w = this.zoomStopWidth;
var sz = {
w: this.zoomStopWidth,
h: this.zoomStopHeight * this.map.getNumZoomLevels()
};
var imgLocation = OpenLayers.Util.getImageLocation("zoombar.png");
var div = null;
if (OpenLayers.Util.alphaHack()) {
var id = this.id + "_" + this.map.id;
div = OpenLayers.Util.createAlphaImageDiv(id, centered,
new OpenLayers.Size(sz.w,
this.zoomStopHeight),
{w: sz.w, h: this.zoomStopHeight},
imgLocation,
"absolute", null, "crop");
div.style.height = sz.h + "px";

View File

@@ -535,12 +535,14 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
*/
selectBox: function(position) {
if (position instanceof OpenLayers.Bounds) {
var minXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.left, position.bottom)
);
var maxXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.right, position.top)
);
var minXY = this.map.getLonLatFromPixel({
x: position.left,
y: position.bottom
});
var maxXY = this.map.getLonLatFromPixel({
x: position.right,
y: position.top
});
var bounds = new OpenLayers.Bounds(
minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
);

View File

@@ -63,10 +63,14 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
if (position instanceof OpenLayers.Bounds) {
var bounds;
if (!this.out) {
var minXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.left, position.bottom));
var maxXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.right, position.top));
var minXY = this.map.getLonLatFromPixel({
x: position.left,
y: position.bottom
});
var maxXY = this.map.getLonLatFromPixel({
x: position.right,
y: position.top
});
bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
maxXY.lon, maxXY.lat);
} else {