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
+4 -2
View File
@@ -68,7 +68,8 @@ OpenLayers.Pixel = OpenLayers.Class({
* Determine whether one pixel is equivalent to another * Determine whether one pixel is equivalent to another
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object with
* a 'x' and 'y' properties.
* *
* Returns: * Returns:
* {Boolean} The point passed in as parameter is equal to this. Note that * {Boolean} The point passed in as parameter is equal to this. Note that
@@ -123,7 +124,8 @@ OpenLayers.Pixel = OpenLayers.Class({
* APIMethod: offset * APIMethod: offset
* *
* Parameters * Parameters
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object with
* a 'x' and 'y' properties.
* *
* Returns: * Returns:
* {<OpenLayers.Pixel>} A new Pixel with this pixel's x&y augmented by the * {<OpenLayers.Pixel>} A new Pixel with this pixel's x&y augmented by the
+2 -2
View File
@@ -69,12 +69,12 @@ OpenLayers.Size = OpenLayers.Class({
* Determine where this size is equal to another * Determine where this size is equal to another
* *
* Parameters: * Parameters:
* sz - {<OpenLayers.Size>} * sz - {<OpenLayers.Size>|Object} An OpenLayers.Size or an object with
* a 'w' and 'h' properties.
* *
* Returns: * Returns:
* {Boolean} The passed in size has the same h and w properties as this one. * {Boolean} The passed in size has the same h and w properties as this one.
* Note that if sz passed in is null, returns false. * Note that if sz passed in is null, returns false.
*
*/ */
equals:function(sz) { equals:function(sz) {
var equals = false; var equals = false;
+10 -7
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 * Callback from the handlers.box set up when <box> selection is on
* *
* Parameters: * 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) { selectBox: function(position) {
var bounds; var bounds;
if (position instanceof OpenLayers.Bounds) { if (position instanceof OpenLayers.Bounds) {
var minXY = this.map.getLonLatFromPixel( var minXY = this.map.getLonLatFromPixel({
new OpenLayers.Pixel(position.left, position.bottom) x: position.left,
); y: position.bottom
var maxXY = this.map.getLonLatFromPixel( });
new OpenLayers.Pixel(position.right, position.top) var maxXY = this.map.getLonLatFromPixel({
); x: position.right,
y: position.top
});
bounds = new OpenLayers.Bounds( bounds = new OpenLayers.Bounds(
minXY.lon, minXY.lat, maxXY.lon, maxXY.lat minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
); );
+6 -6
View File
@@ -234,8 +234,8 @@ OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, {
for (var i=0; i<this.intervals.length; ++i) { for (var i=0; i<this.intervals.length; ++i) {
llInterval = this.intervals[i]; //could do this for both x and y?? llInterval = this.intervals[i]; //could do this for both x and y??
var delta = llInterval/2; var delta = llInterval/2;
var p1 = mapCenterLL.offset(new OpenLayers.Pixel(-delta, -delta)); //test coords in EPSG:4326 space var p1 = mapCenterLL.offset({x: -delta, y: -delta}); //test coords in EPSG:4326 space
var p2 = mapCenterLL.offset(new OpenLayers.Pixel( delta, delta)); var p2 = mapCenterLL.offset({x: delta, y: delta});
OpenLayers.Projection.transform(p1, llProj, mapProj); // convert them back to map projection OpenLayers.Projection.transform(p1, llProj, mapProj); // convert them back to map projection
OpenLayers.Projection.transform(p2, llProj, mapProj); OpenLayers.Projection.transform(p2, llProj, mapProj);
var distSq = (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y); 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 newPoint = mapCenterLL.clone();
var mapXY; var mapXY;
do { do {
newPoint = newPoint.offset(new OpenLayers.Pixel(0,llInterval)); newPoint = newPoint.offset({x: 0, y: llInterval});
mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj);
centerLonPoints.unshift(newPoint); centerLonPoints.unshift(newPoint);
} while (mapBounds.containsPixel(mapXY) && ++iter<1000); } while (mapBounds.containsPixel(mapXY) && ++iter<1000);
newPoint = mapCenterLL.clone(); newPoint = mapCenterLL.clone();
do { do {
newPoint = newPoint.offset(new OpenLayers.Pixel(0,-llInterval)); newPoint = newPoint.offset({x: 0, y: -llInterval});
mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj);
centerLonPoints.push(newPoint); centerLonPoints.push(newPoint);
} while (mapBounds.containsPixel(mapXY) && ++iter<1000); } while (mapBounds.containsPixel(mapXY) && ++iter<1000);
@@ -277,13 +277,13 @@ OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, {
var centerLatPoints = [mapCenterLL.clone()]; var centerLatPoints = [mapCenterLL.clone()];
newPoint = mapCenterLL.clone(); newPoint = mapCenterLL.clone();
do { do {
newPoint = newPoint.offset(new OpenLayers.Pixel(-llInterval, 0)); newPoint = newPoint.offset({x: -llInterval, y: 0});
mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj);
centerLatPoints.unshift(newPoint); centerLatPoints.unshift(newPoint);
} while (mapBounds.containsPixel(mapXY) && ++iter<1000); } while (mapBounds.containsPixel(mapXY) && ++iter<1000);
newPoint = mapCenterLL.clone(); newPoint = mapCenterLL.clone();
do { do {
newPoint = newPoint.offset(new OpenLayers.Pixel(llInterval, 0)); newPoint = newPoint.offset({x: llInterval, y: 0});
mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj); mapXY = OpenLayers.Projection.transform(newPoint.clone(), llProj, mapProj);
centerLatPoints.push(newPoint); centerLatPoints.push(newPoint);
} while (mapBounds.containsPixel(mapXY) && ++iter<1000); } while (mapBounds.containsPixel(mapXY) && ++iter<1000);
+27 -21
View File
@@ -41,7 +41,7 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* class name olControlOverviewMapElement) may have padding or other style * class name olControlOverviewMapElement) may have padding or other style
* attributes added via CSS. * attributes added via CSS.
*/ */
size: new OpenLayers.Size(180, 90), size: {w: 180, h: 90},
/** /**
* APIProperty: layers * APIProperty: layers
@@ -659,12 +659,14 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* translated into lon/lat bounds for the overview map * translated into lon/lat bounds for the overview map
*/ */
getMapBoundsFromRectBounds: function(pxBounds) { getMapBoundsFromRectBounds: function(pxBounds) {
var leftBottomPx = new OpenLayers.Pixel(pxBounds.left, var leftBottomLonLat = this.getLonLatFromOverviewPx({
pxBounds.bottom); x: pxBounds.left,
var rightTopPx = new OpenLayers.Pixel(pxBounds.right, y: pxBounds.bottom
pxBounds.top); });
var leftBottomLonLat = this.getLonLatFromOverviewPx(leftBottomPx); var rightTopLonLat = this.getLonLatFromOverviewPx({
var rightTopLonLat = this.getLonLatFromOverviewPx(rightTopPx); x: pxBounds.right,
y: pxBounds.top
});
return new OpenLayers.Bounds(leftBottomLonLat.lon, leftBottomLonLat.lat, return new OpenLayers.Bounds(leftBottomLonLat.lon, leftBottomLonLat.lat,
rightTopLonLat.lon, rightTopLonLat.lat); rightTopLonLat.lon, rightTopLonLat.lat);
}, },
@@ -674,22 +676,27 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* Get a map location from a pixel location * Get a map location from a pixel location
* *
* Parameters: * Parameters:
* overviewMapPx - {<OpenLayers.Pixel>} * overviewMapPx - {<OpenLayers.Pixel>|Object} OpenLayers.Pixel or
* an object with a
* 'x' and 'y' properties.
* *
* Returns: * Returns:
* {<OpenLayers.LonLat>} Location which is the passed-in overview map * {Object} Location which is the passed-in overview map
* OpenLayers.Pixel, translated into lon/lat by the overview map * OpenLayers.Pixel, translated into lon/lat by the overview
* map. An object with a 'lon' and 'lat' properties.
*/ */
getLonLatFromOverviewPx: function(overviewMapPx) { getLonLatFromOverviewPx: function(overviewMapPx) {
var size = this.ovmap.size; var size = this.ovmap.size;
var res = this.ovmap.getResolution(); var res = this.ovmap.getResolution();
var center = this.ovmap.getExtent().getCenterLonLat(); var center = this.ovmap.getExtent().getCenterLonLat();
var delta_x = overviewMapPx.x - (size.w / 2); var deltaX = overviewMapPx.x - (size.w / 2);
var delta_y = overviewMapPx.y - (size.h / 2); var deltaY = overviewMapPx.y - (size.h / 2);
return new OpenLayers.LonLat(center.lon + delta_x * res , return {
center.lat - delta_y * res); lon: center.lon + deltaX * res,
lat: center.lat - deltaY * res
};
}, },
/** /**
@@ -700,19 +707,18 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
* lonlat - {<OpenLayers.LonLat>} * lonlat - {<OpenLayers.LonLat>}
* *
* Returns: * 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 * translated into overview map pixels
*/ */
getOverviewPxFromLonLat: function(lonlat) { getOverviewPxFromLonLat: function(lonlat) {
var res = this.ovmap.getResolution(); var res = this.ovmap.getResolution();
var extent = this.ovmap.getExtent(); var extent = this.ovmap.getExtent();
var px = null;
if (extent) { if (extent) {
px = new OpenLayers.Pixel( return {
Math.round(1/res * (lonlat.lon - extent.left)), x: Math.round(1/res * (lonlat.lon - extent.left)),
Math.round(1/res * (extent.top - lonlat.lat))); y: Math.round(1/res * (extent.top - lonlat.lat))
};
} }
return px;
}, },
CLASS_NAME: 'OpenLayers.Control.OverviewMap' CLASS_NAME: 'OpenLayers.Control.OverviewMap'
+1 -1
View File
@@ -87,7 +87,7 @@ OpenLayers.Control.PanZoom = OpenLayers.Class(OpenLayers.Control, {
// place the controls // place the controls
this.buttons = []; 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); var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y);
this._addButton("panup", "north-mini.png", centered, sz); this._addButton("panup", "north-mini.png", centered, sz);
+7 -7
View File
@@ -151,7 +151,7 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
// place the controls // place the controls
this.buttons = []; this.buttons = [];
var sz = new OpenLayers.Size(18,18); var sz = {w: 18, h: 18};
if (this.panIcons) { if (this.panIcons) {
var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y); var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y);
var wposition = sz.w; 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 zoomsToEnd = this.map.getNumZoomLevels() - 1 - this.map.getZoom();
var slider = OpenLayers.Util.createAlphaImageDiv(id, var slider = OpenLayers.Util.createAlphaImageDiv(id,
centered.add(-1, zoomsToEnd * this.zoomStopHeight), centered.add(-1, zoomsToEnd * this.zoomStopHeight),
new OpenLayers.Size(20,9), {w: 20, h: 9},
imgLocation, imgLocation,
"absolute"); "absolute");
slider.style.cursor = "move"; slider.style.cursor = "move";
@@ -217,17 +217,17 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
"click": this.doubleClick "click": this.doubleClick
}); });
var sz = new OpenLayers.Size(); var sz = {
sz.h = this.zoomStopHeight * this.map.getNumZoomLevels(); w: this.zoomStopWidth,
sz.w = this.zoomStopWidth; h: this.zoomStopHeight * this.map.getNumZoomLevels()
};
var imgLocation = OpenLayers.Util.getImageLocation("zoombar.png"); var imgLocation = OpenLayers.Util.getImageLocation("zoombar.png");
var div = null; var div = null;
if (OpenLayers.Util.alphaHack()) { if (OpenLayers.Util.alphaHack()) {
var id = this.id + "_" + this.map.id; var id = this.id + "_" + this.map.id;
div = OpenLayers.Util.createAlphaImageDiv(id, centered, div = OpenLayers.Util.createAlphaImageDiv(id, centered,
new OpenLayers.Size(sz.w, {w: sz.w, h: this.zoomStopHeight},
this.zoomStopHeight),
imgLocation, imgLocation,
"absolute", null, "crop"); "absolute", null, "crop");
div.style.height = sz.h + "px"; div.style.height = sz.h + "px";
+8 -6
View File
@@ -535,12 +535,14 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
*/ */
selectBox: function(position) { selectBox: function(position) {
if (position instanceof OpenLayers.Bounds) { if (position instanceof OpenLayers.Bounds) {
var minXY = this.map.getLonLatFromPixel( var minXY = this.map.getLonLatFromPixel({
new OpenLayers.Pixel(position.left, position.bottom) x: position.left,
); y: position.bottom
var maxXY = this.map.getLonLatFromPixel( });
new OpenLayers.Pixel(position.right, position.top) var maxXY = this.map.getLonLatFromPixel({
); x: position.right,
y: position.top
});
var bounds = new OpenLayers.Bounds( var bounds = new OpenLayers.Bounds(
minXY.lon, minXY.lat, maxXY.lon, maxXY.lat minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
); );
+8 -4
View File
@@ -63,10 +63,14 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
if (position instanceof OpenLayers.Bounds) { if (position instanceof OpenLayers.Bounds) {
var bounds; var bounds;
if (!this.out) { if (!this.out) {
var minXY = this.map.getLonLatFromPixel( var minXY = this.map.getLonLatFromPixel({
new OpenLayers.Pixel(position.left, position.bottom)); x: position.left,
var maxXY = this.map.getLonLatFromPixel( y: position.bottom
new OpenLayers.Pixel(position.right, position.top)); });
var maxXY = this.map.getLonLatFromPixel({
x: position.right,
y: position.top
});
bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
maxXY.lon, maxXY.lat); maxXY.lon, maxXY.lat);
} else { } else {
+3 -2
View File
@@ -97,8 +97,9 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
*/ */
startBox: function (xy) { startBox: function (xy) {
this.callback("start", []); this.callback("start", []);
this.zoomBox = OpenLayers.Util.createDiv('zoomBox', this.zoomBox = OpenLayers.Util.createDiv('zoomBox', {
new OpenLayers.Pixel(-9999, -9999)); x: -9999, y: -9999
});
this.zoomBox.className = this.boxDivClassName; this.zoomBox.className = this.boxDivClassName;
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
+25 -13
View File
@@ -29,13 +29,16 @@ OpenLayers.Icon = OpenLayers.Class({
/** /**
* Property: size * Property: size
* {<OpenLayers.Size>} * {<OpenLayers.Size>|Object} An OpenLayers.Size or
* an object with a 'w' and 'h' properties.
*/ */
size: null, size: null,
/** /**
* Property: offset * Property: offset
* {<OpenLayers.Pixel>} distance in pixels to offset the image when being rendered * {<OpenLayers.Pixel>|Object} distance in pixels to offset the
* image when being rendered. An OpenLayers.Pixel or an object
* with a 'x' and 'y' properties.
*/ */
offset: null, offset: null,
@@ -53,7 +56,8 @@ OpenLayers.Icon = OpenLayers.Class({
/** /**
* Property: px * Property: px
* {<OpenLayers.Pixel>} * {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object
* with a 'x' and 'y' properties.
*/ */
px: null, px: null,
@@ -62,14 +66,18 @@ OpenLayers.Icon = OpenLayers.Class({
* Creates an icon, which is an image tag in a div. * Creates an icon, which is an image tag in a div.
* *
* url - {String} * url - {String}
* size - {<OpenLayers.Size>} * size - {<OpenLayers.Size>|Object} An OpenLayers.Size or an
* offset - {<OpenLayers.Pixel>} * object with a 'w' and 'h'
* properties.
* offset - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an
* object with a 'x' and 'y'
* properties.
* calculateOffset - {Function} * calculateOffset - {Function}
*/ */
initialize: function(url, size, offset, calculateOffset) { initialize: function(url, size, offset, calculateOffset) {
this.url = url; this.url = url;
this.size = (size) ? size : new OpenLayers.Size(20,20); this.size = size || {w: 20, h: 20};
this.offset = offset ? offset : new OpenLayers.Pixel(-(this.size.w/2), -(this.size.h/2)); this.offset = offset || {x: -(this.size.w/2), y: -(this.size.h/2)};
this.calculateOffset = calculateOffset; this.calculateOffset = calculateOffset;
var id = OpenLayers.Util.createUniqueID("OL_Icon_"); var id = OpenLayers.Util.createUniqueID("OL_Icon_");
@@ -107,7 +115,8 @@ OpenLayers.Icon = OpenLayers.Class({
* Method: setSize * Method: setSize
* *
* Parameters: * Parameters:
* size - {<OpenLayers.Size>} * size - {<OpenLayers.Size>|Object} An OpenLayers.Size or
* an object with a 'w' and 'h' properties.
*/ */
setSize: function(size) { setSize: function(size) {
if (size != null) { if (size != null) {
@@ -134,7 +143,8 @@ OpenLayers.Icon = OpenLayers.Class({
* Move the div to the given pixel. * Move the div to the given pixel.
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an
* object with a 'x' and 'y' properties.
* *
* Returns: * Returns:
* {DOMElement} A new DOM Image of this icon set at the location passed-in * {DOMElement} A new DOM Image of this icon set at the location passed-in
@@ -153,7 +163,6 @@ OpenLayers.Icon = OpenLayers.Class({
/** /**
* Method: erase * Method: erase
* Erase the underlying image element. * Erase the underlying image element.
*
*/ */
erase: function() { erase: function() {
if (this.imageDiv != null && this.imageDiv.parentNode != null) { if (this.imageDiv != null && this.imageDiv.parentNode != null) {
@@ -179,7 +188,8 @@ OpenLayers.Icon = OpenLayers.Class({
* move icon to passed in px. * move icon to passed in px.
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>|Object} the pixel position to move to.
* An OpenLayers.Pixel or an object with a 'x' and 'y' properties.
*/ */
moveTo: function (px) { moveTo: function (px) {
//if no px passed in, use stored location //if no px passed in, use stored location
@@ -194,8 +204,10 @@ OpenLayers.Icon = OpenLayers.Class({
if (this.calculateOffset) { if (this.calculateOffset) {
this.offset = this.calculateOffset(this.size); this.offset = this.calculateOffset(this.size);
} }
var offsetPx = this.px.offset(this.offset); OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, {
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, offsetPx); x: this.px.x + this.offset.x,
y: this.px.y + this.offset.y
});
} }
} }
}, },
+7 -3
View File
@@ -1227,7 +1227,9 @@ OpenLayers.Layer = OpenLayers.Class({
* APIMethod: getLonLatFromViewPortPx * APIMethod: getLonLatFromViewPortPx
* *
* Parameters: * Parameters:
* viewPortPx - {<OpenLayers.Pixel>} * viewPortPx - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or
* an object with a 'x'
* and 'y' properties.
* *
* Returns: * Returns:
* {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in * {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in
@@ -1256,11 +1258,13 @@ OpenLayers.Layer = OpenLayers.Class({
* fractional pixel values. * fractional pixel values.
* *
* Parameters: * Parameters:
* lonlat - {<OpenLayers.LonLat>} * lonlat - {<OpenLayers.LonLat>|Object} An OpenLayers.LonLat or
* an object with a 'lon'
* and 'lat' properties.
* *
* Returns: * Returns:
* {<OpenLayers.Pixel>} An <OpenLayers.Pixel> which is the passed-in * {<OpenLayers.Pixel>} An <OpenLayers.Pixel> which is the passed-in
* <OpenLayers.LonLat>,translated into view port pixels. * lonlat translated into view port pixels.
*/ */
getViewPortPxFromLonLat: function (lonlat, resolution) { getViewPortPxFromLonLat: function (lonlat, resolution) {
var px = null; var px = null;
+12 -9
View File
@@ -38,18 +38,21 @@ OpenLayers.Layer.Boxes = OpenLayers.Class(OpenLayers.Layer.Markers, {
* marker - {<OpenLayers.Marker.Box>} * marker - {<OpenLayers.Marker.Box>}
*/ */
drawMarker: function(marker) { drawMarker: function(marker) {
var bounds = marker.bounds; var topleft = this.map.getLayerPxFromLonLat({
var topleft = this.map.getLayerPxFromLonLat( lon: marker.bounds.left,
new OpenLayers.LonLat(bounds.left, bounds.top)); lat: marker.bounds.top
var botright = this.map.getLayerPxFromLonLat( });
new OpenLayers.LonLat(bounds.right, bounds.bottom)); var botright = this.map.getLayerPxFromLonLat({
lon: marker.bounds.right,
lat: marker.bounds.bottom
});
if (botright == null || topleft == null) { if (botright == null || topleft == null) {
marker.display(false); marker.display(false);
} else { } else {
var sz = new OpenLayers.Size( var markerDiv = marker.draw(topleft, {
Math.max(1, botright.x - topleft.x), w: Math.max(1, botright.x - topleft.x),
Math.max(1, botright.y - topleft.y)); h: Math.max(1, botright.y - topleft.y)
var markerDiv = marker.draw(topleft, sz); });
if (!marker.drawn) { if (!marker.drawn) {
this.div.appendChild(markerDiv); this.div.appendChild(markerDiv);
marker.drawn = true; marker.drawn = true;
+10 -16
View File
@@ -213,25 +213,19 @@ OpenLayers.Layer.FixedZoomLevels = OpenLayers.Class({
* bounds of the current viewPort. * bounds of the current viewPort.
*/ */
getExtent: function () { getExtent: function () {
var extent = null;
var size = this.map.getSize(); var size = this.map.getSize();
var tl = this.getLonLatFromViewPortPx({
x: 0, y: 0
});
var br = this.getLonLatFromViewPortPx({
x: size.w, y: size.h
});
var tlPx = new OpenLayers.Pixel(0,0); if ((tl != null) && (br != null)) {
var tlLL = this.getLonLatFromViewPortPx(tlPx); return new OpenLayers.Bounds(tl.lon, br.lat, br.lon, tl.lat);
} else {
var brPx = new OpenLayers.Pixel(size.w, size.h); return null;
var brLL = this.getLonLatFromViewPortPx(brPx);
if ((tlLL != null) && (brLL != null)) {
extent = new OpenLayers.Bounds(tlLL.lon,
brLL.lat,
brLL.lon,
tlLL.lat);
} }
return extent;
}, },
/** /**
+2 -5
View File
@@ -337,11 +337,8 @@ OpenLayers.Layer.Google.v3 = {
var lat = this.getLatitudeFromMapObjectLonLat(moLonLat); var lat = this.getLatitudeFromMapObjectLonLat(moLonLat);
var res = this.map.getResolution(); var res = this.map.getResolution();
var extent = this.map.getExtent(); var extent = this.map.getExtent();
var px = new OpenLayers.Pixel( return this.getMapObjectPixelFromXY((1/res * (lon - extent.left)),
(1/res * (lon - extent.left)), (1/res * (extent.top - lat)));
(1/res * (extent.top - lat))
);
return this.getMapObjectPixelFromXY(px.x, px.y);
}, },
+8 -5
View File
@@ -645,8 +645,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
center.lon + (tileWidth/2), center.lon + (tileWidth/2),
center.lat + (tileHeight/2)); center.lat + (tileHeight/2));
var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top); var px = this.map.getLayerPxFromLonLat({
var px = this.map.getLayerPxFromLonLat(ul); lon: tileBounds.left,
lat: tileBounds.top
});
if (!this.grid.length) { if (!this.grid.length) {
this.grid[0] = []; this.grid[0] = [];
@@ -1002,9 +1004,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
var offsetX = parseInt(this.map.layerContainerDiv.style.left); var offsetX = parseInt(this.map.layerContainerDiv.style.left);
var offsetY = parseInt(this.map.layerContainerDiv.style.top); var offsetY = parseInt(this.map.layerContainerDiv.style.top);
var tlViewPort = tlLayer.add(offsetX, offsetY); var tlViewPort = tlLayer.add(offsetX, offsetY);
var tileSize = this.tileSize.clone(); var tileSize = {
tileSize.w *= scale; w: this.tileSize.w * scale,
tileSize.h *= scale; h: this.tileSize.h * scale
};
if (tlViewPort.x > -tileSize.w * (buffer - 1)) { if (tlViewPort.x > -tileSize.w * (buffer - 1)) {
this.shiftColumn(true); this.shiftColumn(true);
} else if (tlViewPort.x < -tileSize.w * buffer) { } else if (tlViewPort.x < -tileSize.w * buffer) {
+4 -2
View File
@@ -164,8 +164,10 @@ OpenLayers.Layer.Image = OpenLayers.Class(OpenLayers.Layer, {
this.setTileSize(); this.setTileSize();
//determine new position (upper left corner of new bounds) //determine new position (upper left corner of new bounds)
var ul = new OpenLayers.LonLat(this.extent.left, this.extent.top); var ulPx = this.map.getLayerPxFromLonLat({
var ulPx = this.map.getLayerPxFromLonLat(ul); lon: this.extent.left,
lat: this.extent.top
});
if(firstRendering) { if(firstRendering) {
//create the new tile //create the new tile
+35 -28
View File
@@ -398,7 +398,8 @@ OpenLayers.Map = OpenLayers.Class({
/** /**
* Property: minPx * Property: minPx
* {<OpenLayers.Pixel>} Lower left of maxExtent in viewport pixel space. * {Object} An object with a 'x' and 'y' values that is the lower
* left of maxExtent in viewport pixel space.
* Used to verify in moveByPx that the new location we're moving to * Used to verify in moveByPx that the new location we're moving to
* is valid. It is also used in the getLonLatFromViewPortPx function * is valid. It is also used in the getLonLatFromViewPortPx function
* of Layer. * of Layer.
@@ -407,7 +408,8 @@ OpenLayers.Map = OpenLayers.Class({
/** /**
* Property: maxPx * Property: maxPx
* {<OpenLayers.Pixel>} Top right of maxExtent in viewport pixel space. * {Object} An object with a 'x' and 'y' values that is the top
* right of maxExtent in viewport pixel space.
* Used to verify in moveByPx that the new location we're moving to * Used to verify in moveByPx that the new location we're moving to
* is valid. * is valid.
*/ */
@@ -1469,16 +1471,13 @@ OpenLayers.Map = OpenLayers.Class({
} }
if ((center != null) && (resolution != null)) { if ((center != null) && (resolution != null)) {
var halfWDeg = (this.size.w * resolution) / 2;
var halfHDeg = (this.size.h * resolution) / 2;
var size = this.getSize(); extent = new OpenLayers.Bounds(center.lon - halfWDeg,
var w_deg = size.w * resolution; center.lat - halfHDeg,
var h_deg = size.h * resolution; center.lon + halfWDeg,
center.lat + halfHDeg);
extent = new OpenLayers.Bounds(center.lon - w_deg / 2,
center.lat - h_deg / 2,
center.lon + w_deg / 2,
center.lat + h_deg / 2);
} }
return extent; return extent;
@@ -1517,9 +1516,10 @@ OpenLayers.Map = OpenLayers.Class({
*/ */
getCachedCenter: function() { getCachedCenter: function() {
if (!this.center && this.size) { if (!this.center && this.size) {
this.center = this.getLonLatFromViewPortPx( this.center = this.getLonLatFromViewPortPx({
new OpenLayers.Pixel(this.size.w / 2, this.size.h / 2) x: this.size.w / 2,
); y: this.size.h / 2
});
} }
return this.center; return this.center;
}, },
@@ -1714,7 +1714,7 @@ OpenLayers.Map = OpenLayers.Class({
*/ */
adjustZoom: function(zoom) { adjustZoom: function(zoom) {
var resolution, resolutions = this.baseLayer.resolutions, var resolution, resolutions = this.baseLayer.resolutions,
maxResolution = this.getMaxExtent().getWidth() / this.getSize().w; maxResolution = this.getMaxExtent().getWidth() / this.size.w;
if (this.getResolutionForZoom(zoom) > maxResolution) { if (this.getResolutionForZoom(zoom) > maxResolution) {
for (var i=zoom|0, ii=resolutions.length; i<ii; ++i) { for (var i=zoom|0, ii=resolutions.length; i<ii; ++i) {
if (resolutions[i] <= maxResolution) { if (resolutions[i] <= maxResolution) {
@@ -1832,10 +1832,14 @@ OpenLayers.Map = OpenLayers.Class({
var latDelta = maxExtentCenter.lat - this.center.lat; var latDelta = maxExtentCenter.lat - this.center.lat;
var extentWidth = Math.round(maxExtent.getWidth() / res); var extentWidth = Math.round(maxExtent.getWidth() / res);
var extentHeight = Math.round(maxExtent.getHeight() / res); var extentHeight = Math.round(maxExtent.getHeight() / res);
var left = (this.size.w - extentWidth) / 2 - lonDelta / res; this.minPx = {
var top = (this.size.h - extentHeight) / 2 - latDelta / res; x: (this.size.w - extentWidth) / 2 - lonDelta / res,
this.minPx = new OpenLayers.Pixel(left, top); y: (this.size.h - extentHeight) / 2 - latDelta / res
this.maxPx = new OpenLayers.Pixel(left + extentWidth, top + extentHeight); };
this.maxPx = {
x: this.minPx.x + Math.round(maxExtent.getWidth() / res),
y: this.minPx.y + Math.round(maxExtent.getHeight() / res)
};
} }
if (zoomChanged) { if (zoomChanged) {
@@ -2313,15 +2317,15 @@ OpenLayers.Map = OpenLayers.Class({
zoomToScale: function(scale, closest) { zoomToScale: function(scale, closest) {
var res = OpenLayers.Util.getResolutionFromScale(scale, var res = OpenLayers.Util.getResolutionFromScale(scale,
this.baseLayer.units); this.baseLayer.units);
var size = this.getSize();
var w_deg = size.w * res; var halfWDeg = (this.size.w * res) / 2;
var h_deg = size.h * res; var halfHDeg = (this.size.h * res) / 2;
var center = this.getCachedCenter(); var center = this.getCachedCenter();
var extent = new OpenLayers.Bounds(center.lon - w_deg / 2, var extent = new OpenLayers.Bounds(center.lon - halfWDeg,
center.lat - h_deg / 2, center.lat - halfHDeg,
center.lon + w_deg / 2, center.lon + halfWDeg,
center.lat + h_deg / 2); center.lat + halfHDeg);
this.zoomToExtent(extent, closest); this.zoomToExtent(extent, closest);
}, },
@@ -2342,7 +2346,9 @@ OpenLayers.Map = OpenLayers.Class({
* Method: getLonLatFromViewPortPx * Method: getLonLatFromViewPortPx
* *
* Parameters: * Parameters:
* viewPortPx - {<OpenLayers.Pixel>} * viewPortPx - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or
* an object with a 'x'
* and 'y' properties.
* *
* Returns: * Returns:
* {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in view * {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in view
@@ -2385,7 +2391,8 @@ OpenLayers.Map = OpenLayers.Class({
* APIMethod: getLonLatFromPixel * APIMethod: getLonLatFromPixel
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object with
* a 'x' and 'y' properties.
* *
* Returns: * Returns:
* {<OpenLayers.LonLat>} An OpenLayers.LonLat corresponding to the given * {<OpenLayers.LonLat>} An OpenLayers.LonLat corresponding to the given
+8 -11
View File
@@ -135,7 +135,8 @@ OpenLayers.Marker = OpenLayers.Class({
* Move the marker to the new location. * Move the marker to the new location.
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} the pixel position to move to * px - {<OpenLayers.Pixel>|Object} the pixel position to move to.
* An OpenLayers.Pixel or an object with a 'x' and 'y' properties.
*/ */
moveTo: function (px) { moveTo: function (px) {
if ((px != null) && (this.icon != null)) { if ((px != null) && (this.icon != null)) {
@@ -181,9 +182,10 @@ OpenLayers.Marker = OpenLayers.Class({
*/ */
inflate: function(inflate) { inflate: function(inflate) {
if (this.icon) { if (this.icon) {
var newSize = new OpenLayers.Size(this.icon.size.w * inflate, this.icon.setSize({
this.icon.size.h * inflate); w: this.icon.size.w * inflate,
this.icon.setSize(newSize); h: this.icon.size.h * inflate
});
} }
}, },
@@ -231,13 +233,8 @@ OpenLayers.Marker = OpenLayers.Class({
* {<OpenLayers.Icon>} A default OpenLayers.Icon to use for a marker * {<OpenLayers.Icon>} A default OpenLayers.Icon to use for a marker
*/ */
OpenLayers.Marker.defaultIcon = function() { OpenLayers.Marker.defaultIcon = function() {
var url = OpenLayers.Util.getImageLocation("marker.png"); return new OpenLayers.Icon(OpenLayers.Util.getImageLocation("marker.png"),
var size = new OpenLayers.Size(21, 25); {w: 21, h: 25}, {x: -10.5, y: -25});
var calculateOffset = function(size) {
return new OpenLayers.Pixel(-(size.w/2), -size.h);
};
return new OpenLayers.Icon(url, size, null, calculateOffset);
}; };
+6 -5
View File
@@ -533,11 +533,12 @@ OpenLayers.Popup = OpenLayers.Class({
} else { } else {
//make a new OL.Size object with the clipped dimensions // make a new 'size' object with the clipped dimensions
// set or null if not clipped. // set or null if not clipped.
var fixedSize = new OpenLayers.Size(); var fixedSize = {
fixedSize.w = (safeSize.w < realSize.w) ? safeSize.w : null; w: (safeSize.w < realSize.w) ? safeSize.w : null,
fixedSize.h = (safeSize.h < realSize.h) ? safeSize.h : null; h: (safeSize.h < realSize.h) ? safeSize.h : null
};
if (fixedSize.w && fixedSize.h) { if (fixedSize.w && fixedSize.h) {
//content is too big in both directions, so we will use //content is too big in both directions, so we will use
@@ -872,7 +873,7 @@ OpenLayers.Popup = OpenLayers.Class({
addCloseBox: function(callback) { addCloseBox: function(callback) {
this.closeDiv = OpenLayers.Util.createDiv( this.closeDiv = OpenLayers.Util.createDiv(
this.id + "_close", null, new OpenLayers.Size(17, 17) this.id + "_close", null, {w: 17, h: 17}
); );
this.closeDiv.className = "olPopupCloseBox"; this.closeDiv.className = "olPopupCloseBox";
+26 -10
View File
@@ -140,8 +140,12 @@ OpenLayers.Util.indexOf = function(array, obj) {
* Parameters: * Parameters:
* element - {DOMElement} DOM element to modify. * element - {DOMElement} DOM element to modify.
* id - {String} The element id attribute to set. * id - {String} The element id attribute to set.
* px - {<OpenLayers.Pixel>} The left and top style position. * px - {<OpenLayers.Pixel>|Object} The element left and top position,
* sz - {<OpenLayers.Size>} The width and height style attributes. * OpenLayers.Pixel or an object with
* a 'x' and 'y' properties.
* sz - {<OpenLayers.Size>|Object} The element width and height,
* OpenLayers.Size or an object with a
* 'w' and 'h' properties.
* position - {String} The position attribute. eg: absolute, * position - {String} The position attribute. eg: absolute,
* relative, etc. * relative, etc.
* border - {String} The style.border attribute. eg: * border - {String} The style.border attribute. eg:
@@ -192,8 +196,12 @@ OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position,
* id - {String} An identifier for this element. If no id is * id - {String} An identifier for this element. If no id is
* passed an identifier will be created * passed an identifier will be created
* automatically. * automatically.
* px - {<OpenLayers.Pixel>} The element left and top position. * px - {<OpenLayers.Pixel>|Object} The element left and top position,
* sz - {<OpenLayers.Size>} The element width and height. * OpenLayers.Pixel or an object with
* a 'x' and 'y' properties.
* sz - {<OpenLayers.Size>|Object} The element width and height,
* OpenLayers.Size or an object with a
* 'w' and 'h' properties.
* imgURL - {String} A url pointing to an image to use as a * imgURL - {String} A url pointing to an image to use as a
* background image. * background image.
* position - {String} The style.position value. eg: absolute, * position - {String} The style.position value. eg: absolute,
@@ -235,8 +243,12 @@ OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position,
* Parameters: * Parameters:
* id - {String} The id field for the img. If none assigned one will be * id - {String} The id field for the img. If none assigned one will be
* automatically generated. * automatically generated.
* px - {<OpenLayers.Pixel>} The left and top positions. * px - {<OpenLayers.Pixel>|Object} The element left and top position,
* sz - {<OpenLayers.Size>} The style.width and style.height values. * OpenLayers.Pixel or an object with
* a 'x' and 'y' properties.
* sz - {<OpenLayers.Size>|Object} The element width and height,
* OpenLayers.Size or an object with a
* 'w' and 'h' properties.
* imgURL - {String} The url to use as the image source. * imgURL - {String} The url to use as the image source.
* position - {String} The style.position value. * position - {String} The style.position value.
* border - {String} The border to place around the image. * border - {String} The border to place around the image.
@@ -331,8 +343,10 @@ OpenLayers.Util.alphaHack = function() {
* Parameters: * Parameters:
* div - {DOMElement} Div containing Alpha-adjusted Image * div - {DOMElement} Div containing Alpha-adjusted Image
* id - {String} * id - {String}
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>|Object} OpenLayers.Pixel or an object with
* sz - {<OpenLayers.Size>} * a 'x' and 'y' properties.
* sz - {<OpenLayers.Size>|Object} OpenLayers.Size or an object with
* a 'w' and 'h' properties.
* imgURL - {String} * imgURL - {String}
* position - {String} * position - {String}
* border - {String} * border - {String}
@@ -379,8 +393,10 @@ OpenLayers.Util.modifyAlphaImageDiv = function(div, id, px, sz, imgURL,
* *
* Parameters: * Parameters:
* id - {String} * id - {String}
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>|Object} OpenLayers.Pixel or an object with
* sz - {<OpenLayers.Size>} * a 'x' and 'y' properties.
* sz - {<OpenLayers.Size>|Object} OpenLayers.Size or an object with
* a 'w' and 'h' properties.
* imgURL - {String} * imgURL - {String}
* position - {String} * position - {String}
* border - {String} * border - {String}
+1 -1
View File
@@ -417,7 +417,7 @@
translatedPX = {}; translatedPX = {};
layer.map = { layer.map = {
getLayerPxFromLonLat: function(ul) { getLayerPxFromLonLat: function(ul) {
t.ok(ul.equals(desiredUL), "correct ul passed to translation"); t.ok(ul.lon === desiredUL.lon && ul.lat === desiredUL.lat, "correct ul passed to translation");
return translatedPX; return translatedPX;
}, },
getResolution: function() { getResolution: function() {
+1
View File
@@ -1421,6 +1421,7 @@
var m = { var m = {
'baseLayer': { 'units': {} }, 'baseLayer': { 'units': {} },
'size': {'w': 10, 'h': 15},
'getSize': function() { return {'w': 10, 'h': 15}; }, 'getSize': function() { return {'w': 10, 'h': 15}; },
'getCachedCenter': function() { return {'lon': -5, 'lat': -25}; }, 'getCachedCenter': function() { return {'lon': -5, 'lat': -25}; },
'zoomToExtent': function(extent, closest) { 'zoomToExtent': function(extent, closest) {