Merge branch 'master' of github.com:openlayers/ol3
This commit is contained in:
@@ -53,7 +53,7 @@ ol.Bounds.prototype.setProjection = function(projection) {
|
||||
ol.Bounds.prototype.intersects = function(bounds) {
|
||||
var otherProj = bounds.getProjection();
|
||||
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());
|
||||
};
|
||||
@@ -70,13 +70,13 @@ ol.Bounds.prototype.doTransform = function(proj) {
|
||||
throw new Error("Bounds must have a projection before transforming.");
|
||||
}
|
||||
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(
|
||||
this.maxX_, this.maxY_, undefined, this.projection_).transform(proj);
|
||||
this.maxX_, this.maxY_, undefined, this.projection_).doTransform(proj);
|
||||
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(
|
||||
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 y = [tl.getY(), tr.getY(), bl.getY(), br.getY()].sort();
|
||||
|
||||
@@ -143,7 +143,7 @@ ol.Map.DEFAULT_CONTROLS = ["navigation"];
|
||||
*/
|
||||
ol.Map.prototype.getCenter = function() {
|
||||
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();
|
||||
center.setProjection(proj);
|
||||
}
|
||||
this.center_ = center.transform(this.getProjection());
|
||||
this.center_ = center.doTransform(this.getProjection());
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ goog.require('ol.event.Events');
|
||||
* The Tile class.
|
||||
* @constructor
|
||||
* @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
|
||||
@@ -21,9 +21,9 @@ ol.Tile = function(url, bounds) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Bounds}
|
||||
* @type {ol.Bounds|undefined}
|
||||
*/
|
||||
this.bounds_ = bounds;
|
||||
this.bounds_ = opt_bounds;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -66,7 +66,7 @@ ol.Tile.prototype.createImage = function() {
|
||||
* Load the tile. A tile should loaded only once.
|
||||
*/
|
||||
ol.Tile.prototype.load = function() {
|
||||
goog.asserts.assert(!this.loaded && this.loading_);
|
||||
goog.asserts.assert(!this.loaded && !this.loading_);
|
||||
this.loading_ = true;
|
||||
this.img_.src = this.url_;
|
||||
};
|
||||
@@ -81,7 +81,7 @@ ol.Tile.prototype.getUrl = function() {
|
||||
|
||||
/**
|
||||
* Get the tile bounds.
|
||||
* @return {ol.Bounds}
|
||||
* @return {ol.Bounds|undefined}
|
||||
*/
|
||||
ol.Tile.prototype.getBounds = function() {
|
||||
return this.bounds_;
|
||||
@@ -155,15 +155,15 @@ ol.Tile.createImage = (function() {
|
||||
* for the tiles.
|
||||
* @param {number} width
|
||||
* @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) {
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Tile}
|
||||
*/
|
||||
var Tile = function(url, bounds) {
|
||||
goog.base(this, url, bounds);
|
||||
var Tile = function(url, opt_bounds) {
|
||||
goog.base(this, url, opt_bounds);
|
||||
};
|
||||
goog.inherits(Tile, ol.Tile);
|
||||
/** @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 {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,
|
||||
* 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)
|
||||
.concat(goog.events.getListeners(this, type, false));
|
||||
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) {
|
||||
returnValue = listeners[i].handleEvent(opt_evt);
|
||||
if (returnValue === false) {
|
||||
|
||||
@@ -6,16 +6,16 @@ goog.require('ol.Projection');
|
||||
goog.require('ol.base');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.Collection objects.
|
||||
*
|
||||
* Creates ol.geom.Collection objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.Geometry>} components An array of components.
|
||||
*
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.Collection = function(components) {
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Function>}
|
||||
@@ -23,19 +23,19 @@ ol.geom.Collection = function(components) {
|
||||
this.typeBlacklist_ = [
|
||||
ol.geom.Collection
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Function>}
|
||||
*/
|
||||
this.typeWhitelist_ = [];
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.geom.Geometry>}
|
||||
*/
|
||||
this.components_ = [];
|
||||
|
||||
|
||||
if (arguments.length === 1 && goog.isDef(components)) {
|
||||
this.setComponents(components);
|
||||
}
|
||||
@@ -44,14 +44,14 @@ ol.geom.Collection = function(components) {
|
||||
goog.inherits(ol.geom.Collection, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* Sets the list of disallowed types for the collection.
|
||||
* Sets the list of disallowed types for the collection.
|
||||
* @param {Array.<Function>} typeBlacklist Array of constructors to disallow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setTypeBlacklist = function(typeBlacklist){
|
||||
this.typeBlacklist_ = typeBlacklist;
|
||||
};
|
||||
/**
|
||||
* Gets the list of disallowed types for the collection.
|
||||
* Gets the list of disallowed types for the collection.
|
||||
* @return {Array.<Function>} Array of constructors to disallow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getTypeBlacklist = function(){
|
||||
@@ -59,14 +59,14 @@ ol.geom.Collection.prototype.getTypeBlacklist = function(){
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the list of always allowed types for the collection.
|
||||
* Sets the list of always allowed types for the collection.
|
||||
* @param {Array.<Function>} typeWhitelist Array of constructors to allow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setTypeWhitelist = function(typeWhitelist){
|
||||
this.typeWhitelist_ = typeWhitelist;
|
||||
};
|
||||
/**
|
||||
* Gets the list of always allowed types for the collection.
|
||||
* Gets the list of always allowed types for the collection.
|
||||
* @return {Array.<Function>} Array of constructors to allow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getTypeWhitelist = function(){
|
||||
@@ -76,7 +76,7 @@ ol.geom.Collection.prototype.getTypeWhitelist = function(){
|
||||
|
||||
/**
|
||||
* Sets the Collection's components.
|
||||
*
|
||||
*
|
||||
* @return {Array.<ol.geom.Geometry>} An array of components.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getComponents = function() {
|
||||
@@ -85,12 +85,12 @@ ol.geom.Collection.prototype.getComponents = function() {
|
||||
|
||||
/**
|
||||
* Gets the Collection's components.
|
||||
*
|
||||
*
|
||||
* @param {Array.<ol.geom.Geometry>} components An array of components.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setComponents = function(components) {
|
||||
var allValidTypes = goog.array.every(
|
||||
components,
|
||||
components,
|
||||
this.isAllowedComponent,
|
||||
this
|
||||
);
|
||||
@@ -105,7 +105,7 @@ ol.geom.Collection.prototype.setComponents = function(components) {
|
||||
|
||||
/**
|
||||
* Adds the given component to the list of components at the specified index.
|
||||
*
|
||||
*
|
||||
* @param {ol.geom.Geometry} component A component to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
@@ -121,14 +121,14 @@ ol.geom.Collection.prototype.addComponent = function(component, index) {
|
||||
/**
|
||||
* Checks whether the passed component is an instance of any of the constructors
|
||||
* listed in the passed list.
|
||||
*
|
||||
*
|
||||
* @param {ol.geom.Geometry} component The component to check.
|
||||
* @param {Array.<Function>} list The List of constructors to check the
|
||||
* @param {Array.<Function>} list The List of constructors to check the
|
||||
* component against.
|
||||
*
|
||||
* @return {boolean} Whether the passed component is an instance of any of the
|
||||
*
|
||||
* @return {boolean} Whether the passed component is an instance of any of the
|
||||
* constructors listed in the passed list.
|
||||
*
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
ol.geom.Collection.prototype.isOnList = function(component, list) {
|
||||
@@ -143,9 +143,9 @@ ol.geom.Collection.prototype.isOnList = function(component, list) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether the passed component is allowed according to the black and
|
||||
* Checks whether the passed component is allowed according to the black and
|
||||
* whitelists.
|
||||
*
|
||||
*
|
||||
* @param {ol.geom.Geometry} component The component to check.
|
||||
* @return {boolean} Whether the passed component is allowed as part of this
|
||||
* collection according to black- and whitelist.
|
||||
@@ -160,9 +160,30 @@ ol.geom.Collection.prototype.isAllowedComponent = function(component){
|
||||
|
||||
/**
|
||||
* Removes the given component from the list of components.
|
||||
*
|
||||
*
|
||||
* @param {ol.geom.Geometry} component A component to be removed.
|
||||
*/
|
||||
ol.geom.Collection.prototype.removeComponent = function(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;
|
||||
};
|
||||
@@ -1,15 +1,17 @@
|
||||
goog.provide('ol.geom.Geometry');
|
||||
goog.provide('ol.geom.Geometry');
|
||||
|
||||
goog.require('ol.geom.IGeometry');
|
||||
goog.require('ol.Bounds');
|
||||
|
||||
/**
|
||||
* Creates ol.Geometry objects.
|
||||
*
|
||||
*
|
||||
* @export
|
||||
* @implements {ol.geom.IGeometry}
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.Geometry = function() {
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Bounds|undefined}
|
||||
@@ -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() {
|
||||
//FIXME: stub only to get popups working
|
||||
return new ol.Loc(-76,45);
|
||||
// throw an error to enforce subclasses to implement it properly
|
||||
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;
|
||||
};
|
||||
|
||||
27
src/ol/geom/IGeometry.js
Normal file
27
src/ol/geom/IGeometry.js
Normal file
@@ -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,17 +2,18 @@ goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Collection');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.Projection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.LineString objects.
|
||||
*
|
||||
* Creates ol.geom.LineString objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points building the
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points building the
|
||||
* linestrings vertices.
|
||||
*
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.LineString = function(vertices) {
|
||||
@@ -21,14 +22,14 @@ ol.geom.LineString = function(vertices) {
|
||||
* @type {Array.<ol.geom.Point>}
|
||||
*/
|
||||
this.vertices_ = vertices;
|
||||
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* Sets the LineString's points.
|
||||
*
|
||||
*
|
||||
* @return {Array.<ol.geom.Point>} An array of points.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getVertices = function() {
|
||||
@@ -37,7 +38,7 @@ ol.geom.LineString.prototype.getVertices = function() {
|
||||
|
||||
/**
|
||||
* Gets the LineString's points.
|
||||
*
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points.
|
||||
*/
|
||||
ol.geom.LineString.prototype.setVertices = function(vertices) {
|
||||
@@ -46,7 +47,7 @@ ol.geom.LineString.prototype.setVertices = function(vertices) {
|
||||
|
||||
/**
|
||||
* Adds the given vertex to the list of vertices at the specified index.
|
||||
*
|
||||
*
|
||||
* @param {ol.geom.Point} vertex A point to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
@@ -56,9 +57,20 @@ ol.geom.LineString.prototype.addVertex = function(vertex, index) {
|
||||
|
||||
/**
|
||||
* Removes the given vertex from the list of vertices.
|
||||
*
|
||||
*
|
||||
* @param {ol.geom.Point} vertex A point to be removed.
|
||||
*/
|
||||
ol.geom.LineString.prototype.removeVertex = function(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();
|
||||
};
|
||||
@@ -4,12 +4,12 @@ goog.require('goog.array');
|
||||
goog.require('ol.geom.Collection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.MultiPoint objects.
|
||||
*
|
||||
* Creates ol.geom.MultiPoint objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Collection}
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.MultiPoint = function(points) {
|
||||
@@ -18,14 +18,14 @@ ol.geom.MultiPoint = function(points) {
|
||||
if (arguments.length === 1 && goog.isDef(points)) {
|
||||
this.setPoints(points);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.MultiPoint, ol.geom.Collection);
|
||||
|
||||
/**
|
||||
* Sets the MultiPoint's points.
|
||||
*
|
||||
*
|
||||
* @return {Array.<ol.geom.Point>} An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.getPoints = function() {
|
||||
@@ -34,7 +34,7 @@ ol.geom.MultiPoint.prototype.getPoints = function() {
|
||||
|
||||
/**
|
||||
* Gets the MultiPoint's points.
|
||||
*
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.setPoints = function(points) {
|
||||
@@ -43,7 +43,7 @@ ol.geom.MultiPoint.prototype.setPoints = function(points) {
|
||||
|
||||
/**
|
||||
* Adds the given point to the list of points at the specified index.
|
||||
*
|
||||
*
|
||||
* @param {ol.geom.Point} point A point to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
@@ -53,7 +53,7 @@ ol.geom.MultiPoint.prototype.addPoint = function(point, index) {
|
||||
|
||||
/**
|
||||
* Removes the given point from the list of points.
|
||||
*
|
||||
*
|
||||
* @param {ol.geom.Point} point A point to be removed.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.removePoint = function(point) {
|
||||
|
||||
@@ -7,17 +7,17 @@ goog.require('ol.coord.AccessorInterface');
|
||||
goog.require('ol.base');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.Point objects.
|
||||
*
|
||||
* Creates ol.geom.Point objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @param {number=} opt_z Z.
|
||||
* @param {ol.Projection=} opt_projection Projection.
|
||||
*
|
||||
*
|
||||
* @implements {ol.coord.AccessorInterface}
|
||||
*
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.Point = function(x, y, opt_z, opt_projection) {
|
||||
@@ -26,19 +26,19 @@ ol.geom.Point = function(x, y, opt_z, opt_projection) {
|
||||
* @type {number}
|
||||
*/
|
||||
this.x_ = x;
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.y_ = y;
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.z_ = opt_z;
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
@@ -109,12 +109,12 @@ ol.geom.Point.prototype.setZ = function(z) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform this point to another coordinate reference system. This
|
||||
* Transform this point to another coordinate reference system. This
|
||||
* requires that this point has a projection set already (if not, an error
|
||||
* will be thrown). Returns a new point object and does not modify this
|
||||
* point.
|
||||
*
|
||||
* @param {string|!ol.Projection} proj The destination projection. Can be
|
||||
* @param {string|!ol.Projection} proj The destination projection. Can be
|
||||
* supplied as a projection instance of a string identifier.
|
||||
* @returns {!ol.geom.Point} A new location.
|
||||
*/
|
||||
@@ -140,7 +140,24 @@ ol.geom.Point.prototype._transform = function(proj) {
|
||||
ol.error(msg);
|
||||
}
|
||||
ol.Projection.transform(point, sourceProj, 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
|
||||
* @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_);
|
||||
|
||||
@@ -62,7 +62,7 @@ ol.layer.TileLayer = function() {
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.tileOriginCorner_ = 'bl';
|
||||
this.tileOriginCorner_ = 'tl';
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -70,6 +70,18 @@ ol.layer.TileLayer = function() {
|
||||
*/
|
||||
this.maxResolution_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.xRight_ = true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.yDown_ = true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
@@ -92,6 +104,33 @@ ol.layer.TileLayer = function() {
|
||||
|
||||
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
|
||||
@@ -172,7 +211,7 @@ ol.layer.TileLayer.prototype.getMaxResolution = function() {
|
||||
if (!goog.isNull(extent)) {
|
||||
this.maxResolution_ = Math.max(
|
||||
(extent.getMaxX() - extent.getMinX()) / this.tileWidth_,
|
||||
(extent.getMaxY() - extent.getMaxX()) / this.tileHeight_);
|
||||
(extent.getMaxY() - extent.getMinY()) / this.tileHeight_);
|
||||
}
|
||||
}
|
||||
return this.maxResolution_;
|
||||
@@ -285,6 +324,25 @@ ol.layer.TileLayer.prototype.getTile = function(url, bounds) {
|
||||
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.
|
||||
* @param {ol.Bounds} bounds
|
||||
|
||||
@@ -26,6 +26,12 @@ ol.renderer.TileLayerRenderer = function(container, layer) {
|
||||
* @private
|
||||
*/
|
||||
this.rendererdBounds_ = null;
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.layerResolutions_ = layer.getResolutions();
|
||||
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
@@ -43,7 +49,27 @@ ol.renderer.TileLayerRenderer = function(container, layer) {
|
||||
|
||||
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}
|
||||
|
||||
Reference in New Issue
Block a user