Redefine ol.Coordinate to be Array.<number>

This commit is contained in:
Tom Payne
2013-04-04 19:39:18 +02:00
parent 6fc86b81c7
commit 02196c94b5
74 changed files with 613 additions and 687 deletions

View File

@@ -43,8 +43,8 @@ ol.animation.bounce = function(options) {
ol.animation.pan = function(options) {
var source = options.source;
var start = goog.isDef(options.start) ? options.start : goog.now();
var sourceX = source.x;
var sourceY = source.y;
var sourceX = source[0];
var sourceY = source[1];
var duration = goog.isDef(options.duration) ? options.duration : 1000;
var easing = goog.isDef(options.easing) ?
options.easing : ol.easing.inAndOut;
@@ -55,11 +55,11 @@ ol.animation.pan = function(options) {
return true;
} else if (frameState.time < start + duration) {
var delta = 1 - easing((frameState.time - start) / duration);
var deltaX = sourceX - frameState.view2DState.center.x;
var deltaY = sourceY - frameState.view2DState.center.y;
var deltaX = sourceX - frameState.view2DState.center[0];
var deltaY = sourceY - frameState.view2DState.center[1];
frameState.animate = true;
frameState.view2DState.center.x += delta * deltaX;
frameState.view2DState.center.y += delta * deltaY;
frameState.view2DState.center[0] += delta * deltaX;
frameState.view2DState.center[1] += delta * deltaY;
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
return true;
} else {

View File

@@ -8,7 +8,6 @@ goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.style');
goog.require('ol.Coordinate');
goog.require('ol.CoordinateFormatType');
goog.require('ol.MapEvent');
goog.require('ol.MapEventType');
@@ -179,9 +178,7 @@ ol.control.MousePosition.prototype.updateHTML_ = function(pixel) {
var map = this.getMap();
var coordinate = map.getCoordinateFromPixel(pixel);
if (!goog.isNull(coordinate)) {
var vertex = [coordinate.x, coordinate.y];
vertex = this.transform_(vertex, vertex);
coordinate = new ol.Coordinate(vertex[0], vertex[1]);
this.transform_(coordinate, coordinate);
if (goog.isDef(this.coordinateFormat_)) {
html = this.coordinateFormat_(coordinate);
} else {

View File

@@ -167,7 +167,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function(frameState) {
// Convert pointResolution from degrees to meters
this.toEPSG4326_ = null;
cosLatitude = Math.cos(goog.math.toRadians(center.y));
cosLatitude = Math.cos(goog.math.toRadians(center[1]));
pointResolution *= Math.PI * cosLatitude * ol.sphere.NORMAL.radius / 180;
projectionUnits = ol.ProjectionUnits.METERS;
@@ -180,9 +180,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function(frameState) {
this.toEPSG4326_ = ol.projection.getTransformFromProjections(
projection, ol.projection.get('EPSG:4326'));
}
var vertex = [center.x, center.y];
vertex = this.toEPSG4326_(vertex, vertex, 2);
cosLatitude = Math.cos(goog.math.toRadians(vertex[1]));
cosLatitude = Math.cos(goog.math.toRadians(this.toEPSG4326_(center)[1]));
var radius = ol.sphere.NORMAL.radius;
if (projectionUnits == ol.ProjectionUnits.FEET) {
radius /= 0.3048;

View File

@@ -1,5 +1,5 @@
@exportSymbol ol.Coordinate
@exportSymbol ol.Coordinate.createStringXY
@exportSymbol ol.Coordinate.toStringHDMS
@exportSymbol ol.Coordinate.toStringXY
@exportSymbol ol.Coordinate.fromProjectedArray
@exportSymbol ol.coordinate
@exportSymbol ol.coordinate.createStringXY
@exportSymbol ol.coordinate.toStringHDMS
@exportSymbol ol.coordinate.toStringXY
@exportSymbol ol.coordinate.fromProjectedArray

View File

@@ -1,8 +1,8 @@
goog.provide('ol.Coordinate');
goog.provide('ol.CoordinateFormatType');
goog.provide('ol.coordinate');
goog.require('goog.math');
goog.require('goog.math.Vec2');
/**
@@ -11,44 +11,38 @@ goog.require('goog.math.Vec2');
ol.CoordinateFormatType;
/**
* Two dimensional coordinate which does not know its projection.
*
* @constructor
* @extends {goog.math.Vec2}
* @param {number} x X.
* @param {number} y Y.
* @param {number=} opt_z Z.
* @typedef {Array.<number>}
*/
ol.Coordinate = function(x, y, opt_z) {
goog.base(this, x, y);
/**
* @expose
* @type {number}
*/
this.z = goog.isDef(opt_z) ? opt_z : NaN;
};
goog.inherits(ol.Coordinate, goog.math.Vec2);
ol.Coordinate;
/**
* @const
* @type {ol.Coordinate}
*/
ol.Coordinate.ZERO = new ol.Coordinate(0, 0);
ol.coordinate.ZERO = [0, 0];
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @param {ol.Coordinate} delta Delta.
* @return {ol.Coordinate} Coordinate.
*/
ol.coordinate.add = function(coordinate, delta) {
coordinate[0] += delta[0];
coordinate[1] += delta[1];
return coordinate;
};
/**
* @param {number=} opt_precision Precision.
* @return {ol.CoordinateFormatType} Coordinate format.
*/
ol.Coordinate.createStringXY = function(opt_precision) {
ol.coordinate.createStringXY = function(opt_precision) {
return function(coordinate) {
return ol.Coordinate.toStringXY(coordinate, opt_precision);
return ol.coordinate.toStringXY(coordinate, opt_precision);
};
};
@@ -59,7 +53,7 @@ ol.Coordinate.createStringXY = function(opt_precision) {
* @param {string} hemispheres Hemispheres.
* @return {string} String.
*/
ol.Coordinate.degreesToStringHDMS_ = function(degrees, hemispheres) {
ol.coordinate.degreesToStringHDMS_ = function(degrees, hemispheres) {
var normalizedDegrees = goog.math.modulo(degrees + 180, 360) - 180;
var x = Math.abs(Math.round(3600 * normalizedDegrees));
return Math.floor(x / 3600) + '\u00b0 ' +
@@ -69,14 +63,42 @@ ol.Coordinate.degreesToStringHDMS_ = function(degrees, hemispheres) {
};
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} angle Angle.
* @return {ol.Coordinate} Coordinate.
*/
ol.coordinate.rotate = function(coordinate, angle) {
var cosAngle = Math.cos(angle);
var sinAngle = Math.sin(angle);
var x = coordinate[0] * cosAngle - coordinate[1] * sinAngle;
var y = coordinate[1] * cosAngle + coordinate[0] * sinAngle;
coordinate[0] = x;
coordinate[1] = y;
return coordinate;
};
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} s Scale.
* @return {ol.Coordinate} Coordinate.
*/
ol.coordinate.scale = function(coordinate, s) {
coordinate[0] *= s;
coordinate[1] *= s;
return coordinate;
};
/**
* @param {ol.Coordinate|undefined} coordinate Coordinate.
* @return {string} Hemisphere, degrees, minutes and seconds.
*/
ol.Coordinate.toStringHDMS = function(coordinate) {
ol.coordinate.toStringHDMS = function(coordinate) {
if (goog.isDef(coordinate)) {
return ol.Coordinate.degreesToStringHDMS_(coordinate.y, 'NS') + ' ' +
ol.Coordinate.degreesToStringHDMS_(coordinate.x, 'EW');
return ol.coordinate.degreesToStringHDMS_(coordinate[1], 'NS') + ' ' +
ol.coordinate.degreesToStringHDMS_(coordinate[0], 'EW');
} else {
return '';
}
@@ -88,11 +110,11 @@ ol.Coordinate.toStringHDMS = function(coordinate) {
* @param {number=} opt_precision Precision.
* @return {string} XY.
*/
ol.Coordinate.toStringXY = function(coordinate, opt_precision) {
ol.coordinate.toStringXY = function(coordinate, opt_precision) {
if (goog.isDef(coordinate)) {
var precision = opt_precision || 0;
return coordinate.x.toFixed(precision) + ', ' +
coordinate.y.toFixed(precision);
return coordinate[0].toFixed(precision) + ', ' +
coordinate[1].toFixed(precision);
} else {
return '';
}
@@ -105,11 +127,11 @@ ol.Coordinate.toStringXY = function(coordinate, opt_precision) {
* @param {string} axis the axis info.
* @return {ol.Coordinate} The coordinate created.
*/
ol.Coordinate.fromProjectedArray = function(array, axis) {
ol.coordinate.fromProjectedArray = function(array, axis) {
var firstAxis = axis.charAt(0);
if (firstAxis === 'n' || firstAxis === 's') {
return new ol.Coordinate(array[1], array[0]);
return [array[1], array[0]];
} else {
return new ol.Coordinate(array[0], array[1]);
return array;
}
};

View File

@@ -45,9 +45,9 @@ ol.Ellipsoid.prototype.vincenty =
var maxIterations = goog.isDef(opt_maxIterations) ?
opt_maxIterations : 100;
var f = this.flattening;
var lat1 = goog.math.toRadians(c1.y);
var lat2 = goog.math.toRadians(c2.y);
var deltaLon = goog.math.toRadians(c2.x - c1.x);
var lat1 = goog.math.toRadians(c1[1]);
var lat2 = goog.math.toRadians(c2[1]);
var deltaLon = goog.math.toRadians(c2[0] - c1[0]);
var U1 = Math.atan((1 - f) * Math.tan(lat1));
var cosU1 = Math.cos(U1);
var sinU1 = Math.sin(U1);

View File

@@ -31,12 +31,12 @@ goog.inherits(ol.Extent, ol.Rectangle);
*/
ol.Extent.boundingExtent = function(var_args) {
var coordinate0 = arguments[0];
var extent = new ol.Extent(coordinate0.x, coordinate0.y,
coordinate0.x, coordinate0.y);
var extent = new ol.Extent(coordinate0[0], coordinate0[1],
coordinate0[0], coordinate0[1]);
var i;
for (i = 1; i < arguments.length; ++i) {
var coordinate = arguments[i];
extent.extendXY(coordinate.x, coordinate.y);
extent.extendXY(coordinate[0], coordinate[1]);
}
return extent;
};
@@ -68,8 +68,8 @@ ol.Extent.getForView2DAndSize = function(center, resolution, rotation, size) {
for (i = 0; i < 4; ++i) {
x = xs[i];
y = ys[i];
xs[i] = center.x + x * cosRotation - y * sinRotation;
ys[i] = center.y + x * sinRotation + y * cosRotation;
xs[i] = center[0] + x * cosRotation - y * sinRotation;
ys[i] = center[1] + x * sinRotation + y * cosRotation;
}
var minX = Math.min.apply(null, xs);
var minY = Math.min.apply(null, ys);
@@ -87,8 +87,8 @@ ol.Extent.getForView2DAndSize = function(center, resolution, rotation, size) {
* @return {boolean} Contains.
*/
ol.Extent.prototype.containsCoordinate = function(coordinate) {
return this.minX <= coordinate.x && coordinate.x <= this.maxX &&
this.minY <= coordinate.y && coordinate.y <= this.maxY;
return this.minX <= coordinate[0] && coordinate[0] <= this.maxX &&
this.minY <= coordinate[1] && coordinate[1] <= this.maxY;
};
@@ -109,7 +109,7 @@ ol.Extent.prototype.containsExtent = function(extent) {
* @return {ol.Coordinate} Bottom left coordinate.
*/
ol.Extent.prototype.getBottomLeft = function() {
return new ol.Coordinate(this.minX, this.minY);
return [this.minX, this.minY];
};
@@ -117,7 +117,7 @@ ol.Extent.prototype.getBottomLeft = function() {
* @return {ol.Coordinate} Bottom right coordinate.
*/
ol.Extent.prototype.getBottomRight = function() {
return new ol.Coordinate(this.maxX, this.minY);
return [this.maxX, this.minY];
};
@@ -125,7 +125,7 @@ ol.Extent.prototype.getBottomRight = function() {
* @return {ol.Coordinate} Top left coordinate.
*/
ol.Extent.prototype.getTopLeft = function() {
return new ol.Coordinate(this.minX, this.maxY);
return [this.minX, this.maxY];
};
@@ -133,7 +133,7 @@ ol.Extent.prototype.getTopLeft = function() {
* @return {ol.Coordinate} Top right coordinate.
*/
ol.Extent.prototype.getTopRight = function() {
return new ol.Coordinate(this.maxX, this.maxY);
return [this.maxX, this.maxY];
};

View File

@@ -80,10 +80,8 @@ ol.Geolocation.prototype.handleProjectionChanged_ = function() {
this.transformFn_ = ol.projection.getTransformFromProjections(
ol.projection.get('EPSG:4326'), projection);
if (!goog.isNull(this.position_)) {
var vertex = [this.position_.x, this.position_.y];
vertex = this.transformFn_(vertex, vertex, 2);
this.set(ol.GeolocationProperty.POSITION,
new ol.Coordinate(vertex[0], vertex[1]));
this.set(
ol.GeolocationProperty.POSITION, this.transformFn_(this.position_));
}
}
};
@@ -130,11 +128,13 @@ ol.Geolocation.prototype.positionChange_ = function(position) {
undefined : coords.altitudeAccuracy);
this.set(ol.GeolocationProperty.HEADING, goog.isNull(coords.heading) ?
undefined : goog.math.toRadians(coords.heading));
this.position_ = new ol.Coordinate(coords.longitude, coords.latitude);
var vertex = [coords.longitude, coords.latitude];
vertex = this.transformFn_(vertex, vertex, 2);
this.set(ol.GeolocationProperty.POSITION,
new ol.Coordinate(vertex[0], vertex[1]));
if (goog.isNull(this.position_)) {
this.position_ = [coords.longitude, coords.latitude];
} else {
this.position_[0] = coords.longitude;
this.position_[1] = coords.latitude;
}
this.set(ol.GeolocationProperty.POSITION, this.transformFn_(this.position_));
this.set(ol.GeolocationProperty.SPEED,
goog.isNull(coords.speed) ? undefined : coords.speed);
};

View File

@@ -3,12 +3,12 @@
goog.provide('ol.interaction.DragPan');
goog.require('goog.asserts');
goog.require('ol.Coordinate');
goog.require('ol.Kinetic');
goog.require('ol.Pixel');
goog.require('ol.PreRenderFunction');
goog.require('ol.View2D');
goog.require('ol.ViewHint');
goog.require('ol.coordinate');
goog.require('ol.interaction.ConditionType');
goog.require('ol.interaction.Drag');
@@ -61,11 +61,9 @@ ol.interaction.DragPan.prototype.handleDrag = function(mapBrowserEvent) {
goog.asserts.assert(view instanceof ol.View2D);
var resolution = view.getResolution();
var rotation = view.getRotation();
var delta =
new ol.Coordinate(-resolution * this.deltaX, resolution * this.deltaY);
delta.rotate(rotation);
var newCenter = new ol.Coordinate(
this.startCenter.x + delta.x, this.startCenter.y + delta.y);
var newCenter = [-resolution * this.deltaX, resolution * this.deltaY];
ol.coordinate.rotate(newCenter, rotation);
ol.coordinate.add(newCenter, this.startCenter);
map.requestRenderFrame();
view.setCenter(newCenter);
};

View File

@@ -4,8 +4,8 @@ goog.provide('ol.interaction.KeyboardPan');
goog.require('goog.events.KeyCodes');
goog.require('goog.events.KeyHandler.EventType');
goog.require('ol.Coordinate');
goog.require('ol.View2D');
goog.require('ol.coordinate');
goog.require('ol.interaction.Interaction');
@@ -67,8 +67,8 @@ ol.interaction.KeyboardPan.prototype.handleMapBrowserEvent =
} else {
deltaY = mapUnitsDelta;
}
var delta = new ol.Coordinate(deltaX, deltaY);
delta.rotate(rotation);
var delta = [deltaX, deltaY];
ol.coordinate.rotate(delta, rotation);
view.pan(map, delta, ol.interaction.KEYBOARD_PAN_DURATION);
keyEvent.preventDefault();
mapBrowserEvent.preventDefault();

View File

@@ -2,12 +2,12 @@
goog.provide('ol.interaction.TouchPan');
goog.require('goog.asserts');
goog.require('ol.Coordinate');
goog.require('ol.Kinetic');
goog.require('ol.Pixel');
goog.require('ol.PreRenderFunction');
goog.require('ol.View');
goog.require('ol.ViewHint');
goog.require('ol.coordinate');
goog.require('ol.interaction.Touch');
@@ -55,10 +55,10 @@ ol.interaction.TouchPan.prototype.handleTouchMove = function(mapBrowserEvent) {
var deltaX = this.lastCentroid.x - centroid.x;
var deltaY = centroid.y - this.lastCentroid.y;
var view = mapBrowserEvent.map.getView();
var center = new ol.Coordinate(deltaX, deltaY)
.scale(view.getResolution())
.rotate(view.getRotation())
.add(view.getCenter());
var center = [deltaX, deltaY];
ol.coordinate.scale(center, view.getResolution());
ol.coordinate.rotate(center, view.getRotation());
ol.coordinate.add(center, view.getCenter());
view.setCenter(center);
}
this.lastCentroid = centroid;

View File

@@ -25,7 +25,6 @@ goog.require('goog.style');
goog.require('ol.BrowserFeature');
goog.require('ol.Collection');
goog.require('ol.Color');
goog.require('ol.Coordinate');
goog.require('ol.Extent');
goog.require('ol.FrameState');
goog.require('ol.IView');
@@ -400,7 +399,8 @@ ol.Map.prototype.getCoordinateFromPixel = function(pixel) {
} else {
var vec3 = [pixel.x, pixel.y, 0];
goog.vec.Mat4.multVec3(frameState.pixelToCoordinateMatrix, vec3, vec3);
return new ol.Coordinate(vec3[0], vec3[1]);
vec3.length = 2;
return vec3;
}
};
@@ -434,7 +434,7 @@ ol.Map.prototype.getPixelFromCoordinate = function(coordinate) {
if (goog.isNull(frameState)) {
return null;
} else {
var vec3 = [coordinate.x, coordinate.y, 0];
var vec3 = [coordinate[0], coordinate[1], 0];
goog.vec.Mat4.multVec3(frameState.coordinateToPixelMatrix, vec3, vec3);
return new ol.Pixel(vec3[0], vec3[1]);
}
@@ -508,8 +508,8 @@ ol.Map.prototype.getTilePriority =
// between the center of the tile and the focus. The factor of 65536 means
// that the prioritization should behave as desired for tiles up to
// 65536 * Math.log(2) = 45426 pixels from the focus.
var deltaX = tileCenter.x - frameState.focus.x;
var deltaY = tileCenter.y - frameState.focus.y;
var deltaX = tileCenter[0] - frameState.focus[0];
var deltaY = tileCenter[1] - frameState.focus[1];
return 65536 * Math.log(tileResolution) +
Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution;
};

View File

@@ -1,6 +1,6 @@
goog.provide('ol.parser.ogc.WMTSCapabilities_v1_0_0');
goog.require('goog.dom.xml');
goog.require('ol.Coordinate');
goog.require('ol.coordinate');
goog.require('ol.parser.XML');
goog.require('ol.parser.ogc.OWSCommon_v1_1_0');
goog.require('ol.projection');
@@ -80,7 +80,7 @@ ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
var coords = topLeftCorner.split(' ');
var axisOrientation =
ol.projection.get(obj['supportedCRS']).getAxisOrientation();
obj['topLeftCorner'] = ol.Coordinate.fromProjectedArray(
obj['topLeftCorner'] = ol.coordinate.fromProjectedArray(
[parseFloat(coords[0]), parseFloat(coords[1])], axisOrientation);
},
'TileWidth': function(node, obj) {

View File

@@ -141,5 +141,5 @@ ol.projection.EPSG3857.toEPSG4326 = function(input, opt_output, opt_dimension) {
*/
ol.projection.EPSG3857.prototype.getPointResolution =
function(resolution, point) {
return resolution / ol.math.cosh(point.y / ol.projection.EPSG3857.RADIUS);
return resolution / ol.math.cosh(point[1] / ol.projection.EPSG3857.RADIUS);
};

View File

@@ -6,7 +6,6 @@ goog.provide('ol.projection');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.object');
goog.require('ol.Coordinate');
goog.require('ol.Extent');
goog.require('ol.TransformFunction');
goog.require('ol.sphere.NORMAL');
@@ -226,18 +225,16 @@ ol.Proj4jsProjection_.prototype.getPointResolution =
}));
}
var vertices = [
point.x - resolution / 2, point.y,
point.x + resolution / 2, point.y,
point.x, point.y - resolution / 2,
point.x, point.y + resolution / 2
point[0] - resolution / 2, point[1],
point[0] + resolution / 2, point[1],
point[0], point[1] - resolution / 2,
point[0], point[1] + resolution / 2
];
vertices = this.toEPSG4326_(vertices, vertices, 2);
var width = ol.sphere.NORMAL.haversineDistance(
new ol.Coordinate(vertices[0], vertices[1]),
new ol.Coordinate(vertices[2], vertices[3]));
[vertices[0], vertices[1]], [vertices[2], vertices[3]]);
var height = ol.sphere.NORMAL.haversineDistance(
new ol.Coordinate(vertices[4], vertices[5]),
new ol.Coordinate(vertices[6], vertices[7]));
[vertices[4], vertices[5]], [vertices[6], vertices[7]]);
var pointResolution = (width + height) / 2;
if (this.getUnits() == ol.ProjectionUnits.FEET) {
// The radius of the normal sphere is defined in meters, so we must
@@ -651,9 +648,7 @@ ol.projection.cloneTransform = function(input, opt_output, opt_dimension) {
*/
ol.projection.transform = function(point, source, destination) {
var transformFn = ol.projection.getTransform(source, destination);
var vertex = [point.x, point.y];
vertex = transformFn(vertex, vertex, 2);
return new ol.Coordinate(vertex[0], vertex[1]);
return transformFn(point);
};
@@ -669,9 +664,7 @@ ol.projection.transformWithProjections =
function(point, sourceProjection, destinationProjection) {
var transformFn = ol.projection.getTransformFromProjections(
sourceProjection, destinationProjection);
var vertex = [point.x, point.y];
vertex = transformFn(vertex, vertex, 2);
return new ol.Coordinate(vertex[0], vertex[1]);
return transformFn(point);
};

View File

@@ -1,7 +1,6 @@
goog.provide('ol.Rectangle');
goog.require('goog.asserts');
goog.require('ol.Coordinate');
goog.require('ol.Size');
@@ -91,8 +90,7 @@ ol.Rectangle.prototype.extendXY = function(x, y) {
* @return {ol.Coordinate} Center.
*/
ol.Rectangle.prototype.getCenter = function() {
return new ol.Coordinate(
(this.minX + this.maxX) / 2, (this.minY + this.maxY) / 2);
return [(this.minX + this.maxX) / 2, (this.minY + this.maxY) / 2];
};
@@ -145,9 +143,10 @@ ol.Rectangle.prototype.isEmpty = function() {
* @return {ol.Coordinate} Coordinate.
*/
ol.Rectangle.prototype.normalize = function(coordinate) {
return new ol.Coordinate(
(coordinate.x - this.minX) / this.getWidth(),
(coordinate.y - this.minY) / this.getHeight());
return [
(coordinate[0] - this.minX) / this.getWidth(),
(coordinate[1] - this.minY) / this.getHeight()
];
};

View File

@@ -110,8 +110,8 @@ ol.renderer.canvas.ImageLayer.prototype.renderFrame =
1);
goog.vec.Mat4.translate(
transform,
(imageExtent.minX - viewCenter.x) / imageResolution,
(viewCenter.y - imageExtent.maxY) / imageResolution,
(imageExtent.minX - viewCenter[0]) / imageResolution,
(viewCenter[1] - imageExtent.maxY) / imageResolution,
0);
this.updateAttributions(frameState.attributions, image.getAttributions());

View File

@@ -254,8 +254,8 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
for (tileCoordKey in tilesToDraw) {
tile = tilesToDraw[tileCoordKey];
tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord);
x = (tileExtent.minX - origin.x) / tileResolution;
y = (origin.y - tileExtent.maxY) / tileResolution;
x = (tileExtent.minX - origin[0]) / tileResolution;
y = (origin[1] - tileExtent.maxY) / tileResolution;
width = scale * tileSize.width;
height = scale * tileSize.height;
tileState = tile.getState();
@@ -299,8 +299,8 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
1);
goog.vec.Mat4.translate(
transform,
(origin.x - center.x) / tileResolution,
(center.y - origin.y) / tileResolution,
(origin[0] - center[0]) / tileResolution,
(center[1] - origin[1]) / tileResolution,
0);
};

View File

@@ -236,8 +236,8 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
tileResolution / resolution, tileResolution / resolution, 1);
goog.vec.Mat4.rotateZ(transform, view2DState.rotation);
goog.vec.Mat4.translate(transform,
(sketchOrigin.x - view2DState.center.x) / tileResolution,
(view2DState.center.y - sketchOrigin.y) / tileResolution,
(sketchOrigin[0] - view2DState.center[0]) / tileResolution,
(view2DState.center[1] - sketchOrigin[1]) / tileResolution,
0);
/**
@@ -282,8 +282,8 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
-1 / tileResolution,
1);
goog.vec.Mat4.translate(sketchTransform,
-(sketchOrigin.x + halfWidth * tileResolution),
-(sketchOrigin.y - halfHeight * tileResolution),
-(sketchOrigin[0] + halfWidth * tileResolution),
-(sketchOrigin[1] - halfHeight * tileResolution),
0);
// clear/resize sketch canvas

View File

@@ -96,8 +96,8 @@ ol.renderer.dom.ImageLayer.prototype.renderFrame =
1);
goog.vec.Mat4.translate(
transform,
(imageExtent.minX - viewCenter.x) / imageResolution,
(viewCenter.y - imageExtent.maxY) / imageResolution,
(imageExtent.minX - viewCenter[0]) / imageResolution,
(viewCenter[1] - imageExtent.maxY) / imageResolution,
0);
if (image != this.image_) {
var imageElement = image.getImageElement(this);

View File

@@ -184,8 +184,8 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
resolution / view2DState.resolution, 1);
goog.vec.Mat4.translate(
transform,
(origin.x - center.x) / resolution,
(center.y - origin.y) / resolution,
(origin[0] - center[0]) / resolution,
(center[1] - origin[1]) / resolution,
0);
tileLayerZ.setTransform(transform);
if (tileLayerZKey in newTileLayerZKeys) {

View File

@@ -271,9 +271,10 @@ ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
*/
ol.renderer.Layer.prototype.snapCenterToPixel =
function(center, resolution, size) {
return new ol.Coordinate(
resolution * (Math.round(center.x / resolution) + (size.width % 2) / 2),
resolution * (Math.round(center.y / resolution) + (size.height % 2) / 2));
return [
resolution * (Math.round(center[0] / resolution) + (size.width % 2) / 2),
resolution * (Math.round(center[1] / resolution) + (size.height % 2) / 2)
];
};

View File

@@ -104,8 +104,8 @@ ol.renderer.Map.prototype.calculateMatrices2D = function(frameState) {
goog.vec.Mat4.rotateZ(coordinateToPixelMatrix,
-view2DState.rotation);
goog.vec.Mat4.translate(coordinateToPixelMatrix,
-view2DState.center.x,
-view2DState.center.y,
-view2DState.center[0],
-view2DState.center[1],
0);
var inverted = goog.vec.Mat4.invert(

View File

@@ -163,8 +163,8 @@ ol.renderer.webgl.ImageLayer.prototype.updateProjectionMatrix_ =
2 / canvasExtentWidth, 2 / canvasExtentHeight, 1);
goog.vec.Mat4.rotateZ(projectionMatrix, -viewRotation);
goog.vec.Mat4.translate(projectionMatrix,
imageExtent.minX - viewCenter.x,
imageExtent.minY - viewCenter.y,
imageExtent.minX - viewCenter[0],
imageExtent.minY - viewCenter[1],
0);
goog.vec.Mat4.scale(projectionMatrix,
imageExtent.getWidth() / 2, imageExtent.getHeight() / 2, 1);

View File

@@ -174,8 +174,8 @@ ol.renderer.webgl.Map = function(container, map) {
var tile = /** @type {ol.Tile} */ (element[0]);
var tileCenter = /** @type {ol.Coordinate} */ (element[1]);
var tileResolution = /** @type {number} */ (element[2]);
var deltaX = tileCenter.x - this.focus_.x;
var deltaY = tileCenter.y - this.focus_.y;
var deltaX = tileCenter[0] - this.focus_[0];
var deltaY = tileCenter[1] - this.focus_[1];
return 65536 * Math.log(tileResolution) +
Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution;
}, this),

View File

@@ -156,8 +156,8 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
tileResolution * framebufferDimension,
tileResolution * framebufferDimension);
var origin = tileGrid.getOrigin(z);
var minX = origin.x + tileRange.minX * tileSize.width * tileResolution;
var minY = origin.y + tileRange.minY * tileSize.height * tileResolution;
var minX = origin[0] + tileRange.minX * tileSize.width * tileResolution;
var minY = origin[1] + tileRange.minY * tileSize.height * tileResolution;
framebufferExtent = new ol.Extent(
minX,
minY,
@@ -286,9 +286,9 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
var texCoordMatrix = this.texCoordMatrix;
goog.vec.Mat4.makeIdentity(texCoordMatrix);
goog.vec.Mat4.translate(texCoordMatrix,
(center.x - framebufferExtent.minX) /
(center[0] - framebufferExtent.minX) /
(framebufferExtent.maxX - framebufferExtent.minX),
(center.y - framebufferExtent.minY) /
(center[1] - framebufferExtent.minY) /
(framebufferExtent.maxY - framebufferExtent.minY),
0);
goog.vec.Mat4.rotateZ(texCoordMatrix, view2DState.rotation);

View File

@@ -11,7 +11,6 @@
goog.provide('ol.Sphere');
goog.require('goog.math');
goog.require('ol.Coordinate');
@@ -37,9 +36,9 @@ ol.Sphere = function(radius) {
* @return {number} Spherical law of cosines distance.
*/
ol.Sphere.prototype.cosineDistance = function(c1, c2) {
var lat1 = goog.math.toRadians(c1.y);
var lat2 = goog.math.toRadians(c2.y);
var deltaLon = goog.math.toRadians(c2.x - c1.x);
var lat1 = goog.math.toRadians(c1[1]);
var lat2 = goog.math.toRadians(c2[1]);
var deltaLon = goog.math.toRadians(c2[0] - c1[0]);
return this.radius * Math.acos(
Math.sin(lat1) * Math.sin(lat2) +
Math.cos(lat1) * Math.cos(lat2) * Math.cos(deltaLon));
@@ -73,9 +72,9 @@ ol.Sphere.prototype.crossTrackDistance = function(c1, c2, c3) {
* @return {number} Equirectangular distance.
*/
ol.Sphere.prototype.equirectangularDistance = function(c1, c2) {
var lat1 = goog.math.toRadians(c1.y);
var lat2 = goog.math.toRadians(c2.y);
var deltaLon = goog.math.toRadians(c2.x - c1.x);
var lat1 = goog.math.toRadians(c1[1]);
var lat2 = goog.math.toRadians(c2[1]);
var deltaLon = goog.math.toRadians(c2[0] - c1[0]);
var x = deltaLon * Math.cos((lat1 + lat2) / 2);
var y = lat2 - lat1;
return this.radius * Math.sqrt(x * x + y * y);
@@ -102,10 +101,10 @@ ol.Sphere.prototype.finalBearing = function(c1, c2) {
* @return {number} Haversine distance.
*/
ol.Sphere.prototype.haversineDistance = function(c1, c2) {
var lat1 = goog.math.toRadians(c1.y);
var lat2 = goog.math.toRadians(c2.y);
var lat1 = goog.math.toRadians(c1[1]);
var lat2 = goog.math.toRadians(c2[1]);
var deltaLatBy2 = (lat2 - lat1) / 2;
var deltaLonBy2 = goog.math.toRadians(c2.x - c1.x) / 2;
var deltaLonBy2 = goog.math.toRadians(c2[0] - c1[0]) / 2;
var a = Math.sin(deltaLatBy2) * Math.sin(deltaLatBy2) +
Math.sin(deltaLonBy2) * Math.sin(deltaLonBy2) *
Math.cos(lat1) * Math.cos(lat2);
@@ -121,9 +120,9 @@ ol.Sphere.prototype.haversineDistance = function(c1, c2) {
* @return {number} Initial bearing.
*/
ol.Sphere.prototype.initialBearing = function(c1, c2) {
var lat1 = goog.math.toRadians(c1.y);
var lat2 = goog.math.toRadians(c2.y);
var deltaLon = goog.math.toRadians(c2.x - c1.x);
var lat1 = goog.math.toRadians(c1[1]);
var lat2 = goog.math.toRadians(c2[1]);
var deltaLon = goog.math.toRadians(c2[0] - c1[0]);
var y = Math.sin(deltaLon) * Math.cos(lat2);
var x = Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(deltaLon);
@@ -153,17 +152,17 @@ ol.Sphere.prototype.maximumLatitude = function(bearing, latitude) {
* @return {ol.Coordinate} Midpoint.
*/
ol.Sphere.prototype.midpoint = function(c1, c2) {
var lat1 = goog.math.toRadians(c1.y);
var lat2 = goog.math.toRadians(c2.y);
var lon1 = goog.math.toRadians(c1.x);
var deltaLon = goog.math.toRadians(c2.x - c1.x);
var lat1 = goog.math.toRadians(c1[1]);
var lat2 = goog.math.toRadians(c2[1]);
var lon1 = goog.math.toRadians(c1[0]);
var deltaLon = goog.math.toRadians(c2[0] - c1[0]);
var Bx = Math.cos(lat2) * Math.cos(deltaLon);
var By = Math.cos(lat2) * Math.sin(deltaLon);
var cosLat1PlusBx = Math.cos(lat1) + Bx;
var lat = Math.atan2(Math.sin(lat1) + Math.sin(lat2),
Math.sqrt(cosLat1PlusBx * cosLat1PlusBx + By * By));
var lon = lon1 + Math.atan2(By, cosLat1PlusBx);
return new ol.Coordinate(goog.math.toDegrees(lon), goog.math.toDegrees(lat));
return [goog.math.toDegrees(lon), goog.math.toDegrees(lat)];
};
@@ -176,8 +175,8 @@ ol.Sphere.prototype.midpoint = function(c1, c2) {
* @return {ol.Coordinate} Coordinate.
*/
ol.Sphere.prototype.offset = function(c1, distance, bearing) {
var lat1 = goog.math.toRadians(c1.y);
var lon1 = goog.math.toRadians(c1.x);
var lat1 = goog.math.toRadians(c1[1]);
var lon1 = goog.math.toRadians(c1[0]);
var dByR = distance / this.radius;
var lat = Math.asin(
Math.sin(lat1) * Math.cos(dByR) +
@@ -185,5 +184,5 @@ ol.Sphere.prototype.offset = function(c1, distance, bearing) {
var lon = lon1 + Math.atan2(
Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1),
Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
return new ol.Coordinate(goog.math.toDegrees(lon), goog.math.toDegrees(lat));
return [goog.math.toDegrees(lon), goog.math.toDegrees(lat)];
};

View File

@@ -1,7 +1,6 @@
goog.provide('ol.TileCoord');
goog.require('goog.array');
goog.require('ol.Coordinate');
/**
@@ -18,23 +17,29 @@ ol.QuadKeyCharCode = {
/**
* @constructor
* @extends {ol.Coordinate}
* @param {number} z Zoom level.
* @param {number} x X.
* @param {number} y Y.
*/
ol.TileCoord = function(z, x, y) {
goog.base(this, x, y);
/**
* Zoom level.
* @type {number}
*/
this.z = z;
/**
* @type {number}
*/
this.x = x;
/**
* @type {number}
*/
this.y = y;
};
goog.inherits(ol.TileCoord, ol.Coordinate);
/**

View File

@@ -174,10 +174,10 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
var origin = this.getOrigin(z);
var resolution = this.getResolution(z);
var tileSize = this.getTileSize(z);
var minX = origin.x + tileRange.minX * tileSize.width * resolution;
var minY = origin.y + tileRange.minY * tileSize.height * resolution;
var maxX = origin.x + (tileRange.maxX + 1) * tileSize.width * resolution;
var maxY = origin.y + (tileRange.maxY + 1) * tileSize.height * resolution;
var minX = origin[0] + tileRange.minX * tileSize.width * resolution;
var minY = origin[1] + tileRange.minY * tileSize.height * resolution;
var maxX = origin[0] + (tileRange.maxX + 1) * tileSize.width * resolution;
var maxY = origin[1] + (tileRange.maxY + 1) * tileSize.height * resolution;
return new ol.Extent(minX, minY, maxX, maxY);
};
@@ -216,9 +216,10 @@ ol.tilegrid.TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
var origin = this.getOrigin(tileCoord.z);
var resolution = this.getResolution(tileCoord.z);
var tileSize = this.getTileSize(tileCoord.z);
var x = origin.x + (tileCoord.x + 0.5) * tileSize.width * resolution;
var y = origin.y + (tileCoord.y + 0.5) * tileSize.height * resolution;
return new ol.Coordinate(x, y);
return [
origin[0] + (tileCoord.x + 0.5) * tileSize.width * resolution,
origin[1] + (tileCoord.y + 0.5) * tileSize.height * resolution
];
};
@@ -230,8 +231,8 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
var origin = this.getOrigin(tileCoord.z);
var resolution = this.getResolution(tileCoord.z);
var tileSize = this.getTileSize(tileCoord.z);
var minX = origin.x + tileCoord.x * tileSize.width * resolution;
var minY = origin.y + tileCoord.y * tileSize.height * resolution;
var minX = origin[0] + tileCoord.x * tileSize.width * resolution;
var minY = origin[1] + tileCoord.y * tileSize.height * resolution;
var maxX = minX + tileSize.width * resolution;
var maxY = minY + tileSize.height * resolution;
return new ol.Extent(minX, minY, maxX, maxY);
@@ -250,7 +251,7 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
coordinate, resolution) {
return this.getTileCoordForXYAndResolution_(
coordinate.x, coordinate.y, resolution, false);
coordinate[0], coordinate[1], resolution, false);
};
@@ -271,8 +272,8 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
var origin = this.getOrigin(z);
var tileSize = this.getTileSize(z);
var tileCoordX = scale * (x - origin.x) / (resolution * tileSize.width);
var tileCoordY = scale * (y - origin.y) / (resolution * tileSize.height);
var tileCoordX = scale * (x - origin[0]) / (resolution * tileSize.width);
var tileCoordY = scale * (y - origin[1]) / (resolution * tileSize.height);
if (reverseIntersectionPolicy) {
tileCoordX = Math.ceil(tileCoordX) - 1;
@@ -295,7 +296,7 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ =
function(coordinate, z) {
var resolution = this.getResolution(z);
return this.getTileCoordForXYAndResolution_(
coordinate.x, coordinate.y, resolution, false);
coordinate[0], coordinate[1], resolution, false);
};

View File

@@ -1,6 +1,5 @@
goog.provide('ol.tilegrid.XYZ');
goog.require('ol.Coordinate');
goog.require('ol.Size');
goog.require('ol.TileRange');
goog.require('ol.projection');
@@ -24,8 +23,8 @@ ol.tilegrid.XYZ = function(xyzOptions) {
}
goog.base(this, {
origin: new ol.Coordinate(-ol.projection.EPSG3857.HALF_SIZE,
ol.projection.EPSG3857.HALF_SIZE),
origin: [-ol.projection.EPSG3857.HALF_SIZE,
ol.projection.EPSG3857.HALF_SIZE],
resolutions: resolutions,
tileSize: new ol.Size(ol.DEFAULT_TILE_SIZE, ol.DEFAULT_TILE_SIZE)
});

View File

@@ -5,7 +5,6 @@ goog.provide('ol.View2D');
goog.provide('ol.View2DProperty');
goog.require('ol.Constraints');
goog.require('ol.Coordinate');
goog.require('ol.Extent');
goog.require('ol.IView2D');
goog.require('ol.IView3D');
@@ -15,6 +14,7 @@ goog.require('ol.RotationConstraint');
goog.require('ol.Size');
goog.require('ol.View');
goog.require('ol.animation');
goog.require('ol.coordinate');
goog.require('ol.easing');
goog.require('ol.projection');
@@ -94,10 +94,10 @@ ol.View2D.prototype.getExtent = function(size) {
goog.asserts.assert(this.isDef());
var center = this.getCenter();
var resolution = this.getResolution();
var minX = center.x - resolution * size.width / 2;
var minY = center.y - resolution * size.height / 2;
var maxX = center.x + resolution * size.width / 2;
var maxY = center.y + resolution * size.height / 2;
var minX = center[0] - resolution * size.width / 2;
var minY = center[1] - resolution * size.height / 2;
var maxX = center[0] + resolution * size.width / 2;
var maxY = center[1] + resolution * size.height / 2;
return new ol.Extent(minX, minY, maxX, maxY);
};
@@ -171,7 +171,7 @@ ol.View2D.prototype.getView2DState = function() {
var resolution = /** @type {number} */ (this.getResolution());
var rotation = /** @type {number} */ (this.getRotation());
return {
center: new ol.Coordinate(center.x, center.y),
center: center.slice(),
projection: projection,
resolution: resolution,
rotation: rotation
@@ -271,8 +271,7 @@ ol.View2D.prototype.pan = function(map, delta, opt_duration) {
easing: ol.easing.linear
}));
}
this.setCenter(new ol.Coordinate(
currentCenter.x + delta.x, currentCenter.y + delta.y));
this.setCenter([currentCenter[0] + delta[0], currentCenter[1] + delta[1]]);
}
};
@@ -320,12 +319,9 @@ ol.View2D.prototype.rotateWithoutConstraints =
if (goog.isDefAndNotNull(opt_anchor)) {
var anchor = opt_anchor;
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
var center = new ol.Coordinate(
oldCenter.x - anchor.x,
oldCenter.y - anchor.y);
center.rotate(rotation - this.getRotation());
center.x += anchor.x;
center.y += anchor.y;
var center = [oldCenter[0] - anchor[0], oldCenter[1] - anchor[1]];
ol.coordinate.rotate(center, rotation - this.getRotation());
ol.coordinate.add(center, anchor);
map.withFrozenRendering(function() {
this.setCenter(center);
this.setRotation(rotation);
@@ -404,9 +400,11 @@ ol.View2D.prototype.zoomWithoutConstraints =
var anchor = opt_anchor;
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
var oldResolution = this.getResolution();
var x = anchor.x - resolution * (anchor.x - oldCenter.x) / oldResolution;
var y = anchor.y - resolution * (anchor.y - oldCenter.y) / oldResolution;
var center = new ol.Coordinate(x, y);
var x =
anchor[0] - resolution * (anchor[0] - oldCenter[0]) / oldResolution;
var y =
anchor[1] - resolution * (anchor[1] - oldCenter[1]) / oldResolution;
var center = [x, y];
map.withFrozenRendering(function() {
this.setCenter(center);
this.setResolution(resolution);