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
+12 -9
View File
@@ -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;
+10 -16
View File
@@ -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;
},
/**
+2 -5
View File
@@ -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)));
},
+8 -5
View File
@@ -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) {
+4 -2
View File
@@ -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