Merge branch 'exp'
This commit is contained in:
105
src/ol/Bounds.js
105
src/ol/Bounds.js
@@ -1,105 +0,0 @@
|
||||
goog.provide('ol.Bounds');
|
||||
|
||||
goog.require('ol.UnreferencedBounds');
|
||||
goog.require('ol.Loc');
|
||||
goog.require('ol.Projection');
|
||||
|
||||
goog.require('goog.string.format');
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
* @param {number} minX Minimum X.
|
||||
* @param {number} minY Minimum Y.
|
||||
* @param {number} maxX Maximum X.
|
||||
* @param {number} maxY Maximum Y.
|
||||
* @param {ol.Projection=} opt_projection Projection.
|
||||
* @extends {ol.UnreferencedBounds}
|
||||
*/
|
||||
ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) {
|
||||
|
||||
goog.base(this, minX, minY, maxX, maxY);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
|
||||
|
||||
};
|
||||
goog.inherits(ol.Bounds, ol.UnreferencedBounds);
|
||||
|
||||
/**
|
||||
* @return {ol.Projection} Projection.
|
||||
*/
|
||||
ol.Bounds.prototype.getProjection = function() {
|
||||
return this.projection_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
ol.Bounds.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if this bounds intersects the target bounds (bounds that only
|
||||
* touch are considered intersecting).
|
||||
*
|
||||
* @param {ol.Bounds} bounds Target bounds.
|
||||
* @return {boolean} The provided bounds intersects this bounds.
|
||||
*/
|
||||
ol.Bounds.prototype.intersects = function(bounds) {
|
||||
var otherProj = bounds.getProjection();
|
||||
if (!goog.isNull(otherProj) && !goog.isNull(this.projection_)) {
|
||||
bounds = bounds.doTransform(this.projection_);
|
||||
}
|
||||
return goog.base(this, "intersects", bounds.toUnreferencedBounds());
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform this node into another coordinate reference system. Returns a new
|
||||
* bounds instead of modifying this bounds.
|
||||
*
|
||||
* @param {ol.Projection} proj Target projection.
|
||||
* @return {ol.Bounds} A new bounds in the target projection.
|
||||
*/
|
||||
ol.Bounds.prototype.doTransform = function(proj) {
|
||||
if (goog.isNull(this.projection_)) {
|
||||
throw new Error("Bounds must have a projection before transforming.");
|
||||
}
|
||||
var tl = new ol.Loc(
|
||||
this.minX_, this.maxY_, undefined, this.projection_).doTransform(proj);
|
||||
var tr = new ol.Loc(
|
||||
this.maxX_, this.maxY_, undefined, this.projection_).doTransform(proj);
|
||||
var bl = new ol.Loc(
|
||||
this.minX_, this.minY_, undefined, this.projection_).doTransform(proj);
|
||||
var br = new ol.Loc(
|
||||
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();
|
||||
|
||||
return new ol.Bounds(x[0], y[0], x[3], y[3], proj);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a bbox string for this bounds.
|
||||
*
|
||||
* @return {string} The "minx,miny,maxx,maxy" representation of this bounds.
|
||||
*/
|
||||
ol.Bounds.prototype.toBBOX = function() {
|
||||
return goog.string.format(
|
||||
'%f,%f,%f,%f', this.minX_, this.minY_, this.maxX_, this.maxY_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Cast this bounds into an unreferenced bounds.
|
||||
*
|
||||
* @returns {ol.UnreferencedBounds}
|
||||
*/
|
||||
ol.Bounds.prototype.toUnreferencedBounds = function() {
|
||||
return new ol.UnreferencedBounds(
|
||||
this.getMinX(), this.getMinY(), this.getMaxX(), this.getMaxY());
|
||||
};
|
||||
@@ -1,77 +0,0 @@
|
||||
goog.provide('ol.Feature');
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
*/
|
||||
ol.Feature = function() {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.geom.Geometry}
|
||||
*/
|
||||
this.geometry_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.attributes_ = {};
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.geom.Geometry} The geometry associated with the feature.
|
||||
*/
|
||||
ol.Feature.prototype.getGeometry = function() {
|
||||
return this.geometry_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Geometry} geom the geometry for the feature.
|
||||
*/
|
||||
ol.Feature.prototype.setGeometry = function(geom) {
|
||||
this.geometry_ = geom;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {!string} name the attribute value to retrieve.
|
||||
@return {string|number|boolean} the attribute value.
|
||||
*/
|
||||
ol.Feature.prototype.getAttribute = function(name) {
|
||||
return this.attributes_[name];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {!string} name of the attribute to set.
|
||||
* @param {string|number|boolean} value the attribute value to set.
|
||||
*/
|
||||
ol.Feature.prototype.setAttribute = function(name, value) {
|
||||
this.attributes_[name] = value;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} attrs An json structure containing key/value pairs.
|
||||
*/
|
||||
ol.Feature.prototype.setAttributes = function(attrs) {
|
||||
for (var key in attrs) {
|
||||
this.setAttribute(key, attrs[key]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.Feature.prototype.destroy = function() {
|
||||
//remove attributes and geometry, etc.
|
||||
for (var key in this) {
|
||||
delete this[key];
|
||||
}
|
||||
};
|
||||
147
src/ol/Loc.js
147
src/ol/Loc.js
@@ -1,147 +0,0 @@
|
||||
goog.provide('ol.Loc');
|
||||
|
||||
goog.require('ol.Projection');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @param {number=} opt_z Z.
|
||||
* @param {ol.Projection=} opt_projection Projection.
|
||||
*/
|
||||
ol.Loc = function(x, y, opt_z, opt_projection) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.x_ = x;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.y_ = y;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.z_ = opt_z;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Projection|undefined} Projection.
|
||||
*/
|
||||
ol.Loc.prototype.getProjection = function() {
|
||||
return this.projection_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} X.
|
||||
*/
|
||||
ol.Loc.prototype.getX = function() {
|
||||
return this.x_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Y.
|
||||
*/
|
||||
ol.Loc.prototype.getY = function() {
|
||||
return this.y_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Z.
|
||||
*/
|
||||
ol.Loc.prototype.getZ = function() {
|
||||
return this.z_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
ol.Loc.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} x X.
|
||||
*/
|
||||
ol.Loc.prototype.setX = function(x) {
|
||||
this.x_ = x;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} y Y.
|
||||
*/
|
||||
ol.Loc.prototype.setY = function(y) {
|
||||
this.y_ = y;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number|undefined} z Z.
|
||||
*/
|
||||
ol.Loc.prototype.setZ = function(z) {
|
||||
this.z_ = z;
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform this location to a new location given a projection object.
|
||||
*
|
||||
* @param {ol.Projection} proj The destination projection.
|
||||
* @returns {ol.Loc}
|
||||
*/
|
||||
ol.Loc.prototype.doTransform = function(proj) {
|
||||
var point = {'x': this.x_, 'y': this.y_};
|
||||
var sourceProj = this.projection_;
|
||||
if (!goog.isDefAndNotNull(sourceProj)) {
|
||||
throw new Error("Cannot transform a location without a source projection.");
|
||||
}
|
||||
ol.Projection.transform(point, sourceProj, proj);
|
||||
return new ol.Loc(point['x'], point['y'], this.z_, proj);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the passed x, y(, z) delta to a new location.
|
||||
*
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number=} opt_z
|
||||
* @returns {ol.Loc}
|
||||
*/
|
||||
ol.Loc.prototype.add = function(x, y, opt_z) {
|
||||
var newZ;
|
||||
if (goog.isDef(this.z_)) {
|
||||
newZ = (opt_z || 0) + this.z_;
|
||||
}
|
||||
return new ol.Loc(this.x_ + x, this.y_ + y, newZ, this.projection_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up.
|
||||
* @export
|
||||
*/
|
||||
ol.Loc.prototype.destroy = function() {
|
||||
for (var key in this) {
|
||||
delete this[key];
|
||||
}
|
||||
};
|
||||
625
src/ol/Map.js
625
src/ol/Map.js
@@ -1,625 +0,0 @@
|
||||
goog.provide('ol.Map');
|
||||
|
||||
goog.require('ol.Loc');
|
||||
goog.require('ol.Bounds');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.control.Control');
|
||||
goog.require('ol.renderer.MapRenderer');
|
||||
goog.require('ol.handler.Drag');
|
||||
goog.require('ol.handler.MouseWheel');
|
||||
goog.require('ol.handler.Click');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventTarget');
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable the drag handler.
|
||||
*/
|
||||
ol.ENABLE_DRAG_HANDLER = true;
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable the mousewheel handler.
|
||||
*/
|
||||
ol.ENABLE_MOUSEWHEEL_HANDLER = true;
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable the click handler.
|
||||
*/
|
||||
ol.ENABLE_CLICK_HANDLER = true;
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
* @extends {goog.events.EventTarget}
|
||||
*
|
||||
* @event layeradd Fires when a layer is added to the map. The event object
|
||||
* contains a 'layer' property referencing the added layer.
|
||||
*/
|
||||
ol.Map = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.projection_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.userProjection_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Loc}
|
||||
*/
|
||||
this.center_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.zoom_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.numZoomLevels_ = 22;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array}
|
||||
*/
|
||||
this.resolutions_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array}
|
||||
*/
|
||||
this.layers_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array}
|
||||
*/
|
||||
this.controls_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Bounds}
|
||||
*/
|
||||
this.maxExtent_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.maxResolution_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element}
|
||||
*/
|
||||
this.viewport_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {goog.math.Size}
|
||||
*/
|
||||
this.viewportSize_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Node}
|
||||
*/
|
||||
this.mapOverlay_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Node}
|
||||
*/
|
||||
this.staticOverlay_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element}
|
||||
*/
|
||||
this.container_ = null;
|
||||
};
|
||||
goog.inherits(ol.Map, goog.events.EventTarget);
|
||||
|
||||
/**
|
||||
@const
|
||||
@type {string}
|
||||
*/
|
||||
ol.Map.prototype.DEFAULT_PROJECTION = "EPSG:3857";
|
||||
/**
|
||||
@const
|
||||
@type {string}
|
||||
*/
|
||||
ol.Map.prototype.DEFAULT_USER_PROJECTION = "EPSG:4326";
|
||||
/**
|
||||
@const
|
||||
@type {number}
|
||||
*/
|
||||
ol.Map.ZOOM_FACTOR = 2;
|
||||
/**
|
||||
@const
|
||||
@type {number}
|
||||
*/
|
||||
ol.Map.DEFAULT_TILE_SIZE = 256;
|
||||
/**
|
||||
@const
|
||||
@type {Array.<string>}
|
||||
*/
|
||||
ol.Map.DEFAULT_CONTROLS = ["attribution", "zoom"];
|
||||
|
||||
/**
|
||||
* @return {ol.Loc} Map center in map projection.
|
||||
*/
|
||||
ol.Map.prototype.getCenter = function() {
|
||||
return this.center_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {!ol.Projection} Projection.
|
||||
*/
|
||||
ol.Map.prototype.getProjection = function() {
|
||||
if (goog.isNull(this.projection_)) {
|
||||
this.projection_ = new ol.Projection(this.DEFAULT_PROJECTION);
|
||||
}
|
||||
return this.projection_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {!ol.Projection} User projection.
|
||||
*/
|
||||
ol.Map.prototype.getUserProjection = function() {
|
||||
if (goog.isNull(this.userProjection_)) {
|
||||
this.userProjection_ = new ol.Projection(this.DEFAULT_USER_PROJECTION);
|
||||
}
|
||||
return this.userProjection_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Zoom.
|
||||
*/
|
||||
ol.Map.prototype.getZoom = function() {
|
||||
return this.zoom_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} number of zoom levels.
|
||||
*/
|
||||
ol.Map.prototype.getNumZoomLevels = function() {
|
||||
return this.numZoomLevels_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array|undefined} array of resolutions available for this map
|
||||
*/
|
||||
ol.Map.prototype.getResolutions = function() {
|
||||
return this.resolutions_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array|undefined} array of layers available for this map
|
||||
*/
|
||||
ol.Map.prototype.getLayers = function() {
|
||||
return this.layers_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.control.Control>}
|
||||
*/
|
||||
ol.Map.prototype.getControls = function() {
|
||||
return this.controls_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Bounds} the maxExtent for the map
|
||||
*/
|
||||
ol.Map.prototype.getMaxExtent = function() {
|
||||
if (goog.isDefAndNotNull(this.maxExtent_)) {
|
||||
return this.maxExtent_;
|
||||
} else {
|
||||
var projection = this.getProjection();
|
||||
var extent = projection.getExtent();
|
||||
if (goog.isDefAndNotNull(extent)) {
|
||||
extent = new ol.Bounds(
|
||||
extent.getMinX(), extent.getMinY(),
|
||||
extent.getMaxX(), extent.getMaxY());
|
||||
extent.setProjection(projection);
|
||||
return extent;
|
||||
} else {
|
||||
throw('maxExtent must be defined either in the map or the projection');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} the max resolution for the map
|
||||
*/
|
||||
ol.Map.prototype.getMaxResolution = function() {
|
||||
if (goog.isDefAndNotNull(this.maxResolution_)) {
|
||||
return this.maxResolution_;
|
||||
} else {
|
||||
var extent = this.getMaxExtent();
|
||||
var dim = Math.max(
|
||||
(extent.getMaxX()-extent.getMinX()),
|
||||
(extent.getMaxY()-extent.getMinY())
|
||||
);
|
||||
return dim/ol.Map.DEFAULT_TILE_SIZE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} zoom the zoom level being requested
|
||||
* @return {number} the resolution for the map at the given zoom level
|
||||
*/
|
||||
ol.Map.prototype.getResolutionForZoom = function(zoom) {
|
||||
if (goog.isDefAndNotNull(this.resolutions_)) {
|
||||
return this.resolutions_[zoom];
|
||||
} else {
|
||||
var maxResolution = this.getMaxResolution();
|
||||
return maxResolution/Math.pow(ol.Map.ZOOM_FACTOR, zoom);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} the resolution for the map at the given zoom level
|
||||
*/
|
||||
ol.Map.prototype.getResolution = function() {
|
||||
goog.asserts.assert(goog.isDef(this.renderer_));
|
||||
return this.renderer_.getResolution();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* TODO: We'll have to ask the map overlay renderer for this. This method will
|
||||
* not work once map space is not aligned with pixel space.
|
||||
*
|
||||
* @param {goog.math.Coordinate|{x: number, y: number}} pixel
|
||||
* @return {ol.Loc}
|
||||
*/
|
||||
ol.Map.prototype.getLocForViewportPixel = function(pixel) {
|
||||
var size = this.getViewportSize();
|
||||
var center = this.center_;
|
||||
var resolution = this.getResolution();
|
||||
var x = center.getX() + (resolution * (pixel.x - (size.width / 2)));
|
||||
var y = center.getY() - (resolution * (pixel.y - (size.height / 2)));
|
||||
return new ol.Loc(x, y, undefined, this.getProjection());
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: We'll have to ask the map overlay renderer for this. This method will
|
||||
* not work once map space is not aligned with pixel space.
|
||||
*
|
||||
* @param {ol.Loc} loc
|
||||
* @return {{x: number, y: number}}
|
||||
*/
|
||||
ol.Map.prototype.getViewportPixelForLoc = function(loc) {
|
||||
var size = this.getViewportSize();
|
||||
var center = this.center_;
|
||||
var resolution = this.getResolution();
|
||||
return {
|
||||
x: ((loc.getX() - center.getX()) / resolution) + (size.width / 2),
|
||||
y: ((center.getY() - loc.getY()) / resolution) + (size.height / 2)
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {goog.math.Size}
|
||||
*/
|
||||
ol.Map.prototype.getViewportSize = function() {
|
||||
// TODO: listen for resize and set this.viewportSize_ null
|
||||
// https://github.com/openlayers/ol3/issues/2
|
||||
if (goog.isNull(this.viewportSize_)) {
|
||||
this.viewportSize_ = goog.style.getSize(this.viewport_);
|
||||
}
|
||||
return this.viewportSize_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} center Center in map projection.
|
||||
*/
|
||||
ol.Map.prototype.setCenter = function(center) {
|
||||
goog.asserts.assert(!goog.isNull(center.getProjection()));
|
||||
this.center_ = center.doTransform(this.getProjection());
|
||||
this.conditionallyRender();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} zoom
|
||||
*/
|
||||
ol.Map.prototype.setCenterAndZoom = function(center, zoom) {
|
||||
goog.asserts.assert(!goog.isNull(center.getProjection()));
|
||||
this.center_ = center.doTransform(this.getProjection());
|
||||
this.zoom_ = this.limitZoom(zoom);
|
||||
this.conditionallyRender();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} zoom The zoom level to zoom to
|
||||
* @param {goog.math.Coordinate|{x: number, y: number}=} opt_anchor
|
||||
* Optional anchor pixel for the zoom origin.
|
||||
*/
|
||||
ol.Map.prototype.setZoom = function(zoom, opt_anchor) {
|
||||
var currentZoom = this.zoom_,
|
||||
newZoom = this.limitZoom(zoom),
|
||||
newCenter;
|
||||
if (newZoom === currentZoom) {
|
||||
return;
|
||||
}
|
||||
if (goog.isDef(opt_anchor)) {
|
||||
var size = this.getViewportSize(),
|
||||
anchorLoc = this.getLocForViewportPixel(opt_anchor),
|
||||
newRes = this.getResolutionForZoom(newZoom);
|
||||
newCenter = anchorLoc.add(
|
||||
(size.width/2 - opt_anchor.x) * newRes,
|
||||
(opt_anchor.y - size.height/2) * newRes
|
||||
);
|
||||
} else {
|
||||
newCenter = this.center_;
|
||||
}
|
||||
this.setCenterAndZoom(newCenter, newZoom);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
ol.Map.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} userProjection set the user projection.
|
||||
*/
|
||||
ol.Map.prototype.setUserProjection = function(userProjection) {
|
||||
this.userProjection_ = userProjection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} zoom
|
||||
* @return {number} zoom clamped to the range of available zoom levels.
|
||||
*/
|
||||
ol.Map.prototype.limitZoom = function(zoom) {
|
||||
return goog.math.clamp(zoom, 0, this.getNumZoomLevels()-1);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} nZoom Zoom.
|
||||
*/
|
||||
ol.Map.prototype.setNumZoomLevels = function(nZoom) {
|
||||
this.numZoomLevels_ = nZoom;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array} resolutions the map resolutions if set on the map
|
||||
*/
|
||||
ol.Map.prototype.setResolutions = function(resolutions) {
|
||||
this.resolutions_ = resolutions;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array} layers the layers set on the map
|
||||
*/
|
||||
ol.Map.prototype.setLayers = function(layers) {
|
||||
//TODO remove layers properly if there are layers already
|
||||
this.layers_ = [];
|
||||
this.addLayers(layers);
|
||||
};
|
||||
|
||||
ol.Map.prototype.addLayers = function(layers) {
|
||||
var layer;
|
||||
for (var i=0, ii=layers.length; i<ii; ++i) {
|
||||
layer = layers[i];
|
||||
this.layers_.push(layer);
|
||||
goog.events.dispatchEvent(this, {type: 'layeradd', 'layer': layer});
|
||||
}
|
||||
this.conditionallyRender();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.control.Control>|undefined} opt_controls
|
||||
*/
|
||||
ol.Map.prototype.setControls = function(opt_controls) {
|
||||
if (!this.controls_) {
|
||||
var control;
|
||||
for (var i=0, ii=opt_controls.length; i<ii; ++i) {
|
||||
control = opt_controls[i];
|
||||
if (!(control instanceof ol.control.Control)) {
|
||||
control = new ol.control.CONTROL_MAP[control]();
|
||||
}
|
||||
control.setMap(this);
|
||||
}
|
||||
this.controls_ = opt_controls;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Bounds} extent the maxExtent for the map
|
||||
*/
|
||||
ol.Map.prototype.setMaxExtent = function(extent) {
|
||||
this.maxExtent_ = extent;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} maxResolution the max resolution for the map
|
||||
*/
|
||||
ol.Map.prototype.setMaxResolution = function(maxResolution) {
|
||||
this.maxResolution_ = maxResolution;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Element} container the container to render the map to
|
||||
*/
|
||||
ol.Map.prototype.setContainer = function(container) {
|
||||
this.container_ = container;
|
||||
this.setViewport();
|
||||
this.createRenderer();
|
||||
//TODO Controls could be set earlier, but we need to deal with content that
|
||||
// controls place on overlays.
|
||||
this.setControls(ol.Map.DEFAULT_CONTROLS);
|
||||
// conditionally render
|
||||
this.conditionallyRender();
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if everything is ready. Render if so.
|
||||
*/
|
||||
ol.Map.prototype.conditionallyRender = function() {
|
||||
if (goog.isDef(this.renderer_) && !goog.isNull(this.layers_) &&
|
||||
goog.isDef(this.zoom_) && !goog.isNull(this.center_)) {
|
||||
this.renderer_.draw(this.layers_, this.center_,
|
||||
this.getResolutionForZoom(this.zoom_)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Element}
|
||||
*/
|
||||
ol.Map.prototype.getViewport = function() {
|
||||
return this.viewport_;
|
||||
};
|
||||
|
||||
ol.Map.prototype.setViewport = function() {
|
||||
if (!this.viewport_) {
|
||||
this.viewport_ = /** @type {Element} */ (goog.dom.createDom('div', {
|
||||
'class': 'ol-viewport',
|
||||
'style': 'width:100%;height:100%;top:0;left:0;position:relative;overflow:hidden'
|
||||
}));
|
||||
this.initHandlers();
|
||||
}
|
||||
goog.dom.appendChild(this.container_, this.viewport_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Init the map event handlers.
|
||||
*/
|
||||
ol.Map.prototype.initHandlers = function() {
|
||||
goog.asserts.assert(!goog.isNull(this.viewport_));
|
||||
|
||||
var handler,
|
||||
states = /** @type {ol.handler.states} */ ({});
|
||||
|
||||
if (ol.ENABLE_DRAG_HANDLER) {
|
||||
handler = new ol.handler.Drag(this, states);
|
||||
this.registerDisposable(handler);
|
||||
}
|
||||
if (ol.ENABLE_MOUSEWHEEL_HANDLER) {
|
||||
handler = new ol.handler.MouseWheel(this, states);
|
||||
this.registerDisposable(handler);
|
||||
}
|
||||
if (ol.ENABLE_CLICK_HANDLER) {
|
||||
handler = new ol.handler.Click(this, states);
|
||||
this.registerDisposable(handler);
|
||||
}
|
||||
};
|
||||
|
||||
ol.Map.prototype.createRenderer = function() {
|
||||
var Renderer = ol.renderer.MapRenderer.pickRendererType(
|
||||
ol.Map.preferredRenderers);
|
||||
this.renderer_ = new Renderer(this.viewport_);
|
||||
|
||||
//TODO Consider making a renderer responsible for managing the overlays
|
||||
var viewport = this.viewport_;
|
||||
if (!this.mapOverlay_ && !this.staticOverlay_) {
|
||||
var staticCls = 'ol-overlay-static';
|
||||
this.mapOverlay_ = goog.dom.createDom('div', 'ol-overlay-map');
|
||||
this.staticOverlay_ = goog.dom.createDom('div', {
|
||||
'class': staticCls,
|
||||
'style': 'width:100%;height:100%;top:0;left:0;position:absolute;z-index:1'
|
||||
});
|
||||
}
|
||||
if (!goog.isNull(viewport)) {
|
||||
goog.dom.append(viewport, this.mapOverlay_, this.staticOverlay_);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: This method will need to be reworked/revisited when renderers can
|
||||
* display a map that is rotated or otherwise not aligned with pixel space.
|
||||
*
|
||||
* @param {number} dx pixels to move in x direction
|
||||
* @param {number} dy pixels to move in x direction
|
||||
*/
|
||||
ol.Map.prototype.moveByViewportPx = function(dx, dy) {
|
||||
if (!goog.isNull(this.center_) && goog.isDef(this.zoom_)) {
|
||||
var resolution = this.getResolutionForZoom(this.zoom_),
|
||||
center = new ol.Loc(
|
||||
this.center_.getX() - dx * resolution,
|
||||
this.center_.getY() + dy * resolution
|
||||
);
|
||||
center.setProjection(this.getProjection());
|
||||
this.setCenter(center);
|
||||
}
|
||||
};
|
||||
|
||||
ol.Map.prototype.zoomIn = function() {
|
||||
this.setZoom(this.zoom_+1);
|
||||
};
|
||||
|
||||
ol.Map.prototype.zoomOut = function() {
|
||||
this.setZoom(this.zoom_-1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Node} the map overlay element
|
||||
*/
|
||||
ol.Map.prototype.getMapOverlay = function() {
|
||||
return this.mapOverlay_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Node} the static overlay element
|
||||
*/
|
||||
ol.Map.prototype.getStaticOverlay = function() {
|
||||
return this.staticOverlay_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.Map.prototype.disposeInternal = function() {
|
||||
goog.base(this, 'disposeInternal');
|
||||
//remove layers, etc.
|
||||
for (var key in this) {
|
||||
delete this[key];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* List of preferred renderer types. Map renderers have a getType method
|
||||
* that returns a string describing their type. This list determines the
|
||||
* preferences for picking a layer renderer.
|
||||
*
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
ol.Map.preferredRenderers = ["webgl", "canvas"];
|
||||
|
||||
343
src/ol/Popup.js
343
src/ol/Popup.js
@@ -1,343 +0,0 @@
|
||||
goog.provide('ol.Popup');
|
||||
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.Loc');
|
||||
goog.require('ol.Feature');
|
||||
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
* @param {ol.Map} map the map on which the popup is placed.
|
||||
* @param {ol.Loc|ol.Feature=} opt_anchor the anchor object for the popup.
|
||||
* @param {string=} opt_placement the placement of the arrow on the popup.
|
||||
* @param {boolean=} opt_close include a close button on the popup
|
||||
*/
|
||||
ol.Popup = function(map, opt_anchor, opt_placement, opt_close) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Map}
|
||||
*/
|
||||
this.map_ = map;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Loc|ol.Feature|undefined}
|
||||
*/
|
||||
this.anchor_ = opt_anchor;
|
||||
|
||||
/**
|
||||
* can be 'top','bottom','right','left','auto'
|
||||
* TODO: 'auto' not yet implemented
|
||||
* @private
|
||||
* @type {!string}
|
||||
*/
|
||||
this.placement_ = goog.isDefAndNotNull(opt_placement)?opt_placement:'top';
|
||||
|
||||
/**
|
||||
* include a close button on the popup - defaults to true.
|
||||
* @private
|
||||
* @type {boolean|undefined}
|
||||
*/
|
||||
this.closeButton_ = goog.isDefAndNotNull(opt_close) ? opt_close : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.content_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.template_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element}
|
||||
*/
|
||||
this.container_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.arrowOffset_ = 30; //FIXME: set this from CSS dynamically somehow?
|
||||
|
||||
/**
|
||||
* if the CSS sets either width or height assume the app is specifying the
|
||||
* size of the popup, if not auto size the popup.
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.autoSize_ = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
ol.Popup.CLASS_NAME = 'ol-popup';
|
||||
|
||||
/**
|
||||
* @return {ol.Map} Projection.
|
||||
*/
|
||||
ol.Popup.prototype.getMap = function() {
|
||||
return this.map_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map the map object to hold this popup.
|
||||
*/
|
||||
ol.Popup.prototype.setMap = function(map) {
|
||||
this.map_ = map;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Feature|ol.Loc|undefined} the anchor .
|
||||
*/
|
||||
ol.Popup.prototype.getAnchor = function() {
|
||||
return this.anchor_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Feature|ol.Loc} anchor the anchor location to place this popup.
|
||||
*/
|
||||
ol.Popup.prototype.setAnchor = function(anchor) {
|
||||
this.anchor_ = anchor;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string|undefined} the placement value relative to the anchor.
|
||||
*/
|
||||
ol.Popup.prototype.getPlacement = function() {
|
||||
return this.placement_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} placement where to place this popup relative to the anchor.
|
||||
*/
|
||||
ol.Popup.prototype.setPlacement = function(placement) {
|
||||
if (!goog.isNull(this.container_)) {
|
||||
goog.dom.classes.remove(this.container_,
|
||||
ol.Popup.CLASS_NAME+'-'+this.placement_);
|
||||
goog.dom.classes.add(this.container_,ol.Popup.CLASS_NAME+'-'+placement);
|
||||
}
|
||||
this.placement_ = placement;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string|undefined} static content to be displayed in the popup (HTML)
|
||||
*/
|
||||
ol.Popup.prototype.getContent = function() {
|
||||
return this.content_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} content the content to be displayed this popup.
|
||||
*/
|
||||
ol.Popup.prototype.setContent = function(content) {
|
||||
this.content_ = content;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @returns {string} generates the content
|
||||
*/
|
||||
ol.Popup.prototype.generateContent_ = function() {
|
||||
//set the content
|
||||
if ( goog.isDefAndNotNull(this.content_) ) {
|
||||
return this.content_;
|
||||
} else {
|
||||
if ( goog.isDefAndNotNull(this.template_) &&
|
||||
goog.isDefAndNotNull(this.anchor_) &&
|
||||
(this.anchor_ instanceof ol.Feature)) {
|
||||
//set content from feature attributes on the template
|
||||
//TODO: this.setContent(template.apply(this.anchor_.getAttributes()));
|
||||
return this.template_; //stub to return something
|
||||
} else {
|
||||
ol.error('ol.Popup unabale to generate any content');
|
||||
return '<p>no content</p>';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string|undefined} the anchor .
|
||||
*/
|
||||
ol.Popup.prototype.getTemplate = function() {
|
||||
return this.template_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} template the map object to hold this popup.
|
||||
*/
|
||||
ol.Popup.prototype.setTemplate = function(template) {
|
||||
this.template_ = template;
|
||||
};
|
||||
|
||||
/**
|
||||
* Open the popup.
|
||||
* @param {ol.Feature|ol.Loc} opt_arg feature or location for the anchor
|
||||
*/
|
||||
ol.Popup.prototype.doOpen = function(opt_arg) {
|
||||
if (goog.isDef(opt_arg)) {
|
||||
this.setAnchor(opt_arg);
|
||||
}
|
||||
|
||||
//create popup container if it's not created already
|
||||
if (goog.isNull(this.container_)) {
|
||||
this.container_ = goog.dom.createElement('div');
|
||||
goog.dom.classes.add(this.container_,
|
||||
ol.Popup.CLASS_NAME, ol.Popup.CLASS_NAME+'-'+this.placement_);
|
||||
|
||||
//see if the style class sets width or height
|
||||
if (goog.style.getStyle(this.container_, 'width').length>0 ||
|
||||
goog.style.getStyle(this.container_, 'height').length>0 ) {
|
||||
this.autoSize_ = false;
|
||||
}
|
||||
|
||||
if (this.closeButton_) {
|
||||
var closeButton = goog.dom.createElement('div');
|
||||
goog.dom.appendChild(this.container_, closeButton);
|
||||
goog.dom.classes.add(closeButton, ol.Popup.CLASS_NAME+'-close');
|
||||
}
|
||||
goog.events.listen(this.map_, 'click', this.clickHandler,
|
||||
undefined, this);
|
||||
goog.dom.appendChild(this.map_.getMapOverlay(), this.container_);
|
||||
}
|
||||
|
||||
this.childContent_=goog.dom.htmlToDocumentFragment(this.generateContent_());
|
||||
goog.dom.appendChild(this.container_, this.childContent_);
|
||||
|
||||
if (this.autoSize_) {
|
||||
this.registerImageListeners();
|
||||
}
|
||||
|
||||
this.setAnchorOffset_();
|
||||
};
|
||||
|
||||
ol.Popup.prototype.setAnchorOffset_ = function() {
|
||||
|
||||
if (goog.isNull(this.container_.parentNode)) {
|
||||
//this means the popup has already been closed, nothing to do here
|
||||
//which might happen while waiting for images to load
|
||||
return;
|
||||
}
|
||||
|
||||
if (!goog.isDefAndNotNull(this.anchor_)) {
|
||||
//must have an anchor when trying to set the position
|
||||
ol.error("ol.Popup must have an anchor to set the position");
|
||||
return;
|
||||
}
|
||||
|
||||
//position the element
|
||||
if (this.anchor_ instanceof ol.Feature) {
|
||||
this.pos_ = this.anchor_.getGeometry().getCentroid();
|
||||
} else {
|
||||
this.pos_ = new ol.geom.Point(this.anchor_.getX(), this.anchor_.getY());
|
||||
}
|
||||
var pos = /** @type {ol.Loc} */ (this.pos_);
|
||||
var popupPosPx = this.map_.getViewportPixelForLoc(pos);
|
||||
var popupSize = goog.style.getSize(this.container_);
|
||||
|
||||
switch(this.placement_) {
|
||||
default:
|
||||
case 'auto':
|
||||
//TODO: switch based on map quadrant
|
||||
break;
|
||||
case 'top':
|
||||
case 'bottom':
|
||||
popupPosPx[0] -= popupSize.width / 2.0;
|
||||
|
||||
if (this.placement_ == "bottom") {
|
||||
popupPosPx[1] -= popupSize.height + this.arrowOffset_;
|
||||
} else {
|
||||
popupPosPx[1] += this.arrowOffset_;
|
||||
}
|
||||
break;
|
||||
case 'left':
|
||||
case 'right':
|
||||
popupPosPx[1] -= popupSize.height / 2.0;
|
||||
|
||||
if (this.placement_ == "right") {
|
||||
popupPosPx[0] -= popupSize.width + this.arrowOffset_;
|
||||
} else {
|
||||
popupPosPx[0] += this.arrowOffset_;
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.moveTo_(popupPosPx);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* registerImageListeners
|
||||
* Called when an image contained by the popup loaded. this function
|
||||
* updates the popup size, then unregisters the image load listener.
|
||||
*/
|
||||
ol.Popup.prototype.registerImageListeners = function() {
|
||||
|
||||
// As the images load, this function will call setAnchorOffset_() to
|
||||
// resize the popup to fit the content div (which presumably is now
|
||||
// bigger than when the image was not loaded).
|
||||
//
|
||||
//cycle through the images and if their size is 0x0, that means that
|
||||
// they haven't been loaded yet, so we attach the listener, which
|
||||
// will fire when the images finish loading and will resize the
|
||||
// popup accordingly to its new size.
|
||||
var images = this.container_.getElementsByTagName("img");
|
||||
for (var i = 0, len = images.length; i < len; i++) {
|
||||
var img = images[i];
|
||||
if (img.width == 0 || img.height == 0) {
|
||||
goog.events.listenOnce(img, 'load',
|
||||
goog.bind(this.setAnchorOffset_, this));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param px - {goog.} the top and left position of the popup div.
|
||||
*/
|
||||
ol.Popup.prototype.moveTo_ = function(px) {
|
||||
if (goog.isDefAndNotNull(px)) {
|
||||
goog.style.setPosition(this.container_, px[0], px[1]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Click handler
|
||||
* @param {Event} evt the event generated by a click
|
||||
*/
|
||||
ol.Popup.prototype.clickHandler = function(evt) {
|
||||
var target = /** @type {Node} */ evt.target;
|
||||
if (goog.dom.classes.has(target,ol.Popup.CLASS_NAME+'-close')) {
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up.
|
||||
* @export
|
||||
*/
|
||||
ol.Popup.prototype.close = function() {
|
||||
goog.dom.removeChildren(this.container_);
|
||||
goog.dom.removeNode(this.container_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up.
|
||||
* @export
|
||||
*/
|
||||
ol.Popup.prototype.destroy = function() {
|
||||
for (var key in this) {
|
||||
delete this[key];
|
||||
}
|
||||
};
|
||||
@@ -1,257 +0,0 @@
|
||||
goog.provide('ol.Projection');
|
||||
goog.require('ol.UnreferencedBounds');
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
* @param {string} code Projection identifier.
|
||||
*/
|
||||
ol.Projection = function(code) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.code_ = code;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.units_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.proj_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.UnreferencedBounds}
|
||||
*/
|
||||
this.extent_ = null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} Code.
|
||||
*/
|
||||
ol.Projection.prototype.getCode = function() {
|
||||
return this.code_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} code Code.
|
||||
*/
|
||||
ol.Projection.prototype.setCode = function(code) {
|
||||
this.code_ = code;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string|undefined} Units abbreviation.
|
||||
*/
|
||||
ol.Projection.prototype.getUnits = function() {
|
||||
return this.units_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} units Units abbreviation.
|
||||
*/
|
||||
ol.Projection.prototype.setUnits = function(units) {
|
||||
this.units_ = units;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the validity extent of the coordinate reference system.
|
||||
*
|
||||
* @return {ol.UnreferencedBounds} The valididty extent.
|
||||
*/
|
||||
ol.Projection.prototype.getExtent = function() {
|
||||
if (goog.isNull(this.extent_)) {
|
||||
var defs = ol.Projection.defaults[this.code_];
|
||||
if (goog.isDef(defs)) {
|
||||
var ext = defs.maxExtent;
|
||||
if (goog.isDef(ext)) {
|
||||
this.setExtent(new ol.UnreferencedBounds(ext[0],ext[1],ext[2],ext[3]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.extent_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {!ol.UnreferencedBounds} extent Validity extent.
|
||||
*/
|
||||
ol.Projection.prototype.setExtent = function(extent) {
|
||||
this.extent_ = extent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Transforms is an object, with from properties, each of which may
|
||||
* have a to property. This allows you to define projections without
|
||||
* requiring support for proj4js to be included.
|
||||
*
|
||||
* This object has keys which correspond to a 'source' projection object. The
|
||||
* keys should be strings, corresponding to the projection.getCode() value.
|
||||
* Each source projection object should have a set of destination projection
|
||||
* keys included in the object.
|
||||
*
|
||||
* Each value in the destination object should be a transformation function,
|
||||
* where the function is expected to be passed an object with a .x and a .y
|
||||
* property. The function should return the object, with the .x and .y
|
||||
* transformed according to the transformation function.
|
||||
*
|
||||
* Note - Properties on this object should not be set directly. To add a
|
||||
* transform method to this object, use the <addTransform> method. For an
|
||||
* example of usage, see the OpenLayers.Layer.SphericalMercator file.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
ol.Projection.transforms = {};
|
||||
|
||||
/**
|
||||
* Defaults for the SRS codes known to OpenLayers (currently EPSG:4326, CRS:84,
|
||||
* urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857, EPSG:102113 and
|
||||
* EPSG:102100). Keys are the SRS code, values are units, maxExtent (the
|
||||
* validity extent for the SRS) and yx (true if this SRS is known to have a
|
||||
* reverse axis order).
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
ol.Projection.defaults = {
|
||||
"EPSG:4326": {
|
||||
units: "degrees",
|
||||
maxExtent: [-180, -90, 180, 90],
|
||||
yx: true
|
||||
},
|
||||
"CRS:84": {
|
||||
units: "degrees",
|
||||
maxExtent: [-180, -90, 180, 90]
|
||||
},
|
||||
"EPSG:900913": {
|
||||
units: "m",
|
||||
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34]
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set a custom transform method between two projections. Use this method in
|
||||
* cases where the proj4js lib is not available or where custom projections
|
||||
* need to be handled.
|
||||
*
|
||||
* @param {string} from The code for the source projection.
|
||||
* @param {string} to The code for the destination projection.
|
||||
* @param {function(Object)} method A function that takes an object with x and
|
||||
* y properties as an argument and transforms that point from the source to
|
||||
* the destination projection in place. The original point should be
|
||||
* modified.
|
||||
*/
|
||||
ol.Projection.addTransform = function(from, to, method) {
|
||||
if (method === ol.Projection.nullTransform) {
|
||||
var defaults = ol.Projection.defaults[from];
|
||||
if (defaults && !ol.Projection.defaults[to]) {
|
||||
ol.Projection.defaults[to] = defaults;
|
||||
}
|
||||
}
|
||||
if(!ol.Projection.transforms[from]) {
|
||||
ol.Projection.transforms[from] = {};
|
||||
}
|
||||
ol.Projection.transforms[from][to] = method;
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform a point coordinate from one projection to another.
|
||||
*
|
||||
* @param {Object} point Object with x and y properties.
|
||||
* @param {ol.Projection} source Source projection.
|
||||
* @param {ol.Projection} dest Destination projection.
|
||||
*/
|
||||
ol.Projection.transform = function(point, source, dest) {
|
||||
goog.asserts.assertObject(point);
|
||||
goog.asserts.assertObject(source);
|
||||
goog.asserts.assertObject(dest);
|
||||
if (source.proj_ && dest.proj_) {
|
||||
// TODO: implement Proj4js handling
|
||||
// point = Proj4js.transform(source.proj_, dest.proj_, point);
|
||||
} else {
|
||||
var sourceCode = source.getCode();
|
||||
var destCode = dest.getCode();
|
||||
var transforms = ol.Projection.transforms;
|
||||
if (transforms[sourceCode] && transforms[sourceCode][destCode]) {
|
||||
transforms[sourceCode][destCode](point);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A null transformation - useful for defining projection aliases when
|
||||
* proj4js is not available:
|
||||
*
|
||||
* ol.Projection.addTransform("EPSG:3857", "EPSG:900913",
|
||||
* ol.Projection.nullTransform);
|
||||
* ol.Projection.addTransform("EPSG:900913", "EPSG:3857",
|
||||
* ol.Projection.nullTransform);
|
||||
*
|
||||
* @type {function(Object)}
|
||||
*/
|
||||
ol.Projection.nullTransform = function(point) {
|
||||
return point;
|
||||
};
|
||||
|
||||
/**
|
||||
* Note: Transforms for web mercator <-> geographic
|
||||
* OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100.
|
||||
* OpenLayers originally started referring to EPSG:900913 as web mercator.
|
||||
* The EPSG has declared EPSG:3857 to be web mercator.
|
||||
* ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as
|
||||
* equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084.
|
||||
* For geographic, OpenLayers recognizes EPSG:4326, CRS:84 and
|
||||
* urn:ogc:def:crs:EPSG:6.6:4326. OpenLayers also knows about the reverse axis
|
||||
* order for EPSG:4326.
|
||||
*/
|
||||
(function() {
|
||||
|
||||
var pole = 20037508.34;
|
||||
|
||||
function inverseMercator(xy) {
|
||||
xy.x = 180 * xy.x / pole;
|
||||
xy.y = 180 / Math.PI * (2 * Math.atan(Math.exp((xy.y / pole) * Math.PI)) - Math.PI / 2);
|
||||
return xy;
|
||||
}
|
||||
|
||||
function forwardMercator(xy) {
|
||||
xy.x = xy.x * pole / 180;
|
||||
xy.y = Math.log(Math.tan((90 + xy.y) * Math.PI / 360)) / Math.PI * pole;
|
||||
return xy;
|
||||
}
|
||||
|
||||
function map(base, codes) {
|
||||
var add = ol.Projection.addTransform;
|
||||
var same = ol.Projection.nullTransform;
|
||||
var i, len, code, other, j;
|
||||
for (i=0, len=codes.length; i<len; ++i) {
|
||||
code = codes[i];
|
||||
add(base, code, forwardMercator);
|
||||
add(code, base, inverseMercator);
|
||||
for (j=i+1; j<len; ++j) {
|
||||
other = codes[j];
|
||||
add(code, other, same);
|
||||
add(other, code, same);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// list of equivalent codes for web mercator
|
||||
var mercator = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"],
|
||||
geographic = ["CRS:84", "urn:ogc:def:crs:EPSG:6.6:4326", "EPSG:4326"],
|
||||
i;
|
||||
for (i=mercator.length-1; i>=0; --i) {
|
||||
map(mercator[i], geographic);
|
||||
}
|
||||
for (i=geographic.length-1; i>=0; --i) {
|
||||
map(geographic[i], mercator);
|
||||
}
|
||||
|
||||
})();
|
||||
169
src/ol/Tile.js
169
src/ol/Tile.js
@@ -1,169 +0,0 @@
|
||||
goog.provide('ol.Tile');
|
||||
|
||||
goog.require('ol.Bounds');
|
||||
|
||||
goog.require('goog.events.EventTarget');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.asserts');
|
||||
|
||||
/**
|
||||
* The Tile class.
|
||||
* @constructor
|
||||
* @extends {goog.events.EventTarget}
|
||||
* @param {string} url
|
||||
* @param {ol.Bounds|undefined} opt_bounds
|
||||
*/
|
||||
ol.Tile = function(url, opt_bounds) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.url_ = url;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Bounds|undefined}
|
||||
*/
|
||||
this.bounds_ = opt_bounds;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.loaded_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.loading_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLImageElement}
|
||||
*/
|
||||
this.img_ = this.createImage();
|
||||
goog.events.listenOnce(this.img_, goog.events.EventType.LOAD,
|
||||
this.handleImageLoad, false, this);
|
||||
goog.events.listenOnce(this.img_, goog.events.EventType.ERROR,
|
||||
this.handleImageError, false, this);
|
||||
};
|
||||
goog.inherits(ol.Tile, goog.events.EventTarget);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @return {HTMLImageElement}
|
||||
*/
|
||||
ol.Tile.prototype.createImage = function() {
|
||||
// overriden by subclasses
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the tile. A tile should loaded only once.
|
||||
*/
|
||||
ol.Tile.prototype.load = function() {
|
||||
goog.asserts.assert(!this.loaded_ && !this.loading_);
|
||||
this.loading_ = true;
|
||||
this.img_.src = this.url_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the tile url.
|
||||
* @return {string}
|
||||
*/
|
||||
ol.Tile.prototype.getUrl = function() {
|
||||
return this.url_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the tile bounds.
|
||||
* @return {ol.Bounds|undefined}
|
||||
*/
|
||||
ol.Tile.prototype.getBounds = function() {
|
||||
return this.bounds_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the tile image.
|
||||
* @return {HTMLImageElement}
|
||||
*/
|
||||
ol.Tile.prototype.getImg = function() {
|
||||
return this.img_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle load event on the image.
|
||||
* @param {goog.events.BrowserEvent} evt Event.
|
||||
*/
|
||||
ol.Tile.prototype.handleImageLoad = function(evt) {
|
||||
this.loading_ = false;
|
||||
this.loaded_ = true;
|
||||
this.img_.style.visibility = "inherit";
|
||||
this.img_.style.opacity = 1; // TODO: allow for layer opacity
|
||||
goog.events.dispatchEvent(this, 'load');
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle load error event on the image.
|
||||
* @param {goog.events.BrowserEvent} evt Event.
|
||||
*/
|
||||
ol.Tile.prototype.handleImageError = function(evt) {
|
||||
this.loading_ = false;
|
||||
goog.events.dispatchEvent(this, 'error');
|
||||
};
|
||||
|
||||
/**
|
||||
* Is the tile loaded already?
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.Tile.prototype.isLoaded = function() {
|
||||
return this.loaded_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is the tile being loaded?
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.Tile.prototype.isLoading = function() {
|
||||
return this.loading_;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ol.Tile.prototype.destroy = function() {
|
||||
goog.events.dispatchEvent(this, 'destroy');
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a tile constructor, for specific width and height values
|
||||
* for the tiles.
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @return {function(new:ol.Tile, string, ol.Bounds=)}
|
||||
*/
|
||||
ol.Tile.createConstructor = function(width, height) {
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Tile}
|
||||
*/
|
||||
var Tile = function(url, opt_bounds) {
|
||||
goog.base(this, url, opt_bounds);
|
||||
};
|
||||
goog.inherits(Tile, ol.Tile);
|
||||
/** @inheritDoc */
|
||||
Tile.prototype.createImage = (function() {
|
||||
var img = document.createElement("img");
|
||||
img.className = "olTile";
|
||||
img.style.position = "absolute";
|
||||
img.style.width = width + "px";
|
||||
img.style.height = height + "px";
|
||||
img.style.opacity = 0;
|
||||
img.src = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";
|
||||
return function() {
|
||||
return img.cloneNode(false);
|
||||
};
|
||||
})();
|
||||
return Tile;
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
goog.provide('ol.TileCache');
|
||||
|
||||
goog.require('goog.structs.LinkedMap');
|
||||
|
||||
/**
|
||||
* A cache of ol.Tile objects.
|
||||
* @constructor
|
||||
* @extends {goog.structs.LinkedMap}
|
||||
* @param {number=} opt_size
|
||||
*/
|
||||
ol.TileCache = function(opt_size) {
|
||||
goog.base(this, opt_size || 100, true /* cache mode */);
|
||||
};
|
||||
|
||||
goog.inherits(ol.TileCache, goog.structs.LinkedMap);
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.TileCache.prototype.removeNode = function(node) {
|
||||
goog.base(this, 'removeNode', node);
|
||||
node.value.destroy();
|
||||
};
|
||||
@@ -1,66 +0,0 @@
|
||||
goog.provide('ol.TileSet');
|
||||
|
||||
/**
|
||||
* The TileSet class. A TileSet instance represents a collection of
|
||||
* tiles. Tiles of a TileSet have the same resolution, width and
|
||||
* height.
|
||||
* @constructor
|
||||
* @param {Array.<Array.<ol.Tile>>} tiles
|
||||
* @param {number} tileWidth
|
||||
* @param {number} tileHeight
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.TileSet = function(tiles, tileWidth, tileHeight, resolution) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Array.<ol.Tile>>}
|
||||
*/
|
||||
this.tiles_ = tiles;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.tileWidth_ = tileWidth;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.tileHeight_ = tileHeight;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.resolution_ = resolution;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Array.<Array.<ol.Tile>>}
|
||||
*/
|
||||
ol.TileSet.prototype.getTiles = function() {
|
||||
return this.tiles_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
ol.TileSet.prototype.getResolution = function() {
|
||||
return this.resolution_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
ol.TileSet.prototype.getTileHeight = function() {
|
||||
return this.tileHeight_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
ol.TileSet.prototype.getTileWidth = function() {
|
||||
return this.tileWidth_;
|
||||
};
|
||||
@@ -1,130 +0,0 @@
|
||||
goog.provide('ol.UnreferencedBounds');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {number} minX Minimum X.
|
||||
* @param {number} minY Minimum Y.
|
||||
* @param {number} maxX Maximum X.
|
||||
* @param {number} maxY Maximum Y.
|
||||
*/
|
||||
ol.UnreferencedBounds = function(minX, minY, maxX, maxY) {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.minX_ = minX;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.minY_ = minY;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxX_ = maxX;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxY_ = maxY;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Minimun X.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.getMinX = function() {
|
||||
return this.minX_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} minX Minimum X.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.setMinX = function(minX) {
|
||||
this.minX_ = minX;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} Minimun Y.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.getMinY = function() {
|
||||
return this.minY_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} minY Minimum Y.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.setMinY = function(minY) {
|
||||
this.minY_ = minY;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} Maximun X.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.getMaxX = function() {
|
||||
return this.maxX_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} maxX Maximum X.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.setMaxX = function(maxX) {
|
||||
this.maxX_ = maxX;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} Maximun Y.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.getMaxY = function() {
|
||||
return this.maxY_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} maxY Maximum Y.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.setMaxY = function(maxY) {
|
||||
this.maxY_ = maxY;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} Bounds width.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.getWidth = function() {
|
||||
return this.maxX_ - this.minX_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} Bounds height.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.getHeight = function() {
|
||||
return this.maxY_ - this.minY_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if this bounds intersects the target bounds (bounds that only
|
||||
* touch are considered intersecting).
|
||||
*
|
||||
* @param {ol.UnreferencedBounds} bounds Target bounds.
|
||||
* @return {boolean} The provided bounds intersects this bounds.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.intersects = function(bounds) {
|
||||
return !(
|
||||
// this is left
|
||||
(this.minX_ > bounds.getMaxX()) ||
|
||||
|
||||
// this is right
|
||||
(this.maxX_ < bounds.getMinX()) ||
|
||||
|
||||
// this is above
|
||||
(this.minY_ > bounds.getMaxY()) ||
|
||||
|
||||
// this is below
|
||||
(this.maxY_ < bounds.getMinY())
|
||||
);
|
||||
};
|
||||
@@ -1,46 +0,0 @@
|
||||
goog.provide('ol.base');
|
||||
goog.provide('ol.error');
|
||||
|
||||
/**
|
||||
* @param {string} message Message.
|
||||
*/
|
||||
ol.error = function(message) {
|
||||
if (ol.error.VERBOSE_ERRORS) {
|
||||
throw new Error(message);
|
||||
} else {
|
||||
throw null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Compilation with public API, let's accept options from external world
|
||||
* @define {boolean}
|
||||
*/
|
||||
ol.API = true;
|
||||
|
||||
/**
|
||||
* @define {boolean}
|
||||
*/
|
||||
ol.error.VERBOSE_ERRORS = true;
|
||||
|
||||
/**
|
||||
* Options passed in the API from external world are checked for wrong keys
|
||||
* @define {boolean}
|
||||
*/
|
||||
ol.CHECK_KEYS = true;
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object.
|
||||
* @param {!Array.<string>} allowedKeys Allowed keys.
|
||||
*/
|
||||
ol.base.checkKeys = function(obj, allowedKeys) {
|
||||
if (ol.CHECK_KEYS) {
|
||||
var keys = goog.object.getKeys(obj);
|
||||
goog.array.forEach(allowedKeys, function(allowedKey) {
|
||||
goog.array.remove(keys, allowedKey);
|
||||
});
|
||||
if (!goog.array.isEmpty(keys)) {
|
||||
ol.error('object contains invalid keys: ' + keys.join(', '));
|
||||
}
|
||||
}
|
||||
};
|
||||
22
src/ol/collection_test.js
Normal file
22
src/ol/collection_test.js
Normal file
@@ -0,0 +1,22 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol');
|
||||
goog.require('ol3.Collection');
|
||||
|
||||
|
||||
function testCreateFromArray() {
|
||||
var array = [0, 1, 2];
|
||||
var collection = ol.collection(array);
|
||||
assertTrue(collection instanceof ol3.Collection);
|
||||
assertEquals(3, collection.getLength());
|
||||
assertEquals(0, collection.getAt(0));
|
||||
assertEquals(1, collection.getAt(1));
|
||||
assertEquals(2, collection.getAt(2));
|
||||
}
|
||||
|
||||
|
||||
function testCreateFromCollection() {
|
||||
var collection1 = new ol3.Collection();
|
||||
var collection2 = ol.collection(collection1);
|
||||
assertTrue(collection1 === collection2);
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
goog.provide('ol.control.Attribution');
|
||||
|
||||
goog.require('ol.control.Control');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.Event');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Control}
|
||||
* @param {boolean|undefined} opt_autoActivate
|
||||
*/
|
||||
ol.control.Attribution = function(opt_autoActivate) {
|
||||
|
||||
goog.base(this, opt_autoActivate);
|
||||
|
||||
/**
|
||||
* @type {Node}
|
||||
*/
|
||||
this.container_ = null;
|
||||
|
||||
/**
|
||||
* Activate this control when it is added to a map. Default is true.
|
||||
*
|
||||
* @type {boolean} autoActivate
|
||||
*/
|
||||
this.autoActivate_ =
|
||||
goog.isDef(opt_autoActivate) ? opt_autoActivate : true;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.Attribution, ol.control.Control);
|
||||
|
||||
/**
|
||||
* @const {string}
|
||||
*/
|
||||
ol.control.Attribution.prototype.CLS = 'ol-control-attribution';
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map
|
||||
*/
|
||||
ol.control.Attribution.prototype.setMap = function(map) {
|
||||
var staticOverlay = map.getStaticOverlay();
|
||||
if (goog.isNull(this.container_)) {
|
||||
this.container_ = goog.dom.createDom('div', this.CLS);
|
||||
goog.events.listen(this.container_, 'click',
|
||||
goog.events.Event.stopPropagation);
|
||||
}
|
||||
if (!goog.isNull(staticOverlay)) {
|
||||
goog.dom.append(staticOverlay, this.container_);
|
||||
}
|
||||
goog.base(this, 'setMap', map);
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.control.Attribution.prototype.activate = function() {
|
||||
var active = goog.base(this, 'activate');
|
||||
if (active) {
|
||||
goog.events.listen(this.map_, 'layeradd', this.update, false, this);
|
||||
this.update();
|
||||
}
|
||||
return active;
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.control.Attribution.prototype.deactivate = function() {
|
||||
var inactive = goog.base(this, 'deactivate');
|
||||
if (inactive) {
|
||||
goog.events.unlisten(this.map_, 'layeradd', this.update, false, this);
|
||||
}
|
||||
return inactive;
|
||||
};
|
||||
|
||||
ol.control.Attribution.prototype.update = function() {
|
||||
var attribution = [],
|
||||
layers = this.map_.getLayers(), layerAttribution;
|
||||
for (var i=0, ii=layers.length; i<ii; ++i) {
|
||||
layerAttribution = layers[i].getAttribution();
|
||||
if (layerAttribution &&
|
||||
!~goog.array.indexOf(attribution, layerAttribution)) {
|
||||
attribution.push(layerAttribution);
|
||||
}
|
||||
}
|
||||
this.container_.innerHTML = attribution.join(', ');
|
||||
};
|
||||
|
||||
ol.control.Attribution.prototype.destroy = function() {
|
||||
goog.events.unlisten(this.container_, 'click',
|
||||
goog.events.Event.stopPropagation);
|
||||
goog.dom.removeNode(this.container_);
|
||||
goog.base(this, 'destroy');
|
||||
};
|
||||
|
||||
ol.control.addControl('attribution', ol.control.Attribution);
|
||||
@@ -1,85 +0,0 @@
|
||||
goog.provide('ol.control');
|
||||
goog.provide('ol.control.Control');
|
||||
|
||||
goog.require('goog.object');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {Object}
|
||||
*/
|
||||
ol.control.CONTROL_MAP = {};
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {Function} Control
|
||||
*/
|
||||
ol.control.addControl = function(name, Control) {
|
||||
ol.control.CONTROL_MAP[name] = Control;
|
||||
};
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {boolean|undefined} opt_autoActivate
|
||||
*/
|
||||
ol.control.Control = function(opt_autoActivate) {
|
||||
|
||||
/**
|
||||
* @type {ol.Map} map
|
||||
* @protected
|
||||
*/
|
||||
this.map_ = null;
|
||||
|
||||
/**
|
||||
* @type {boolean} active
|
||||
* @private
|
||||
*/
|
||||
this.active_ = false;
|
||||
|
||||
/**
|
||||
* Activate this control when it is added to a map. Default is false.
|
||||
*
|
||||
* @type {boolean} autoActivate
|
||||
*/
|
||||
this.autoActivate_ =
|
||||
goog.isDef(opt_autoActivate) ? opt_autoActivate : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Map} getMap
|
||||
*/
|
||||
ol.control.Control.prototype.getMap = function() {
|
||||
return this.map_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map
|
||||
*/
|
||||
ol.control.Control.prototype.setMap = function(map) {
|
||||
this.map_ = map;
|
||||
if (this.autoActivate_) {
|
||||
this.activate();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.control.Control.prototype.activate = function() {
|
||||
var returnValue = !this.active_;
|
||||
this.active_ = true;
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.control.Control.prototype.deactivate = function() {
|
||||
var returnValue = this.active_;
|
||||
this.active_ = false;
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
ol.control.Control.prototype.destroy = function() {
|
||||
this.deactivate();
|
||||
goog.object.clear(this);
|
||||
};
|
||||
@@ -1,122 +0,0 @@
|
||||
goog.provide('ol.control.Zoom');
|
||||
|
||||
goog.require('ol.control.Control');
|
||||
|
||||
goog.require('goog.dom');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Control}
|
||||
* @param {boolean|undefined} opt_autoActivate
|
||||
*/
|
||||
ol.control.Zoom = function(opt_autoActivate) {
|
||||
|
||||
goog.base(this, opt_autoActivate);
|
||||
|
||||
/**
|
||||
* @type {Node}
|
||||
*/
|
||||
this.inButton_ = null;
|
||||
|
||||
/**
|
||||
* @type {Node}
|
||||
*/
|
||||
this.outButton_ = null;
|
||||
|
||||
/**
|
||||
* Activate this control when it is added to a map. Default is true.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.autoActivate_ =
|
||||
goog.isDef(opt_autoActivate) ? opt_autoActivate : true;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.Zoom, ol.control.Control);
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map
|
||||
*/
|
||||
ol.control.Zoom.prototype.setMap = function(map) {
|
||||
var container = goog.dom.createDom('div', ol.control.Zoom.RES.CLS);
|
||||
this.inButton_ = goog.dom.createDom(
|
||||
'div', ol.control.Zoom.RES.IN_CLS,
|
||||
goog.dom.createDom('a', {'href': '#zoomIn'})
|
||||
);
|
||||
goog.dom.setTextContent(
|
||||
/** @type {Element} */ (this.inButton_.firstChild),
|
||||
ol.control.Zoom.RES.IN_TEXT
|
||||
);
|
||||
this.outButton_ = goog.dom.createDom(
|
||||
'div', ol.control.Zoom.RES.OUT_CLS,
|
||||
goog.dom.createDom('a', {'href': '#zoomOut'})
|
||||
);
|
||||
goog.dom.setTextContent(
|
||||
/** @type {Element} */ (this.outButton_.firstChild),
|
||||
ol.control.Zoom.RES.OUT_TEXT
|
||||
);
|
||||
goog.dom.append(container, this.inButton_, this.outButton_);
|
||||
|
||||
var overlay = map.getStaticOverlay();
|
||||
if (goog.isDefAndNotNull(overlay)) {
|
||||
goog.dom.append(overlay, container);
|
||||
}
|
||||
goog.base(this, 'setMap', map);
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.control.Zoom.prototype.activate = function() {
|
||||
var active = goog.base(this, 'activate');
|
||||
if (active) {
|
||||
goog.events.listen(this.inButton_, 'click', this.handleIn, false, this);
|
||||
goog.events.listen(this.outButton_, 'click', this.handleOut, false, this);
|
||||
}
|
||||
return active;
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
ol.control.Zoom.prototype.deactivate = function() {
|
||||
var inactive = goog.base(this, 'deactivate');
|
||||
if (inactive) {
|
||||
goog.events.unlisten(this.inButton_, 'click', this.handleIn, false, this);
|
||||
goog.events.unlisten(this.outButton_, 'click', this.handleOut, false, this);
|
||||
}
|
||||
return inactive;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
ol.control.Zoom.prototype.handleIn = function(evt) {
|
||||
this.map_.zoomIn();
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
ol.control.Zoom.prototype.handleOut = function(evt) {
|
||||
this.map_.zoomOut();
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
};
|
||||
|
||||
ol.control.Zoom.prototype.destroy = function() {
|
||||
goog.dom.removeNode(goog.dom.getElementByClass(
|
||||
ol.control.Zoom.RES.CLS,
|
||||
/** @type {Element} */ (this.map_.getStaticOverlay())
|
||||
));
|
||||
goog.base(this, 'destroy');
|
||||
};
|
||||
|
||||
ol.control.addControl('zoom', ol.control.Zoom);
|
||||
|
||||
ol.control.Zoom.RES = {
|
||||
CLS: 'ol-control-zoom',
|
||||
IN_CLS: 'ol-control-zoom-in',
|
||||
OUT_CLS: 'ol-control-zoom-out',
|
||||
IN_TEXT: '+',
|
||||
OUT_TEXT: '\u2212'
|
||||
};
|
||||
@@ -1,58 +0,0 @@
|
||||
goog.provide('ol.coord.AccessorInterface');
|
||||
|
||||
goog.require('ol.Projection');
|
||||
|
||||
/**
|
||||
* The AccessorInterface in coord package
|
||||
*
|
||||
* @interface
|
||||
*
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @param {number=} opt_z Z.
|
||||
* @param {ol.Projection=} opt_projection Projection.
|
||||
*/
|
||||
ol.coord.AccessorInterface = function(x, y, opt_z, opt_projection){
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} X.
|
||||
*/
|
||||
ol.coord.AccessorInterface.prototype.getX = function(){};
|
||||
|
||||
/**
|
||||
* @return {number} Y.
|
||||
*/
|
||||
ol.coord.AccessorInterface.prototype.getY = function(){};
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Z.
|
||||
*/
|
||||
ol.coord.AccessorInterface.prototype.getZ = function(){};
|
||||
|
||||
/**
|
||||
* @return {ol.Projection|undefined} Projection.
|
||||
*/
|
||||
ol.coord.AccessorInterface.prototype.getProjection = function() {};
|
||||
|
||||
/**
|
||||
* @param {number} x X.
|
||||
*/
|
||||
ol.coord.AccessorInterface.prototype.setX = function(x){};
|
||||
|
||||
/**
|
||||
* @param {number} y Y.
|
||||
*/
|
||||
ol.coord.AccessorInterface.prototype.setY = function(y){};
|
||||
|
||||
/**
|
||||
* @param {number|undefined} z Z.
|
||||
*/
|
||||
ol.coord.AccessorInterface.prototype.setZ = function(z){};
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
ol.coord.AccessorInterface.prototype.setProjection = function(projection) {};
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
goog.provide('ol.geom.Collection');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.base');
|
||||
|
||||
/**
|
||||
* 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>}
|
||||
*/
|
||||
this.typeBlacklist_ = [
|
||||
ol.geom.Collection
|
||||
];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Function>}
|
||||
*/
|
||||
this.typeWhitelist_ = [
|
||||
ol.geom.MultiPoint,
|
||||
ol.geom.MultiLineString
|
||||
// TODO uncomment when implemented
|
||||
// ,ol.geom.MultiPolygon
|
||||
];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.geom.Geometry>}
|
||||
*/
|
||||
this.components_ = [];
|
||||
|
||||
if (arguments.length === 1 && goog.isDef(components)) {
|
||||
this.setComponents(components);
|
||||
}
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.Collection, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return {Array.<Function>} Array of constructors to disallow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getTypeBlacklist = function(){
|
||||
return this.typeBlacklist_;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return {Array.<Function>} Array of constructors to allow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getTypeWhitelist = function(){
|
||||
return this.typeWhitelist_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the Collection's components.
|
||||
*
|
||||
* @return {Array.<ol.geom.Geometry>} An array of components.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getComponents = function() {
|
||||
return this.components_;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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,
|
||||
this.isAllowedComponent,
|
||||
this
|
||||
);
|
||||
if (allValidTypes) {
|
||||
this.components_ = components;
|
||||
} else {
|
||||
var msg = 'ol.geom.Collection: at least one component passed to '
|
||||
+ 'setComponents is not allowed.';
|
||||
ol.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
ol.geom.Collection.prototype.addComponent = function(component, index) {
|
||||
if (this.isAllowedComponent(component)) {
|
||||
goog.array.insertAt(this.components_, component, index);
|
||||
} else {
|
||||
var msg = 'ol.geom.Collection: component is not allowed to be added.';
|
||||
ol.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
* component against.
|
||||
*
|
||||
* @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) {
|
||||
var isOnList = !goog.array.every(list, function(listedConstr){
|
||||
if (component instanceof listedConstr) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return isOnList;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
ol.geom.Collection.prototype.isAllowedComponent = function(component){
|
||||
var whitelist = this.getTypeWhitelist(),
|
||||
blacklist = this.getTypeBlacklist(),
|
||||
isOnWhitelist = this.isOnList(component, whitelist),
|
||||
isOnBlacklist = this.isOnList(component, blacklist);
|
||||
return (isOnWhitelist || !isOnBlacklist);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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();
|
||||
if (goog.isDefAndNotNull(singleCentroid)) {
|
||||
sum_x += singleCentroid.getX();
|
||||
sum_y += singleCentroid.getX();
|
||||
} else {
|
||||
len--;
|
||||
}
|
||||
});
|
||||
centroid = new ol.geom.Point(sum_x / len, sum_y / len);
|
||||
}
|
||||
return centroid;
|
||||
};
|
||||
@@ -1,58 +0,0 @@
|
||||
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}
|
||||
*/
|
||||
this.bounds_ = undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Bounds|undefined} The ol.Bounds.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getBounds = function() {
|
||||
return this.bounds_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Bounds} bounds The new ol.Bounds.
|
||||
* @return {ol.geom.Geometry} This.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.setBounds = function(bounds) {
|
||||
this.bounds_ = bounds;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the centroid of the geometry.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the geometry.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getCentroid = function() {
|
||||
// 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;
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
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(){};
|
||||
@@ -1,76 +0,0 @@
|
||||
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.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points building the
|
||||
* linestrings vertices.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.LineString = function(vertices) {
|
||||
/**
|
||||
* @private
|
||||
* @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() {
|
||||
return this.vertices_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the LineString's points.
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points.
|
||||
*/
|
||||
ol.geom.LineString.prototype.setVertices = function(vertices) {
|
||||
this.vertices_ = 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.
|
||||
*/
|
||||
ol.geom.LineString.prototype.addVertex = function(vertex, index) {
|
||||
goog.array.insertAt(this.vertices_,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();
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
goog.provide('ol.geom.MultiLineString');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Collection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.MultiLineString objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Collection}
|
||||
* @param {Array.<ol.geom.LineString>} linestrings An array of linestrings.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.MultiLineString = function(linestrings) {
|
||||
this.setTypeWhitelist([ol.geom.LineString]);
|
||||
this.setTypeBlacklist([ol.geom.Geometry]);
|
||||
if (arguments.length === 1 && goog.isDef(linestrings)) {
|
||||
this.setLineStrings(linestrings);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.MultiLineString, ol.geom.Collection);
|
||||
|
||||
/**
|
||||
* Gets the MultiLineString's linestrings.
|
||||
*
|
||||
* @return {Array.<ol.geom.LineString>} An array of linestrings.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getLineStrings = function() {
|
||||
return this.getComponents();
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the MultiLineString's linestrings.
|
||||
*
|
||||
* @param {Array.<ol.geom.LineString>} linestrings An array of linestrings.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.setLineStrings = function(linestrings) {
|
||||
this.setComponents(linestrings);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given linestring to the list of linestrings at the specified index.
|
||||
*
|
||||
* @param {ol.geom.LineString} linestring A linestring to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.addLineString = function(linestring, index) {
|
||||
this.addComponent(linestring, index);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given linestring from the list of linestrings.
|
||||
*
|
||||
* @param {ol.geom.LineString} linestring A linestring to be removed.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.removeLineString = function(linestring) {
|
||||
this.removeComponent(linestring);
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
goog.provide('ol.geom.MultiPoint');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Collection');
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.setTypeWhitelist([ol.geom.Point]);
|
||||
this.setTypeBlacklist([ol.geom.Geometry]);
|
||||
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() {
|
||||
return this.getComponents();
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the MultiPoint's points.
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.setPoints = function(points) {
|
||||
this.setComponents(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.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.addPoint = function(point, index) {
|
||||
this.addComponent(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) {
|
||||
this.removeComponent(point);
|
||||
};
|
||||
@@ -1,163 +0,0 @@
|
||||
goog.provide('ol.geom.Point');
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.coord.AccessorInterface');
|
||||
goog.require('ol.base');
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.x_ = x;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.y_ = y;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.z_ = opt_z;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.Point, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* @return {number} X.
|
||||
*/
|
||||
ol.geom.Point.prototype.getX = function() {
|
||||
return this.x_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Y.
|
||||
*/
|
||||
ol.geom.Point.prototype.getY = function() {
|
||||
return this.y_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Z.
|
||||
*/
|
||||
ol.geom.Point.prototype.getZ = function() {
|
||||
return this.z_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Projection|undefined} Projection.
|
||||
*/
|
||||
ol.geom.Point.prototype.getProjection = function() {
|
||||
return this.projection_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
ol.geom.Point.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} x X.
|
||||
*/
|
||||
ol.geom.Point.prototype.setX = function(x) {
|
||||
this.x_ = x;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} y Y.
|
||||
*/
|
||||
ol.geom.Point.prototype.setY = function(y) {
|
||||
this.y_ = y;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number|undefined} z Z.
|
||||
*/
|
||||
ol.geom.Point.prototype.setZ = function(z) {
|
||||
this.z_ = z;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
* supplied as a projection instance of a string identifier.
|
||||
* @returns {!ol.geom.Point} A new location.
|
||||
*/
|
||||
ol.geom.Point.prototype.transform = function(proj) {
|
||||
if (goog.isString(proj)) {
|
||||
proj = new ol.Projection(proj);
|
||||
}
|
||||
return this._transform(proj);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform this point to a new location given a projection object.
|
||||
*
|
||||
* @param {!ol.Projection} proj The destination projection.
|
||||
* @returns {!ol.geom.Point}
|
||||
* @private
|
||||
*/
|
||||
ol.geom.Point.prototype._transform = function(proj) {
|
||||
var point = {'x': this.x_, 'y': this.y_};
|
||||
var sourceProj = this.projection_;
|
||||
if (!goog.isDefAndNotNull(sourceProj)) {
|
||||
var msg = 'Cannot transform a point without a source projection.';
|
||||
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;
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
goog.provide('ol.layer.Layer');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @export
|
||||
*/
|
||||
ol.layer.Layer = function() {
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
* @protected
|
||||
*/
|
||||
this.attribution_;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
ol.layer.Layer.prototype.getAttribution = function() {
|
||||
return this.attribution_;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
goog.provide('ol.layer.OSM');
|
||||
|
||||
goog.require('ol.layer.XYZ');
|
||||
|
||||
/**
|
||||
* Class for OSM layers.
|
||||
*
|
||||
* @export
|
||||
* @constructor
|
||||
* @extends {ol.layer.XYZ}
|
||||
*/
|
||||
ol.layer.OSM = function() {
|
||||
|
||||
//TODO Is this attribution still correct?
|
||||
/** @inheritDoc */
|
||||
this.attribution_ = "Data CC-By-SA by <a target='_blank' href='http://openstreetmap.org/'>OpenStreetMap</a>";
|
||||
|
||||
goog.base(this, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png');
|
||||
};
|
||||
|
||||
goog.inherits(ol.layer.OSM, ol.layer.XYZ);
|
||||
@@ -1,490 +0,0 @@
|
||||
goog.provide('ol.layer.TileLayer');
|
||||
|
||||
goog.require('ol.error');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.Tile');
|
||||
goog.require('ol.TileCache');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.layer.Layer}
|
||||
*/
|
||||
ol.layer.TileLayer = function() {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.url_ = undefined;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.projection_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Bounds}
|
||||
*/
|
||||
this.extent_ = null;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.tileWidth_ = 256;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.tileHeight_ = 256;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {function(new:ol.Tile, string, ol.Bounds=)}
|
||||
*/
|
||||
this.Tile = ol.Tile.createConstructor(this.tileWidth_, this.tileHeight_);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.tileOriginX_ = undefined;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.tileOriginY_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.tileOriginCorner_ = 'tl';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.maxResolution_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.xRight_ = true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.yDown_ = true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.numZoomLevels_ = undefined;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.resolutions_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.TileCache}
|
||||
*/
|
||||
this.cache_ = new ol.TileCache();
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
* @return {string}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getTileUrl = function(x, y, z) {
|
||||
// overridden by subclasses
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string|undefined} The layer URL.
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getUrl = function() {
|
||||
return this.url_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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
|
||||
* and no projection.
|
||||
* @return {ol.UnreferencedBounds}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getExtent = function() {
|
||||
if (!goog.isNull(this.extent_)) {
|
||||
return this.extent_;
|
||||
}
|
||||
if (!goog.isNull(this.projection_)) {
|
||||
return this.projection_.getExtent();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get tile size.
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getTileSize = function() {
|
||||
return [this.tileWidth_, this.tileHeight_];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get tile origin.
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getTileOrigin = function() {
|
||||
if (goog.isDef(this.tileOriginX_) &&
|
||||
goog.isDef(this.tileOriginY_)) {
|
||||
return [this.tileOriginX_, this.tileOriginY_];
|
||||
}
|
||||
var errmsg = 'Cannot calculate tile origin; ';
|
||||
if (goog.isDef(this.tileOriginCorner_)) {
|
||||
var extent = this.getExtent();
|
||||
if (!goog.isNull(extent)) {
|
||||
var tileOriginX, tileOriginY;
|
||||
switch (this.tileOriginCorner_) {
|
||||
case "tl":
|
||||
tileOriginX = extent.getMinX();
|
||||
tileOriginY = extent.getMaxY();
|
||||
break;
|
||||
case "tr":
|
||||
tileOriginX = extent.getMaxX();
|
||||
tileOriginY = extent.getMaxY();
|
||||
break;
|
||||
case "bl":
|
||||
tileOriginX = extent.getMinX();
|
||||
tileOriginY = extent.getMinY();
|
||||
break;
|
||||
case "br":
|
||||
tileOriginX = extent.getMaxX();
|
||||
tileOriginY = extent.getMinY();
|
||||
break;
|
||||
default:
|
||||
errmsg += 'tileOriginCorner value is incorrect.';
|
||||
ol.error(errmsg);
|
||||
}
|
||||
return [tileOriginX, tileOriginY];
|
||||
}
|
||||
errmsg += 'layer has no extent.';
|
||||
ol.error(errmsg);
|
||||
}
|
||||
errmsg += 'layer has no tileOriginCorner.';
|
||||
ol.error(errmsg);
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get max resolution. Return undefined if the layer has no maxResolution,
|
||||
* and no extent from which maxResolution could be derived.
|
||||
* @return {number|undefined}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getMaxResolution = function() {
|
||||
if (!goog.isDef(this.maxResolution_)) {
|
||||
var extent = this.getExtent();
|
||||
if (!goog.isNull(extent)) {
|
||||
this.maxResolution_ = Math.max(
|
||||
(extent.getMaxX() - extent.getMinX()) / this.tileWidth_,
|
||||
(extent.getMaxY() - extent.getMinY()) / this.tileHeight_);
|
||||
}
|
||||
}
|
||||
return this.maxResolution_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the number of the zoom levels.
|
||||
* @return {number|undefined}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getNumZoomLevels = function() {
|
||||
return this.numZoomLevels_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get layer resolutions. Return null if the layer has no resolutions.
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getResolutions = function() {
|
||||
if (goog.isNull(this.resolutions_)) {
|
||||
var maxResolution = this.getMaxResolution(),
|
||||
numZoomLevels = this.getNumZoomLevels();
|
||||
if (goog.isDef(maxResolution) && goog.isDef(numZoomLevels)) {
|
||||
this.resolutions_ = [];
|
||||
for (var i = 0; i < numZoomLevels; i++) {
|
||||
this.resolutions_[i] = maxResolution / Math.pow(2, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.resolutions_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the layer URL.
|
||||
* @param {string} url
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setUrl = function(url) {
|
||||
this.url_ = url;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set layer projection.
|
||||
* @param {ol.Projection} projection
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set layer extent.
|
||||
* @param {ol.Bounds} extent
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setExtent = function(extent) {
|
||||
this.extent_ = extent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set tile origin.
|
||||
* @param {number} tileOriginX
|
||||
* @param {number} tileOriginY
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setTileOrigin = function(tileOriginX, tileOriginY) {
|
||||
this.tileOriginX_ = tileOriginX;
|
||||
this.tileOriginY_ = tileOriginY;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set tile origin corner.
|
||||
* @param {string} tileOriginCorner
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setTileOriginCorner = function(tileOriginCorner) {
|
||||
this.tileOriginCorner_ = tileOriginCorner;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set maximum resolution.
|
||||
* @param {number} maxResolution
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setMaxResolution = function(maxResolution) {
|
||||
this.maxResolution_ = maxResolution;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the number of zoom levels.
|
||||
* @param {number} numZoomLevels
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setNumZoomLevels = function(numZoomLevels) {
|
||||
this.numZoomLevels_ = numZoomLevels;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set resolutions for the layer.
|
||||
* @param {Array.<number>} resolutions
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.setResolutions = function(resolutions) {
|
||||
this.resolutions_ = resolutions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a tile from the cache, or create a tile and add to
|
||||
* the cache.
|
||||
* @param url {string}
|
||||
* @param bounds {ol.Bounds}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getTile = function(url, bounds) {
|
||||
var tile = this.cache_.get(url);
|
||||
if (!goog.isDef(tile)) {
|
||||
tile = new this.Tile(url, bounds);
|
||||
this.cache_.set(tile.getUrl(), 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) {
|
||||
if (!this.validXY(x, y, z)) {
|
||||
return null;
|
||||
}
|
||||
var tileUrl = this.getTileUrl(x, y, z);
|
||||
var tile = this.cache_.get(tileUrl);
|
||||
if (!goog.isDef(tile)) {
|
||||
tile = new this.Tile(tileUrl);
|
||||
this.cache_.set(tileUrl, tile);
|
||||
}
|
||||
return tile;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if the tile x/y/z intersects the layer extent. Always
|
||||
* return true if the layer has no extent.
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.validXY = function(x, y, z) {
|
||||
var extent = this.getExtent();
|
||||
if (goog.isNull(extent)) {
|
||||
return true;
|
||||
}
|
||||
var extentMinX = extent.getMinX(),
|
||||
extentMinY = extent.getMinY(),
|
||||
extentMaxX = extent.getMaxX(),
|
||||
extentMaxY = extent.getMaxY();
|
||||
var tileOrigin = this.getTileOrigin(),
|
||||
tileOriginX = tileOrigin[0],
|
||||
tileOriginY = tileOrigin[1];
|
||||
var resolution = this.getResolutions()[z];
|
||||
var tileWidth = this.tileWidth_ * resolution,
|
||||
tileHeight = this.tileHeight_ * resolution;
|
||||
var minX, maxX;
|
||||
if (this.xRight_) {
|
||||
minX = Math.floor((extentMinX - tileOriginX) / tileWidth);
|
||||
maxX = Math.ceil((extentMaxX - tileOriginX) / tileWidth) - 1;
|
||||
} else {
|
||||
minX = Math.floor((tileOriginX - extentMaxX) / tileWidth);
|
||||
maxX = Math.ceil((tileOriginX - extentMinX) / tileWidth) - 1;
|
||||
}
|
||||
var minY, maxY;
|
||||
if (this.yDown_) {
|
||||
minY = Math.floor((tileOriginY - extentMaxY) / tileHeight);
|
||||
maxY = Math.ceil((tileOriginY - extentMinY) / tileHeight) - 1;
|
||||
} else {
|
||||
minY = Math.floor((extentMinY - tileOriginY) / tileHeight);
|
||||
maxY = Math.ceil((extentMaxY - tileOriginY) / tileHeight) - 1;
|
||||
}
|
||||
return x >= minX && x <= maxX && y >= minY && y <= maxY;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get data from the layer. This is the layer's main API function.
|
||||
* @param {ol.Bounds} bounds
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getData = function(bounds, resolution) {
|
||||
var me = this,
|
||||
zoomAndRes = me.getZoomAndRes(resolution),
|
||||
zoom = zoomAndRes[0];
|
||||
resolution = zoomAndRes[1];
|
||||
|
||||
// define some values used for the actual tiling
|
||||
var boundsMinX = bounds.getMinX(),
|
||||
boundsMaxX = bounds.getMaxX(),
|
||||
boundsMinY = bounds.getMinY(),
|
||||
boundsMaxY = bounds.getMaxY(),
|
||||
tileWidth = me.tileWidth_,
|
||||
tileHeight = me.tileHeight_,
|
||||
tileOrigin = me.getTileOrigin(),
|
||||
tileOriginX = tileOrigin[0],
|
||||
tileOriginY = tileOrigin[1],
|
||||
tileWidthGeo = tileWidth * resolution,
|
||||
tileHeightGeo = tileHeight * resolution;
|
||||
|
||||
// make sure we don't create tiles outside the layer extent
|
||||
var extent = this.getExtent();
|
||||
if (extent) {
|
||||
boundsMinX = Math.max(boundsMinX, extent.getMinX());
|
||||
boundsMaxX = Math.min(boundsMaxX, extent.getMaxX());
|
||||
boundsMinY = Math.max(boundsMinY, extent.getMinY());
|
||||
boundsMaxY = Math.min(boundsMaxY, extent.getMaxY());
|
||||
}
|
||||
|
||||
var offsetX = Math.floor(
|
||||
(boundsMinX - tileOriginX) / tileWidthGeo),
|
||||
offsetY = Math.floor(
|
||||
(tileOriginY - boundsMaxY) / tileHeightGeo),
|
||||
gridLeft = tileOriginX + tileWidthGeo * offsetX,
|
||||
gridTop = tileOriginY - tileHeightGeo * offsetY;
|
||||
|
||||
// now tile
|
||||
var tiles = [],
|
||||
tile,
|
||||
url,
|
||||
tileBottom, tileRight, tileBounds;
|
||||
for (var y=0, tileTop=gridTop; tileTop > boundsMinY;
|
||||
++y, tileTop-=tileHeightGeo) {
|
||||
tiles[y] = [];
|
||||
tileBottom = tileTop - tileHeightGeo;
|
||||
for (var x=0, tileLeft=gridLeft; tileLeft < boundsMaxX;
|
||||
++x, tileLeft+=tileWidthGeo) {
|
||||
tileRight = tileLeft + tileWidthGeo;
|
||||
tileBounds = new ol.Bounds(tileLeft, tileBottom,
|
||||
tileRight, tileTop, this.projection_);
|
||||
url = this.getTileUrl(offsetX + x, offsetY + y, zoom);
|
||||
tile = this.getTile(url, tileBounds);
|
||||
tiles[y][x] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
return new ol.TileSet(tiles, tileWidth, tileHeight, resolution);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the zoom level (z) and layer resolution for the given resolution.
|
||||
* @param {number} resolution
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.layer.TileLayer.prototype.getZoomAndRes = function(resolution) {
|
||||
var delta = Number.POSITIVE_INFINITY,
|
||||
currentDelta,
|
||||
resolutions = this.getResolutions(),
|
||||
zoom;
|
||||
for (var i=resolutions.length-1; i>=0; --i) {
|
||||
currentDelta = Math.abs(resolutions[i] - resolution);
|
||||
if (currentDelta > delta) {
|
||||
break;
|
||||
}
|
||||
delta = currentDelta;
|
||||
}
|
||||
zoom = i + 1;
|
||||
return [zoom, resolutions[zoom]];
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
goog.provide('ol.layer.WMS');
|
||||
|
||||
goog.require('goog.Uri');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
|
||||
/**
|
||||
* Class for WMS layers.
|
||||
*
|
||||
* @export
|
||||
* @constructor
|
||||
* @extends {ol.layer.TileLayer}
|
||||
* @param {string} url The WMS URL.
|
||||
* @param {Array.<string>} layers List of layers.
|
||||
* @param {string|undefined} format Image format (e.g. "image/jpeg")
|
||||
*/
|
||||
ol.layer.WMS = function(url, layers, format) {
|
||||
goog.base(this);
|
||||
this.setUrl(url);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
this.layers_ = layers;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.format_ = format;
|
||||
};
|
||||
|
||||
goog.inherits(ol.layer.WMS, ol.layer.TileLayer);
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object}
|
||||
*/
|
||||
ol.layer.WMS.prototype.DEFAULT_PARAMS = {
|
||||
"SERVICE": "WMS",
|
||||
"VERSION": "1.1.1",
|
||||
"REQUEST": "GetMap",
|
||||
"STYLES": "",
|
||||
"FORMAT": "image/png"
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.layer.WMS.prototype.getTileUrl = function(x, y, z) {
|
||||
var tileOrigin = this.getTileOrigin(),
|
||||
tileOriginX = tileOrigin[0],
|
||||
tileOriginY = tileOrigin[1];
|
||||
var resolution = this.getResolutions()[z];
|
||||
var tileWidth = this.tileWidth_ * resolution,
|
||||
tileHeight = this.tileHeight_ * resolution;
|
||||
var minX = tileOriginX + (x * tileWidth),
|
||||
maxY = tileOriginY - (y * tileHeight),
|
||||
maxX = minX + tileWidth,
|
||||
minY = maxY - tileHeight;
|
||||
|
||||
var qd = new goog.Uri.QueryData();
|
||||
qd.extend(this.DEFAULT_PARAMS);
|
||||
qd.set('WIDTH', this.tileWidth_);
|
||||
qd.set('HEIGHT', this.tileHeight_);
|
||||
qd.set('BBOX', [minX, minY, maxX, maxY].join(','));
|
||||
qd.set('LAYERS', [this.layers_].join(','));
|
||||
// FIXME this requires a projection in the layer, which should
|
||||
// not be required
|
||||
qd.set('SRS', this.projection_.getCode());
|
||||
var uri = new goog.Uri(this.getUrl());
|
||||
uri.setQueryData(qd);
|
||||
return uri.toString();
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
goog.provide('ol.layer.XYZ');
|
||||
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.TileSet');
|
||||
|
||||
/**
|
||||
* Class for XYZ layers.
|
||||
*
|
||||
* @export
|
||||
* @constructor
|
||||
* @extends {ol.layer.TileLayer}
|
||||
* @param {string} url URL template. E.g.
|
||||
* http://a.tile.openstreetmap.org/{z}/{x}/{y}.png.
|
||||
*/
|
||||
ol.layer.XYZ = function(url) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.setUrl(url);
|
||||
this.setProjection(new ol.Projection("EPSG:3857"));
|
||||
this.setNumZoomLevels(22);
|
||||
};
|
||||
|
||||
goog.inherits(ol.layer.XYZ, ol.layer.TileLayer);
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.layer.XYZ.prototype.getTileUrl = function(x, y, z) {
|
||||
var base = this.getUrl();
|
||||
return base.replace('{x}', x + '')
|
||||
.replace('{y}', y + '')
|
||||
.replace('{z}', z + '');
|
||||
};
|
||||
19
src/ol/object_test.js
Normal file
19
src/ol/object_test.js
Normal file
@@ -0,0 +1,19 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol');
|
||||
goog.require('ol3.Object');
|
||||
|
||||
|
||||
function testObject1() {
|
||||
var obj = {k: 1};
|
||||
obj = ol.object(obj);
|
||||
assertTrue(obj instanceof ol3.Object);
|
||||
assertEquals(1, obj.get('k'));
|
||||
}
|
||||
|
||||
|
||||
function testObject2() {
|
||||
var obj1 = new ol3.Object();
|
||||
var obj2 = ol.object(obj1);
|
||||
assertTrue(obj2 === obj1);
|
||||
}
|
||||
|
||||
168
src/ol/ol.js
Normal file
168
src/ol/ol.js
Normal file
@@ -0,0 +1,168 @@
|
||||
goog.provide('ol');
|
||||
goog.provide('ol.layer');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('ol3.Collection');
|
||||
goog.require('ol3.Coordinate');
|
||||
goog.require('ol3.Layer');
|
||||
goog.require('ol3.Map');
|
||||
goog.require('ol3.Object');
|
||||
goog.require('ol3.Projection');
|
||||
goog.require('ol3.createMap');
|
||||
goog.require('ol3.layer.OpenStreetMap');
|
||||
|
||||
|
||||
goog.exportSymbol('ol', ol);
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Array|ol3.Collection}
|
||||
*/
|
||||
ol.Collection;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Array.<number>|ol3.Coordinate|{x: number, y: number}}
|
||||
*/
|
||||
ol.Coordinate;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{center: (ol.Coordinate|undefined),
|
||||
* layers: (ol.Collection|undefined),
|
||||
* renderTo: (Element|string|undefined),
|
||||
* resolution: (number|undefined),
|
||||
* zoom: (number|undefined)}}
|
||||
*/
|
||||
ol.MapOptions;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object|ol3.Object}
|
||||
*/
|
||||
ol.Object;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {ol3.Projection|string}
|
||||
*/
|
||||
ol.Projection;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Collection} collection Collection.
|
||||
* @return {ol3.Collection} Collection.
|
||||
*/
|
||||
ol.collection = function(collection) {
|
||||
if (collection instanceof ol3.Collection) {
|
||||
return collection;
|
||||
} else if (goog.isArray(collection)) {
|
||||
var array = /** @type {Array} */ collection;
|
||||
return new ol3.Collection(collection);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
goog.exportProperty(ol, 'collection', ol.collection);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {ol3.Coordinate} Coordinate.
|
||||
*/
|
||||
ol.coordinate = function(coordinate) {
|
||||
if (coordinate instanceof ol3.Coordinate) {
|
||||
return coordinate;
|
||||
} else if (goog.isArray(coordinate)) {
|
||||
var array = /** @type {Array.<number>} */ coordinate;
|
||||
return new ol3.Coordinate(array[1], array[0]);
|
||||
} else if (goog.isObject(coordinate)) {
|
||||
var object = /** @type {{x: number, y: number}} */ coordinate;
|
||||
return new ol3.Coordinate(object.x, object.y);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
goog.exportProperty(ol, 'coordinate', ol.coordinate);
|
||||
|
||||
|
||||
goog.exportProperty(ol, 'layer', ol.layer);
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol3.Layer} Layer.
|
||||
*/
|
||||
ol.layer.osm = function() {
|
||||
return new ol3.layer.OpenStreetMap();
|
||||
};
|
||||
goog.exportProperty(ol.layer, 'osm', ol.layer.osm);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapOptions=} opt_mapOptions Options.
|
||||
* @return {ol3.Map} Map.
|
||||
*/
|
||||
ol.map = function(opt_mapOptions) {
|
||||
var options = opt_mapOptions || {};
|
||||
var center = ol.coordinate(/** @type {ol.Coordinate} */
|
||||
(goog.object.get(options, 'center', null)));
|
||||
var layers = ol.collection(/** @type {ol.Collection} */
|
||||
(goog.object.get(options, 'layers', null)));
|
||||
var projection = ol.projection(/** @type {ol.Projection} */
|
||||
(goog.object.get(options, 'projection', 'EPSG:3857')));
|
||||
var resolution = /** @type {number|undefined} */
|
||||
goog.object.get(options, 'resolution');
|
||||
if (!goog.isDef(resolution) && goog.object.containsKey(options, 'zoom')) {
|
||||
var zoom = /** @type {number} */ goog.object.get(options, 'zoom');
|
||||
resolution = ol3.Projection.EPSG_3857_HALF_SIZE / (128 << zoom);
|
||||
}
|
||||
var target = goog.dom.getElement(/** @type {Element|string} */
|
||||
(goog.object.get(options, 'renderTo', 'map')));
|
||||
var userProjection = ol.projection(/** @type {ol.Projection} */
|
||||
(goog.object.get(options, 'userProjection', 'EPSG:4326')));
|
||||
var map = ol3.createMap(target, {
|
||||
'layers': layers,
|
||||
'projection': projection,
|
||||
'resolution': resolution,
|
||||
'userProjection': userProjection
|
||||
});
|
||||
if (!goog.isNull(center)) {
|
||||
map.setUserCenter(center);
|
||||
}
|
||||
return map;
|
||||
};
|
||||
goog.exportProperty(ol, 'map', ol.map);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Object} object Object.
|
||||
* @return {ol3.Object} Object.
|
||||
*/
|
||||
ol.object = function(object) {
|
||||
if (object instanceof ol3.Object) {
|
||||
return object;
|
||||
} else if (goog.isObject(object)) {
|
||||
var values = /** @type {Object} */ object;
|
||||
return new ol3.Object(values);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
goog.exportProperty(ol, 'object', ol.object);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
* @return {ol3.Projection} Projection.
|
||||
*/
|
||||
ol.projection = function(projection) {
|
||||
if (projection instanceof ol3.Projection) {
|
||||
return projection;
|
||||
} else if (goog.isString(projection)) {
|
||||
var code = /** @type {string} */ projection;
|
||||
return ol3.Projection.getFromCode(code);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
goog.exportProperty(ol, 'projection', ol.projection);
|
||||
@@ -1,314 +0,0 @@
|
||||
goog.provide('ol.renderer.Composite');
|
||||
|
||||
goog.require('ol.renderer.MapRenderer');
|
||||
goog.require('ol.renderer.LayerRenderer');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.Loc');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.style');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
* @extends {ol.renderer.MapRenderer}
|
||||
*/
|
||||
ol.renderer.Composite = function(container) {
|
||||
|
||||
goog.base(this, container);
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.renderer.LayerRenderer>}
|
||||
* @private
|
||||
*/
|
||||
this.renderers_ = [];
|
||||
|
||||
/**
|
||||
* Pixel buffer for renderer container.
|
||||
*
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.buffer_ = 128;
|
||||
|
||||
/**
|
||||
* @type {Element}
|
||||
* @private
|
||||
*/
|
||||
this.target_ = null;
|
||||
|
||||
/**
|
||||
* The current top left corner location of the target element (map coords).
|
||||
*
|
||||
* @type {ol.Loc}
|
||||
* @private
|
||||
*/
|
||||
this.targetOrigin_ = null;
|
||||
|
||||
/**
|
||||
* The pixel offset of the target element with respect to its container.
|
||||
*
|
||||
* @type {goog.math.Coordinate}
|
||||
* @private
|
||||
*/
|
||||
this.targetOffset_ = null;
|
||||
|
||||
/**
|
||||
* @type {Object}
|
||||
* @private
|
||||
*/
|
||||
this.layerContainers_ = {};
|
||||
|
||||
};
|
||||
goog.inherits(ol.renderer.Composite, ol.renderer.MapRenderer);
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.layer.Layer>} layers
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
* @param {boolean} animate
|
||||
*/
|
||||
ol.renderer.Composite.prototype.draw = function(layers, center, resolution, animate) {
|
||||
if (goog.isNull(this.target_)) {
|
||||
// first rendering
|
||||
this.createTarget_(center, resolution);
|
||||
}
|
||||
|
||||
// TODO: deal with layer order and removal
|
||||
|
||||
if (this.renderedResolution_) {
|
||||
if (resolution !== this.renderedResolution_) {
|
||||
// TODO: apply transition to old target
|
||||
this.resetTarget_(center, resolution);
|
||||
}
|
||||
}
|
||||
this.renderedResolution_ = resolution;
|
||||
|
||||
// shift target element to account for center change
|
||||
if (this.renderedCenter_) {
|
||||
this.shiftTarget_(center, resolution);
|
||||
}
|
||||
this.renderedCenter_ = center;
|
||||
|
||||
// update each layer renderer
|
||||
var renderer;
|
||||
for (var i=0, ii=layers.length; i<ii; ++i) {
|
||||
renderer = this.getOrCreateRenderer_(layers[i], i);
|
||||
renderer.draw(center, resolution);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new target element for layer renderer containers.
|
||||
*
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.renderer.Composite.prototype.createTarget_ = function(center, resolution) {
|
||||
this.targetOrigin_ = this.getOriginForCenterAndRes_(center, resolution);
|
||||
|
||||
var containerSize = this.getContainerSize();
|
||||
var containerWidth = containerSize.width;
|
||||
var containerHeight = containerSize.height;
|
||||
var buffer = this.buffer_;
|
||||
|
||||
var targetWidth = containerWidth + (2 * buffer);
|
||||
var targetHeight = containerHeight + (2 * buffer);
|
||||
var offset = new goog.math.Coordinate(-buffer, -buffer);
|
||||
|
||||
var target = goog.dom.createDom('div', {
|
||||
'class': 'ol-renderer-composite',
|
||||
'style': 'width:' + targetWidth + 'px;height:' + targetHeight + 'px;' +
|
||||
'top:' + offset.y + 'px;left:' + offset.x + 'px;' +
|
||||
'position:absolute'
|
||||
});
|
||||
this.target_ = target;
|
||||
this.targetOffset_ = offset;
|
||||
this.renderedCenter_ = center;
|
||||
goog.dom.appendChild(this.container_, target);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
* @return {ol.Loc}
|
||||
*/
|
||||
ol.renderer.Composite.prototype.getOriginForCenterAndRes_ = function(center, resolution) {
|
||||
var containerSize = this.getContainerSize();
|
||||
var containerWidth = containerSize.width;
|
||||
var containerHeight = containerSize.height;
|
||||
var buffer = this.buffer_;
|
||||
var targetWidth = containerWidth + (2 * buffer);
|
||||
var targetHeight = containerHeight + (2 * buffer);
|
||||
return new ol.Loc(
|
||||
center.getX() - (resolution * targetWidth / 2),
|
||||
center.getY() + (resolution * targetHeight / 2)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adjust the position of the renderer target given the new center.
|
||||
*
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.renderer.Composite.prototype.shiftTarget_ = function(center, resolution) {
|
||||
var oldCenter = this.renderedCenter_;
|
||||
var dx = Math.round((oldCenter.getX() - center.getX()) / resolution);
|
||||
var dy = Math.round((center.getY() - oldCenter.getY()) / resolution);
|
||||
if (!(dx == 0 && dy == 0)) {
|
||||
var offset = this.targetOffset_;
|
||||
offset.x += Math.round((oldCenter.getX() - center.getX()) / resolution);
|
||||
offset.y += Math.round((center.getY() - oldCenter.getY()) / resolution);
|
||||
goog.style.setPosition(this.target_, offset);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reposition the target element back to the original offset.
|
||||
*
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.renderer.Composite.prototype.resetTarget_ = function(center, resolution) {
|
||||
this.targetOrigin_ = this.getOriginForCenterAndRes_(center, resolution);
|
||||
for (var i=0, ii=this.renderers_.length; i<ii; ++i) {
|
||||
this.renderers_[i].setContainerOrigin(this.targetOrigin_);
|
||||
}
|
||||
var offset = new goog.math.Coordinate(-this.buffer_, -this.buffer_);
|
||||
this.targetOffset_ = offset;
|
||||
this.renderedCenter_ = center;
|
||||
goog.style.setPosition(this.target_, offset);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer
|
||||
* @param {number} index
|
||||
*/
|
||||
ol.renderer.Composite.prototype.getOrCreateRenderer_ = function(layer, index) {
|
||||
var renderer = this.getRenderer_(layer);
|
||||
if (goog.isNull(renderer)) {
|
||||
renderer = this.createRenderer_(layer);
|
||||
goog.array.insertAt(this.renderers_, renderer, index);
|
||||
}
|
||||
return renderer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer
|
||||
* @return {ol.renderer.LayerRenderer}
|
||||
*/
|
||||
ol.renderer.Composite.prototype.getRenderer_ = function(layer) {
|
||||
function finder(candidate) {
|
||||
return candidate.getLayer() === layer;
|
||||
}
|
||||
var renderer = goog.array.find(this.renderers_, finder);
|
||||
return /** @type {ol.renderer.LayerRenderer} */ renderer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer
|
||||
*/
|
||||
ol.renderer.Composite.prototype.createRenderer_ = function(layer) {
|
||||
var Renderer = this.pickRendererType(layer);
|
||||
goog.asserts.assert(Renderer, "No supported renderer for layer: " + layer);
|
||||
|
||||
var container = goog.dom.createDom('div', {
|
||||
'class': 'ol-renderer-composite-layer',
|
||||
'style': 'width:100%;height:100%;top:0;left:0;position:absolute'
|
||||
});
|
||||
goog.dom.appendChild(this.target_, container);
|
||||
var renderer = new Renderer(container, layer);
|
||||
renderer.setContainerOrigin(this.targetOrigin_);
|
||||
this.layerContainers_[goog.getUid(renderer)] = container;
|
||||
return renderer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.renderer.LayerRenderer} renderer
|
||||
* @return {Element}
|
||||
*/
|
||||
ol.renderer.Composite.prototype.getRendererContainer_ = function(renderer) {
|
||||
var container = this.layerContainers_[goog.getUid(renderer)];
|
||||
goog.asserts.assert(goog.isDef(container));
|
||||
return container;
|
||||
};
|
||||
|
||||
/**
|
||||
* List of preferred renderer types. Layer renderers have a getType method
|
||||
* that returns a string describing their type. This list determines the
|
||||
* preferences for picking a layer renderer.
|
||||
*
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
ol.renderer.Composite.preferredRenderers = ["svg", "canvas", "vml"];
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer
|
||||
* @returns {Function}
|
||||
*/
|
||||
ol.renderer.Composite.prototype.pickRendererType = function(layer) {
|
||||
// maps candidate renderer types to candidate renderers
|
||||
var types = {};
|
||||
|
||||
function picker(Candidate) {
|
||||
var supports = Candidate['isSupported']() && Candidate['canRender'](layer);
|
||||
if (supports) {
|
||||
types[Candidate['getType']()] = Candidate;
|
||||
}
|
||||
return supports;
|
||||
}
|
||||
var Candidates = goog.array.filter(ol.renderer.Composite.registry_, picker);
|
||||
|
||||
// check to see if any preferred renderers are available
|
||||
var preferences = ol.renderer.Composite.preferredRenderers;
|
||||
|
||||
var Renderer;
|
||||
for (var i=0, ii=preferences.length; i<ii; ++i) {
|
||||
Renderer = types[preferences[i]];
|
||||
if (Renderer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we didn't find any of the preferred renderers, use the first
|
||||
return Renderer || Candidates[0] || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {Array.<Function>}
|
||||
* @private
|
||||
*/
|
||||
ol.renderer.Composite.registry_ = [];
|
||||
|
||||
/**
|
||||
* @param {Function} Renderer
|
||||
*/
|
||||
ol.renderer.Composite.register = function(Renderer) {
|
||||
ol.renderer.Composite.registry_.push(Renderer);
|
||||
};
|
||||
|
||||
/**
|
||||
* return {string}
|
||||
*/
|
||||
ol.renderer.Composite.getType = function() {
|
||||
// TODO: revisit
|
||||
return "composite";
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: determine if there is a better way to register these renderers
|
||||
*
|
||||
* @export
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.renderer.Composite.isSupported = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
ol.renderer.MapRenderer.register(ol.renderer.Composite);
|
||||
@@ -1,98 +0,0 @@
|
||||
goog.provide('ol.renderer.LayerRenderer');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.math.Size');
|
||||
|
||||
/**
|
||||
* A single layer renderer that will be created by the composite map renderer.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
* @param {!ol.layer.Layer} layer
|
||||
*/
|
||||
ol.renderer.LayerRenderer = function(container, layer) {
|
||||
|
||||
/**
|
||||
* @type {!Element}
|
||||
* @protected
|
||||
*/
|
||||
this.container_ = container;
|
||||
|
||||
/**
|
||||
* @type {goog.math.Size}
|
||||
* @private
|
||||
*/
|
||||
this.containerSize_ = null;
|
||||
|
||||
/**
|
||||
* Location of the top-left corner of the renderer container in map coords.
|
||||
*
|
||||
* @type {ol.Loc}
|
||||
* @protected
|
||||
*/
|
||||
this.containerOrigin_ = null;
|
||||
|
||||
/**
|
||||
* @type {!ol.layer.Layer}
|
||||
* @protected
|
||||
*/
|
||||
this.layer_ = layer;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {goog.math.Size}
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.LayerRenderer.prototype.getContainerSize = function() {
|
||||
// TODO: listen for resize and set this.constainerSize_ null
|
||||
// https://github.com/openlayers/ol3/issues/2
|
||||
if (goog.isNull(this.containerSize_)) {
|
||||
this.containerSize_ = goog.style.getSize(this.container_);
|
||||
}
|
||||
return this.containerSize_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the location of the top-left corner of the renderer container.
|
||||
*
|
||||
* @param {ol.Loc} origin The container origin.
|
||||
*/
|
||||
ol.renderer.LayerRenderer.prototype.setContainerOrigin = function(origin) {
|
||||
this.containerOrigin_ = origin;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get layer being rendered.
|
||||
*
|
||||
* @returns {!ol.layer.Layer}
|
||||
*/
|
||||
ol.renderer.LayerRenderer.prototype.getLayer = function() {
|
||||
return this.layer_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an identifying string for this renderer.
|
||||
*
|
||||
* @returns {string|undefined}
|
||||
*/
|
||||
ol.renderer.LayerRenderer.prototype.getType = function() {};
|
||||
|
||||
/**
|
||||
* Determine if this renderer is supported in the given environment.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
ol.renderer.LayerRenderer.isSupported = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if this renderer is capable of renderering the given layer.
|
||||
*
|
||||
* @param {ol.layer.Layer} layer
|
||||
* @returns {boolean}
|
||||
*/
|
||||
ol.renderer.LayerRenderer.canRender = function(layer) {
|
||||
return false;
|
||||
};
|
||||
@@ -1,110 +0,0 @@
|
||||
goog.provide('ol.renderer.MapRenderer');
|
||||
|
||||
goog.require('goog.style');
|
||||
goog.require('goog.math.Size');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
*/
|
||||
ol.renderer.MapRenderer = function(container) {
|
||||
|
||||
/**
|
||||
* @type !Element
|
||||
* @protected
|
||||
*/
|
||||
this.container_ = container;
|
||||
|
||||
/**
|
||||
* @type {goog.math.Size}
|
||||
* @private
|
||||
*/
|
||||
this.containerSize_ = null;
|
||||
|
||||
/**
|
||||
* @type {ol.Loc}
|
||||
* @protected
|
||||
*/
|
||||
this.renderedCenter_;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @protected
|
||||
*/
|
||||
this.renderedResolution_;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {goog.math.Size}
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.getContainerSize = function() {
|
||||
// TODO: listen for resize and set this.constainerSize_ null
|
||||
// https://github.com/openlayers/ol3/issues/2
|
||||
if (goog.isNull(this.containerSize_)) {
|
||||
this.containerSize_ = goog.style.getSize(this.container_);
|
||||
}
|
||||
return this.containerSize_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.layer.Layer>} layers
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
* @param {boolean} animate
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.draw = function(layers, center, resolution, animate) {
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} The rendered resolution.
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.getResolution = function() {
|
||||
return this.renderedResolution_;
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: determine a closure friendly way to register map renderers.
|
||||
* @type {Array}
|
||||
* @private
|
||||
*/
|
||||
ol.renderer.MapRenderer.registry_ = [];
|
||||
|
||||
/**
|
||||
* @param {Function} Renderer
|
||||
*/
|
||||
ol.renderer.MapRenderer.register = function(Renderer) {
|
||||
ol.renderer.MapRenderer.registry_.push(Renderer);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<string>} preferences List of preferred renderer types.
|
||||
* @returns {Function} A renderer constructor.
|
||||
*/
|
||||
ol.renderer.MapRenderer.pickRendererType = function(preferences) {
|
||||
// map of candidate renderer types to candidate renderers
|
||||
var types = {};
|
||||
|
||||
function picker(Candidate) {
|
||||
var supports = Candidate.isSupported();
|
||||
if (supports) {
|
||||
types[Candidate.getType()] = Candidate;
|
||||
}
|
||||
return supports;
|
||||
}
|
||||
var Candidates = goog.array.filter(ol.renderer.MapRenderer.registry_, picker);
|
||||
|
||||
// check to see if any preferred renderers are available
|
||||
var Renderer;
|
||||
for (var i=0, ii=preferences.length; i<ii; ++i) {
|
||||
Renderer = types[preferences[i]];
|
||||
if (Renderer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we didn't find any of the preferred renderers, use the first
|
||||
return Renderer || Candidates[0] || null;
|
||||
};
|
||||
@@ -1,352 +0,0 @@
|
||||
goog.provide('ol.renderer.TileLayerRenderer');
|
||||
|
||||
goog.require('ol.renderer.LayerRenderer');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.renderer.Composite');
|
||||
goog.require('ol.TileSet');
|
||||
goog.require('ol.Bounds');
|
||||
|
||||
goog.require('goog.style');
|
||||
goog.require('goog.math.Box');
|
||||
|
||||
|
||||
/**
|
||||
* A single layer renderer that will be created by the composite map renderer.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
* @param {!ol.layer.Layer} layer
|
||||
* @extends {ol.renderer.LayerRenderer}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer = function(container, layer) {
|
||||
|
||||
goog.base(this, container, layer);
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.layerResolutions_ = layer.getResolutions();
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.tileOrigin_ = layer.getTileOrigin();
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.tileSize_ = layer.getTileSize();
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.xRight_ = layer.getXRight();
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.yDown_ = layer.getYDown();
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderedResolution_ = undefined;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderedZ_ = undefined;
|
||||
|
||||
};
|
||||
goog.inherits(ol.renderer.TileLayerRenderer, ol.renderer.LayerRenderer);
|
||||
|
||||
/**
|
||||
* Render the layer.
|
||||
*
|
||||
* @param {!ol.Loc} center
|
||||
* @param {number} resolution
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.draw = function(center, resolution) {
|
||||
if (resolution !== this.renderedResolution_) {
|
||||
this.changeResolution_(resolution);
|
||||
}
|
||||
var z = this.renderedZ_;
|
||||
var tileOrigin = this.tileOrigin_;
|
||||
|
||||
var offset = this.getTileOffset_();
|
||||
var tileBox = this.getTileBox_(center, resolution);
|
||||
|
||||
var fragment = document.createDocumentFragment();
|
||||
var ijz, key, tile, xyz, box, img, newTiles = false;
|
||||
for (var i=tileBox.left; i<tileBox.right; ++i) {
|
||||
for (var j=tileBox.top; j<tileBox.bottom; ++j) {
|
||||
ijz = [i, j, z];
|
||||
key = ijz.join(",");
|
||||
tile = this.renderedTiles_[key];
|
||||
if (!tile) {
|
||||
xyz = this.getTileCoordsFromNormalizedCoords_(ijz);
|
||||
tile = this.layer_.getTileForXYZ(xyz[0], xyz[1], xyz[2]);
|
||||
if (tile) {
|
||||
if (!tile.isLoaded() && !tile.isLoading()) {
|
||||
tile.load();
|
||||
}
|
||||
this.renderedTiles_[key] = tile;
|
||||
box = this.getTilePixelBox_(ijz, resolution);
|
||||
img = tile.getImg();
|
||||
img.style.top = (box.top - offset.y) + "px";
|
||||
img.style.left = (box.left - offset.x) + "px";
|
||||
/**
|
||||
* We need to set the size here even if the scale is 1
|
||||
* because the image may have been scaled previously. If
|
||||
* we want to avoid setting size unnecessarily, the tile
|
||||
* should keep track of the scale.
|
||||
*/
|
||||
img.style.height = (box.bottom - box.top) + "px";
|
||||
img.style.width = (box.right - box.left) + "px";
|
||||
goog.dom.appendChild(fragment, img);
|
||||
newTiles = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newTiles) {
|
||||
this.container_.appendChild(fragment);
|
||||
}
|
||||
|
||||
this.renderedTileBox_ = tileBox;
|
||||
this.removeInvisibleTiles_();
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the pixel offset between the tile origin and the container origin.
|
||||
* TODO: cache this and invalidate it with changes to the container origin.
|
||||
*
|
||||
* @return {goog.math.Coordinate}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.getTileOffset_ = function() {
|
||||
var resolution = this.renderedResolution_;
|
||||
return new goog.math.Coordinate(
|
||||
Math.round((this.containerOrigin_.getX() - this.tileOrigin_[0]) / resolution),
|
||||
Math.round((this.tileOrigin_[1] - this.containerOrigin_.getY()) / resolution)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} ijz
|
||||
* @param {number} resolution
|
||||
* @return {goog.math.Box}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.getTilePixelBox_ = function(ijz, resolution) {
|
||||
var tileResolution = this.layerResolutions_[ijz[2]];
|
||||
var scale = resolution / tileResolution;
|
||||
var tileSize = this.tileSize_;
|
||||
|
||||
// desired tile size (in fractional pixels)
|
||||
var fpxTileWidth = tileSize[0] / scale;
|
||||
var fpxTileHeight = tileSize[1] / scale;
|
||||
|
||||
var col = ijz[0];
|
||||
var left = Math.round(col * fpxTileWidth); // inclusive
|
||||
var right = Math.round((col + 1) * fpxTileWidth); // exclusive
|
||||
|
||||
var row = ijz[1];
|
||||
var top = Math.round(row * fpxTileHeight); // inclusive
|
||||
var bottom = Math.round((row + 1) * fpxTileWidth); // exclusive
|
||||
|
||||
return new goog.math.Box(top, right, bottom, left);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} loc
|
||||
* @param {number} resolution
|
||||
* @return {goog.math.Coordinate}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.getNormalizedTileCoord_ = function(loc, resolution) {
|
||||
var tileOrigin = this.tileOrigin_;
|
||||
var tileSize = this.tileSize_;
|
||||
var pair = this.getPreferredResAndZ_(resolution);
|
||||
var tileResolution = pair[0];
|
||||
var z = pair[1];
|
||||
var scale = resolution / tileResolution;
|
||||
|
||||
// offset from tile origin in pixel space
|
||||
var dx = Math.floor((loc.getX() - tileOrigin[0]) / resolution);
|
||||
var dy = Math.floor((tileOrigin[1] - loc.getY()) / resolution);
|
||||
|
||||
// desired tile size (in fractional pixels)
|
||||
var fpxTileWidth = tileSize[0] / scale;
|
||||
var fpxTileHeight = tileSize[1] / scale;
|
||||
|
||||
// determine normalized col number (0 based, ascending right)
|
||||
var col = Math.floor(dx / fpxTileWidth);
|
||||
// determine normalized row number (0 based, ascending down)
|
||||
var row = Math.floor(dy / fpxTileHeight);
|
||||
|
||||
var box = this.getTilePixelBox_([col, row, z], resolution);
|
||||
|
||||
// adjust col to allow for stretched tiles
|
||||
if (dx < box.left) {
|
||||
col -= 1;
|
||||
} else if (dx >= box.right) {
|
||||
col += 1;
|
||||
}
|
||||
|
||||
// adjust row to allow for stretched tiles
|
||||
if (dy < box.top) {
|
||||
row -= 1;
|
||||
} else if (dy >= box.bottom) {
|
||||
row += 1;
|
||||
}
|
||||
|
||||
return new goog.math.Coordinate(col, row);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} resolution
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.getPreferredResAndZ_ = (function() {
|
||||
var cache = {};
|
||||
return function(resolution) {
|
||||
if (resolution in cache) {
|
||||
return cache[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;
|
||||
}
|
||||
}
|
||||
var pair = cache[resolution] = [r, z];
|
||||
return pair;
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* Tiles rendered at the current resolution;
|
||||
* @type {Object}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.renderedTiles_ = {};
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} ijz
|
||||
* @return {Array.<number>}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.getTileCoordsFromNormalizedCoords_ = function(ijz) {
|
||||
return [
|
||||
this.xRight_ ? ijz[0] : -ijz[0] - 1,
|
||||
this.yDown_ ? ijz[1] : -ijz[1] - 1,
|
||||
ijz[2]
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} center
|
||||
* @param {number} resolution
|
||||
* @return {goog.math.Box}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.getTileBox_ = function(center, resolution) {
|
||||
var size = this.getContainerSize();
|
||||
var halfWidth = size.width / 2;
|
||||
var halfHeight = size.height / 2;
|
||||
|
||||
var leftTop = new ol.Loc(
|
||||
center.getX() - (resolution * halfWidth),
|
||||
center.getY() + (resolution * halfHeight));
|
||||
|
||||
var rightBottom = new ol.Loc(
|
||||
center.getX() + (resolution * halfWidth),
|
||||
center.getY() - (resolution * halfHeight));
|
||||
|
||||
var ltCoord = this.getNormalizedTileCoord_(leftTop, resolution);
|
||||
var rbCoord = this.getNormalizedTileCoord_(rightBottom, resolution);
|
||||
|
||||
// right and bottom are treated as excluded, so we increment for the box
|
||||
rbCoord.x += 1;
|
||||
rbCoord.y += 1;
|
||||
|
||||
return goog.math.Box.boundingBox(ltCoord, rbCoord);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get rid of tiles outside the rendered extent.
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.removeInvisibleTiles_ = function() {
|
||||
var index, prune, i, j, z, tile;
|
||||
var box = this.renderedTileBox_;
|
||||
for (var ijz in this.renderedTiles_) {
|
||||
index = ijz.split(",");
|
||||
i = +index[0];
|
||||
j = +index[1];
|
||||
z = +index[2];
|
||||
prune = this.renderedZ_ !== z ||
|
||||
i < box.left || // beyond on the left side
|
||||
i >= box.right || // beyond on the right side
|
||||
j < box.top || // above
|
||||
j >= box.bottom; // below
|
||||
if (prune) {
|
||||
tile = this.renderedTiles_[ijz];
|
||||
delete this.renderedTiles_[ijz];
|
||||
this.container_.removeChild(tile.getImg());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Deal with changes in resolution.
|
||||
* TODO: implement the animation
|
||||
*
|
||||
* @param {number} resolution New resolution.
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.prototype.changeResolution_ = function(resolution) {
|
||||
var pair = this.getPreferredResAndZ_(resolution);
|
||||
this.renderedZ_ = pair[1];
|
||||
this.renderedResolution_ = resolution;
|
||||
this.renderedTiles_ = {};
|
||||
goog.dom.removeChildren(this.container_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get an identifying string for this renderer.
|
||||
*
|
||||
* @export
|
||||
* @returns {string}
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.getType = function() {
|
||||
// TODO: revisit
|
||||
return "tile";
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if this renderer type is supported in this environment.
|
||||
*
|
||||
* @export
|
||||
* @return {boolean} This renderer is supported.
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.isSupported = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if this renderer can render the given layer.
|
||||
*
|
||||
* @export
|
||||
* @param {ol.layer.Layer} layer The candidate layer.
|
||||
* @return {boolean} This renderer is capable of rendering the layer.
|
||||
*/
|
||||
ol.renderer.TileLayerRenderer.canRender = function(layer) {
|
||||
return layer instanceof ol.layer.TileLayer;
|
||||
};
|
||||
|
||||
ol.renderer.Composite.register(ol.renderer.TileLayerRenderer);
|
||||
@@ -1,276 +0,0 @@
|
||||
/**
|
||||
* @fileoverview WebGL based MapRenderer drawing all the supplied layers in OpenGL
|
||||
*/
|
||||
|
||||
goog.provide('ol.renderer.WebGL');
|
||||
|
||||
goog.require('ol.renderer.MapRenderer');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.Loc');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.vec.Mat4');
|
||||
goog.require('goog.webgl');
|
||||
|
||||
/**
|
||||
* Initialization of the native WebGL renderer (canvas, context, layers)
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
* @extends {ol.renderer.MapRenderer}
|
||||
*/
|
||||
ol.renderer.WebGL = function(container) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Element}
|
||||
*/
|
||||
this.canvas_ = goog.dom.createDom('canvas', 'ol-renderer-webgl-canvas'); // Suppose to have: style: 'width:100%;height:100%;'
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLRenderingContext}
|
||||
*/
|
||||
this.gl_ = (this.canvas_.getContext('experimental-webgl', {
|
||||
'alpha': false,
|
||||
'depth': false,
|
||||
'antialias': true,
|
||||
'stencil': false,
|
||||
'preserveDrawingBuffer': false
|
||||
}));
|
||||
goog.asserts.assert(!goog.isNull(this.gl_), "The WebGL is not supported on your browser. Check http://get.webgl.org/");
|
||||
|
||||
goog.dom.append(container, this.canvas_);
|
||||
|
||||
goog.base(this, container);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, WebGLTexture>}
|
||||
*/
|
||||
this.textureCache_ = {};
|
||||
|
||||
var gl = this.gl_;
|
||||
|
||||
var clearColor = [0, 0, 0]; // hardcoded background color
|
||||
gl.clearColor(clearColor[0], clearColor[1], clearColor[2], 1);
|
||||
gl.disable(goog.webgl.DEPTH_TEST);
|
||||
gl.disable(goog.webgl.SCISSOR_TEST);
|
||||
gl.disable(goog.webgl.CULL_FACE);
|
||||
|
||||
var fragmentShader = gl.createShader(goog.webgl.FRAGMENT_SHADER);
|
||||
gl.shaderSource(fragmentShader, [
|
||||
'precision mediump float;',
|
||||
'',
|
||||
'uniform sampler2D uTexture;',
|
||||
'',
|
||||
'varying vec2 vTexCoord;',
|
||||
'',
|
||||
'void main(void) {',
|
||||
' gl_FragColor = vec4(vec3(texture2D(uTexture, vTexCoord)), 1.);',
|
||||
'}'
|
||||
].join('\n'));
|
||||
gl.compileShader(fragmentShader);
|
||||
if (!gl.getShaderParameter(fragmentShader, goog.webgl.COMPILE_STATUS)) {
|
||||
window.console.log(gl.getShaderInfoLog(fragmentShader));
|
||||
goog.asserts.assert(gl.getShaderParameter(fragmentShader, goog.webgl.COMPILE_STATUS));
|
||||
}
|
||||
|
||||
var vertexShader = gl.createShader(goog.webgl.VERTEX_SHADER);
|
||||
gl.shaderSource(vertexShader, [
|
||||
'attribute vec2 aPosition;',
|
||||
'attribute vec2 aTexCoord;',
|
||||
'',
|
||||
'uniform mat4 uMVPMatrix;',
|
||||
'',
|
||||
'varying vec2 vTexCoord;',
|
||||
'',
|
||||
'void main(void) {',
|
||||
' gl_Position = uMVPMatrix * vec4(aPosition, 0.0, 1.0);',
|
||||
' vTexCoord = aTexCoord;',
|
||||
'}'
|
||||
].join('\n'));
|
||||
if (!gl.getShaderParameter(vertexShader, goog.webgl.COMPILE_STATUS)) {
|
||||
window.console.log(gl.getShaderInfoLog(vertexShader));
|
||||
goog.asserts.assert(gl.getShaderParameter(vertexShader, goog.webgl.COMPILE_STATUS));
|
||||
}
|
||||
|
||||
var program = gl.createProgram();
|
||||
gl.attachShader(program, fragmentShader);
|
||||
gl.attachShader(program, vertexShader);
|
||||
gl.linkProgram(program);
|
||||
if (!gl.getProgramParameter(program, goog.webgl.LINK_STATUS)) {
|
||||
window.console.log(gl.getProgramInfoLog(program));
|
||||
goog.asserts.assert(gl.getProgramParameter(program, goog.webgl.LINK_STATUS));
|
||||
}
|
||||
|
||||
this.mvpMatrixLocation_ = gl.getUniformLocation(program, 'uMVPMatrix');
|
||||
this.textureLocation_ = gl.getUniformLocation(program, 'uTexture');
|
||||
|
||||
var texCoordBuffer = gl.createBuffer();
|
||||
gl.bindBuffer(goog.webgl.ARRAY_BUFFER, texCoordBuffer);
|
||||
gl.bufferData(goog.webgl.ARRAY_BUFFER, new Float32Array([0, 1, 1, 1, 0, 0, 1, 0]), goog.webgl.STATIC_DRAW);
|
||||
var texCoordLocation = gl.getAttributeLocation(program, 'aTexCoord');
|
||||
gl.enableVertexAttribArray(texCoordLocation);
|
||||
gl.vertexAttribPointer(texCoordLocation, 2, goog.webgl.FLOAT, false, 0, 0);
|
||||
gl.bindBuffer(goog.webgl.ARRAY_BUFFER, null);
|
||||
|
||||
this.positionLocation_ = gl.getAttributeLocation(program, 'aPosition');
|
||||
gl.enableVertexAttribArray(this.positionLocation_);
|
||||
this.positionBuffer_ = gl.createBuffer();
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.renderer.WebGL, ol.renderer.MapRenderer);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if this renderer type is supported in this environment.
|
||||
* A static method.
|
||||
* @returns {boolean} This renderer is supported.
|
||||
*/
|
||||
ol.renderer.WebGL.isSupported = function() {
|
||||
return !goog.isNull( goog.dom.createDom('canvas').getContext('experimental-webgl') );
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Tile} tile Tile.
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.WebGL.prototype.bindTexture = function(tile) {
|
||||
var gl = this.gl_;
|
||||
var url = tile.getUrl();
|
||||
if (url in this.textureCache_) {
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.textureCache_[url]);
|
||||
} else {
|
||||
var texture = gl.createTexture();
|
||||
gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
|
||||
gl.texImage2D(goog.webgl.TEXTURE_2D, 0, goog.webgl.RGBA, goog.webgl.RGBA, goog.webgl.UNSIGNED_BYTE, tile.getImg());
|
||||
gl.texParameteri(goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MAG_FILTER, goog.webgl.LINEAR);
|
||||
gl.texParameteri(goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MIN_FILTER, goog.webgl.LINEAR);
|
||||
this.textureCache_[url] = texture;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Tile} tile Tile.
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.WebGL.prototype.handleTileLoad = function(tile) {
|
||||
this.redraw();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Tile} tile Tile.
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.WebGL.prototype.handleTileDestroy = function(tile) {
|
||||
var gl = this.gl_;
|
||||
var url = tile.getUrl();
|
||||
if (url in this.textureCache_) {
|
||||
gl.deleteTexture(this.textureCache_[url]);
|
||||
delete this.textureCache_[url];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.WebGL.prototype.draw = function(layers, center, resolution, animate) {
|
||||
|
||||
var gl = this.gl_;
|
||||
|
||||
var width = this.canvas_.width;
|
||||
var height = this.canvas_.height;
|
||||
|
||||
var bounds = new ol.Bounds(
|
||||
center.getX() - width * resolution / 2,
|
||||
center.getY() - height * resolution / 2,
|
||||
center.getX() + width * resolution / 2,
|
||||
center.getY() + height * resolution / 2,
|
||||
center.getProjection());
|
||||
|
||||
/** @type {goog.vec.Mat4.Type} */
|
||||
var cameraMatrix;
|
||||
goog.vec.Mat4.makeIdentity(cameraMatrix);
|
||||
goog.vec.Mat4.scale(cameraMatrix, resolution, resolution, 1);
|
||||
goog.vec.Mat4.translate(cameraMatrix, -center.getX(), -center.getY(), 0);
|
||||
|
||||
/** @type {goog.vec.Mat4.Type} */
|
||||
var positionToViewportMatrix;
|
||||
goog.vec.Mat4.makeIdentity(positionToViewportMatrix);
|
||||
goog.vec.Mat4.scale(positionToViewportMatrix, 1 / width, 1 / height, 1);
|
||||
goog.vec.Mat4.multMat(positionToViewportMatrix, cameraMatrix, positionToViewportMatrix);
|
||||
|
||||
/** @type {goog.vec.Mat4.Type} */
|
||||
var viewportToPositionMatrix;
|
||||
var inverted = goog.vec.Mat4.invert(positionToViewportMatrix, viewportToPositionMatrix);
|
||||
goog.asserts.assert(inverted);
|
||||
|
||||
/** @type {goog.vec.Mat4.Type} */
|
||||
var targetPixelToPositionMatrix;
|
||||
goog.vec.Mat4.makeIdentity(targetPixelToPositionMatrix);
|
||||
goog.vec.Mat4.translate(targetPixelToPositionMatrix, -1, 1, 0);
|
||||
goog.vec.Mat4.scale(targetPixelToPositionMatrix, 2 / width, -2 / height, 1);
|
||||
goog.vec.Mat4.multMat(viewportToPositionMatrix, targetPixelToPositionMatrix, targetPixelToPositionMatrix);
|
||||
|
||||
gl.clear(goog.webgl.COLOR_BUFFER_BIT);
|
||||
gl.bindBuffer(goog.webgl.ARRAY_BUFFER, this.positionBuffer_);
|
||||
gl.uniform1i(this.textureLocation_, 0);
|
||||
gl.uniformMatrix4fv(this.positionLocation_, false, positionToViewportMatrix);
|
||||
|
||||
goog.array.forEach(layers, function(layer) {
|
||||
if (!(layer instanceof ol.layer.TileLayer)) {
|
||||
return;
|
||||
}
|
||||
var tileLayer = /** @type {ol.layer.TileLayer} */ (layer);
|
||||
var tileSet = layer.getData(bounds, resolution);
|
||||
var tiles = tileSet.getTiles();
|
||||
var i, j, row, tile, tileBounds, positions, texture;
|
||||
for (i = 0; i < tiles.length; ++i) {
|
||||
row = tiles[i];
|
||||
for (j = 0; j < row.length; ++j) {
|
||||
tile = row[j];
|
||||
if (!tile.isLoaded()) {
|
||||
if (!tile.isLoading()) {
|
||||
goog.events.listen(tile, 'load', this.handleTileLoad,
|
||||
undefined, this);
|
||||
goog.events.listen(tile, 'destroy', this.handleTileDestroy,
|
||||
undefined, this);
|
||||
tile.load();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
tileBounds = tile.getBounds();
|
||||
positions = [
|
||||
tileBounds.getMinX(), tileBounds.getMinY(),
|
||||
tileBounds.getMaxX(), tileBounds.getMinY(),
|
||||
tileBounds.getMinX(), tileBounds.getMaxY(),
|
||||
tileBounds.getMaxX(), tileBounds.getMaxY()
|
||||
];
|
||||
gl.bufferData(goog.webgl.ARRAY_BUFFER, new Float32Array(positions), goog.webgl.DYNAMIC_DRAW);
|
||||
gl.vertexAttribPointer(this.positionLocation_, 2, goog.webgl.FLOAT, false, 0, 0);
|
||||
this.bindTexture(tile);
|
||||
gl.drawArrays(goog.webgl.TRIANGLES, 0, 4);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.renderedLayers_ = layers;
|
||||
this.renderedCenter_ = center;
|
||||
this.renderedResolution_ = resolution;
|
||||
this.renderedAnimate_ = animate;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.renderer.WebGL.prototype.redraw = function() {
|
||||
this.draw(this.renderedLayers_, this.renderedCenter_, this.renderedResolution_, this.renderedAnimate_);
|
||||
};
|
||||
Reference in New Issue
Block a user