Skip to content

Commit

Permalink
Redefine ol.Pixel to be Array.<number>
Browse files Browse the repository at this point in the history
  • Loading branch information
fredj committed May 31, 2013
1 parent 075f4aa commit be081fd
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 48 deletions.
13 changes: 7 additions & 6 deletions src/ol/control/dragboxcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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])));
};
5 changes: 2 additions & 3 deletions src/ol/control/mousepositioncontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
};


Expand Down
9 changes: 4 additions & 5 deletions src/ol/interaction/dragpaninteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/ol/interaction/dragrotateinteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/ol/interaction/touchinteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};


Expand Down
14 changes: 7 additions & 7 deletions src/ol/interaction/touchpaninteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/ol/interaction/touchrotateinteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ol/interaction/touchzoominteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/ol/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/ol/mapbrowserevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};
Expand Down
8 changes: 4 additions & 4 deletions src/ol/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ 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;
}
} else {
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;
}
Expand All @@ -297,15 +297,15 @@ 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;
}
} else {
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;
}
Expand Down
13 changes: 2 additions & 11 deletions src/ol/pixel.js
Original file line number Diff line number Diff line change
@@ -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.<number>}
*/
ol.Pixel = function(x, y) {
goog.base(this, x, y);
};
goog.inherits(ol.Pixel, goog.math.Coordinate);
ol.Pixel;
4 changes: 2 additions & 2 deletions src/ol/renderer/canvas/canvasvectorrenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit be081fd

Please sign in to comment.