diff --git a/src/ol/control/dragboxcontrol.js b/src/ol/control/dragboxcontrol.js index b02e8a5afb4..d77afef74c5 100644 --- a/src/ol/control/dragboxcontrol.js +++ b/src/ol/control/dragboxcontrol.js @@ -59,7 +59,8 @@ ol.control.DragBox.prototype.setMap = function(map) { if (!goog.isNull(map)) { this.startPixel_ = map.getPixelFromCoordinate(this.startCoordinate_); goog.asserts.assert(goog.isDef(this.startPixel_)); - goog.style.setPosition(this.element, this.startPixel_); + goog.style.setPosition(this.element, + this.startPixel_[0], this.startPixel_[1]); goog.style.setBorderBoxSize(this.element, new ol.Size(0, 0)); this.listenerKeys.push(goog.events.listen( map, ol.MapBrowserEvent.EventType.DRAG, this.updateBox_, false, this)); @@ -76,10 +77,10 @@ ol.control.DragBox.prototype.updateBox_ = function(mapBrowserEvent) { var coordinate = mapBrowserEvent.getCoordinate(); goog.asserts.assert(goog.isDef(coordinate)); var currentPixel = map.getPixelFromCoordinate(coordinate); - goog.style.setPosition(this.element, new ol.Pixel( - Math.min(currentPixel.x, this.startPixel_.x), - Math.min(currentPixel.y, this.startPixel_.y))); + goog.style.setPosition(this.element, + Math.min(currentPixel[0], this.startPixel_[0]), + Math.min(currentPixel[1], this.startPixel_[1])); goog.style.setBorderBoxSize(this.element, new ol.Size( - Math.abs(currentPixel.x - this.startPixel_.x), - Math.abs(currentPixel.y - this.startPixel_.y))); + Math.abs(currentPixel[0] - this.startPixel_[0]), + Math.abs(currentPixel[1] - this.startPixel_[1]))); }; diff --git a/src/ol/control/mousepositioncontrol.js b/src/ol/control/mousepositioncontrol.js index 5903c49bce3..9e848c9b800 100644 --- a/src/ol/control/mousepositioncontrol.js +++ b/src/ol/control/mousepositioncontrol.js @@ -115,9 +115,8 @@ ol.control.MousePosition.prototype.handleMouseMove = function(browserEvent) { var map = this.getMap(); var eventPosition = goog.style.getRelativePosition( browserEvent, map.getViewport()); - var pixel = new ol.Pixel(eventPosition.x, eventPosition.y); - this.updateHTML_(pixel); - this.lastMouseMovePixel_ = pixel; + this.lastMouseMovePixel_ = [eventPosition.x, eventPosition.y]; + this.updateHTML_(this.lastMouseMovePixel_); }; diff --git a/src/ol/interaction/dragpaninteraction.js b/src/ol/interaction/dragpaninteraction.js index 5588159fc48..9f8220f0c28 100644 --- a/src/ol/interaction/dragpaninteraction.js +++ b/src/ol/interaction/dragpaninteraction.js @@ -4,7 +4,6 @@ goog.provide('ol.interaction.DragPan'); goog.require('goog.asserts'); goog.require('ol.Kinetic'); -goog.require('ol.Pixel'); goog.require('ol.PreRenderFunction'); goog.require('ol.View2D'); goog.require('ol.ViewHint'); @@ -91,10 +90,10 @@ ol.interaction.DragPan.prototype.handleDragEnd = function(mapBrowserEvent) { map.addPreRenderFunction(this.kineticPreRenderFn_); var centerpx = map.getPixelFromCoordinate(center); - var destpx = new ol.Pixel( - centerpx.x - distance * Math.cos(angle), - centerpx.y - distance * Math.sin(angle)); - var dest = map.getCoordinateFromPixel(destpx); + var dest = map.getCoordinateFromPixel([ + centerpx[0] - distance * Math.cos(angle), + centerpx[1] - distance * Math.sin(angle) + ]); view.setCenter(dest); } else if (interacting === 0) { map.requestRenderFrame(); diff --git a/src/ol/interaction/dragrotateinteraction.js b/src/ol/interaction/dragrotateinteraction.js index 1369340c87d..4130ea87d9c 100644 --- a/src/ol/interaction/dragrotateinteraction.js +++ b/src/ol/interaction/dragrotateinteraction.js @@ -51,7 +51,8 @@ ol.interaction.DragRotate.prototype.handleDrag = function(mapBrowserEvent) { var map = mapBrowserEvent.map; var size = map.getSize(); var offset = mapBrowserEvent.getPixel(); - var theta = Math.atan2(size.height / 2 - offset.y, offset.x - size.width / 2); + var theta = + Math.atan2(size.height / 2 - offset[1], offset[0] - size.width / 2); if (goog.isDef(this.lastAngle_)) { var delta = theta - this.lastAngle_; var view = map.getView(); diff --git a/src/ol/interaction/touchinteraction.js b/src/ol/interaction/touchinteraction.js index 322b572dd15..60a57ffe484 100644 --- a/src/ol/interaction/touchinteraction.js +++ b/src/ol/interaction/touchinteraction.js @@ -52,7 +52,7 @@ ol.interaction.Touch.centroid = function(touches) { clientX += touches[i].clientX; clientY += touches[i].clientY; } - return new ol.Pixel(clientX / length, clientY / length); + return [clientX / length, clientY / length]; }; diff --git a/src/ol/interaction/touchpaninteraction.js b/src/ol/interaction/touchpaninteraction.js index 9467b85a55c..a13585c0d48 100644 --- a/src/ol/interaction/touchpaninteraction.js +++ b/src/ol/interaction/touchpaninteraction.js @@ -58,10 +58,10 @@ ol.interaction.TouchPan.prototype.handleTouchMove = function(mapBrowserEvent) { var centroid = ol.interaction.Touch.centroid(this.targetTouches); if (!goog.isNull(this.lastCentroid)) { if (this.kinetic_) { - this.kinetic_.update(centroid.x, centroid.y); + this.kinetic_.update(centroid[0], centroid[1]); } - var deltaX = this.lastCentroid.x - centroid.x; - var deltaY = centroid.y - this.lastCentroid.y; + var deltaX = this.lastCentroid[0] - centroid[0]; + var deltaY = centroid[1] - this.lastCentroid[1]; var map = mapBrowserEvent.map; var view = map.getView(); var center = [deltaX, deltaY]; @@ -91,10 +91,10 @@ ol.interaction.TouchPan.prototype.handleTouchEnd = this.kineticPreRenderFn_ = this.kinetic_.pan(center); map.addPreRenderFunction(this.kineticPreRenderFn_); var centerpx = map.getPixelFromCoordinate(center); - var destpx = new ol.Pixel( - centerpx.x - distance * Math.cos(angle), - centerpx.y - distance * Math.sin(angle)); - var dest = map.getCoordinateFromPixel(destpx); + var dest = map.getCoordinateFromPixel([ + centerpx[0] - distance * Math.cos(angle), + centerpx[1] - distance * Math.sin(angle) + ]); view.setCenter(dest); } else if (interacting === 0) { map.requestRenderFrame(); diff --git a/src/ol/interaction/touchrotateinteraction.js b/src/ol/interaction/touchrotateinteraction.js index 291d8156f02..d7c737cc3ea 100644 --- a/src/ol/interaction/touchrotateinteraction.js +++ b/src/ol/interaction/touchrotateinteraction.js @@ -97,8 +97,8 @@ ol.interaction.TouchRotate.prototype.handleTouchMove = // touch0,touch1 and previousTouch0,previousTouch1 var viewportPosition = goog.style.getClientPosition(map.getViewport()); var centroid = ol.interaction.Touch.centroid(this.targetTouches); - centroid.x -= viewportPosition.x; - centroid.y -= viewportPosition.y; + centroid[0] -= viewportPosition[0]; + centroid[1] -= viewportPosition[1]; this.anchor_ = map.getCoordinateFromPixel(centroid); // rotate diff --git a/src/ol/interaction/touchzoominteraction.js b/src/ol/interaction/touchzoominteraction.js index d68e2f853d2..18145f38960 100644 --- a/src/ol/interaction/touchzoominteraction.js +++ b/src/ol/interaction/touchzoominteraction.js @@ -78,8 +78,8 @@ ol.interaction.TouchZoom.prototype.handleTouchMove = // scale anchor point. var viewportPosition = goog.style.getClientPosition(map.getViewport()); var centroid = ol.interaction.Touch.centroid(this.targetTouches); - centroid.x -= viewportPosition.x; - centroid.y -= viewportPosition.y; + centroid[0] -= viewportPosition[0]; + centroid[1] -= viewportPosition[1]; this.anchor_ = map.getCoordinateFromPixel(centroid); // scale, bypass the resolution constraint diff --git a/src/ol/map.js b/src/ol/map.js index ae1625b9951..e6597922be0 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -421,7 +421,7 @@ ol.Map.prototype.getCoordinateFromPixel = function(pixel) { if (goog.isNull(frameState)) { return null; } else { - var vec2 = [pixel.x, pixel.y]; + var vec2 = pixel.slice(); return ol.vec.Mat4.multVec2(frameState.pixelToCoordinateMatrix, vec2, vec2); } }; @@ -470,8 +470,7 @@ ol.Map.prototype.getPixelFromCoordinate = function(coordinate) { return null; } else { var vec2 = coordinate.slice(0, 2); - ol.vec.Mat4.multVec2(frameState.coordinateToPixelMatrix, vec2, vec2); - return new ol.Pixel(vec2[0], vec2[1]); + return ol.vec.Mat4.multVec2(frameState.coordinateToPixelMatrix, vec2, vec2); } }; diff --git a/src/ol/mapbrowserevent.js b/src/ol/mapbrowserevent.js index e3518aea7e0..c7f42901a93 100644 --- a/src/ol/mapbrowserevent.js +++ b/src/ol/mapbrowserevent.js @@ -82,7 +82,7 @@ ol.MapBrowserEvent.prototype.getPixel = function() { if (goog.isNull(this.pixel_)) { var eventPosition = goog.style.getRelativePosition( this.browserEvent, this.map.getViewport()); - this.pixel_ = new ol.Pixel(eventPosition.x, eventPosition.y); + this.pixel_ = [eventPosition.x, eventPosition.y]; } return this.pixel_; }; diff --git a/src/ol/overlay.js b/src/ol/overlay.js index 79808efa005..fda2888a74c 100644 --- a/src/ol/overlay.js +++ b/src/ol/overlay.js @@ -279,7 +279,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { if (this.rendered_.left_ !== '') { this.rendered_.left_ = style.left = ''; } - var right = Math.round(mapSize.width - pixel.x) + 'px'; + var right = Math.round(mapSize.width - pixel[0]) + 'px'; if (this.rendered_.right_ != right) { this.rendered_.right_ = style.right = right; } @@ -287,7 +287,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { if (this.rendered_.right_ !== '') { this.rendered_.right_ = style.right = ''; } - var left = Math.round(pixel.x) + 'px'; + var left = Math.round(pixel[0]) + 'px'; if (this.rendered_.left_ != left) { this.rendered_.left_ = style.left = left; } @@ -297,7 +297,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { if (this.rendered_.bottom_ !== '') { this.rendered_.bottom_ = style.bottom = ''; } - var top = Math.round(pixel.y) + 'px'; + var top = Math.round(pixel[1]) + 'px'; if (this.rendered_.top_ != top) { this.rendered_.top_ = style.top = top; } @@ -305,7 +305,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { if (this.rendered_.top_ !== '') { this.rendered_.top_ = style.top = ''; } - var bottom = Math.round(mapSize.height - pixel.y) + 'px'; + var bottom = Math.round(mapSize.height - pixel[1]) + 'px'; if (this.rendered_.bottom_ != bottom) { this.rendered_.bottom_ = style.bottom = bottom; } diff --git a/src/ol/pixel.js b/src/ol/pixel.js index 39eb9070bf0..40c8a11da8c 100644 --- a/src/ol/pixel.js +++ b/src/ol/pixel.js @@ -1,16 +1,7 @@ goog.provide('ol.Pixel'); -goog.require('goog.math.Coordinate'); - - /** - * @constructor - * @extends {goog.math.Coordinate} - * @param {number} x X. - * @param {number} y Y. + * @typedef {Array.} */ -ol.Pixel = function(x, y) { - goog.base(this, x, y); -}; -goog.inherits(ol.Pixel, goog.math.Coordinate); +ol.Pixel; diff --git a/src/ol/renderer/canvas/canvasvectorrenderer.js b/src/ol/renderer/canvas/canvasvectorrenderer.js index a5ac95d2298..12e37da1c87 100644 --- a/src/ol/renderer/canvas/canvasvectorrenderer.js +++ b/src/ol/renderer/canvas/canvasvectorrenderer.js @@ -42,8 +42,8 @@ ol.renderer.canvas.VectorRenderer = var context = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d')), - dx = goog.isDef(opt_offset) ? opt_offset.x : 0, - dy = goog.isDef(opt_offset) ? opt_offset.y : 0; + dx = goog.isDef(opt_offset) ? opt_offset[0] : 0, + dy = goog.isDef(opt_offset) ? opt_offset[1] : 0; /** * @type {goog.vec.Mat4.Number}