Merge branch 'master' of github.com:openlayers/ol3
This commit is contained in:
@@ -25,7 +25,6 @@
|
|||||||
// "generateExports": true
|
// "generateExports": true
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
|
||||||
"checks": {
|
"checks": {
|
||||||
// acceptable values are "ERROR", "WARNING", and "OFF"
|
// acceptable values are "ERROR", "WARNING", and "OFF"
|
||||||
"accessControls": "WARNING",
|
"accessControls": "WARNING",
|
||||||
@@ -4,8 +4,7 @@
|
|||||||
"output-file": "hello-epi-compiled.js",
|
"output-file": "hello-epi-compiled.js",
|
||||||
|
|
||||||
"inputs": [
|
"inputs": [
|
||||||
"hello-epi.js",
|
"hello-epi.js"
|
||||||
"../src/ol.js"
|
|
||||||
],
|
],
|
||||||
"paths": [
|
"paths": [
|
||||||
"../src"
|
"../src"
|
||||||
+8
-2
@@ -1,8 +1,14 @@
|
|||||||
/* This is a code which is going to be compiled together with the library */
|
/* This is a code which is going to be compiled together with the library */
|
||||||
|
|
||||||
|
goog.require('ol.Map');
|
||||||
|
goog.require('ol.layer.OSM');
|
||||||
|
goog.require('ol.Loc');
|
||||||
|
|
||||||
|
goog.require('goog.dom');
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
var map = new ol.Map()
|
var map = new ol.Map();
|
||||||
// .render('map')
|
map.setContainer(goog.dom.getElement('map'));
|
||||||
map.setLayers( [ new ol.layer.OSM() ] );
|
map.setLayers( [ new ol.layer.OSM() ] );
|
||||||
map.setCenter( new ol.Loc(45, 5));
|
map.setCenter( new ol.Loc(45, 5));
|
||||||
map.setZoom(10);
|
map.setZoom(10);
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
var map = ol.map()
|
var map = ol.map()
|
||||||
.render('map')
|
.renderTo('map')
|
||||||
.layers([ol.layer.osm()])
|
.layers([ol.layer.osm()])
|
||||||
.center([45, 5])
|
.center([45, 5])
|
||||||
.zoom(10);
|
.zoom(10);
|
||||||
|
|||||||
@@ -24,3 +24,12 @@ ol.geom.Geometry.prototype.bounds = function(opt_arg) {
|
|||||||
return this.getBounds();
|
return this.getBounds();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the centroid of the geometry.
|
||||||
|
*
|
||||||
|
* @returns {ol.geom.Point} The centroid of the geometry.
|
||||||
|
*/
|
||||||
|
ol.geom.Geometry.prototype.centroid = function() {
|
||||||
|
return this.getCentroid();
|
||||||
|
};
|
||||||
@@ -111,3 +111,12 @@ ol.geom.Point.prototype.projection = function(opt_arg){
|
|||||||
return this.getProjection();
|
return this.getProjection();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the centroid of this point; which is a clone of the point itself.
|
||||||
|
*
|
||||||
|
* @return {ol.geom.Point} The centroid.
|
||||||
|
*/
|
||||||
|
ol.geom.Point.prototype.centroid = function() {
|
||||||
|
return this.getCentroid();
|
||||||
|
};
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ goog.exportProperty(ol.Feature.prototype, 'geometry', ol.Feature.prototype.geome
|
|||||||
goog.exportSymbol('ol.geom.geometry', ol.geom.geometry);
|
goog.exportSymbol('ol.geom.geometry', ol.geom.geometry);
|
||||||
goog.exportSymbol('ol.geom.Geometry', ol.geom.Geometry);
|
goog.exportSymbol('ol.geom.Geometry', ol.geom.Geometry);
|
||||||
goog.exportProperty(ol.geom.Geometry.prototype, 'bounds', ol.geom.Geometry.prototype.bounds);
|
goog.exportProperty(ol.geom.Geometry.prototype, 'bounds', ol.geom.Geometry.prototype.bounds);
|
||||||
|
goog.exportProperty(ol.geom.Geometry.prototype, 'centroid', ol.geom.Geometry.prototype.centroid);
|
||||||
|
|
||||||
// ol.geom.collection
|
// ol.geom.collection
|
||||||
goog.exportSymbol('ol.geom.collection', ol.geom.collection);
|
goog.exportSymbol('ol.geom.collection', ol.geom.collection);
|
||||||
@@ -67,6 +68,7 @@ goog.exportProperty(ol.geom.Collection.prototype, 'components', ol.geom.Collecti
|
|||||||
goog.exportProperty(ol.geom.Collection.prototype, 'add', ol.geom.Collection.prototype.add);
|
goog.exportProperty(ol.geom.Collection.prototype, 'add', ol.geom.Collection.prototype.add);
|
||||||
goog.exportProperty(ol.geom.Collection.prototype, 'addAll', ol.geom.Collection.prototype.addAll);
|
goog.exportProperty(ol.geom.Collection.prototype, 'addAll', ol.geom.Collection.prototype.addAll);
|
||||||
goog.exportProperty(ol.geom.Collection.prototype, 'remove', ol.geom.Collection.prototype.remove);
|
goog.exportProperty(ol.geom.Collection.prototype, 'remove', ol.geom.Collection.prototype.remove);
|
||||||
|
goog.exportProperty(ol.geom.Collection.prototype, 'centroid', ol.geom.Collection.prototype.centroid);
|
||||||
|
|
||||||
// ol.geom.point
|
// ol.geom.point
|
||||||
goog.exportSymbol('ol.geom.point', ol.geom.point);
|
goog.exportSymbol('ol.geom.point', ol.geom.point);
|
||||||
@@ -75,6 +77,7 @@ goog.exportProperty(ol.geom.Point.prototype, 'x', ol.geom.Point.prototype.x);
|
|||||||
goog.exportProperty(ol.geom.Point.prototype, 'y', ol.geom.Point.prototype.y);
|
goog.exportProperty(ol.geom.Point.prototype, 'y', ol.geom.Point.prototype.y);
|
||||||
goog.exportProperty(ol.geom.Point.prototype, 'z', ol.geom.Point.prototype.z);
|
goog.exportProperty(ol.geom.Point.prototype, 'z', ol.geom.Point.prototype.z);
|
||||||
goog.exportProperty(ol.geom.Point.prototype, 'projection', ol.geom.Point.prototype.projection);
|
goog.exportProperty(ol.geom.Point.prototype, 'projection', ol.geom.Point.prototype.projection);
|
||||||
|
goog.exportProperty(ol.geom.Point.prototype, 'centroid', ol.geom.Point.prototype.centroid);
|
||||||
|
|
||||||
// ol.geom.linestring
|
// ol.geom.linestring
|
||||||
goog.exportSymbol('ol.geom.linestring', ol.geom.linestring);
|
goog.exportSymbol('ol.geom.linestring', ol.geom.linestring);
|
||||||
@@ -83,6 +86,7 @@ goog.exportProperty(ol.geom.LineString.prototype, 'vertices', ol.geom.LineString
|
|||||||
goog.exportProperty(ol.geom.LineString.prototype, 'add', ol.geom.LineString.prototype.add);
|
goog.exportProperty(ol.geom.LineString.prototype, 'add', ol.geom.LineString.prototype.add);
|
||||||
goog.exportProperty(ol.geom.LineString.prototype, 'addAll', ol.geom.LineString.prototype.addAll);
|
goog.exportProperty(ol.geom.LineString.prototype, 'addAll', ol.geom.LineString.prototype.addAll);
|
||||||
goog.exportProperty(ol.geom.LineString.prototype, 'remove', ol.geom.LineString.prototype.remove);
|
goog.exportProperty(ol.geom.LineString.prototype, 'remove', ol.geom.LineString.prototype.remove);
|
||||||
|
goog.exportProperty(ol.geom.LineString.prototype, 'centroid', ol.geom.LineString.prototype.centroid);
|
||||||
|
|
||||||
// ol.geom.multipoint
|
// ol.geom.multipoint
|
||||||
goog.exportSymbol('ol.geom.multipoint', ol.geom.multipoint);
|
goog.exportSymbol('ol.geom.multipoint', ol.geom.multipoint);
|
||||||
@@ -91,6 +95,7 @@ goog.exportProperty(ol.geom.MultiPoint.prototype, 'points', ol.geom.MultiPoint.p
|
|||||||
goog.exportProperty(ol.geom.MultiPoint.prototype, 'add', ol.geom.MultiPoint.prototype.add);
|
goog.exportProperty(ol.geom.MultiPoint.prototype, 'add', ol.geom.MultiPoint.prototype.add);
|
||||||
goog.exportProperty(ol.geom.MultiPoint.prototype, 'addAll', ol.geom.MultiPoint.prototype.addAll);
|
goog.exportProperty(ol.geom.MultiPoint.prototype, 'addAll', ol.geom.MultiPoint.prototype.addAll);
|
||||||
goog.exportProperty(ol.geom.MultiPoint.prototype, 'remove', ol.geom.MultiPoint.prototype.remove);
|
goog.exportProperty(ol.geom.MultiPoint.prototype, 'remove', ol.geom.MultiPoint.prototype.remove);
|
||||||
|
goog.exportProperty(ol.geom.MultiPoint.prototype, 'centroid', ol.geom.MultiPoint.prototype.centroid);
|
||||||
|
|
||||||
// LOOKUP FOR DYNMICALLY REGISTERED CONTROLS DOES NOT RUN WELL NOW IN THE ADVANCED MODE
|
// LOOKUP FOR DYNMICALLY REGISTERED CONTROLS DOES NOT RUN WELL NOW IN THE ADVANCED MODE
|
||||||
// HACK TO PUSH COMPILER TO NOT STRIP THE NAVIGATION CONTROL. TO BE FIXED.
|
// HACK TO PUSH COMPILER TO NOT STRIP THE NAVIGATION CONTROL. TO BE FIXED.
|
||||||
|
|||||||
+5
-5
@@ -53,7 +53,7 @@ ol.Bounds.prototype.setProjection = function(projection) {
|
|||||||
ol.Bounds.prototype.intersects = function(bounds) {
|
ol.Bounds.prototype.intersects = function(bounds) {
|
||||||
var otherProj = bounds.getProjection();
|
var otherProj = bounds.getProjection();
|
||||||
if (!goog.isNull(otherProj) && !goog.isNull(this.projection_)) {
|
if (!goog.isNull(otherProj) && !goog.isNull(this.projection_)) {
|
||||||
bounds = bounds.transform(this.projection_);
|
bounds = bounds.doTransform(this.projection_);
|
||||||
}
|
}
|
||||||
return goog.base(this, "intersects", bounds.toUnreferencedBounds());
|
return goog.base(this, "intersects", bounds.toUnreferencedBounds());
|
||||||
};
|
};
|
||||||
@@ -70,13 +70,13 @@ ol.Bounds.prototype.doTransform = function(proj) {
|
|||||||
throw new Error("Bounds must have a projection before transforming.");
|
throw new Error("Bounds must have a projection before transforming.");
|
||||||
}
|
}
|
||||||
var tl = new ol.Loc(
|
var tl = new ol.Loc(
|
||||||
this.minX_, this.maxY_, undefined, this.projection_).transform(proj);
|
this.minX_, this.maxY_, undefined, this.projection_).doTransform(proj);
|
||||||
var tr = new ol.Loc(
|
var tr = new ol.Loc(
|
||||||
this.maxX_, this.maxY_, undefined, this.projection_).transform(proj);
|
this.maxX_, this.maxY_, undefined, this.projection_).doTransform(proj);
|
||||||
var bl = new ol.Loc(
|
var bl = new ol.Loc(
|
||||||
this.minX_, this.minY_, undefined, this.projection_).transform(proj);
|
this.minX_, this.minY_, undefined, this.projection_).doTransform(proj);
|
||||||
var br = new ol.Loc(
|
var br = new ol.Loc(
|
||||||
this.maxX_, this.minY_, undefined, this.projection_).transform(proj);
|
this.maxX_, this.minY_, undefined, this.projection_).doTransform(proj);
|
||||||
|
|
||||||
var x = [tl.getX(), tr.getX(), bl.getX(), br.getX()].sort();
|
var x = [tl.getX(), tr.getX(), bl.getX(), br.getX()].sort();
|
||||||
var y = [tl.getY(), tr.getY(), bl.getY(), br.getY()].sort();
|
var y = [tl.getY(), tr.getY(), bl.getY(), br.getY()].sort();
|
||||||
|
|||||||
+2
-2
@@ -143,7 +143,7 @@ ol.Map.DEFAULT_CONTROLS = ["navigation"];
|
|||||||
*/
|
*/
|
||||||
ol.Map.prototype.getCenter = function() {
|
ol.Map.prototype.getCenter = function() {
|
||||||
var proj = this.getUserProjection();
|
var proj = this.getUserProjection();
|
||||||
return this.center_.transform(proj);
|
return this.center_.doTransform(proj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ ol.Map.prototype.setCenter = function(center) {
|
|||||||
proj = this.getUserProjection();
|
proj = this.getUserProjection();
|
||||||
center.setProjection(proj);
|
center.setProjection(proj);
|
||||||
}
|
}
|
||||||
this.center_ = center.transform(this.getProjection());
|
this.center_ = center.doTransform(this.getProjection());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -9,9 +9,9 @@ goog.require('ol.event.Events');
|
|||||||
* The Tile class.
|
* The Tile class.
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
* @param {ol.Bounds} bounds
|
* @param {ol.Bounds|undefined} opt_bounds
|
||||||
*/
|
*/
|
||||||
ol.Tile = function(url, bounds) {
|
ol.Tile = function(url, opt_bounds) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -21,9 +21,9 @@ ol.Tile = function(url, bounds) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Bounds}
|
* @type {ol.Bounds|undefined}
|
||||||
*/
|
*/
|
||||||
this.bounds_ = bounds;
|
this.bounds_ = opt_bounds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -66,7 +66,7 @@ ol.Tile.prototype.createImage = function() {
|
|||||||
* Load the tile. A tile should loaded only once.
|
* Load the tile. A tile should loaded only once.
|
||||||
*/
|
*/
|
||||||
ol.Tile.prototype.load = function() {
|
ol.Tile.prototype.load = function() {
|
||||||
goog.asserts.assert(!this.loaded && this.loading_);
|
goog.asserts.assert(!this.loaded && !this.loading_);
|
||||||
this.loading_ = true;
|
this.loading_ = true;
|
||||||
this.img_.src = this.url_;
|
this.img_.src = this.url_;
|
||||||
};
|
};
|
||||||
@@ -81,7 +81,7 @@ ol.Tile.prototype.getUrl = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the tile bounds.
|
* Get the tile bounds.
|
||||||
* @return {ol.Bounds}
|
* @return {ol.Bounds|undefined}
|
||||||
*/
|
*/
|
||||||
ol.Tile.prototype.getBounds = function() {
|
ol.Tile.prototype.getBounds = function() {
|
||||||
return this.bounds_;
|
return this.bounds_;
|
||||||
@@ -155,15 +155,15 @@ ol.Tile.createImage = (function() {
|
|||||||
* for the tiles.
|
* for the tiles.
|
||||||
* @param {number} width
|
* @param {number} width
|
||||||
* @param {number} height
|
* @param {number} height
|
||||||
* @return {function(new:ol.Tile, string, ol.Bounds)}
|
* @return {function(new:ol.Tile, string, ol.Bounds=)}
|
||||||
*/
|
*/
|
||||||
ol.Tile.createConstructor = function(width, height) {
|
ol.Tile.createConstructor = function(width, height) {
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.Tile}
|
* @extends {ol.Tile}
|
||||||
*/
|
*/
|
||||||
var Tile = function(url, bounds) {
|
var Tile = function(url, opt_bounds) {
|
||||||
goog.base(this, url, bounds);
|
goog.base(this, url, opt_bounds);
|
||||||
};
|
};
|
||||||
goog.inherits(Tile, ol.Tile);
|
goog.inherits(Tile, ol.Tile);
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
|
|||||||
@@ -219,6 +219,8 @@ ol.event.Events.prototype.unregister = function(type, listener, opt_scope) {
|
|||||||
*
|
*
|
||||||
* @param {string} type The type of the event to trigger.
|
* @param {string} type The type of the event to trigger.
|
||||||
* @param {Object=} opt_evt The event object that will be passed to listeners.
|
* @param {Object=} opt_evt The event object that will be passed to listeners.
|
||||||
|
* This object will always have a 'type' property with the event type and
|
||||||
|
* an 'object' property referencing this Events instance.
|
||||||
*
|
*
|
||||||
* @return {boolean} The last listener return. If a listener returns false,
|
* @return {boolean} The last listener return. If a listener returns false,
|
||||||
* the chain of listeners will stop getting called.
|
* the chain of listeners will stop getting called.
|
||||||
@@ -228,8 +230,9 @@ ol.event.Events.prototype.triggerEvent = function(type, opt_evt) {
|
|||||||
listeners = goog.events.getListeners(this, type, true)
|
listeners = goog.events.getListeners(this, type, true)
|
||||||
.concat(goog.events.getListeners(this, type, false));
|
.concat(goog.events.getListeners(this, type, false));
|
||||||
if (arguments.length === 1) {
|
if (arguments.length === 1) {
|
||||||
opt_evt = {type: type};
|
opt_evt = {'type': type};
|
||||||
}
|
}
|
||||||
|
opt_evt['object'] = this.object_;
|
||||||
for (var i=0, ii=listeners.length; i<ii; ++i) {
|
for (var i=0, ii=listeners.length; i<ii; ++i) {
|
||||||
returnValue = listeners[i].handleEvent(opt_evt);
|
returnValue = listeners[i].handleEvent(opt_evt);
|
||||||
if (returnValue === false) {
|
if (returnValue === false) {
|
||||||
|
|||||||
@@ -166,3 +166,24 @@ ol.geom.Collection.prototype.isAllowedComponent = function(component){
|
|||||||
ol.geom.Collection.prototype.removeComponent = function(component) {
|
ol.geom.Collection.prototype.removeComponent = function(component) {
|
||||||
goog.array.remove(this.components_, component);
|
goog.array.remove(this.components_, component);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the centroid for this geometry collection.
|
||||||
|
*
|
||||||
|
* @returns {ol.geom.Point} The centroid of the collection.
|
||||||
|
*/
|
||||||
|
ol.geom.Collection.prototype.getCentroid = function() {
|
||||||
|
var components = this.getComponents(),
|
||||||
|
len = components.length,
|
||||||
|
sum_x = 0, sum_y = 0,
|
||||||
|
centroid = null;
|
||||||
|
if (len > 0) {
|
||||||
|
goog.array.forEach(components, function(component){
|
||||||
|
var singleCentroid = component.getCentroid();
|
||||||
|
sum_x += singleCentroid.getX();
|
||||||
|
sum_y += singleCentroid.getX();
|
||||||
|
});
|
||||||
|
centroid = new ol.geom.Point(sum_x / len, sum_y / len);
|
||||||
|
}
|
||||||
|
return centroid;
|
||||||
|
};
|
||||||
+18
-3
@@ -1,11 +1,13 @@
|
|||||||
goog.provide('ol.geom.Geometry');
|
goog.provide('ol.geom.Geometry');
|
||||||
|
|
||||||
|
goog.require('ol.geom.IGeometry');
|
||||||
goog.require('ol.Bounds');
|
goog.require('ol.Bounds');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates ol.Geometry objects.
|
* Creates ol.Geometry objects.
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
|
* @implements {ol.geom.IGeometry}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
ol.geom.Geometry = function() {
|
ol.geom.Geometry = function() {
|
||||||
@@ -34,10 +36,23 @@ ol.geom.Geometry.prototype.setBounds = function(bounds) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns ol.Loc
|
* Returns the centroid of the geometry.
|
||||||
|
*
|
||||||
|
* @returns {ol.geom.Point} The centroid of the geometry.
|
||||||
*/
|
*/
|
||||||
ol.geom.Geometry.prototype.getCentroid = function() {
|
ol.geom.Geometry.prototype.getCentroid = function() {
|
||||||
//FIXME: stub only to get popups working
|
// throw an error to enforce subclasses to implement it properly
|
||||||
return new ol.Loc(-76,45);
|
ol.error('ol.geom.Geometry: getCentroid must be implemented by subclasses');
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the area of the geometry.
|
||||||
|
*
|
||||||
|
* @returns {number} The area of the geometry.
|
||||||
|
*/
|
||||||
|
ol.geom.Geometry.prototype.getArea = function() {
|
||||||
|
// throw an error to enforce subclasses to implement it properly
|
||||||
|
ol.error('ol.geom.Geometry: getArea must be implemented by subclasses');
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
goog.provide('ol.geom.IGeometry');
|
||||||
|
|
||||||
|
//goog.require('ol.geom.Point');
|
||||||
|
//goog.require('ol.Bounds');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for geometry classes forcing ol.geom.* classes to implement
|
||||||
|
* expected functionality.
|
||||||
|
*
|
||||||
|
* @interface
|
||||||
|
*/
|
||||||
|
ol.geom.IGeometry = function(){};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.geom.Point} The centroid of the geometry.
|
||||||
|
*/
|
||||||
|
ol.geom.IGeometry.prototype.getCentroid = function(){};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.Bounds|undefined} The centroid of the geometry.
|
||||||
|
*/
|
||||||
|
ol.geom.IGeometry.prototype.getBounds = function(){};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {number} The area of the geometry.
|
||||||
|
*/
|
||||||
|
ol.geom.IGeometry.prototype.getArea = function(){};
|
||||||
@@ -2,6 +2,7 @@ goog.provide('ol.geom.LineString');
|
|||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.Geometry');
|
||||||
|
goog.require('ol.geom.Collection');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.Projection');
|
goog.require('ol.Projection');
|
||||||
|
|
||||||
@@ -62,3 +63,14 @@ ol.geom.LineString.prototype.addVertex = function(vertex, index) {
|
|||||||
ol.geom.LineString.prototype.removeVertex = function(vertex) {
|
ol.geom.LineString.prototype.removeVertex = function(vertex) {
|
||||||
goog.array.remove(this.vertices_, vertex);
|
goog.array.remove(this.vertices_, vertex);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the centroid for this linestring.
|
||||||
|
*
|
||||||
|
* @returns {ol.geom.Point} The centroid of the linestring.
|
||||||
|
*/
|
||||||
|
ol.geom.LineString.prototype.getCentroid = function() {
|
||||||
|
var vertices = this.getVertices(),
|
||||||
|
collection = new ol.geom.Collection(vertices);
|
||||||
|
return collection.getCentroid();
|
||||||
|
};
|
||||||
@@ -144,3 +144,20 @@ ol.geom.Point.prototype._transform = function(proj) {
|
|||||||
return new ol.geom.Point(point['x'], point['y'], this.z_, proj);
|
return new ol.geom.Point(point['x'], point['y'], this.z_, proj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the centroid of the point.
|
||||||
|
*
|
||||||
|
* @returns {ol.geom.Point} The centroid of the point.
|
||||||
|
*/
|
||||||
|
ol.geom.Point.prototype.getCentroid = function() {
|
||||||
|
return new ol.geom.Point(this.x_, this.y_, this.z_, this.projection_);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the area of the geometry whcih is always 0.
|
||||||
|
*
|
||||||
|
* @returns {number} The area of the point (always 0).
|
||||||
|
*/
|
||||||
|
ol.geom.Point.prototype.getArea = function() {
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ ol.layer.TileLayer = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {function(new:ol.Tile, string, ol.Bounds)}
|
* @type {function(new:ol.Tile, string, ol.Bounds=)}
|
||||||
*/
|
*/
|
||||||
this.Tile = ol.Tile.createConstructor(this.tileWidth_, this.tileHeight_);
|
this.Tile = ol.Tile.createConstructor(this.tileWidth_, this.tileHeight_);
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ ol.layer.TileLayer = function() {
|
|||||||
* @private
|
* @private
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.tileOriginCorner_ = 'bl';
|
this.tileOriginCorner_ = 'tl';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -70,6 +70,18 @@ ol.layer.TileLayer = function() {
|
|||||||
*/
|
*/
|
||||||
this.maxResolution_ = undefined;
|
this.maxResolution_ = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.xRight_ = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.yDown_ = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {number|undefined}
|
* @type {number|undefined}
|
||||||
@@ -92,6 +104,33 @@ ol.layer.TileLayer = function() {
|
|||||||
|
|
||||||
goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
|
goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean} The tile index increases from left to right.
|
||||||
|
*/
|
||||||
|
ol.layer.TileLayer.prototype.getXRight = function() {
|
||||||
|
return this.xRight_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean} The tile index increases from top to bottom.
|
||||||
|
*/
|
||||||
|
ol.layer.TileLayer.prototype.getYDown = function() {
|
||||||
|
return this.yDown_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {boolean} right The tile index increases from left to right.
|
||||||
|
*/
|
||||||
|
ol.layer.TileLayer.prototype.setXRight = function(right) {
|
||||||
|
this.xRight_ = right;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {boolean} down The tile index increases from top to bottom.
|
||||||
|
*/
|
||||||
|
ol.layer.TileLayer.prototype.setYDown = function(down) {
|
||||||
|
this.yDown_ = down;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get layer extent. Return null if the layer has no extent
|
* Get layer extent. Return null if the layer has no extent
|
||||||
@@ -172,7 +211,7 @@ ol.layer.TileLayer.prototype.getMaxResolution = function() {
|
|||||||
if (!goog.isNull(extent)) {
|
if (!goog.isNull(extent)) {
|
||||||
this.maxResolution_ = Math.max(
|
this.maxResolution_ = Math.max(
|
||||||
(extent.getMaxX() - extent.getMinX()) / this.tileWidth_,
|
(extent.getMaxX() - extent.getMinX()) / this.tileWidth_,
|
||||||
(extent.getMaxY() - extent.getMaxX()) / this.tileHeight_);
|
(extent.getMaxY() - extent.getMinY()) / this.tileHeight_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.maxResolution_;
|
return this.maxResolution_;
|
||||||
@@ -285,6 +324,25 @@ ol.layer.TileLayer.prototype.getTile = function(url, bounds) {
|
|||||||
return tile;
|
return tile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a tile from the cache, or create a tile and add to
|
||||||
|
* the cache.
|
||||||
|
* @param {number} x
|
||||||
|
* @param {number} y
|
||||||
|
* @param {number} z
|
||||||
|
*/
|
||||||
|
ol.layer.TileLayer.prototype.getTileForXYZ = function(x, y, z) {
|
||||||
|
var url = this.url_.replace('{x}', x + '')
|
||||||
|
.replace('{y}', y + '')
|
||||||
|
.replace('{z}', z + '');
|
||||||
|
var tile = this.cache_.get(url);
|
||||||
|
if (!goog.isDef(tile)) {
|
||||||
|
tile = new this.Tile(url);
|
||||||
|
this.cache_.set(tile.getUrl(), tile);
|
||||||
|
}
|
||||||
|
return tile;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get data from the layer. This is the layer's main API function.
|
* Get data from the layer. This is the layer's main API function.
|
||||||
* @param {ol.Bounds} bounds
|
* @param {ol.Bounds} bounds
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ ol.renderer.TileLayerRenderer = function(container, layer) {
|
|||||||
*/
|
*/
|
||||||
this.rendererdBounds_ = null;
|
this.rendererdBounds_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Array.<number>}
|
||||||
|
*/
|
||||||
|
this.layerResolutions_ = layer.getResolutions();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number|undefined}
|
* @type {number|undefined}
|
||||||
* @private
|
* @private
|
||||||
@@ -43,7 +49,27 @@ ol.renderer.TileLayerRenderer = function(container, layer) {
|
|||||||
|
|
||||||
goog.inherits(ol.renderer.TileLayerRenderer, ol.renderer.LayerRenderer);
|
goog.inherits(ol.renderer.TileLayerRenderer, ol.renderer.LayerRenderer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} resolution
|
||||||
|
* @return {Array.<number>}
|
||||||
|
*/
|
||||||
|
ol.renderer.TileLayerRenderer.prototype.getPreferredResAndZ_ = function(resolution) {
|
||||||
|
var minDiff = Number.POSITIVE_INFINITY;
|
||||||
|
var candidate, diff, z, r;
|
||||||
|
for (var i=0, ii=this.layerResolutions_.length; i<ii; ++i) {
|
||||||
|
// assumes sorted resolutions
|
||||||
|
candidate = this.layerResolutions_[i];
|
||||||
|
diff = Math.abs(resolution - candidate);
|
||||||
|
if (diff < minDiff) {
|
||||||
|
z = i;
|
||||||
|
r = candidate;
|
||||||
|
minDiff = diff;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [r, z];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {goog.math.Size}
|
* @return {goog.math.Size}
|
||||||
|
|||||||
@@ -166,4 +166,47 @@ describe("ol.geom.point", function() {
|
|||||||
expect(p_obj.projection()).toEqual(jasmine.any(ol.Projection));
|
expect(p_obj.projection()).toEqual(jasmine.any(ol.Projection));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("the centroid method is functional", function(){
|
||||||
|
it("returns an instance of ol.geom.Point", function(){
|
||||||
|
expect(pNoZ_arr.centroid()).toBeA(ol.geom.Point);
|
||||||
|
expect(pWithZ_arr.centroid()).toBeA(ol.geom.Point);
|
||||||
|
expect(p_arr.centroid()).toBeA(ol.geom.Point);
|
||||||
|
|
||||||
|
expect(pNoZ_obj.centroid()).toBeA(ol.geom.Point);
|
||||||
|
expect(pWithZ_obj.centroid()).toBeA(ol.geom.Point);
|
||||||
|
expect(p_obj.centroid()).toBeA(ol.geom.Point);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does return a clone and not the point itself", function(){
|
||||||
|
expect(pNoZ_arr.centroid()).not.toBe(pNoZ_arr);
|
||||||
|
expect(pWithZ_arr.centroid()).not.toBe(pWithZ_arr);
|
||||||
|
expect(p_arr.centroid()).not.toBe(p_arr);
|
||||||
|
|
||||||
|
expect(pNoZ_obj.centroid()).not.toBe(pNoZ_obj);
|
||||||
|
expect(pWithZ_obj.centroid()).not.toBe(pWithZ_obj);
|
||||||
|
expect(p_obj.centroid()).not.toBe(p_obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("has the expected coordinates", function(){
|
||||||
|
var c1 = pNoZ_arr.centroid(),
|
||||||
|
c2 = pWithZ_arr.centroid(),
|
||||||
|
c3 = p_arr.centroid(),
|
||||||
|
c4 = pNoZ_obj.centroid(),
|
||||||
|
c5 = pWithZ_obj.centroid(),
|
||||||
|
c6 = p_obj.centroid();
|
||||||
|
|
||||||
|
expect(c1.x() + ',' + c1.y()).toBe('21,4');
|
||||||
|
expect(c2.x() + ',' + c2.y()).toBe('21,4');
|
||||||
|
expect(c3.x() + ',' + c3.y()).toBe('21,4');
|
||||||
|
expect(c4.x() + ',' + c4.y()).toBe('21,4');
|
||||||
|
expect(c5.x() + ',' + c5.y()).toBe('21,4');
|
||||||
|
expect(c6.x() + ',' + c6.y()).toBe('21,4');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns point(0,0) when the point was constructed without args", function(){
|
||||||
|
var c = pNoArgs.centroid();
|
||||||
|
expect(c.x() + ',' + c.y()).toBe('0,0');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -123,4 +123,27 @@ describe("ol.geom.Point", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("the getCentroid method is functional", function(){
|
||||||
|
it("returns an instance of ol.geom.Point", function(){
|
||||||
|
expect(p2Args.getCentroid()).toBeA(ol.geom.Point);
|
||||||
|
expect(p3Args.getCentroid()).toBeA(ol.geom.Point);
|
||||||
|
expect(p4Args.getCentroid()).toBeA(ol.geom.Point);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does return a clone and not the point itself", function(){
|
||||||
|
expect(p2Args.getCentroid()).not.toBe(p2Args);
|
||||||
|
expect(p3Args.getCentroid()).not.toBe(p3Args);
|
||||||
|
expect(p4Args.getCentroid()).not.toBe(p4Args);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("has the expected coordinates", function(){
|
||||||
|
var c2 = p2Args.getCentroid(),
|
||||||
|
c3 = p3Args.getCentroid(),
|
||||||
|
c4 = p4Args.getCentroid();
|
||||||
|
|
||||||
|
expect(c2.getX() + ',' + c2.getY()).toBe('21,4');
|
||||||
|
expect(c3.getX() + ',' + c3.getY()).toBe('21,4');
|
||||||
|
expect(c4.getX() + ',' + c4.getY()).toBe('21,4');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,6 +22,26 @@ describe('ol.layer.TileLayer', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('axis orientation', function() {
|
||||||
|
var layer = new ol.layer.TileLayer();
|
||||||
|
|
||||||
|
it('increases from left to right by default', function() {
|
||||||
|
expect(layer.getXRight()).toBe(true);
|
||||||
|
});
|
||||||
|
it('increases from top to bottom by default', function() {
|
||||||
|
expect(layer.getYDown()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows people to set things backwards', function() {
|
||||||
|
var backwards = new ol.layer.TileLayer();
|
||||||
|
backwards.setXRight(false);
|
||||||
|
expect(backwards.getXRight()).toBe(false);
|
||||||
|
backwards.setYDown(false);
|
||||||
|
expect(backwards.getYDown()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('get tile origin', function() {
|
describe('get tile origin', function() {
|
||||||
var layer;
|
var layer;
|
||||||
|
|
||||||
@@ -50,7 +70,7 @@ describe('ol.layer.TileLayer', function() {
|
|||||||
|
|
||||||
it('returns the expected origin', function() {
|
it('returns the expected origin', function() {
|
||||||
var origin = layer.getTileOrigin();
|
var origin = layer.getTileOrigin();
|
||||||
expect(origin).toEqual([-180, -90]);
|
expect(origin).toEqual([-180, 90]);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -329,4 +349,26 @@ describe('ol.layer.TileLayer', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('get a tile', function() {
|
||||||
|
var layer;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
layer = new ol.layer.TileLayer();
|
||||||
|
layer.setUrl('/{z}/{x}/{y}');
|
||||||
|
layer.setResolutions([1, 0.5, 0.25]);
|
||||||
|
layer.setTileOrigin(-128, 128);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the expected tile', function() {
|
||||||
|
var tile = layer.getTileForXYZ(1, 2, 2);
|
||||||
|
expect(tile.getUrl()).toEqual('/2/1/2');
|
||||||
|
//var bounds = tile.getBounds();
|
||||||
|
//expect(bounds.getMinX()).toEqual(-64);
|
||||||
|
//expect(bounds.getMinY()).toEqual(0);
|
||||||
|
//expect(bounds.getMaxX()).toEqual(0);
|
||||||
|
//expect(bounds.getMaxY()).toEqual(64);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,5 +15,61 @@ describe("ol.renderer.TileLayerRenderer", function() {
|
|||||||
expect(ol.renderer.TileLayerRenderer.canRender(layer)).toBe(false);
|
expect(ol.renderer.TileLayerRenderer.canRender(layer)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("getPreferredResAndZ_", function() {
|
||||||
|
var layer = new ol.layer.TileLayer();
|
||||||
|
var resolutions = [100, 80, 50, 10, 1, 0.1];
|
||||||
|
layer.setResolutions(resolutions);
|
||||||
|
|
||||||
|
var container = document.createElement("div");
|
||||||
|
var renderer = new ol.renderer.TileLayerRenderer(container, layer);
|
||||||
|
|
||||||
|
it("gets the max resolution", function() {
|
||||||
|
var pair = renderer.getPreferredResAndZ_(100);
|
||||||
|
expect(pair[0]).toBe(100);
|
||||||
|
expect(pair[1]).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gets the min resolution", function() {
|
||||||
|
var pair = renderer.getPreferredResAndZ_(0.1);
|
||||||
|
expect(pair[0]).toBe(0.1);
|
||||||
|
expect(pair[1]).toBe(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gets the max when bigger", function() {
|
||||||
|
var pair = renderer.getPreferredResAndZ_(200);
|
||||||
|
expect(pair[0]).toBe(100);
|
||||||
|
expect(pair[1]).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gets the min when smaller", function() {
|
||||||
|
var pair = renderer.getPreferredResAndZ_(0.01);
|
||||||
|
expect(pair[0]).toBe(0.1);
|
||||||
|
expect(pair[1]).toBe(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gets the first when in the middle", function() {
|
||||||
|
var pair = renderer.getPreferredResAndZ_(90);
|
||||||
|
expect(pair[0]).toBe(100);
|
||||||
|
expect(pair[1]).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gets the closer when elsewhere", function() {
|
||||||
|
var pair = renderer.getPreferredResAndZ_(89);
|
||||||
|
expect(pair[0]).toBe(80);
|
||||||
|
expect(pair[1]).toBe(1);
|
||||||
|
|
||||||
|
pair = renderer.getPreferredResAndZ_(49);
|
||||||
|
expect(pair[0]).toBe(50);
|
||||||
|
expect(pair[1]).toBe(2);
|
||||||
|
|
||||||
|
pair = renderer.getPreferredResAndZ_(0.5);
|
||||||
|
expect(pair[0]).toBe(0.1);
|
||||||
|
expect(pair[1]).toBe(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user