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:
@@ -68,7 +68,8 @@ OpenLayers.Pixel = OpenLayers.Class({
|
||||
* Determine whether one pixel is equivalent to another
|
||||
*
|
||||
* Parameters:
|
||||
* px - {<OpenLayers.Pixel>}
|
||||
* px - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object with
|
||||
* a 'x' and 'y' properties.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The point passed in as parameter is equal to this. Note that
|
||||
@@ -123,7 +124,8 @@ OpenLayers.Pixel = OpenLayers.Class({
|
||||
* APIMethod: offset
|
||||
*
|
||||
* Parameters
|
||||
* px - {<OpenLayers.Pixel>}
|
||||
* px - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object with
|
||||
* a 'x' and 'y' properties.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Pixel>} A new Pixel with this pixel's x&y augmented by the
|
||||
|
||||
@@ -69,12 +69,12 @@ OpenLayers.Size = OpenLayers.Class({
|
||||
* Determine where this size is equal to another
|
||||
*
|
||||
* Parameters:
|
||||
* sz - {<OpenLayers.Size>}
|
||||
* sz - {<OpenLayers.Size>|Object} An OpenLayers.Size or an object with
|
||||
* a 'w' and 'h' properties.
|
||||
*
|
||||
* Returns:
|
||||
* {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.
|
||||
*
|
||||
*/
|
||||
equals:function(sz) {
|
||||
var equals = false;
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -97,8 +97,9 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
|
||||
*/
|
||||
startBox: function (xy) {
|
||||
this.callback("start", []);
|
||||
this.zoomBox = OpenLayers.Util.createDiv('zoomBox',
|
||||
new OpenLayers.Pixel(-9999, -9999));
|
||||
this.zoomBox = OpenLayers.Util.createDiv('zoomBox', {
|
||||
x: -9999, y: -9999
|
||||
});
|
||||
this.zoomBox.className = this.boxDivClassName;
|
||||
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
||||
|
||||
|
||||
@@ -29,13 +29,16 @@ OpenLayers.Icon = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* Property: size
|
||||
* {<OpenLayers.Size>}
|
||||
* {<OpenLayers.Size>|Object} An OpenLayers.Size or
|
||||
* an object with a 'w' and 'h' properties.
|
||||
*/
|
||||
size: null,
|
||||
|
||||
/**
|
||||
* 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,
|
||||
|
||||
@@ -53,7 +56,8 @@ OpenLayers.Icon = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* Property: px
|
||||
* {<OpenLayers.Pixel>}
|
||||
* {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object
|
||||
* with a 'x' and 'y' properties.
|
||||
*/
|
||||
px: null,
|
||||
|
||||
@@ -62,14 +66,18 @@ OpenLayers.Icon = OpenLayers.Class({
|
||||
* Creates an icon, which is an image tag in a div.
|
||||
*
|
||||
* url - {String}
|
||||
* size - {<OpenLayers.Size>}
|
||||
* offset - {<OpenLayers.Pixel>}
|
||||
* size - {<OpenLayers.Size>|Object} An OpenLayers.Size or an
|
||||
* 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}
|
||||
*/
|
||||
initialize: function(url, size, offset, calculateOffset) {
|
||||
this.url = url;
|
||||
this.size = (size) ? size : new OpenLayers.Size(20,20);
|
||||
this.offset = offset ? offset : new OpenLayers.Pixel(-(this.size.w/2), -(this.size.h/2));
|
||||
this.size = size || {w: 20, h: 20};
|
||||
this.offset = offset || {x: -(this.size.w/2), y: -(this.size.h/2)};
|
||||
this.calculateOffset = calculateOffset;
|
||||
|
||||
var id = OpenLayers.Util.createUniqueID("OL_Icon_");
|
||||
@@ -107,7 +115,8 @@ OpenLayers.Icon = OpenLayers.Class({
|
||||
* Method: setSize
|
||||
*
|
||||
* Parameters:
|
||||
* size - {<OpenLayers.Size>}
|
||||
* size - {<OpenLayers.Size>|Object} An OpenLayers.Size or
|
||||
* an object with a 'w' and 'h' properties.
|
||||
*/
|
||||
setSize: function(size) {
|
||||
if (size != null) {
|
||||
@@ -134,7 +143,8 @@ OpenLayers.Icon = OpenLayers.Class({
|
||||
* Move the div to the given pixel.
|
||||
*
|
||||
* Parameters:
|
||||
* px - {<OpenLayers.Pixel>}
|
||||
* px - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an
|
||||
* object with a 'x' and 'y' properties.
|
||||
*
|
||||
* Returns:
|
||||
* {DOMElement} A new DOM Image of this icon set at the location passed-in
|
||||
@@ -153,7 +163,6 @@ OpenLayers.Icon = OpenLayers.Class({
|
||||
/**
|
||||
* Method: erase
|
||||
* Erase the underlying image element.
|
||||
*
|
||||
*/
|
||||
erase: function() {
|
||||
if (this.imageDiv != null && this.imageDiv.parentNode != null) {
|
||||
@@ -179,7 +188,8 @@ OpenLayers.Icon = OpenLayers.Class({
|
||||
* move icon to passed in px.
|
||||
*
|
||||
* 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) {
|
||||
//if no px passed in, use stored location
|
||||
@@ -194,8 +204,10 @@ OpenLayers.Icon = OpenLayers.Class({
|
||||
if (this.calculateOffset) {
|
||||
this.offset = this.calculateOffset(this.size);
|
||||
}
|
||||
var offsetPx = this.px.offset(this.offset);
|
||||
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, offsetPx);
|
||||
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, {
|
||||
x: this.px.x + this.offset.x,
|
||||
y: this.px.y + this.offset.y
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1227,7 +1227,9 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
* APIMethod: getLonLatFromViewPortPx
|
||||
*
|
||||
* Parameters:
|
||||
* viewPortPx - {<OpenLayers.Pixel>}
|
||||
* viewPortPx - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or
|
||||
* an object with a 'x'
|
||||
* and 'y' properties.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in
|
||||
@@ -1256,11 +1258,13 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
* fractional pixel values.
|
||||
*
|
||||
* Parameters:
|
||||
* lonlat - {<OpenLayers.LonLat>}
|
||||
* lonlat - {<OpenLayers.LonLat>|Object} An OpenLayers.LonLat or
|
||||
* an object with a 'lon'
|
||||
* and 'lat' properties.
|
||||
*
|
||||
* Returns:
|
||||
* {<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) {
|
||||
var px = null;
|
||||
|
||||
@@ -38,18 +38,21 @@ OpenLayers.Layer.Boxes = OpenLayers.Class(OpenLayers.Layer.Markers, {
|
||||
* marker - {<OpenLayers.Marker.Box>}
|
||||
*/
|
||||
drawMarker: function(marker) {
|
||||
var bounds = marker.bounds;
|
||||
var topleft = this.map.getLayerPxFromLonLat(
|
||||
new OpenLayers.LonLat(bounds.left, bounds.top));
|
||||
var botright = this.map.getLayerPxFromLonLat(
|
||||
new OpenLayers.LonLat(bounds.right, bounds.bottom));
|
||||
var topleft = this.map.getLayerPxFromLonLat({
|
||||
lon: marker.bounds.left,
|
||||
lat: marker.bounds.top
|
||||
});
|
||||
var botright = this.map.getLayerPxFromLonLat({
|
||||
lon: marker.bounds.right,
|
||||
lat: marker.bounds.bottom
|
||||
});
|
||||
if (botright == null || topleft == null) {
|
||||
marker.display(false);
|
||||
} else {
|
||||
var sz = new OpenLayers.Size(
|
||||
Math.max(1, botright.x - topleft.x),
|
||||
Math.max(1, botright.y - topleft.y));
|
||||
var markerDiv = marker.draw(topleft, sz);
|
||||
var markerDiv = marker.draw(topleft, {
|
||||
w: Math.max(1, botright.x - topleft.x),
|
||||
h: Math.max(1, botright.y - topleft.y)
|
||||
});
|
||||
if (!marker.drawn) {
|
||||
this.div.appendChild(markerDiv);
|
||||
marker.drawn = true;
|
||||
|
||||
@@ -213,25 +213,19 @@ OpenLayers.Layer.FixedZoomLevels = OpenLayers.Class({
|
||||
* bounds of the current viewPort.
|
||||
*/
|
||||
getExtent: function () {
|
||||
var extent = null;
|
||||
|
||||
|
||||
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);
|
||||
var tlLL = this.getLonLatFromViewPortPx(tlPx);
|
||||
|
||||
var brPx = new OpenLayers.Pixel(size.w, size.h);
|
||||
var brLL = this.getLonLatFromViewPortPx(brPx);
|
||||
|
||||
if ((tlLL != null) && (brLL != null)) {
|
||||
extent = new OpenLayers.Bounds(tlLL.lon,
|
||||
brLL.lat,
|
||||
brLL.lon,
|
||||
tlLL.lat);
|
||||
if ((tl != null) && (br != null)) {
|
||||
return new OpenLayers.Bounds(tl.lon, br.lat, br.lon, tl.lat);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return extent;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -337,11 +337,8 @@ OpenLayers.Layer.Google.v3 = {
|
||||
var lat = this.getLatitudeFromMapObjectLonLat(moLonLat);
|
||||
var res = this.map.getResolution();
|
||||
var extent = this.map.getExtent();
|
||||
var px = new OpenLayers.Pixel(
|
||||
(1/res * (lon - extent.left)),
|
||||
(1/res * (extent.top - lat))
|
||||
);
|
||||
return this.getMapObjectPixelFromXY(px.x, px.y);
|
||||
return this.getMapObjectPixelFromXY((1/res * (lon - extent.left)),
|
||||
(1/res * (extent.top - lat)));
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -645,8 +645,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
center.lon + (tileWidth/2),
|
||||
center.lat + (tileHeight/2));
|
||||
|
||||
var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top);
|
||||
var px = this.map.getLayerPxFromLonLat(ul);
|
||||
var px = this.map.getLayerPxFromLonLat({
|
||||
lon: tileBounds.left,
|
||||
lat: tileBounds.top
|
||||
});
|
||||
|
||||
if (!this.grid.length) {
|
||||
this.grid[0] = [];
|
||||
@@ -1002,9 +1004,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
var offsetX = parseInt(this.map.layerContainerDiv.style.left);
|
||||
var offsetY = parseInt(this.map.layerContainerDiv.style.top);
|
||||
var tlViewPort = tlLayer.add(offsetX, offsetY);
|
||||
var tileSize = this.tileSize.clone();
|
||||
tileSize.w *= scale;
|
||||
tileSize.h *= scale;
|
||||
var tileSize = {
|
||||
w: this.tileSize.w * scale,
|
||||
h: this.tileSize.h * scale
|
||||
};
|
||||
if (tlViewPort.x > -tileSize.w * (buffer - 1)) {
|
||||
this.shiftColumn(true);
|
||||
} else if (tlViewPort.x < -tileSize.w * buffer) {
|
||||
|
||||
@@ -164,8 +164,10 @@ OpenLayers.Layer.Image = OpenLayers.Class(OpenLayers.Layer, {
|
||||
this.setTileSize();
|
||||
|
||||
//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(ul);
|
||||
var ulPx = this.map.getLayerPxFromLonLat({
|
||||
lon: this.extent.left,
|
||||
lat: this.extent.top
|
||||
});
|
||||
|
||||
if(firstRendering) {
|
||||
//create the new tile
|
||||
|
||||
@@ -398,7 +398,8 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* 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
|
||||
* is valid. It is also used in the getLonLatFromViewPortPx function
|
||||
* of Layer.
|
||||
@@ -407,7 +408,8 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* 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
|
||||
* is valid.
|
||||
*/
|
||||
@@ -1469,16 +1471,13 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
}
|
||||
|
||||
if ((center != null) && (resolution != null)) {
|
||||
|
||||
var size = this.getSize();
|
||||
var w_deg = size.w * resolution;
|
||||
var h_deg = size.h * resolution;
|
||||
|
||||
extent = new OpenLayers.Bounds(center.lon - w_deg / 2,
|
||||
center.lat - h_deg / 2,
|
||||
center.lon + w_deg / 2,
|
||||
center.lat + h_deg / 2);
|
||||
var halfWDeg = (this.size.w * resolution) / 2;
|
||||
var halfHDeg = (this.size.h * resolution) / 2;
|
||||
|
||||
extent = new OpenLayers.Bounds(center.lon - halfWDeg,
|
||||
center.lat - halfHDeg,
|
||||
center.lon + halfWDeg,
|
||||
center.lat + halfHDeg);
|
||||
}
|
||||
|
||||
return extent;
|
||||
@@ -1517,9 +1516,10 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
*/
|
||||
getCachedCenter: function() {
|
||||
if (!this.center && this.size) {
|
||||
this.center = this.getLonLatFromViewPortPx(
|
||||
new OpenLayers.Pixel(this.size.w / 2, this.size.h / 2)
|
||||
);
|
||||
this.center = this.getLonLatFromViewPortPx({
|
||||
x: this.size.w / 2,
|
||||
y: this.size.h / 2
|
||||
});
|
||||
}
|
||||
return this.center;
|
||||
},
|
||||
@@ -1714,7 +1714,7 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
*/
|
||||
adjustZoom: function(zoom) {
|
||||
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) {
|
||||
for (var i=zoom|0, ii=resolutions.length; i<ii; ++i) {
|
||||
if (resolutions[i] <= maxResolution) {
|
||||
@@ -1832,10 +1832,14 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
var latDelta = maxExtentCenter.lat - this.center.lat;
|
||||
var extentWidth = Math.round(maxExtent.getWidth() / res);
|
||||
var extentHeight = Math.round(maxExtent.getHeight() / res);
|
||||
var left = (this.size.w - extentWidth) / 2 - lonDelta / res;
|
||||
var top = (this.size.h - extentHeight) / 2 - latDelta / res;
|
||||
this.minPx = new OpenLayers.Pixel(left, top);
|
||||
this.maxPx = new OpenLayers.Pixel(left + extentWidth, top + extentHeight);
|
||||
this.minPx = {
|
||||
x: (this.size.w - extentWidth) / 2 - lonDelta / res,
|
||||
y: (this.size.h - extentHeight) / 2 - latDelta / res
|
||||
};
|
||||
this.maxPx = {
|
||||
x: this.minPx.x + Math.round(maxExtent.getWidth() / res),
|
||||
y: this.minPx.y + Math.round(maxExtent.getHeight() / res)
|
||||
};
|
||||
}
|
||||
|
||||
if (zoomChanged) {
|
||||
@@ -2313,15 +2317,15 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
zoomToScale: function(scale, closest) {
|
||||
var res = OpenLayers.Util.getResolutionFromScale(scale,
|
||||
this.baseLayer.units);
|
||||
var size = this.getSize();
|
||||
var w_deg = size.w * res;
|
||||
var h_deg = size.h * res;
|
||||
|
||||
var halfWDeg = (this.size.w * res) / 2;
|
||||
var halfHDeg = (this.size.h * res) / 2;
|
||||
var center = this.getCachedCenter();
|
||||
|
||||
var extent = new OpenLayers.Bounds(center.lon - w_deg / 2,
|
||||
center.lat - h_deg / 2,
|
||||
center.lon + w_deg / 2,
|
||||
center.lat + h_deg / 2);
|
||||
var extent = new OpenLayers.Bounds(center.lon - halfWDeg,
|
||||
center.lat - halfHDeg,
|
||||
center.lon + halfWDeg,
|
||||
center.lat + halfHDeg);
|
||||
this.zoomToExtent(extent, closest);
|
||||
},
|
||||
|
||||
@@ -2342,7 +2346,9 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
* Method: getLonLatFromViewPortPx
|
||||
*
|
||||
* Parameters:
|
||||
* viewPortPx - {<OpenLayers.Pixel>}
|
||||
* viewPortPx - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or
|
||||
* an object with a 'x'
|
||||
* and 'y' properties.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in view
|
||||
@@ -2385,7 +2391,8 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
* APIMethod: getLonLatFromPixel
|
||||
*
|
||||
* Parameters:
|
||||
* px - {<OpenLayers.Pixel>}
|
||||
* px - {<OpenLayers.Pixel>|Object} An OpenLayers.Pixel or an object with
|
||||
* a 'x' and 'y' properties.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.LonLat>} An OpenLayers.LonLat corresponding to the given
|
||||
|
||||
@@ -135,7 +135,8 @@ OpenLayers.Marker = OpenLayers.Class({
|
||||
* Move the marker to the new location.
|
||||
*
|
||||
* 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) {
|
||||
if ((px != null) && (this.icon != null)) {
|
||||
@@ -181,9 +182,10 @@ OpenLayers.Marker = OpenLayers.Class({
|
||||
*/
|
||||
inflate: function(inflate) {
|
||||
if (this.icon) {
|
||||
var newSize = new OpenLayers.Size(this.icon.size.w * inflate,
|
||||
this.icon.size.h * inflate);
|
||||
this.icon.setSize(newSize);
|
||||
this.icon.setSize({
|
||||
w: this.icon.size.w * inflate,
|
||||
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.Marker.defaultIcon = function() {
|
||||
var url = OpenLayers.Util.getImageLocation("marker.png");
|
||||
var size = new OpenLayers.Size(21, 25);
|
||||
var calculateOffset = function(size) {
|
||||
return new OpenLayers.Pixel(-(size.w/2), -size.h);
|
||||
};
|
||||
|
||||
return new OpenLayers.Icon(url, size, null, calculateOffset);
|
||||
return new OpenLayers.Icon(OpenLayers.Util.getImageLocation("marker.png"),
|
||||
{w: 21, h: 25}, {x: -10.5, y: -25});
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -533,11 +533,12 @@ OpenLayers.Popup = OpenLayers.Class({
|
||||
|
||||
} 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.
|
||||
var fixedSize = new OpenLayers.Size();
|
||||
fixedSize.w = (safeSize.w < realSize.w) ? safeSize.w : null;
|
||||
fixedSize.h = (safeSize.h < realSize.h) ? safeSize.h : null;
|
||||
var fixedSize = {
|
||||
w: (safeSize.w < realSize.w) ? safeSize.w : null,
|
||||
h: (safeSize.h < realSize.h) ? safeSize.h : null
|
||||
};
|
||||
|
||||
if (fixedSize.w && fixedSize.h) {
|
||||
//content is too big in both directions, so we will use
|
||||
@@ -872,7 +873,7 @@ OpenLayers.Popup = OpenLayers.Class({
|
||||
addCloseBox: function(callback) {
|
||||
|
||||
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";
|
||||
|
||||
|
||||
@@ -140,8 +140,12 @@ OpenLayers.Util.indexOf = function(array, obj) {
|
||||
* Parameters:
|
||||
* element - {DOMElement} DOM element to modify.
|
||||
* id - {String} The element id attribute to set.
|
||||
* px - {<OpenLayers.Pixel>} The left and top style position.
|
||||
* sz - {<OpenLayers.Size>} The width and height style attributes.
|
||||
* px - {<OpenLayers.Pixel>|Object} The element left and top position,
|
||||
* 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,
|
||||
* relative, etc.
|
||||
* 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
|
||||
* passed an identifier will be created
|
||||
* automatically.
|
||||
* px - {<OpenLayers.Pixel>} The element left and top position.
|
||||
* sz - {<OpenLayers.Size>} The element width and height.
|
||||
* px - {<OpenLayers.Pixel>|Object} The element left and top position,
|
||||
* 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
|
||||
* background image.
|
||||
* position - {String} The style.position value. eg: absolute,
|
||||
@@ -235,8 +243,12 @@ OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position,
|
||||
* Parameters:
|
||||
* id - {String} The id field for the img. If none assigned one will be
|
||||
* automatically generated.
|
||||
* px - {<OpenLayers.Pixel>} The left and top positions.
|
||||
* sz - {<OpenLayers.Size>} The style.width and style.height values.
|
||||
* px - {<OpenLayers.Pixel>|Object} The element left and top position,
|
||||
* 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.
|
||||
* position - {String} The style.position value.
|
||||
* border - {String} The border to place around the image.
|
||||
@@ -331,8 +343,10 @@ OpenLayers.Util.alphaHack = function() {
|
||||
* Parameters:
|
||||
* div - {DOMElement} Div containing Alpha-adjusted Image
|
||||
* id - {String}
|
||||
* px - {<OpenLayers.Pixel>}
|
||||
* sz - {<OpenLayers.Size>}
|
||||
* px - {<OpenLayers.Pixel>|Object} OpenLayers.Pixel or an object with
|
||||
* a 'x' and 'y' properties.
|
||||
* sz - {<OpenLayers.Size>|Object} OpenLayers.Size or an object with
|
||||
* a 'w' and 'h' properties.
|
||||
* imgURL - {String}
|
||||
* position - {String}
|
||||
* border - {String}
|
||||
@@ -379,8 +393,10 @@ OpenLayers.Util.modifyAlphaImageDiv = function(div, id, px, sz, imgURL,
|
||||
*
|
||||
* Parameters:
|
||||
* id - {String}
|
||||
* px - {<OpenLayers.Pixel>}
|
||||
* sz - {<OpenLayers.Size>}
|
||||
* px - {<OpenLayers.Pixel>|Object} OpenLayers.Pixel or an object with
|
||||
* a 'x' and 'y' properties.
|
||||
* sz - {<OpenLayers.Size>|Object} OpenLayers.Size or an object with
|
||||
* a 'w' and 'h' properties.
|
||||
* imgURL - {String}
|
||||
* position - {String}
|
||||
* border - {String}
|
||||
|
||||
@@ -417,7 +417,7 @@
|
||||
translatedPX = {};
|
||||
layer.map = {
|
||||
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;
|
||||
},
|
||||
getResolution: function() {
|
||||
|
||||
@@ -1421,6 +1421,7 @@
|
||||
|
||||
var m = {
|
||||
'baseLayer': { 'units': {} },
|
||||
'size': {'w': 10, 'h': 15},
|
||||
'getSize': function() { return {'w': 10, 'h': 15}; },
|
||||
'getCachedCenter': function() { return {'lon': -5, 'lat': -25}; },
|
||||
'zoomToExtent': function(extent, closest) {
|
||||
|
||||
Reference in New Issue
Block a user