Create ol.Coordinate around goog.math.Coordinate

This commit is contained in:
Tom Payne
2012-07-19 10:34:12 +02:00
parent d62ba69458
commit c547404615
22 changed files with 155 additions and 131 deletions

View File

@@ -1,5 +1,5 @@
goog.require('goog.math.Coordinate');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol.Coordinate');
goog.require('ol.RendererHint'); goog.require('ol.RendererHint');
goog.require('ol.createMap'); goog.require('ol.createMap');
goog.require('ol.tilelayer.createOpenStreetMap'); goog.require('ol.tilelayer.createOpenStreetMap');
@@ -18,7 +18,7 @@ layer = ol.tilelayer.createOpenStreetMap({
map.getLayers().push(layer); map.getLayers().push(layer);
var resolutions = layer.getStore().getResolutions(); var resolutions = layer.getStore().getResolutions();
map1.setCenter(new goog.math.Coordinate(0, 0)); map1.setCenter(new ol.Coordinate(0, 0));
map1.setResolution(resolutions[0]); map1.setResolution(resolutions[0]);
if (twoMaps) { if (twoMaps) {

View File

@@ -6,6 +6,7 @@ goog.provide('ol.control.Drag');
goog.require('goog.events.EventType'); goog.require('goog.events.EventType');
goog.require('goog.functions'); goog.require('goog.functions');
goog.require('ol.Control'); goog.require('ol.Control');
goog.require('ol.Coordinate');
goog.require('ol.MapBrowserEvent'); goog.require('ol.MapBrowserEvent');
@@ -45,12 +46,12 @@ ol.control.Drag = function() {
this.offsetY = 0; this.offsetY = 0;
/** /**
* @type {goog.math.Coordinate} * @type {ol.Coordinate}
*/ */
this.startCenter = null; this.startCenter = null;
/** /**
* @type {goog.math.Coordinate} * @type {ol.Coordinate}
*/ */
this.startCoordinate = null; this.startCoordinate = null;

View File

@@ -1,6 +1,6 @@
goog.provide('ol.control.DragPan'); goog.provide('ol.control.DragPan');
goog.require('goog.math.Coordinate'); goog.require('ol.Coordinate');
goog.require('ol.MapBrowserEvent'); goog.require('ol.MapBrowserEvent');
goog.require('ol.control.Drag'); goog.require('ol.control.Drag');
@@ -22,7 +22,7 @@ goog.inherits(ol.control.DragPan, ol.control.Drag);
ol.control.DragPan.prototype.handleDrag = function(mapBrowserEvent) { ol.control.DragPan.prototype.handleDrag = function(mapBrowserEvent) {
var map = mapBrowserEvent.map; var map = mapBrowserEvent.map;
var resolution = map.getResolution(); var resolution = map.getResolution();
var center = new goog.math.Coordinate( var center = new ol.Coordinate(
this.startCenter.x - resolution * this.deltaX, this.startCenter.x - resolution * this.deltaX,
this.startCenter.y + resolution * this.deltaY); this.startCenter.y + resolution * this.deltaY);
map.setCenter(center); map.setCenter(center);

24
src/ol/coordinate.js Normal file
View File

@@ -0,0 +1,24 @@
goog.provide('ol.Coordinate');
goog.require('goog.math.Coordinate');
/**
* @constructor
* @extends {goog.math.Coordinate}
* @param {number} x X.
* @param {number} y Y.
*/
ol.Coordinate = function(x, y) {
goog.base(this, x, y);
};
goog.inherits(ol.Coordinate, goog.math.Coordinate);
/**
* @return {ol.Coordinate} Clone.
*/
ol.Coordinate.prototype.clone = function() {
return new ol.Coordinate(this.x, this.y);
};

View File

@@ -1,5 +1,6 @@
goog.provide('ol.dom.LayerRenderer'); goog.provide('ol.dom.LayerRenderer');
goog.require('ol.Coordinate');
goog.require('ol.LayerRenderer'); goog.require('ol.LayerRenderer');
@@ -23,7 +24,7 @@ ol.dom.LayerRenderer = function(map, layer, target) {
/** /**
* Top left corner of the target in map coords. * Top left corner of the target in map coords.
* *
* @type {goog.math.Coordinate} * @type {ol.Coordinate}
* @protected * @protected
*/ */
this.origin = null; this.origin = null;
@@ -44,7 +45,7 @@ ol.dom.LayerRenderer.prototype.getMap = function() {
/** /**
* Set the location of the top left corner of the target. * Set the location of the top left corner of the target.
* *
* @param {goog.math.Coordinate} origin Origin. * @param {ol.Coordinate} origin Origin.
*/ */
ol.dom.LayerRenderer.prototype.setOrigin = function(origin) { ol.dom.LayerRenderer.prototype.setOrigin = function(origin) {
this.origin = origin; this.origin = origin;

View File

@@ -3,8 +3,8 @@ goog.provide('ol.dom.Map');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.dom'); goog.require('goog.dom');
goog.require('goog.dom.TagName'); goog.require('goog.dom.TagName');
goog.require('goog.math.Coordinate');
goog.require('goog.style'); goog.require('goog.style');
goog.require('ol.Coordinate');
goog.require('ol.Map'); goog.require('ol.Map');
goog.require('ol.TileLayer'); goog.require('ol.TileLayer');
goog.require('ol.dom.TileLayerRenderer'); goog.require('ol.dom.TileLayerRenderer');
@@ -48,7 +48,7 @@ ol.dom.Map = function(target, opt_values) {
this.layerPanes_ = {}; this.layerPanes_ = {};
/** /**
* @type {goog.math.Coordinate|undefined} * @type {ol.Coordinate|undefined}
* @private * @private
*/ */
this.renderedCenter_ = undefined; this.renderedCenter_ = undefined;
@@ -56,7 +56,7 @@ ol.dom.Map = function(target, opt_values) {
/** /**
* The pixel offset of the layers pane with respect to its container. * The pixel offset of the layers pane with respect to its container.
* *
* @type {goog.math.Coordinate} * @type {ol.Coordinate}
* @private * @private
*/ */
this.layersPaneOffset_ = null; this.layersPaneOffset_ = null;
@@ -77,7 +77,7 @@ goog.inherits(ol.dom.Map, ol.Map);
* @private * @private
*/ */
ol.dom.Map.prototype.resetLayersPane_ = function() { ol.dom.Map.prototype.resetLayersPane_ = function() {
var offset = new goog.math.Coordinate(0, 0); var offset = new ol.Coordinate(0, 0);
goog.style.setPosition(this.layersPane_, offset); goog.style.setPosition(this.layersPane_, offset);
this.layersPaneOffset_ = offset; this.layersPaneOffset_ = offset;
@@ -97,7 +97,7 @@ ol.dom.Map.prototype.setOrigin_ = function() {
var targetSize = this.getSize(); var targetSize = this.getSize();
var targetWidth = targetSize.width; var targetWidth = targetSize.width;
var targetHeight = targetSize.height; var targetHeight = targetSize.height;
var origin = new goog.math.Coordinate( var origin = new ol.Coordinate(
center.x - resolution * targetWidth / 2, center.x - resolution * targetWidth / 2,
center.y + resolution * targetHeight / 2); center.y + resolution * targetHeight / 2);
goog.object.forEach(this.layerRenderers, function(layerRenderer) { goog.object.forEach(this.layerRenderers, function(layerRenderer) {

View File

@@ -1,5 +1,6 @@
goog.provide('ol.dom.TileLayerRenderer'); goog.provide('ol.dom.TileLayerRenderer');
goog.require('ol.Coordinate');
goog.require('ol.dom.LayerRenderer'); goog.require('ol.dom.LayerRenderer');
@@ -91,7 +92,7 @@ ol.dom.TileLayerRenderer.prototype.redraw = function() {
* @param {ol.Extent} extent Map extent. * @param {ol.Extent} extent Map extent.
* @param {ol.TileBounds} tileBounds Tile bounds. * @param {ol.TileBounds} tileBounds Tile bounds.
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
* @return {goog.math.Coordinate} Offset. * @return {ol.Coordinate} Offset.
*/ */
ol.dom.TileLayerRenderer.prototype.getTilesMapOffset_ = function( ol.dom.TileLayerRenderer.prototype.getTilesMapOffset_ = function(
extent, tileBounds, resolution) { extent, tileBounds, resolution) {
@@ -103,7 +104,7 @@ ol.dom.TileLayerRenderer.prototype.getTilesMapOffset_ = function(
var tileCoord = new ol.TileCoord(z, tileBounds.minX, tileBounds.maxY); var tileCoord = new ol.TileCoord(z, tileBounds.minX, tileBounds.maxY);
var tileCoordExtent = tileGrid.getTileCoordExtent(tileCoord); var tileCoordExtent = tileGrid.getTileCoordExtent(tileCoord);
var offset = new goog.math.Coordinate( var offset = new ol.Coordinate(
Math.round((this.origin.x - tileCoordExtent.minX) / resolution), Math.round((this.origin.x - tileCoordExtent.minX) / resolution),
Math.round((tileCoordExtent.maxY - this.origin.y) / resolution)); Math.round((tileCoordExtent.maxY - this.origin.y) / resolution));

View File

@@ -1,5 +1,6 @@
goog.provide('ol.Extent'); goog.provide('ol.Extent');
goog.require('ol.Coordinate');
goog.require('ol.Rectangle'); goog.require('ol.Rectangle');
goog.require('ol.TransformFunction'); goog.require('ol.TransformFunction');
@@ -20,7 +21,7 @@ goog.inherits(ol.Extent, ol.Rectangle);
/** /**
* @param {...goog.math.Coordinate} var_args Coordinates. * @param {...ol.Coordinate} var_args Coordinates.
* @return {!ol.Extent} Boundin extent. * @return {!ol.Extent} Boundin extent.
*/ */
ol.Extent.boundingExtent = function(var_args) { ol.Extent.boundingExtent = function(var_args) {
@@ -52,7 +53,7 @@ ol.Extent.prototype.clone = function() {
* @return {ol.Extent} Extent. * @return {ol.Extent} Extent.
*/ */
ol.Extent.prototype.transform = function(transform) { ol.Extent.prototype.transform = function(transform) {
var min = transform(new goog.math.Coordinate(this.minX, this.minY)); var min = transform(new ol.Coordinate(this.minX, this.minY));
var max = transform(new goog.math.Coordinate(this.maxX, this.maxY)); var max = transform(new ol.Coordinate(this.maxX, this.maxY));
return new ol.Extent(min.x, min.y, max.x, max.y); return new ol.Extent(min.x, min.y, max.x, max.y);
}; };

View File

@@ -1,4 +1,3 @@
goog.require('goog.math.Coordinate');
goog.require('goog.testing.jsunit'); goog.require('goog.testing.jsunit');
goog.require('ol.Extent'); goog.require('ol.Extent');
goog.require('ol.Projection'); goog.require('ol.Projection');

View File

@@ -15,11 +15,11 @@ goog.require('goog.events.MouseWheelHandler');
goog.require('goog.events.MouseWheelHandler.EventType'); goog.require('goog.events.MouseWheelHandler.EventType');
goog.require('goog.fx.anim'); goog.require('goog.fx.anim');
goog.require('goog.fx.anim.Animated'); goog.require('goog.fx.anim.Animated');
goog.require('goog.math.Coordinate');
goog.require('goog.math.Size'); goog.require('goog.math.Size');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol.Array'); goog.require('ol.Array');
goog.require('ol.Control'); goog.require('ol.Control');
goog.require('ol.Coordinate');
goog.require('ol.Extent'); goog.require('ol.Extent');
goog.require('ol.LayerRenderer'); goog.require('ol.LayerRenderer');
goog.require('ol.Object'); goog.require('ol.Object');
@@ -264,10 +264,10 @@ ol.Map.prototype.getBackgroundColor = function() {
/** /**
* @return {goog.math.Coordinate|undefined} Center. * @return {ol.Coordinate|undefined} Center.
*/ */
ol.Map.prototype.getCenter = function() { ol.Map.prototype.getCenter = function() {
return /** @type {goog.math.Coordinate} */ (this.get(ol.MapProperty.CENTER)); return /** @type {ol.Coordinate} */ (this.get(ol.MapProperty.CENTER));
}; };
@@ -280,8 +280,8 @@ ol.Map.prototype.getControls = function() {
/** /**
* @param {goog.math.Coordinate} pixel Pixel. * @param {ol.Coordinate} pixel Pixel.
* @return {goog.math.Coordinate} Coordinate. * @return {ol.Coordinate} Coordinate.
*/ */
ol.Map.prototype.getCoordinateFromPixel = function(pixel) { ol.Map.prototype.getCoordinateFromPixel = function(pixel) {
var center = this.getCenter(); var center = this.getCenter();
@@ -292,7 +292,7 @@ ol.Map.prototype.getCoordinateFromPixel = function(pixel) {
goog.asserts.assert(goog.isDef(size)); goog.asserts.assert(goog.isDef(size));
var x = center.x + resolution * (pixel.x - size.width / 2); var x = center.x + resolution * (pixel.x - size.width / 2);
var y = center.y - resolution * (pixel.y - size.height / 2); var y = center.y - resolution * (pixel.y - size.height / 2);
return new goog.math.Coordinate(x, y); return new ol.Coordinate(x, y);
}; };
@@ -326,8 +326,8 @@ ol.Map.prototype.getLayers = function() {
/** /**
* @param {goog.math.Coordinate} coordinate Coordinate. * @param {ol.Coordinate} coordinate Coordinate.
* @return {goog.math.Coordinate} Pixel. * @return {ol.Coordinate} Pixel.
*/ */
ol.Map.prototype.getPixelFromCoordinate = function(coordinate) { ol.Map.prototype.getPixelFromCoordinate = function(coordinate) {
var center = this.getCenter(); var center = this.getCenter();
@@ -338,7 +338,7 @@ ol.Map.prototype.getPixelFromCoordinate = function(coordinate) {
goog.asserts.assert(goog.isDef(size)); goog.asserts.assert(goog.isDef(size));
var x = (coordinate.x - center.x) / resolution + size.width / 2; var x = (coordinate.x - center.x) / resolution + size.width / 2;
var y = (center.y - coordinate.y) / resolution + size.height / 2; var y = (center.y - coordinate.y) / resolution + size.height / 2;
return new goog.math.Coordinate(x, y); return new ol.Coordinate(x, y);
}; };
@@ -389,7 +389,7 @@ ol.Map.prototype.getTarget = function() {
/** /**
* @return {goog.math.Coordinate|undefined} Center in user projection. * @return {ol.Coordinate|undefined} Center in user projection.
*/ */
ol.Map.prototype.getUserCenter = function() { ol.Map.prototype.getUserCenter = function() {
var center = this.getCenter(); var center = this.getCenter();
@@ -681,7 +681,7 @@ ol.Map.prototype.setBackgroundColor = function(backgroundColor) {
/** /**
* @param {goog.math.Coordinate} center Center. * @param {ol.Coordinate} center Center.
*/ */
ol.Map.prototype.setCenter = function(center) { ol.Map.prototype.setCenter = function(center) {
this.set(ol.MapProperty.CENTER, center); this.set(ol.MapProperty.CENTER, center);
@@ -744,7 +744,7 @@ ol.Map.prototype.setProjection = function(projection) {
/** /**
* @param {goog.math.Coordinate} userCenter Center in user projection. * @param {ol.Coordinate} userCenter Center in user projection.
*/ */
ol.Map.prototype.setUserCenter = function(userCenter) { ol.Map.prototype.setUserCenter = function(userCenter) {
this.setCenter(this.userToMapTransform_(userCenter)); this.setCenter(this.userToMapTransform_(userCenter));

View File

@@ -1,7 +1,7 @@
goog.provide('ol.MapBrowserEvent'); goog.provide('ol.MapBrowserEvent');
goog.require('goog.events.BrowserEvent'); goog.require('goog.events.BrowserEvent');
goog.require('goog.math.Coordinate'); goog.require('ol.Coordinate');
goog.require('ol.MapEvent'); goog.require('ol.MapEvent');
@@ -29,20 +29,20 @@ goog.inherits(ol.MapBrowserEvent, ol.MapEvent);
/** /**
* @private * @private
* @type {goog.math.Coordinate} * @type {ol.Coordinate}
*/ */
ol.MapBrowserEvent.prototype.coordinate_; ol.MapBrowserEvent.prototype.coordinate_;
/** /**
* @return {goog.math.Coordinate} Coordinate. * @return {ol.Coordinate} Coordinate.
*/ */
ol.MapBrowserEvent.prototype.getCoordinate = function() { ol.MapBrowserEvent.prototype.getCoordinate = function() {
if (goog.isDef(this.coordinate_)) { if (goog.isDef(this.coordinate_)) {
return this.coordinate_; return this.coordinate_;
} else { } else {
var browserEventObject = this.getBrowserEventObject(); var browserEventObject = this.getBrowserEventObject();
var pixel = new goog.math.Coordinate( var pixel = new ol.Coordinate(
browserEventObject.offsetX, browserEventObject.offsetY); browserEventObject.offsetX, browserEventObject.offsetY);
var coordinate = this.map.getCoordinateFromPixel(pixel); var coordinate = this.map.getCoordinateFromPixel(pixel);
this.coordinate_ = coordinate; this.coordinate_ = coordinate;

View File

@@ -2,8 +2,8 @@ goog.provide('ol.Projection');
goog.require('goog.array'); goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.math.Coordinate');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol.Coordinate');
goog.require('ol.Extent'); goog.require('ol.Extent');
goog.require('ol.TransformFunction'); goog.require('ol.TransformFunction');
@@ -215,8 +215,8 @@ ol.Projection.getTransformFromCodes = function(sourceCode, destinationCode) {
/** /**
* @param {goog.math.Coordinate} point Point. * @param {ol.Coordinate} point Point.
* @return {goog.math.Coordinate} Point. * @return {ol.Coordinate} Point.
*/ */
ol.Projection.identityTransform = function(point) { ol.Projection.identityTransform = function(point) {
return point; return point;
@@ -224,8 +224,8 @@ ol.Projection.identityTransform = function(point) {
/** /**
* @param {goog.math.Coordinate} point Point. * @param {ol.Coordinate} point Point.
* @return {goog.math.Coordinate} Point. * @return {ol.Coordinate} Point.
*/ */
ol.Projection.cloneTransform = function(point) { ol.Projection.cloneTransform = function(point) {
return point.clone(); return point.clone();
@@ -233,10 +233,10 @@ ol.Projection.cloneTransform = function(point) {
/** /**
* @param {goog.math.Coordinate} point Point. * @param {ol.Coordinate} point Point.
* @param {ol.Projection} source Source. * @param {ol.Projection} source Source.
* @param {ol.Projection} destination Destination. * @param {ol.Projection} destination Destination.
* @return {goog.math.Coordinate} Point. * @return {ol.Coordinate} Point.
*/ */
ol.Projection.transform = function(point, source, destination) { ol.Projection.transform = function(point, source, destination) {
var transform = ol.Projection.getTransform(source, destination); var transform = ol.Projection.getTransform(source, destination);
@@ -245,10 +245,10 @@ ol.Projection.transform = function(point, source, destination) {
/** /**
* @param {goog.math.Coordinate} point Point. * @param {ol.Coordinate} point Point.
* @param {string} sourceCode Source code. * @param {string} sourceCode Source code.
* @param {string} destinationCode Destination code. * @param {string} destinationCode Destination code.
* @return {goog.math.Coordinate} Point. * @return {ol.Coordinate} Point.
*/ */
ol.Projection.transformWithCodes = ol.Projection.transformWithCodes =
function(point, sourceCode, destinationCode) { function(point, sourceCode, destinationCode) {
@@ -266,26 +266,26 @@ ol.Projection.EPSG_3857_RADIUS = 6378137;
/** /**
* @param {goog.math.Coordinate} point Point. * @param {ol.Coordinate} point Point.
* @return {goog.math.Coordinate} Point. * @return {ol.Coordinate} Point.
*/ */
ol.Projection.forwardSphericalMercator = function(point) { ol.Projection.forwardSphericalMercator = function(point) {
var x = ol.Projection.EPSG_3857_RADIUS * Math.PI * point.x / 180; var x = ol.Projection.EPSG_3857_RADIUS * Math.PI * point.x / 180;
var y = ol.Projection.EPSG_3857_RADIUS * var y = ol.Projection.EPSG_3857_RADIUS *
Math.log(Math.tan(Math.PI * (point.y + 90) / 360)); Math.log(Math.tan(Math.PI * (point.y + 90) / 360));
return new goog.math.Coordinate(x, y); return new ol.Coordinate(x, y);
}; };
/** /**
* @param {goog.math.Coordinate} point Point. * @param {ol.Coordinate} point Point.
* @return {goog.math.Coordinate} Point. * @return {ol.Coordinate} Point.
*/ */
ol.Projection.inverseSphericalMercator = function(point) { ol.Projection.inverseSphericalMercator = function(point) {
var x = 180 * point.x / (ol.Projection.EPSG_3857_RADIUS * Math.PI); var x = 180 * point.x / (ol.Projection.EPSG_3857_RADIUS * Math.PI);
var y = 360 * Math.atan( var y = 360 * Math.atan(
Math.exp(point.y / ol.Projection.EPSG_3857_RADIUS)) / Math.PI - 90; Math.exp(point.y / ol.Projection.EPSG_3857_RADIUS)) / Math.PI - 90;
return new goog.math.Coordinate(x, y); return new ol.Coordinate(x, y);
}; };

View File

@@ -1,6 +1,6 @@
goog.require('goog.array'); goog.require('goog.array');
goog.require('goog.math.Coordinate');
goog.require('goog.testing.jsunit'); goog.require('goog.testing.jsunit');
goog.require('ol.Coordinate');
goog.require('ol.Projection'); goog.require('ol.Projection');
@@ -36,7 +36,7 @@ function testEpsg4326Equivalence() {
function testIdentityTransform() { function testIdentityTransform() {
var epsg4326 = ol.Projection.getFromCode('EPSG:4326'); var epsg4326 = ol.Projection.getFromCode('EPSG:4326');
var uniqueObject = {}; var uniqueObject = {};
var sourcePoint = new goog.math.Coordinate(uniqueObject, uniqueObject); var sourcePoint = new ol.Coordinate(uniqueObject, uniqueObject);
var destinationPoint = ol.Projection.transform( var destinationPoint = ol.Projection.transform(
sourcePoint, epsg4326, epsg4326); sourcePoint, epsg4326, epsg4326);
assertFalse(sourcePoint === destinationPoint); assertFalse(sourcePoint === destinationPoint);
@@ -47,7 +47,7 @@ function testIdentityTransform() {
function testForwardSphericalMercatorOrigin() { function testForwardSphericalMercatorOrigin() {
var point = ol.Projection.transformWithCodes( var point = ol.Projection.transformWithCodes(
new goog.math.Coordinate(0, 0), 'EPSG:4326', 'EPSG:3857'); new ol.Coordinate(0, 0), 'EPSG:4326', 'EPSG:3857');
assertNotNullNorUndefined(point); assertNotNullNorUndefined(point);
assertEquals(0, point.x); assertEquals(0, point.x);
assertRoughlyEquals(0, point.y, 1e-9); assertRoughlyEquals(0, point.y, 1e-9);
@@ -56,7 +56,7 @@ function testForwardSphericalMercatorOrigin() {
function testInverseSphericalMercatorOrigin() { function testInverseSphericalMercatorOrigin() {
var point = ol.Projection.transformWithCodes( var point = ol.Projection.transformWithCodes(
new goog.math.Coordinate(0, 0), 'EPSG:3857', 'EPSG:4326'); new ol.Coordinate(0, 0), 'EPSG:3857', 'EPSG:4326');
assertNotNullNorUndefined(point); assertNotNullNorUndefined(point);
assertEquals(0, point.x); assertEquals(0, point.x);
assertEquals(0, point.y); assertEquals(0, point.y);
@@ -66,7 +66,7 @@ function testInverseSphericalMercatorOrigin() {
function testForwardSphericalMercatorAlastaira() { function testForwardSphericalMercatorAlastaira() {
// http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/ // http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/
var point = ol.Projection.transformWithCodes( var point = ol.Projection.transformWithCodes(
new goog.math.Coordinate(-5.625, 52.4827802220782), new ol.Coordinate(-5.625, 52.4827802220782),
'EPSG:4326', 'EPSG:4326',
'EPSG:900913'); 'EPSG:900913');
assertNotNullNorUndefined(point); assertNotNullNorUndefined(point);
@@ -78,7 +78,7 @@ function testForwardSphericalMercatorAlastaira() {
function testInverseSphericalMercatorAlastaira() { function testInverseSphericalMercatorAlastaira() {
// http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/ // http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/
var point = ol.Projection.transformWithCodes( var point = ol.Projection.transformWithCodes(
new goog.math.Coordinate(-626172.13571216376, 6887893.4928337997), new ol.Coordinate(-626172.13571216376, 6887893.4928337997),
'EPSG:900913', 'EPSG:900913',
'EPSG:4326'); 'EPSG:4326');
assertNotNullNorUndefined(point); assertNotNullNorUndefined(point);

View File

@@ -1,8 +1,8 @@
goog.provide('ol.Rectangle'); goog.provide('ol.Rectangle');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.math.Coordinate');
goog.require('goog.math.Size'); goog.require('goog.math.Size');
goog.require('ol.Coordinate');
@@ -63,7 +63,7 @@ ol.Rectangle.prototype.clone = function() {
/** /**
* @param {goog.math.Coordinate} coordinate Coordinate. * @param {ol.Coordinate} coordinate Coordinate.
* @return {boolean} Contains. * @return {boolean} Contains.
*/ */
ol.Rectangle.prototype.contains = function(coordinate) { ol.Rectangle.prototype.contains = function(coordinate) {
@@ -73,10 +73,10 @@ ol.Rectangle.prototype.contains = function(coordinate) {
/** /**
* @return {goog.math.Coordinate} Center. * @return {ol.Coordinate} Center.
*/ */
ol.Rectangle.prototype.getCenter = function() { ol.Rectangle.prototype.getCenter = function() {
return new goog.math.Coordinate( return new ol.Coordinate(
(this.minX + this.maxX) / 2, (this.minY + this.maxY) / 2); (this.minX + this.maxX) / 2, (this.minY + this.maxY) / 2);
}; };
@@ -106,11 +106,11 @@ ol.Rectangle.prototype.getWidth = function() {
/** /**
* @param {goog.math.Coordinate} coordinate Coordinate. * @param {ol.Coordinate} coordinate Coordinate.
* @return {goog.math.Coordinate} Coordinate. * @return {ol.Coordinate} Coordinate.
*/ */
ol.Rectangle.prototype.normalize = function(coordinate) { ol.Rectangle.prototype.normalize = function(coordinate) {
return new goog.math.Coordinate( return new ol.Coordinate(
(coordinate.x - this.minX) / this.getWidth(), (coordinate.x - this.minX) / this.getWidth(),
(coordinate.y - this.minY) / this.getHeight()); (coordinate.y - this.minY) / this.getHeight());
}; };

View File

@@ -1,5 +1,5 @@
goog.require('goog.math.Coordinate');
goog.require('goog.testing.jsunit'); goog.require('goog.testing.jsunit');
goog.require('ol.Coordinate');
goog.require('ol.Rectangle'); goog.require('ol.Rectangle');
@@ -25,36 +25,36 @@ function testClone() {
function testContainsPositive() { function testContainsPositive() {
var rectangle = new ol.Rectangle(1, 2, 3, 4); var rectangle = new ol.Rectangle(1, 2, 3, 4);
assertTrue(rectangle.contains(new goog.math.Coordinate(1, 2))); assertTrue(rectangle.contains(new ol.Coordinate(1, 2)));
assertTrue(rectangle.contains(new goog.math.Coordinate(1, 3))); assertTrue(rectangle.contains(new ol.Coordinate(1, 3)));
assertTrue(rectangle.contains(new goog.math.Coordinate(1, 4))); assertTrue(rectangle.contains(new ol.Coordinate(1, 4)));
assertTrue(rectangle.contains(new goog.math.Coordinate(2, 2))); assertTrue(rectangle.contains(new ol.Coordinate(2, 2)));
assertTrue(rectangle.contains(new goog.math.Coordinate(2, 3))); assertTrue(rectangle.contains(new ol.Coordinate(2, 3)));
assertTrue(rectangle.contains(new goog.math.Coordinate(2, 4))); assertTrue(rectangle.contains(new ol.Coordinate(2, 4)));
assertTrue(rectangle.contains(new goog.math.Coordinate(3, 2))); assertTrue(rectangle.contains(new ol.Coordinate(3, 2)));
assertTrue(rectangle.contains(new goog.math.Coordinate(3, 3))); assertTrue(rectangle.contains(new ol.Coordinate(3, 3)));
assertTrue(rectangle.contains(new goog.math.Coordinate(3, 4))); assertTrue(rectangle.contains(new ol.Coordinate(3, 4)));
} }
function testContainsNegative() { function testContainsNegative() {
var rectangle = new ol.Rectangle(1, 2, 3, 4); var rectangle = new ol.Rectangle(1, 2, 3, 4);
assertFalse(rectangle.contains(new goog.math.Coordinate(0, 1))); assertFalse(rectangle.contains(new ol.Coordinate(0, 1)));
assertFalse(rectangle.contains(new goog.math.Coordinate(0, 2))); assertFalse(rectangle.contains(new ol.Coordinate(0, 2)));
assertFalse(rectangle.contains(new goog.math.Coordinate(0, 3))); assertFalse(rectangle.contains(new ol.Coordinate(0, 3)));
assertFalse(rectangle.contains(new goog.math.Coordinate(0, 4))); assertFalse(rectangle.contains(new ol.Coordinate(0, 4)));
assertFalse(rectangle.contains(new goog.math.Coordinate(0, 5))); assertFalse(rectangle.contains(new ol.Coordinate(0, 5)));
assertFalse(rectangle.contains(new goog.math.Coordinate(1, 1))); assertFalse(rectangle.contains(new ol.Coordinate(1, 1)));
assertFalse(rectangle.contains(new goog.math.Coordinate(1, 5))); assertFalse(rectangle.contains(new ol.Coordinate(1, 5)));
assertFalse(rectangle.contains(new goog.math.Coordinate(2, 1))); assertFalse(rectangle.contains(new ol.Coordinate(2, 1)));
assertFalse(rectangle.contains(new goog.math.Coordinate(2, 5))); assertFalse(rectangle.contains(new ol.Coordinate(2, 5)));
assertFalse(rectangle.contains(new goog.math.Coordinate(3, 1))); assertFalse(rectangle.contains(new ol.Coordinate(3, 1)));
assertFalse(rectangle.contains(new goog.math.Coordinate(3, 5))); assertFalse(rectangle.contains(new ol.Coordinate(3, 5)));
assertFalse(rectangle.contains(new goog.math.Coordinate(4, 1))); assertFalse(rectangle.contains(new ol.Coordinate(4, 1)));
assertFalse(rectangle.contains(new goog.math.Coordinate(4, 2))); assertFalse(rectangle.contains(new ol.Coordinate(4, 2)));
assertFalse(rectangle.contains(new goog.math.Coordinate(4, 3))); assertFalse(rectangle.contains(new ol.Coordinate(4, 3)));
assertFalse(rectangle.contains(new goog.math.Coordinate(4, 4))); assertFalse(rectangle.contains(new ol.Coordinate(4, 4)));
assertFalse(rectangle.contains(new goog.math.Coordinate(4, 5))); assertFalse(rectangle.contains(new ol.Coordinate(4, 5)));
} }
@@ -113,23 +113,23 @@ function testNormalize() {
var rectangle = new ol.Rectangle(0, 1, 2, 3); var rectangle = new ol.Rectangle(0, 1, 2, 3);
var coordinate; var coordinate;
coordinate = rectangle.normalize(new goog.math.Coordinate(1, 2)); coordinate = rectangle.normalize(new ol.Coordinate(1, 2));
assertEquals(0.5, coordinate.x); assertEquals(0.5, coordinate.x);
assertEquals(0.5, coordinate.y); assertEquals(0.5, coordinate.y);
coordinate = rectangle.normalize(new goog.math.Coordinate(0, 3)); coordinate = rectangle.normalize(new ol.Coordinate(0, 3));
assertEquals(0, coordinate.x); assertEquals(0, coordinate.x);
assertEquals(1, coordinate.y); assertEquals(1, coordinate.y);
coordinate = rectangle.normalize(new goog.math.Coordinate(2, 1)); coordinate = rectangle.normalize(new ol.Coordinate(2, 1));
assertEquals(1, coordinate.x); assertEquals(1, coordinate.x);
assertEquals(0, coordinate.y); assertEquals(0, coordinate.y);
coordinate = rectangle.normalize(new goog.math.Coordinate(0, 0)); coordinate = rectangle.normalize(new ol.Coordinate(0, 0));
assertEquals(0, coordinate.x); assertEquals(0, coordinate.x);
assertEquals(-0.5, coordinate.y); assertEquals(-0.5, coordinate.y);
coordinate = rectangle.normalize(new goog.math.Coordinate(-1, 1)); coordinate = rectangle.normalize(new ol.Coordinate(-1, 1));
assertEquals(-0.5, coordinate.x); assertEquals(-0.5, coordinate.x);
assertEquals(0, coordinate.y); assertEquals(0, coordinate.y);

View File

@@ -1,13 +1,13 @@
goog.provide('ol.TileCoord'); goog.provide('ol.TileCoord');
goog.require('goog.array'); goog.require('goog.array');
goog.require('goog.math.Coordinate'); goog.require('ol.Coordinate');
/** /**
* @constructor * @constructor
* @extends {goog.math.Coordinate} * @extends {ol.Coordinate}
* @param {number} z Z. * @param {number} z Z.
* @param {number} x X. * @param {number} x X.
* @param {number} y Y. * @param {number} y Y.
@@ -22,7 +22,7 @@ ol.TileCoord = function(z, x, y) {
this.z = z; this.z = z;
}; };
goog.inherits(ol.TileCoord, goog.math.Coordinate); goog.inherits(ol.TileCoord, ol.Coordinate);
/** /**

View File

@@ -1,7 +1,7 @@
goog.provide('ol.tilegrid.createOpenStreetMap'); goog.provide('ol.tilegrid.createOpenStreetMap');
goog.require('goog.math.Coordinate');
goog.require('goog.math.Size'); goog.require('goog.math.Size');
goog.require('ol.Coordinate');
goog.require('ol.Projection'); goog.require('ol.Projection');
goog.require('ol.TileGrid'); goog.require('ol.TileGrid');
@@ -19,7 +19,7 @@ ol.tilegrid.createOpenStreetMap = function(maxZoom) {
} }
var extent = ol.Projection.EPSG_3857_EXTENT; var extent = ol.Projection.EPSG_3857_EXTENT;
var origin = new goog.math.Coordinate( var origin = new ol.Coordinate(
-ol.Projection.EPSG_3857_HALF_SIZE, ol.Projection.EPSG_3857_HALF_SIZE); -ol.Projection.EPSG_3857_HALF_SIZE, ol.Projection.EPSG_3857_HALF_SIZE);
var tileSize = new goog.math.Size(256, 256); var tileSize = new goog.math.Size(256, 256);

View File

@@ -2,8 +2,8 @@ goog.provide('ol.TileGrid');
goog.require('goog.array'); goog.require('goog.array');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.math.Coordinate');
goog.require('goog.math.Size'); goog.require('goog.math.Size');
goog.require('ol.Coordinate');
goog.require('ol.Extent'); goog.require('ol.Extent');
goog.require('ol.TileBounds'); goog.require('ol.TileBounds');
goog.require('ol.TileCoord'); goog.require('ol.TileCoord');
@@ -14,7 +14,7 @@ goog.require('ol.TileCoord');
* @constructor * @constructor
* @param {!Array.<number>} resolutions Resolutions. * @param {!Array.<number>} resolutions Resolutions.
* @param {ol.Extent} extent Extent. * @param {ol.Extent} extent Extent.
* @param {goog.math.Coordinate|!Array.<goog.math.Coordinate>} origin Origin. * @param {ol.Coordinate|!Array.<ol.Coordinate>} origin Origin.
* @param {goog.math.Size=} opt_tileSize Tile size. * @param {goog.math.Size=} opt_tileSize Tile size.
*/ */
ol.TileGrid = function(resolutions, extent, origin, opt_tileSize) { ol.TileGrid = function(resolutions, extent, origin, opt_tileSize) {
@@ -42,17 +42,17 @@ ol.TileGrid = function(resolutions, extent, origin, opt_tileSize) {
/** /**
* @private * @private
* @type {goog.math.Coordinate} * @type {ol.Coordinate}
*/ */
this.origin_ = null; this.origin_ = null;
/** /**
* @private * @private
* @type {Array.<goog.math.Coordinate>} * @type {Array.<ol.Coordinate>}
*/ */
this.origins_ = null; this.origins_ = null;
if (origin instanceof goog.math.Coordinate) { if (origin instanceof ol.Coordinate) {
this.origin_ = origin; this.origin_ = origin;
} else if (goog.isArray(origin)) { } else if (goog.isArray(origin)) {
goog.asserts.assert(origin.length == this.numResolutions_); goog.asserts.assert(origin.length == this.numResolutions_);
@@ -101,17 +101,15 @@ ol.TileGrid.prototype.getExtent = function() {
* @return {ol.TileBounds} Tile bounds. * @return {ol.TileBounds} Tile bounds.
*/ */
ol.TileGrid.prototype.getExtentTileBounds = function(z, extent) { ol.TileGrid.prototype.getExtentTileBounds = function(z, extent) {
var min = var min = this.getTileCoord(z, new ol.Coordinate(extent.minX, extent.minY));
this.getTileCoord(z, new goog.math.Coordinate(extent.minX, extent.minY)); var max = this.getTileCoord(z, new ol.Coordinate(extent.maxX, extent.maxY));
var max =
this.getTileCoord(z, new goog.math.Coordinate(extent.maxX, extent.maxY));
return new ol.TileBounds(min.x, min.y, max.x, max.y); return new ol.TileBounds(min.x, min.y, max.x, max.y);
}; };
/** /**
* @param {number} z Z. * @param {number} z Z.
* @return {goog.math.Coordinate} Origin. * @return {ol.Coordinate} Origin.
*/ */
ol.TileGrid.prototype.getOrigin = function(z) { ol.TileGrid.prototype.getOrigin = function(z) {
if (!goog.isNull(this.origin_)) { if (!goog.isNull(this.origin_)) {
@@ -144,7 +142,7 @@ ol.TileGrid.prototype.getResolutions = function() {
/** /**
* @param {number} z Z. * @param {number} z Z.
* @param {goog.math.Coordinate} coordinate Coordinate. * @param {ol.Coordinate} coordinate Coordinate.
* @return {ol.TileCoord} Tile coordinate. * @return {ol.TileCoord} Tile coordinate.
*/ */
ol.TileGrid.prototype.getTileCoord = function(z, coordinate) { ol.TileGrid.prototype.getTileCoord = function(z, coordinate) {
@@ -160,7 +158,7 @@ ol.TileGrid.prototype.getTileCoord = function(z, coordinate) {
/** /**
* @param {ol.TileCoord} tileCoord Tile coordinate. * @param {ol.TileCoord} tileCoord Tile coordinate.
* @return {goog.math.Coordinate} Tile center. * @return {ol.Coordinate} Tile center.
*/ */
ol.TileGrid.prototype.getTileCoordCenter = function(tileCoord) { ol.TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
var origin = this.getOrigin(tileCoord.z); var origin = this.getOrigin(tileCoord.z);
@@ -168,7 +166,7 @@ ol.TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
var tileSize = this.tileSize_; var tileSize = this.tileSize_;
var x = origin.x + (tileCoord.x + 0.5) * tileSize.width * resolution; var x = origin.x + (tileCoord.x + 0.5) * tileSize.width * resolution;
var y = origin.y + (tileCoord.y + 0.5) * tileSize.height * resolution; var y = origin.y + (tileCoord.y + 0.5) * tileSize.height * resolution;
return new goog.math.Coordinate(x, y); return new ol.Coordinate(x, y);
}; };

View File

@@ -1,6 +1,6 @@
goog.require('goog.math.Coordinate');
goog.require('goog.math.Size'); goog.require('goog.math.Size');
goog.require('goog.testing.jsunit'); goog.require('goog.testing.jsunit');
goog.require('ol.Coordinate');
goog.require('ol.Extent'); goog.require('ol.Extent');
goog.require('ol.TileCoord'); goog.require('ol.TileCoord');
goog.require('ol.TileGrid'); goog.require('ol.TileGrid');
@@ -16,7 +16,7 @@ var tileSize;
function setUp() { function setUp() {
resolutions = [1000, 500, 250, 100]; resolutions = [1000, 500, 250, 100];
extent = new ol.Extent(0, 0, 100000, 100000); extent = new ol.Extent(0, 0, 100000, 100000);
origin = new goog.math.Coordinate(0, 0); origin = new ol.Coordinate(0, 0);
origins = []; origins = [];
tileSize = new goog.math.Size(100, 100); tileSize = new goog.math.Size(100, 100);
} }
@@ -74,27 +74,26 @@ function testCreateTooManyOrigins() {
function testGetTileCoord() { function testGetTileCoord() {
origin = new goog.math.Coordinate(0, 0); origin = new ol.Coordinate(0, 0);
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize); var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
var tileCoord; var tileCoord;
tileCoord = tileGrid.getTileCoord(3, new goog.math.Coordinate(0, 0)); tileCoord = tileGrid.getTileCoord(3, new ol.Coordinate(0, 0));
assertEquals(3, tileCoord.z); assertEquals(3, tileCoord.z);
assertEquals(0, tileCoord.x); assertEquals(0, tileCoord.x);
assertEquals(0, tileCoord.y); assertEquals(0, tileCoord.y);
tileCoord = tileGrid.getTileCoord(3, new goog.math.Coordinate(0, 100000)); tileCoord = tileGrid.getTileCoord(3, new ol.Coordinate(0, 100000));
assertEquals(3, tileCoord.z); assertEquals(3, tileCoord.z);
assertEquals(0, tileCoord.x); assertEquals(0, tileCoord.x);
assertEquals(10, tileCoord.y); assertEquals(10, tileCoord.y);
tileCoord = tileGrid.getTileCoord(3, new goog.math.Coordinate(100000, 0)); tileCoord = tileGrid.getTileCoord(3, new ol.Coordinate(100000, 0));
assertEquals(3, tileCoord.z); assertEquals(3, tileCoord.z);
assertEquals(10, tileCoord.x); assertEquals(10, tileCoord.x);
assertEquals(0, tileCoord.y); assertEquals(0, tileCoord.y);
tileCoord = tileCoord = tileGrid.getTileCoord(3, new ol.Coordinate(100000, 100000));
tileGrid.getTileCoord(3, new goog.math.Coordinate(100000, 100000));
assertEquals(3, tileCoord.z); assertEquals(3, tileCoord.z);
assertEquals(10, tileCoord.x); assertEquals(10, tileCoord.x);
assertEquals(10, tileCoord.y); assertEquals(10, tileCoord.y);
@@ -104,27 +103,26 @@ function testGetTileCoord() {
function testGetTileCoordYSouth() { function testGetTileCoordYSouth() {
origin = new goog.math.Coordinate(0, 100000); origin = new ol.Coordinate(0, 100000);
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize); var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
var tileCoord; var tileCoord;
tileCoord = tileGrid.getTileCoord(3, new goog.math.Coordinate(0, 0)); tileCoord = tileGrid.getTileCoord(3, new ol.Coordinate(0, 0));
assertEquals(3, tileCoord.z); assertEquals(3, tileCoord.z);
assertEquals(0, tileCoord.x); assertEquals(0, tileCoord.x);
assertEquals(-10, tileCoord.y); assertEquals(-10, tileCoord.y);
tileCoord = tileGrid.getTileCoord(3, new goog.math.Coordinate(0, 100000)); tileCoord = tileGrid.getTileCoord(3, new ol.Coordinate(0, 100000));
assertEquals(3, tileCoord.z); assertEquals(3, tileCoord.z);
assertEquals(0, tileCoord.x); assertEquals(0, tileCoord.x);
assertEquals(0, tileCoord.y); assertEquals(0, tileCoord.y);
tileCoord = tileGrid.getTileCoord(3, new goog.math.Coordinate(100000, 0)); tileCoord = tileGrid.getTileCoord(3, new ol.Coordinate(100000, 0));
assertEquals(3, tileCoord.z); assertEquals(3, tileCoord.z);
assertEquals(10, tileCoord.x); assertEquals(10, tileCoord.x);
assertEquals(-10, tileCoord.y); assertEquals(-10, tileCoord.y);
tileCoord = tileCoord = tileGrid.getTileCoord(3, new ol.Coordinate(100000, 100000));
tileGrid.getTileCoord(3, new goog.math.Coordinate(100000, 100000));
assertEquals(3, tileCoord.z); assertEquals(3, tileCoord.z);
assertEquals(10, tileCoord.x); assertEquals(10, tileCoord.x);
assertEquals(0, tileCoord.y); assertEquals(0, tileCoord.y);

View File

@@ -1,4 +1,5 @@
goog.require('goog.testing.jsunit'); goog.require('goog.testing.jsunit');
goog.require('ol.Coordinate');
goog.require('ol.TileCoord'); goog.require('ol.TileCoord');
goog.require('ol.tilestore.createOpenStreetMap'); goog.require('ol.tilestore.createOpenStreetMap');
@@ -13,8 +14,7 @@ function testOpenStreetMap() {
var tileStore = ol.tilestore.createOpenStreetMap(8); var tileStore = ol.tilestore.createOpenStreetMap(8);
var tileGrid = tileStore.getTileGrid(); var tileGrid = tileStore.getTileGrid();
var coordinate = var coordinate = new ol.Coordinate(829330.2064098881, 5933916.615134273);
new goog.math.Coordinate(829330.2064098881, 5933916.615134273);
var tileUrl; var tileUrl;
tileUrl = tileStore.getTileCoordUrl(tileGrid.getTileCoord(0, coordinate)); tileUrl = tileStore.getTileCoordUrl(tileGrid.getTileCoord(0, coordinate));

View File

@@ -1,9 +1,9 @@
goog.provide('ol.TransformFunction'); goog.provide('ol.TransformFunction');
goog.require('goog.math.Coordinate'); goog.require('ol.Coordinate');
/** /**
* @typedef {function(goog.math.Coordinate): goog.math.Coordinate} * @typedef {function(ol.Coordinate): ol.Coordinate}
*/ */
ol.TransformFunction; ol.TransformFunction;

View File

@@ -8,6 +8,7 @@ goog.require('goog.asserts');
goog.require('goog.events.EventType'); goog.require('goog.events.EventType');
goog.require('goog.vec.Mat4'); goog.require('goog.vec.Mat4');
goog.require('goog.webgl'); goog.require('goog.webgl');
goog.require('ol.Coordinate');
goog.require('ol.TileLayer'); goog.require('ol.TileLayer');
goog.require('ol.webgl.LayerRenderer'); goog.require('ol.webgl.LayerRenderer');
goog.require('ol.webgl.shader.Fragment'); goog.require('ol.webgl.shader.Fragment');
@@ -217,7 +218,7 @@ ol.webgl.TileLayerRenderer.prototype.redraw = function() {
var gl = this.getGL(); var gl = this.getGL();
var map = this.getMap(); var map = this.getMap();
var center = /** @type {!goog.math.Coordinate} */ map.getCenter(); var center = /** @type {!ol.Coordinate} */ map.getCenter();
var extent = /** @type {!ol.Extent} */ map.getExtent(); var extent = /** @type {!ol.Extent} */ map.getExtent();
var resolution = /** @type {number} */ map.getResolution(); var resolution = /** @type {number} */ map.getResolution();