Move code to be merged into src/attic

This commit is contained in:
Tom Payne
2012-07-26 00:21:37 +02:00
parent 8d936e7865
commit f3d9b3332c
35 changed files with 1 additions and 41 deletions
+149
View File
@@ -0,0 +1,149 @@
goog.provide('ol.bounds');
goog.require('ol.Bounds');
goog.require('ol.projection');
/**
* @typedef {ol.Bounds|Array.<number>|Object} bounds Location.
*/
ol.LocLike;
/**
* @export
* @param {ol.LocLike} opt_arg Location.
* @return {ol.Bounds} Location.
*/
ol.bounds = function(opt_arg){
if (opt_arg instanceof ol.Bounds) {
return opt_arg;
}
var minX = 0;
var minY = 0;
var maxX = 0;
var maxY = 0;
var projection;
var x = 0;
var y = 0;
var z;
if (goog.isArray(opt_arg)) {
minX = opt_arg[0];
minY = opt_arg[1];
maxX = opt_arg[2];
maxY = opt_arg[3];
} else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['minX', 'minY', 'maxX', 'maxY', 'projection']);
minX = ol.API ? opt_arg['minX'] : opt_arg.minX;
minY = ol.API ? opt_arg['minY'] : opt_arg.minY;
maxX = ol.API ? opt_arg['maxX'] : opt_arg.maxX;
maxY = ol.API ? opt_arg['maxY'] : opt_arg.maxY;
projection = ol.projection(ol.API ? opt_arg['projection'] : opt_arg.projection);
}
else {
throw new Error('ol.bounds');
}
var bounds = new ol.Bounds(minX, minY, maxX, maxY, projection);
return bounds;
};
/**
* @export
* @param {ol.Projection=} opt_arg Projection.
* @return {ol.Bounds|ol.Projection|undefined} Result.
*/
ol.Bounds.prototype.projection = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setProjection(opt_arg);
return this;
}
else {
return this.getProjection();
}
};
/**
* @export
* @param {number=} opt_arg Minimum X.
* @return {!ol.Bounds|number} Result.
*/
ol.Bounds.prototype.minX = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMinX(opt_arg);
return this;
}
else {
return this.getMinX();
}
};
/**
* @export
* @param {number=} opt_arg Minimum Y.
* @return {ol.Bounds|number} Result.
*/
ol.Bounds.prototype.minY = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMinY(opt_arg);
return this;
}
else {
return this.getMinY();
}
};
/**
* @export
* @param {number=} opt_arg Maximum X.
* @return {ol.Bounds|number} Result.
*/
ol.Bounds.prototype.maxX = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMaxX(opt_arg);
return this;
}
else {
return this.getMaxX();
}
};
/**
* @export
* @param {number=} opt_arg Maximum Y.
* @return {ol.Bounds|number} Result.
*/
ol.Bounds.prototype.maxY = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMaxY(opt_arg);
return this;
}
else {
return this.getMaxY();
}
};
/**
* Transform this node into another coordinate reference system. Returns a new
* bounds instead of modifying this bounds.
*
* @param {ol.Projection|string} proj Target projection (or string identifier).
* @return {ol.Bounds} A new bounds in the target projection.
*/
ol.Bounds.prototype.transform = function(proj) {
if (goog.isString(proj)) {
proj = new ol.Projection(proj);
}
return this.doTransform(proj);
};
+92
View File
@@ -0,0 +1,92 @@
goog.provide('ol.feature');
goog.require('ol.base');
goog.require('ol.Feature');
goog.require('ol.geom.Geometry');
/**
* @typedef {ol.Feature|Object|string}
*/
ol.FeatureLike;
/**
* @export
* @param {ol.FeatureLike=} opt_arg Argument.
* @return {ol.Feature} Feature.
*/
ol.feature = function(opt_arg){
/** @type {Object|undefined} */
var properties;
/** @type {ol.geom.Geometry|undefined} */
var geometry;
/** @type {string|undefined} */
var type;
if (arguments.length == 1) {
if (opt_arg instanceof ol.Feature) {
return opt_arg;
}
else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['geometry', 'properties', 'type']);
properties = ol.API ? opt_arg['properties'] : opt_arg.properties;
geometry = ol.API ? opt_arg['geometry'] : opt_arg.geometry;
type = ol.API ? opt_arg['type'] : opt_arg.type;
}
else {
throw new Error('ol.feature');
}
}
var feature = new ol.Feature();
if (goog.isDef(type) && type == 'Feature') {
//this means it is a GeoJSON object
//format.read(opt_arg);
} else {
if (goog.isDef(properties)) {
feature.setAttributes(properties);
}
if (goog.isDef(geometry)) {
feature.setGeometry(geometry);
}
}
return feature;
};
/**
* @export
* @param {!string} attr The name of the attribute to be set.
* @param {string|number|boolean} value The value of the attribute to be set.
* @returns {ol.Feature} The feature so calls can be chained
*/
ol.Feature.prototype.set = function(attr, value) {
this.setAttribute(attr, value);
return this;
};
/**
* @export
* @param {!string} attr The name of the attribute to be set.
* @returns {string|number|boolean|undefined} The attribute value requested.
*/
ol.Feature.prototype.get = function(attr) {
return this.getAttribute(attr);
};
/**
* @export
* @param {ol.geom.Geometry=} opt_arg
* @returns {ol.Feature|ol.geom.Geometry|undefined} get or set the geometry on a feature
*/
ol.Feature.prototype.geometry = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setGeometry(opt_arg);
return this;
} else {
return this.getGeometry();
}
};
+133
View File
@@ -0,0 +1,133 @@
goog.provide('ol.geom.collection');
goog.require('ol.geom.Collection');
goog.require('ol.geom.point');
goog.require('ol.projection');
/**
* @export
* @param {Array.<ol.geom.Geometry>} opt_arg Components.
* @return {ol.geom.Collection} Collection.
*/
ol.geom.collection = function(opt_arg){
if (opt_arg instanceof ol.geom.Collection) {
return opt_arg;
}
var components = [];
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
var allValid = goog.array.every(opt_arg, function(geom){
if (geom instanceof ol.geom.Geometry) {
components.push(geom);
return true;
} else {
return false;
}
});
if (!allValid) {
var msg = 'ol.geom.collection: at least one component '
+ 'definition was no geometry.';
throw new Error(msg);
}
} else {
throw new Error('ol.geom.collection');
}
}
var c = new ol.geom.Collection(components);
return c;
};
goog.inherits(ol.geom.collection, ol.geom.geometry);
/**
* @export
* @param {Array.<ol.geom.Geometry>=} opt_arg An array of point specifications.
* @return {Array.<ol.geom.Geometry>|ol.geom.Collection|undefined} Result.
*/
ol.geom.Collection.prototype.components = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var components = [],
allValid = false;
allValid = goog.array.every(opt_arg, function(geom){
if (geom instanceof ol.geom.Geometry) {
components.push(geom);
return true;
} else {
return false;
}
});
if (!allValid) {
components = [];
}
this.setComponents(components);
return this;
}
else {
return this.getComponents();
}
};
/**
* @export
* @param {ol.geom.Geometry} geom A geometry.
* @param {number=} opt_index An optional index to add the point(s) at. If not
* provided, the point(s) will be added to the end of the list of components.
* @return {ol.geom.Collection} The Collection instance.
*/
ol.geom.Collection.prototype.add = function(geom, opt_index){
var index = this.components_.length;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
this.addComponent(geom, index);
return this;
};
/**
* @export
* @param {Array.<ol.geom.Geometry>} components Some point specifications.
* @param {number=} opt_index An optional index to add the components at. If not
* provided, the components will be added to the end of the list of
* components.
* @return {ol.geom.Collection} The Collection instance.
*/
ol.geom.Collection.prototype.addAll = function(components, opt_index){
var index = this.components_.length;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
goog.array.every(components, function(c){
this.addComponent(c, index);
index++;
return true;
}, this);
return this;
};
/**
* @export
* @param {(ol.geom.Geometry|Array.<ol.geom.Geometry>)} components A point specification or
* an array of point specifications.
* @return {ol.geom.Collection} The Collection instance.
*/
ol.geom.Collection.prototype.remove = function(components){
var compArr = [];
if (!goog.isArray(components)) {
compArr.push(components);
} else {
compArr = components;
}
goog.array.every(compArr, function(c){
this.removeComponent(c);
return true;
}, this);
return this;
};
+35
View File
@@ -0,0 +1,35 @@
goog.provide('ol.geom.geometry');
goog.require('ol.geom.Geometry');
/**
* @export
* @return {ol.geom.Geometry} Geometry..
*/
ol.geom.geometry = function(){
var g = new ol.geom.Geometry();
return g;
};
/**
* @export
* @param {ol.Bounds=} opt_arg new Bounds.
* @return {ol.geom.Geometry|ol.Bounds|undefined} either a Geometry (when used as
* setter) or a Bounds/undefined (if used as getter).
*/
ol.geom.Geometry.prototype.bounds = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setBounds(opt_arg);
} else {
return this.getBounds();
}
};
/**
* Returns the centroid of the geometry.
*
* @returns {ol.geom.Point} The centroid of the geometry.
*/
ol.geom.Geometry.prototype.centroid = function() {
return this.getCentroid();
};
+142
View File
@@ -0,0 +1,142 @@
goog.provide('ol.geom.linestring');
goog.require('ol.geom.LineString');
goog.require('ol.geom.point');
goog.require('ol.projection');
/**
* @typedef {Array.<ol.PointLike>} linestring LineString.
*/
ol.LineStringLike;
/**
* @export
* @param {ol.LineStringLike} opt_arg Points.
* @return {ol.geom.LineString} LineString.
*/
ol.geom.linestring = function(opt_arg){
if (opt_arg instanceof ol.geom.LineString) {
return opt_arg;
}
var vertices = [];
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
var allValid = goog.array.every(opt_arg, function(spec){
var v = ol.geom.point(spec);
if (v instanceof ol.geom.Point) {
vertices.push(v);
return true;
} else {
return false;
}
});
if (!allValid) {
var msg = 'ol.geom.linestring: at least one point '
+ 'definition was erroneous.';
throw new Error(msg);
}
} else {
throw new Error('ol.geom.linestring');
}
}
var ls = new ol.geom.LineString(vertices);
return ls;
};
goog.inherits(ol.geom.linestring, ol.geom.geometry);
/**
* @export
* @param {Array.<ol.PointLike>=} opt_arg An array of vertex specifications.
* @return {Array.<ol.geom.Point>|ol.geom.LineString|undefined} Result.
*/
ol.geom.LineString.prototype.vertices = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var vertices = [],
allValid = false;
goog.array.every(opt_arg, function(spec){
var v = ol.geom.point(spec);
if (v instanceof ol.geom.Point) {
vertices.push(v);
return true;
} else {
return false;
}
});
if (!allValid) {
vertices = [];
}
this.setVertices(vertices);
return this;
}
else {
return this.getVertices();
}
};
/**
* @export
* @param {ol.PointLike} vertex A point specification.
* @param {number=} opt_index An optional index to add the vertices at. If not
* provided, the vertex will be added to the end of the list of vertices.
* @return {ol.geom.LineString} The LineString instance.
*/
ol.geom.LineString.prototype.add = function(vertex, opt_index){
var index = this.vertices_.length,
allValid = false,
v = ol.geom.point(vertex);
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
this.addVertex(v, index);
return this;
};
/**
* @export
* @param {Array.<ol.PointLike>} vertices Some vertex specifications.
* @param {number=} opt_index An optional index to add the vertices at. If not
* provided, the points will be added to the end of the list of vertices.
* @return {ol.geom.LineString} The LineString instance.
*/
ol.geom.LineString.prototype.addAll = function(vertices, opt_index){
var index = this.vertices_.length,
v;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
goog.array.every(vertices, function(vertexSpec){
v = ol.geom.point(vertexSpec);
this.addVertex(v, index);
index++;
return true;
}, this);
return this;
};
/**
* @export
* @param {(ol.geom.Point|Array.<ol.geom.Point>)} vertices A point specification or
* an array of point specifications.
* @return {ol.geom.LineString} The MultiPoint instance.
*/
ol.geom.LineString.prototype.remove = function(vertices){
var vertexArr = [];
if (!goog.isArray(vertices)) {
vertexArr.push(vertices);
} else {
vertexArr = vertices;
}
goog.array.every(vertexArr, function(v){
this.removeVertex(v);
return true;
}, this);
return this;
};
+138
View File
@@ -0,0 +1,138 @@
goog.provide('ol.geom.multilinestring');
goog.require('ol.geom.MultiLineString');
goog.require('ol.geom.point');
goog.require('ol.geom.collection');
goog.require('ol.projection');
/**
* @export
* @param {Array.<ol.LineStringLike>} opt_arg Point.
* @return {ol.geom.MultiLineString} MultiLineString.
*/
ol.geom.multilinestring = function(opt_arg){
if (opt_arg instanceof ol.geom.MultiLineString) {
return opt_arg;
}
var ls = [];
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
var allValid = goog.array.every(opt_arg, function(spec){
var l = ol.geom.linestring(spec);
if (l instanceof ol.geom.LineString) {
ls.push(l);
return true;
} else {
return false;
}
});
if (!allValid) {
var msg = 'ol.geom.linestring: at least one linestring '
+ 'definition was erroneous.';
throw new Error(msg);
}
} else {
throw new Error('ol.geom.multilinestring');
}
}
var mls = new ol.geom.MultiLineString(ls);
return mls;
};
goog.inherits(ol.geom.multilinestring, ol.geom.collection);
/**
* @export
* @param {Array.<ol.LineStringLike>=} opt_arg An array of point specifications.
* @return {Array.<ol.geom.LineString>|ol.geom.MultiLineString|undefined} Result.
*/
ol.geom.MultiLineString.prototype.linestrings = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var ls = [],
allValid = false;
allValid = goog.array.every(opt_arg, function(spec){
var l = ol.geom.linestring(spec);
if (l instanceof ol.geom.LineString) {
ls.push(l);
return true;
} else {
return false;
}
});
if (!allValid) {
ls = [];
}
this.setComponents(ls);
return this;
}
else {
return this.getComponents();
}
};
/**
* @export
* @param {ol.LineStringLike} line A linestring specification.
* @param {number=} opt_index An optional index to add the point(s) at. If not
* provided, the point(s) will be added to the end of the list of points.
* @return {ol.geom.MultiLineString} The MultiPoint instance.
*/
ol.geom.MultiLineString.prototype.add = function(line, opt_index){
var index = this.getLineStrings().length,
l = ol.geom.linestring(line);
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
this.addLineString(l, index);
return this;
};
/**
* @export
* @param {Array.<ol.LineStringLike>} lines Some linestring specifications.
* @param {number=} opt_index An optional index to add the points at. If not
* provided, the linestrings will be added to the end of the list of
* linestrings.
* @return {ol.geom.MultiLineString} The MultiLineString instance.
*/
ol.geom.MultiLineString.prototype.addAll = function(lines, opt_index){
var index = this.getLineStrings().length,
l;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
goog.array.every(lines, function(pointSpec){
l = ol.geom.linestring(pointSpec);
this.addLineString(l, index);
index++;
return true;
}, this);
return this;
};
/**
* @export
* @param {(ol.geom.LineString|Array.<ol.geom.LineString>)} lines A linestring
* specification or an array of linestring specifications.
* @return {ol.geom.MultiLineString} The MultiLineString instance.
*/
ol.geom.MultiLineString.prototype.remove = function(lines){
var lineArr = [];
if (!goog.isArray(lines)) {
lineArr.push(lines);
} else {
lineArr = lines;
}
goog.array.every(lineArr, function(l){
this.removeLineString(l);
return true;
}, this);
return this;
};
+137
View File
@@ -0,0 +1,137 @@
goog.provide('ol.geom.multipoint');
goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.point');
goog.require('ol.geom.collection');
goog.require('ol.projection');
/**
* @export
* @param {Array.<ol.PointLike>} opt_arg Point.
* @return {ol.geom.MultiPoint} MultiPoint.
*/
ol.geom.multipoint = function(opt_arg){
if (opt_arg instanceof ol.geom.MultiPoint) {
return opt_arg;
}
var points = [];
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
var allValid = goog.array.every(opt_arg, function(spec){
var p = ol.geom.point(spec);
if (p instanceof ol.geom.Point) {
points.push(p);
return true;
} else {
return false;
}
});
if (!allValid) {
var msg = 'ol.geom.multipoint: at least one point '
+ 'definition was erroneous.';
throw new Error(msg);
}
} else {
throw new Error('ol.geom.multipoint');
}
}
var mp = new ol.geom.MultiPoint(points);
return mp;
};
goog.inherits(ol.geom.multipoint, ol.geom.collection);
/**
* @export
* @param {Array.<ol.PointLike>=} opt_arg An array of point specifications.
* @return {Array.<ol.geom.Point>|ol.geom.MultiPoint|undefined} Result.
*/
ol.geom.MultiPoint.prototype.points = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var points = [],
allValid = false;
allValid = goog.array.every(opt_arg, function(spec){
var p = ol.geom.point(spec);
if (p instanceof ol.geom.Point) {
points.push(p);
return true;
} else {
return false;
}
});
if (!allValid) {
points = [];
}
this.setComponents(points);
return this;
}
else {
return this.getComponents();
}
};
/**
* @export
* @param {ol.PointLike} point A point specification.
* @param {number=} opt_index An optional index to add the point(s) at. If not
* provided, the point(s) will be added to the end of the list of points.
* @return {ol.geom.MultiPoint} The MultiPoint instance.
*/
ol.geom.MultiPoint.prototype.add = function(point, opt_index){
var index = this.getPoints().length,
p = ol.geom.point(point);
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
this.addPoint(p, index);
return this;
};
/**
* @export
* @param {Array.<ol.PointLike>} points Some point specifications.
* @param {number=} opt_index An optional index to add the points at. If not
* provided, the points will be added to the end of the list of points.
* @return {ol.geom.MultiPoint} The MultiPoint instance.
*/
ol.geom.MultiPoint.prototype.addAll = function(points, opt_index){
var index = this.getPoints().length,
p;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
goog.array.every(points, function(pointSpec){
p = ol.geom.point(pointSpec);
this.addPoint(p, index);
index++;
return true;
}, this);
return this;
};
/**
* @export
* @param {(ol.geom.Point|Array.<ol.geom.Point>)} points A point specification or
* an array of point specifications.
* @return {ol.geom.MultiPoint} The MultiPoint instance.
*/
ol.geom.MultiPoint.prototype.remove = function(points){
var pointArr = [];
if (!goog.isArray(points)) {
pointArr.push(points);
} else {
pointArr = points;
}
goog.array.every(pointArr, function(p){
this.removePoint(p);
return true;
}, this);
return this;
};
+122
View File
@@ -0,0 +1,122 @@
goog.provide('ol.geom.point');
goog.require('ol.geom.Point');
goog.require('ol.projection');
/**
* @typedef {Array.<number>|Object} point Point.
*/
ol.PointLike;
/**
* @export
* @param {ol.PointLike} opt_arg Point.
* @return {ol.geom.Point} Point.
*/
ol.geom.point = function(opt_arg){
if (opt_arg instanceof ol.geom.Point) {
return opt_arg;
}
var x = 0;
var y = 0;
var z;
var projection;
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
x = opt_arg[0];
y = opt_arg[1];
z = opt_arg[2];
projection = opt_arg[3];
} else if (goog.isObject(opt_arg)) {
x = ol.API ? opt_arg['x'] : opt_arg.x;
y = ol.API ? opt_arg['y'] : opt_arg.y;
z = ol.API ? opt_arg['z'] : opt_arg.z;
projection = ol.API ? opt_arg['projection'] : opt_arg.projection;
} else {
throw new Error('ol.geom.point');
}
}
if (goog.isDef(projection)) {
projection = ol.projection(projection);
}
var p = new ol.geom.Point(x,y,z,projection);
return p;
};
goog.inherits(ol.geom.point, ol.geom.geometry);
/**
* @export
* @param {number=} opt_arg X.
* @return {ol.geom.Point|number} Result.
*/
ol.geom.Point.prototype.x = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setX(opt_arg);
return this;
}
else {
return this.getX();
}
};
/**
* @export
* @param {number=} opt_arg Y.
* @return {ol.geom.Point|number} Result.
*/
ol.geom.Point.prototype.y = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setY(opt_arg);
return this;
}
else {
return this.getY();
}
};
/**
* @export
* @param {number=} opt_arg Z.
* @return {ol.geom.Point|number|undefined} Result.
*/
ol.geom.Point.prototype.z = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setZ(opt_arg);
return this;
}
else {
return this.getZ();
}
};
/**
* @export
* @param {ol.Projection=} opt_arg Projection.
* @return {ol.geom.Point|ol.Projection|undefined} Result.
*/
ol.geom.Point.prototype.projection = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setProjection(ol.projection(opt_arg));
return this;
}
else {
return this.getProjection();
}
};
/**
* Returns the centroid of this point; which is a clone of the point itself.
*
* @return {ol.geom.Point} The centroid.
*/
ol.geom.Point.prototype.centroid = function() {
return this.getCentroid();
};
+11
View File
@@ -0,0 +1,11 @@
goog.provide('ol.layer.osm');
goog.require('ol.layer.OSM');
/**
* @export
* @return {ol.layer.OSM}
*/
ol.layer.osm = function() {
return new ol.layer.OSM();
};
+41
View File
@@ -0,0 +1,41 @@
goog.provide('ol.layer.wms');
goog.require('ol.layer.WMS');
/**
* @export
* @param {Object} opt_arg Config object.
* @return {ol.layer.WMS}
*/
ol.layer.wms = function(opt_arg) {
if (opt_arg instanceof ol.layer.WMS) {
return opt_arg;
}
/** @type {string} */
var url;
/** @type {Array.<string>} */
var layers;
/** @type {string} */
var format;
if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['url', 'layers', 'format']);
url = ol.API ? opt_arg['url'] : opt_arg.url;
layers = ol.API ? opt_arg['layers'] : opt_arg.layers;
format = ol.API ? opt_arg['format'] : opt_arg.format;
}
var msg;
if (!goog.isDef(url)) {
msg = 'Cannot create WMS layer; option "url" is missing';
ol.error(msg);
}
if (!goog.isArray(layers)) {
msg = 'Cannot create WMS layer; option "layers" is missing, ' +
'or is not an array';
ol.error(msg);
}
return new ol.layer.WMS(url, layers, format);
};
+31
View File
@@ -0,0 +1,31 @@
goog.provide('ol.layer.xyz');
goog.require('ol.layer.XYZ');
/**
* @export
* @param {Object} opt_arg Config object.
* @return {ol.layer.XYZ}
*/
ol.layer.xyz = function(opt_arg) {
if (opt_arg instanceof ol.layer.XYZ) {
return opt_arg;
}
/** @type {string} */
var url;
var usage = 'ol.layer.xyz accepts an object with a "url" property';
if (goog.isObject(opt_arg)) {
url = ol.API ? opt_arg['url'] : opt_arg.url;
} else {
throw new Error(usage);
}
if (!goog.isDef(url)) {
throw new Error(usage);
}
return new ol.layer.XYZ(url);
};
+146
View File
@@ -0,0 +1,146 @@
goog.provide('ol.loc');
goog.require('ol.Loc');
goog.require('ol.projection');
/**
* @typedef {ol.Loc|Array.<number>|Object} loc Location.
*/
ol.LocLike;
/**
* @export
* @param {ol.LocLike} opt_arg Location.
* @return {ol.Loc} Location.
*/
ol.loc = function(opt_arg){
if (opt_arg instanceof ol.Loc) {
return opt_arg;
}
/** @type {number|undefined} */
var x;
/** @type {number|undefined} */
var y;
/** @type {number|undefined} */
var z;
/** @type {Object|undefined} */
var projection;
var usage = 'ol.loc accepts a coordinate array or an object with x, y, and (optional) z properties';
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
x = opt_arg[0];
y = opt_arg[1];
z = opt_arg[2];
projection = opt_arg[3];
} else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['projection', 'x', 'y', 'z']);
x = ol.API ? opt_arg['x'] : opt_arg.x;
y = ol.API ? opt_arg['y'] : opt_arg.y;
z = ol.API ? opt_arg['z'] : opt_arg.z;
projection = ol.API ? opt_arg['projection'] : opt_arg.projection;
} else {
throw new Error(usage);
}
}
if (!goog.isNumber(x) || !goog.isNumber(y)) {
throw new Error(usage);
}
if (goog.isDef(projection)) {
projection = ol.projection(projection);
}
var loc = new ol.Loc(x, y, z, projection);
return loc;
};
/**
* Transform this location to another coordinate reference system. This
* requires that this location has a projection set already (if not, an error
* will be thrown). Returns a new location object and does not modify this
* location.
*
* @export
* @param {string|ol.Projection} proj The destination projection. Can be
* supplied as a projection instance of a string identifier.
* @returns {ol.Loc} A new location.
*/
ol.Loc.prototype.transform = function(proj) {
if (goog.isString(proj)) {
proj = new ol.Projection(proj);
}
return this.doTransform(proj);
};
/**
* @export
* @param {ol.Projection=} opt_arg Projection.
* @return {ol.Loc|ol.Projection|undefined} Result.
*/
ol.Loc.prototype.projection = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setProjection(ol.projection(opt_arg));
}
else {
return this.getProjection();
}
};
/**
* @export
* @param {number=} opt_arg X.
* @return {ol.Loc|number} Result.
*/
ol.Loc.prototype.x = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setX(opt_arg);
return this;
}
else {
return this.getX();
}
};
/**
* @export
* @param {number=} opt_arg Y.
* @return {ol.Loc|number} Result.
*/
ol.Loc.prototype.y = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setY(opt_arg);
return this;
}
else {
return this.getY();
}
};
/**
* @export
* @param {number=} opt_arg Z.
* @return {ol.Loc|number|undefined} Result.
*/
ol.Loc.prototype.z = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setZ(opt_arg);
}
else {
return this.getZ();
}
};
+249
View File
@@ -0,0 +1,249 @@
goog.provide('ol.map');
goog.require('ol.Loc');
goog.require('ol.Map');
goog.require('ol.Projection');
goog.require('ol.loc');
goog.require('ol.projection');
goog.require('ol.error');
/**
* @typedef {ol.Map|{center, zoom, numZoomLevels, projection, userProjection, maxExtent, maxResolution, resolutions, renderTo, layers, controls}|string}
*/
ol.MapLike;
/**
* @export
* @param {ol.MapLike=} opt_arg Argument.
* @return {ol.Map} Map.
*/
ol.map = function(opt_arg) {
/** @type {ol.Loc|undefined} */
var center;
/** @type {number|undefined} */
var zoom;
/** @type {number|undefined} */
var numZoomLevels;
/** @type {ol.Projection|undefined} */
var projection;
/** @type {ol.Projection|undefined} */
var userProjection;
/** @type {ol.Bounds|undefined} */
var maxExtent;
/** @type {number|undefined} */
var maxResolution;
/** @type {Array.<number>|undefined} */
var resolutions;
/** @type {Element|string|undefined} */
var renderTo;
/** @type {Array|undefined} */
var layers;
/** @type {Array|undefined} */
var controls;
if (arguments.length == 1) {
if (opt_arg instanceof ol.Map) {
return opt_arg;
}
else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['center', 'zoom', 'numZoomLevels', 'projection', 'userProjection', 'maxExtent', 'maxResolution', 'resolutions', 'renderTo', 'layers', 'controls']);
center = ol.API ? opt_arg['center'] : opt_arg.center;
zoom = ol.API ? opt_arg['zoom'] : opt_arg.zoom;
numZoomLevels = ol.API ? opt_arg['numZoomLevels'] : opt_arg.numZoomLevels;
projection = ol.API ? opt_arg['projection'] : opt_arg.projection;
userProjection = ol.API ? opt_arg['userProjection'] : opt_arg.userProjection;
maxExtent = ol.API ? opt_arg['maxExtent'] : opt_arg.maxExtent;
maxResolution = ol.API ? opt_arg['maxResolution'] : opt_arg.maxResolution;
resolutions = ol.API ? opt_arg['resolutions'] : opt_arg.resolutions;
renderTo = ol.API ? opt_arg['renderTo'] : opt_arg.renderTo;
layers = ol.API ? opt_arg['layers'] : opt_arg.layers;
controls = ol.API ? opt_arg['controls'] : opt_arg.controls;
}
else {
throw new Error('ol.map');
}
}
var map = new ol.Map();
if (goog.isDef(center)) {
map.center(center);
}
if (goog.isDef(zoom)) {
map.setZoom(zoom);
}
if (goog.isDef(numZoomLevels)) {
map.setNumZoomLevels(numZoomLevels);
}
if (goog.isDef(projection)) {
map.setProjection(ol.projection(projection));
}
if (goog.isDef(userProjection)) {
map.setUserProjection(ol.projection(userProjection));
}
if (goog.isDef(maxExtent)) {
map.setMaxExtent(ol.bounds(maxExtent));
}
if (goog.isDef(maxResolution)) {
map.setMaxResolution(maxResolution);
}
if (goog.isDef(resolutions)) {
map.setResolutions(resolutions);
}
if (goog.isDef(layers)) {
map.setLayers(layers);
}
if (goog.isDef(controls)) {
map.setControls(controls);
}
if (goog.isDef(renderTo)) {
map.renderTo(renderTo);
}
return map;
};
/**
* @export
* @param {ol.LocLike=} opt_arg
* @returns {ol.Map|ol.Loc|undefined} Map center.
*/
ol.Map.prototype.center = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var loc = ol.loc(opt_arg);
var proj = loc.getProjection();
if (goog.isNull(proj)) {
proj = this.getUserProjection();
loc.setProjection(proj);
}
this.setCenter(loc);
return this;
} else {
var proj = this.getUserProjection();
return this.getCenter().doTransform(proj);
}
};
/**
* @export
* @param {ol.ProjectionLike=} opt_arg
* @returns {ol.Map|ol.Projection|undefined}
*/
ol.Map.prototype.projection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setProjection(ol.projection(opt_arg));
return this;
} else {
return this.getProjection();
}
};
/**
* @export
* @param {ol.ProjectionLike=} opt_arg
* @returns {ol.Map|ol.Projection|undefined}
*/
ol.Map.prototype.userProjection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setUserProjection(ol.projection(opt_arg));
return this;
} else {
return this.getUserProjection();
}
};
/**
* @export
* @param {number=} opt_arg
* @returns {ol.Map|number|undefined} Map center.
*/
ol.Map.prototype.zoom = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setZoom(opt_arg);
return this;
} else {
return this.getZoom();
}
};
/**
* @export
* @param {number=} opt_arg
* @returns {ol.Map|number|undefined} Map center.
*/
ol.Map.prototype.numZoomLevels = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setNumZoomLevels(opt_arg);
return this;
} else {
return this.getNumZoomLevels();
}
};
/**
* @export
* @param {Array=} opt_arg
* @returns {ol.Map|Array|undefined} Map center.
*/
ol.Map.prototype.resolutions = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setResolutions(opt_arg);
return this;
} else {
return this.getResolutions();
}
};
/**
* @export
* @param {Array=} opt_arg
* @returns {ol.Map|Array|undefined} Map center.
*/
ol.Map.prototype.layers = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setLayers(opt_arg);
return this;
} else {
return this.getLayers();
}
};
/**
* @export
* @param {Array=} opt_arg
* @returns {ol.Map|Array|undefined} Map center.
*/
ol.Map.prototype.controls = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setControls(opt_arg);
return this;
} else {
return this.getControls();
}
};
/**
* @export
* @param {Array=} opt_arg
* @returns {ol.Map|ol.Bounds|undefined} Map max extent.
*/
ol.Map.prototype.maxExtent = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMaxExtent(ol.bounds(opt_arg));
return this;
} else {
return this.getMaxExtent();
}
};
/**
* @param {string|Element} arg Render the map to a container
* @returns {ol.Map}
*/
ol.Map.prototype.renderTo = function(arg) {
this.setContainer(goog.dom.getElement(arg));
return this;
};
+139
View File
@@ -0,0 +1,139 @@
goog.provide('ol.popup');
goog.require('ol.Popup');
goog.require('ol.map');
/**
* @typedef {ol.Popup|{map, anchor, placement, content, template}} popup
*/
ol.PopupLike;
/**
* @export
* @param {ol.PopupLike} opt_arg popup object literal.
* @return {ol.Popup} the popup.
*/
ol.popup = function(opt_arg){
if (opt_arg instanceof ol.Popup) {
return opt_arg;
}
/** @type {ol.Map} */
var map;
/** @type {ol.Loc|ol.Feature|undefined} */
var anchor;
/** @type {string|undefined} */
var placement;
/** @type {string|undefined} */
var content;
/** @type {string|undefined} */
var template;
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['map', 'anchor', 'placement', 'content', 'template']);
map = ol.API ? opt_arg['map'] : opt_arg.map;
anchor = ol.API ? opt_arg['anchor'] : opt_arg.anchor;
placement = ol.API ? opt_arg['placement'] : opt_arg.placement;
content = ol.API ? opt_arg['content'] : opt_arg.content;
template = ol.API ? opt_arg['template'] : opt_arg.template;
}
}
var popup = new ol.Popup(map, anchor);
if (goog.isDef(anchor)) {
popup.setAnchor(anchor);
}
if (goog.isDef(placement)) {
popup.setPlacement(placement);
}
if (goog.isDef(content)) {
popup.setContent(content);
}
if (goog.isDef(template)) {
popup.setTemplate(template);
}
return popup;
};
/**
* @export
* @param {ol.Loc|ol.Feature=} opt_arg a feature or a location.
* @return {ol.Popup|ol.Feature|ol.Loc|undefined} Result.
*/
ol.Popup.prototype.anchor = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setAnchor(opt_arg);
return this;
}
else {
return this.getAnchor();
}
};
/**
* @export
* @param {ol.Map=} opt_arg the map .
* @return {ol.Popup|ol.Map|undefined} the map or the popup.
*/
ol.Popup.prototype.map = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMap(opt_arg);
return this;
}
else {
return this.getMap();
}
};
/**
* @export
* @param {string=} opt_arg the content for the map (HTML makrkup)
* @return {ol.Popup|string|undefined} the content or the popup.
*/
ol.Popup.prototype.content = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setContent(opt_arg);
return this;
}
else {
return this.getContent();
}
};
/**
* @export
* @param {string=} opt_arg the template to be used to generate the content
* @return {ol.Popup|string|undefined} the template or the popup.
*/
ol.Popup.prototype.template = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setTemplate(opt_arg);
return this;
}
else {
return this.getTemplate();
}
};
/**
* Open the popup.
* @export
* @param {ol.Feature|ol.Loc} opt_arg feature or location for the anchor
*/
ol.Popup.prototype.open = function(opt_arg) {
this.doOpen(opt_arg);
};
+88
View File
@@ -0,0 +1,88 @@
goog.provide('ol.projection');
goog.require('ol.base');
goog.require('ol.Projection');
/**
* @typedef {ol.Projection|Object|string}
*/
ol.ProjectionLike;
/**
* @export
* @param {ol.ProjectionLike=} opt_arg Argument.
* @return {ol.Projection} Projection.
*/
ol.projection = function(opt_arg){
/** @type {string} */
var code;
/** @type {undefined|number} */
var units;
/** @type {undefined|Array|ol.UnreferencedBounds} */
var extent;
if (arguments.length == 1 && goog.isDefAndNotNull(opt_arg)) {
if (opt_arg instanceof ol.Projection) {
return opt_arg;
}
else if (goog.isString(opt_arg)) {
code = opt_arg;
}
else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['code', 'maxExtent', 'units']);
if (goog.isString(ol.API ? opt_arg['code'] : opt_arg.code)) {
code = ol.API ? opt_arg['code'] : opt_arg.code;
} else {
throw new Error('Projection requires a string code.');
}
units = ol.API ? opt_arg['units'] : opt_arg.units;
extent = ol.API ? opt_arg['maxExtent'] : opt_arg.maxExtent;
}
else {
throw new Error('ol.projection');
}
}
var proj = new ol.Projection(code);
if (goog.isDef(units)) {
proj.setUnits(units);
}
if (goog.isDef(extent)) {
proj.setExtent(
new ol.UnreferencedBounds(extent[0],extent[1],extent[2],extent[3])
);
}
return proj;
};
/**
* @export
* @param {string=} opt_code Code.
* @return {!ol.Projection|string} Result.
*/
ol.Projection.prototype.code = function(opt_code){
if (arguments.length == 1 && goog.isDef(opt_code)) {
this.setCode(opt_code);
return this;
}
else {
return this.getCode();
}
};
/**
* @export
* @param {string=} opt_units Units abbreviation.
* @return {undefined|!ol.Projection|string} Result.
*/
ol.Projection.prototype.units = function(opt_units){
if (goog.isDef(opt_units)) {
return this.setUnits(opt_units);
}
else {
return this.getUnits();
}
};
+77
View File
@@ -0,0 +1,77 @@
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];
}
};
+342
View File
@@ -0,0 +1,342 @@
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');
}
this.map_.getEvents().register('click', this.clickHandler, 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_.getPixelForLoc(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];
}
};
+46
View File
@@ -0,0 +1,46 @@
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(', '));
}
}
};
+83
View File
@@ -0,0 +1,83 @@
goog.provide('ol.event.Drag');
goog.require('ol.event');
goog.require('ol.event.ISequence');
goog.require('goog.functions');
goog.require('goog.fx.Dragger');
goog.require('goog.fx.DragEvent');
goog.require('goog.fx.Dragger.EventType');
/**
* Event sequence that provides a 'dragstart', 'drag' and 'dragend' events.
* Event objects of the 'drag' events have 'deltaX' and 'deltaY' values with
* the relative pixel movement since the previous 'drag' or 'dragstart' event.
*
* @constructor
* @param {ol.event.Events} target The Events instance that handles events.
* @implements {ol.event.ISequence}
* @export
*/
ol.event.Drag = function(target) {
var previousX = 0, previousY = 0,
element = target.getElement(),
dragger = new goog.fx.Dragger(element);
/**
* @private
* @type {goog.fx.Dragger}
*/
this.dragger_ = dragger;
// We want to swallow the click event that gets fired after dragging.
var newSequence;
function unregisterClickStopper() {
target.unregister('click', goog.functions.FALSE, undefined, true);
}
dragger.defaultAction = function(x, y) {};
dragger.addEventListener(goog.fx.Dragger.EventType.START, function(evt) {
evt.target = element;
evt.type = 'dragstart';
previousX = evt.clientX;
previousY = evt.clientY;
newSequence = true;
target.triggerEvent(evt.type, evt);
});
dragger.addEventListener(goog.fx.Dragger.EventType.DRAG, function(evt) {
evt.target = element;
evt.deltaX = evt.clientX - previousX;
evt.deltaY = evt.clientY - previousY;
previousX = evt.clientX;
previousY = evt.clientY;
if (newSequence) {
// Once we are in the drag sequence, we know that we need to
// get rid of the click event that gets fired when we are done
// dragging.
target.register('click', goog.functions.FALSE, undefined, true);
newSequence = false;
}
target.triggerEvent(evt.type, evt);
});
dragger.addEventListener(goog.fx.Dragger.EventType.END, function(evt) {
evt.target = element;
evt.type = 'dragend';
target.triggerEvent(evt.type, evt);
// Unregister the click stopper in the next cycle
window.setTimeout(unregisterClickStopper, 0);
});
// Don't swallow the click event if our sequence cancels early.
dragger.addEventListener(
goog.fx.Dragger.EventType.EARLY_CANCEL, unregisterClickStopper
);
};
/** @inheritDoc */
ol.event.Drag.prototype.destroy = function() {
this.dragger_.dispose();
delete this.dragger_;
};
ol.event.addSequenceProvider('drag', ol.event.Drag);
+322
View File
@@ -0,0 +1,322 @@
goog.provide('ol.event');
goog.provide('ol.event.Events');
goog.require('goog.object');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.events.EventTarget');
goog.require('goog.events.KeyCodes');
goog.require('goog.style');
/**
* @enum {Object}
*/
ol.event.SEQUENCE_PROVIDER_MAP = {};
/**
* @param {string} name
* @param {Function} Sequence
*/
ol.event.addSequenceProvider = function(name, Sequence) {
ol.event.SEQUENCE_PROVIDER_MAP[name] = Sequence;
};
/**
* Determine whether event was caused by a single touch
*
* @param {!Event} evt
* @return {boolean}
*/
ol.event.isSingleTouch = function(evt) {
return !!(evt.touches && evt.touches.length == 1);
};
/**
* Determine whether event was caused by a multi touch
*
* @param {!Event} evt
* @return {boolean}
*/
ol.event.isMultiTouch = function(evt) {
return !!(evt.touches && evt.touches.length > 1);
};
/**
* Is the event a keyboard event with Enter or Space pressed?
*
* @param {!Event} evt
* @return {boolean}
*/
ol.event.isEnterOrSpace = function(evt) {
return evt.type === "keypress" &&
(evt.keyCode === goog.events.KeyCodes.ENTER ||
evt.keyCode === goog.events.KeyCodes.SPACE ||
evt.keyCode === goog.events.KeyCodes.MAC_ENTER);
};
/**
* Construct an ol.event.Events instance.
*
* @constructor
* @extends {goog.events.EventTarget}
* @param {Object} object The object we are creating this instance for.
* @param {!Element=} opt_element An optional element that we want to
* listen to browser events on.
* @param {boolean=} opt_includeXY Should the 'xy' property automatically be
* created for browser pointer events? In general, this should be false. If
* it is true, then pointer events will automatically generate an 'xy'
* property on the event object that is passed, which represents the
* relative position of the pointer to the {@code element}. Default is
* false.
* @param {Array.<String>=} opt_sequences Event sequences to register with
* this Events instance.
*/
ol.event.Events = function(object, opt_element, opt_includeXY, opt_sequences) {
goog.base(this);
/**
* @private
* @type {Object}
* The object that this instance is bound to.
*/
this.object_ = object;
/**
* @private
* @type {Element}
* The element that this instance listens to mouse events on.
*/
this.element_ = null;
/**
* @private
* @type {boolean}
*/
this.includeXY_ = goog.isDef(opt_includeXY) ? opt_includeXY : false;
/**
* @private
* @type {Array.<String>}
*/
this.sequenceProviders_ = goog.isDef(opt_sequences) ? opt_sequences : [];
/**
* @private
* @type {Array.<ol.event.ISequence>}
*/
this.sequences_ = [];
/**
* @private
* @type {Object}
*/
this.listenerCount_ = {};
if (goog.isDef(opt_element)) {
this.setElement(opt_element);
}
};
goog.inherits(ol.event.Events, goog.events.EventTarget);
/**
* @return {Object} The object that this instance is bound to.
*/
ol.event.Events.prototype.getObject = function() {
return this.object_;
};
/**
* @param {boolean} includeXY
*/
ol.event.Events.prototype.setIncludeXY = function(includeXY) {
this.includeXY_ = includeXY;
};
/**
* @return {Element} The element that this instance currently
* listens to browser events on.
*/
ol.event.Events.prototype.getElement = function() {
return this.element_;
};
/**
* Attach this instance to a DOM element. When called, all browser events fired
* on the provided element will be relayed by this instance.
*
* @param {Element|Node} element A DOM element to attach
* browser events to. If called without this argument, all browser events
* will be detached from the element they are currently attached to.
*/
ol.event.Events.prototype.setElement = function(element) {
var types = goog.events.EventType, t;
if (this.element_) {
for (t in types) {
goog.events.unlisten(
this.element_, types[t], this.handleBrowserEvent, true, this
);
}
this.destroySequences();
delete this.element_;
}
this.element_ = /** @type {Element} */ (element) || null;
if (goog.isDefAndNotNull(element)) {
this.createSequences();
for (t in types) {
goog.events.listen(
element, types[t], this.handleBrowserEvent, true, this
);
}
}
};
ol.event.Events.prototype.createSequences = function() {
for (var i=0, ii=this.sequenceProviders_.length; i<ii; ++i) {
this.sequences_.push(
new ol.event.SEQUENCE_PROVIDER_MAP[this.sequenceProviders_[i]](
this
)
);
}
};
ol.event.Events.prototype.destroySequences = function() {
for (var i=this.sequences_.length-1; i>=0; --i) {
this.sequences_[i].destroy();
}
this.sequences_ = [];
};
/**
* Register a listener for an event.
*
* When the event is triggered, the 'listener' function will be called, in the
* context of 'scope'. Imagine we were to register an event, specifying an
* ol.Bounds instance as 'scope'. When the event is triggered, the context in
* the listener function will be our Bounds instance. This means that within
* our listener function, we can access the properties and methods of the
* Bounds instance through the 'this' keyword. So our listener could execute
* something like:
*
* var leftStr = "Left: " + this.minX();
*
* @param {string} type Name of the event to register.
* @param {Function} listener The callback function.
* @param {Object=} opt_scope The object to bind the context to for the
* listener. If no scope is specified, default is this intance's 'object'
* property.
* @param {boolean=} opt_priority Register the listener as priority listener,
* so it gets executed before other listeners? Default is false.
*/
ol.event.Events.prototype.register = function(type, listener, opt_scope,
opt_priority) {
goog.events.listen(
this, type, listener, opt_priority, opt_scope || this.object_
);
this.listenerCount_[type] = (this.listenerCount_[type] || 0) + 1;
};
/**
* Unregister a listener for an event
*
* @param {string} type Name of the event to unregister
* @param {Function} listener The callback function.
* @param {Object=} opt_scope The object to bind the context to for the
* listener. If no scope is specified, default is the event's default
* scope.
* @param {boolean=} opt_priority Listener was registered as priority listener,
* so it gets executed before other listeners. Default is false.
*/
ol.event.Events.prototype.unregister = function(type, listener, opt_scope,
opt_priority) {
var removed = goog.events.unlisten(
this, type, listener, opt_priority, opt_scope || this.object_
);
if (removed) {
this.listenerCount_[type] = (this.listenerCount_[type] || 1) - 1;
}
};
/**
* Trigger a specified registered event.
*
* @param {string} type The type of the event to trigger.
* @param {Object=} opt_evt The event object that will be passed to listeners.
* This object will always have a 'type' property with the event type and
* an 'object' property referencing this Events instance.
*
* @return {boolean} The last listener return. If a listener returns false,
* the chain of listeners will stop getting called. Returns undefined if
* called for an event type that has no listeners.
*/
ol.event.Events.prototype.triggerEvent = function(type, opt_evt) {
var returnValue;
if (this.listenerCount_[type] > 0) {
var listeners = goog.events.getListeners(this, type, true)
.concat(goog.events.getListeners(this, type, false));
if (arguments.length === 1) {
opt_evt = {'type': type};
}
opt_evt['object'] = this.object_;
for (var i=0, ii=listeners.length; i<ii; ++i) {
returnValue = listeners[i].handleEvent(opt_evt);
if (returnValue === false) {
break;
}
}
}
return returnValue;
};
/**
* Prepares browser events before they are dispatched. This takes care to set a
* property 'xy' on the event with the current pointer position (if
* {@code includeXY} is set to true), and normalizes clientX and clientY for
* multi-touch events.
*
* @param {Event} evt Event object.
*/
ol.event.Events.prototype.handleBrowserEvent = function(evt) {
var type = evt.type;
if (this.listenerCount_[type] > 0) {
// add clientX & clientY to all events - corresponds to average x, y
var touches = evt.touches;
if (touches && touches[0]) {
var x = 0;
var y = 0;
var num = touches.length;
var touch;
for (var i=0; i<num; ++i) {
touch = touches[i];
x += touch.clientX;
y += touch.clientY;
}
evt.clientX = x / num;
evt.clientY = y / num;
}
if (this.includeXY_) {
evt.xy = this.getPointerPosition(evt);
}
this.triggerEvent(evt.type, evt);
}
};
/**
* Get the mouse position relative to this Event instance's target element for
* the provided event.
*
* @param {Event} evt Event object
*/
ol.event.Events.prototype.getPointerPosition = function(evt) {
return goog.style.getRelativePosition(evt, this.element_);
};
/**
* Destroy this Events instance.
*/
ol.event.Events.prototype.destroy = function() {
this.setElement(null);
goog.object.clear(this);
};
+22
View File
@@ -0,0 +1,22 @@
goog.provide('ol.event.ISequence');
/**
* Interface for event sequences. Event sequences map sequences of native
* browser events to high level events that the sequence provides.
*
* Implementations are expected to call {@code triggerEvent} on the
* {@code target} to to fire their high level events.
*
* Implementations can expect the {@code target}'s {@code getElement} method
* to return an {Element} at construction time.
*
* @interface
* @param {ol.event.Events} target The Events instance that receives the
* sequence's events.
*/
ol.event.ISequence = function(target) {};
/**
* Destroys the sequence
*/
ol.event.ISequence.prototype.destroy = function() {};
+45
View File
@@ -0,0 +1,45 @@
goog.provide('ol.event.Scroll');
goog.require('ol.event.ISequence');
goog.require('ol.event');
goog.require('goog.events.MouseWheelHandler');
/**
* Event sequence that provides a 'scroll' event. Event objects have 'deltaX'
* and 'deltaY' values with the scroll delta since the previous 'scroll' event.
*
* @constructor
* @param {ol.event.Events} target The Events instance that handles events.
* @implements {ol.event.ISequence}
* @export
*/
ol.event.Scroll = function(target) {
var element = target.getElement(),
handler = new goog.events.MouseWheelHandler(element);
/**
* @private
* @type {goog.events.MouseWheelHandler}
*/
this.handler_ = handler;
handler.addEventListener(
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL,
function(evt) {
evt.type = 'scroll';
evt.target = element;
target.triggerEvent(evt.type, evt);
}
);
};
/** @inheritDoc */
ol.event.Scroll.prototype.destroy = function() {
this.handler_.dispose();
delete this.handler_;
};
ol.event.addSequenceProvider('scroll', ol.event.Scroll);
+198
View File
@@ -0,0 +1,198 @@
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;
};
+58
View File
@@ -0,0 +1,58 @@
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;
};
+27
View File
@@ -0,0 +1,27 @@
goog.provide('ol.geom.IGeometry');
//goog.require('ol.geom.Point');
//goog.require('ol.Bounds');
/**
* Interface for geometry classes forcing ol.geom.* classes to implement
* expected functionality.
*
* @interface
*/
ol.geom.IGeometry = function(){};
/**
* @return {ol.geom.Point} The centroid of the geometry.
*/
ol.geom.IGeometry.prototype.getCentroid = function(){};
/**
* @return {ol.Bounds|undefined} The centroid of the geometry.
*/
ol.geom.IGeometry.prototype.getBounds = function(){};
/**
* @return {number} The area of the geometry.
*/
ol.geom.IGeometry.prototype.getArea = function(){};
+76
View File
@@ -0,0 +1,76 @@
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();
};
+61
View File
@@ -0,0 +1,61 @@
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);
};
+61
View File
@@ -0,0 +1,61 @@
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);
};
+163
View File
@@ -0,0 +1,163 @@
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;
};
+74
View File
@@ -0,0 +1,74 @@
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();
};
+160
View File
@@ -0,0 +1,160 @@
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');
/**
* @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_ = [];
var target = document.createElement("div");
target.className = "ol-renderer-composite";
target.style.position = "absolute";
target.style.height = "100%";
target.style.width = "100%";
container.appendChild(target);
/**
* @type Element
* @private
*/
this.target_ = target;
};
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) {
// TODO: deal with layer order and removal
for (var i=0, ii=layers.length; i<ii; ++i) {
this.getOrCreateRenderer(layers[i], i).draw(center, resolution);
}
this.renderedCenter_ = center;
this.renderedResolution_ = resolution;
};
/**
* @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
*/
ol.renderer.Composite.prototype.getRenderer = function(layer) {
function finder(candidate) {
return candidate.getLayer() === layer;
}
return goog.array.find(this.renderers_, finder);
};
/**
* @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);
return new Renderer(this.target_, layer);
};
/**
* 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);
+71
View File
@@ -0,0 +1,71 @@
goog.provide('ol.renderer.LayerRenderer');
/**
* 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 {!ol.layer.Layer}
* @protected
*/
this.layer_ = layer;
var target = goog.dom.createDom('div', {
'class': 'ol-renderer-layer',
'style': 'position:absolute;height:1px:width:1px'
});
goog.dom.appendChild(container, target);
/**
* @type Element
* @protected
*/
this.target_ = target;
};
/**
* 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;
};
+117
View File
@@ -0,0 +1,117 @@
goog.provide('ol.renderer.MapRenderer');
goog.require('goog.style');
/**
* @constructor
* @param {!Element} container
*/
ol.renderer.MapRenderer = function(container) {
/**
* @type !Element
* @protected
*/
this.container_ = container;
/**
* @type {ol.Loc}
* @protected
*/
this.renderedCenter_;
/**
* @type {number}
* @protected
*/
this.renderedResolution_;
};
/**
* @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) {
};
/**
* 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;
};
/**
* @param {goog.math.Coordinate|{x: number, y: number}} pixel
* @return {ol.Loc}
*/
ol.renderer.MapRenderer.prototype.getLocForPixel = function(pixel) {
var center = this.renderedCenter_,
resolution = this.renderedResolution_,
size = goog.style.getSize(this.container_);
return center.add(
(pixel.x - size.width/2) * resolution,
(size.height/2 - pixel.y) * resolution
);
};
/**
* @param {ol.Loc} loc
* @return {{x: number, y: number}}
*/
ol.renderer.MapRenderer.prototype.getPixelForLoc = function(loc) {
var center = this.renderedCenter_,
resolution = this.renderedResolution_,
size = this.getSize();
return {
x: (size.width*resolution/2 + loc.getX() - center.getX())/resolution,
y: (size.height*resolution/2 - loc.getY() + center.getY())/resolution
};
};
/**
* @return {goog.math.Size} The currently rendered map size in pixels.
*/
ol.renderer.MapRenderer.prototype.getSize = function() {
return goog.style.getSize(this.container_);
};
+338
View File
@@ -0,0 +1,338 @@
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');
/**
* 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 {number}
*/
this.xRight_ = layer.getXRight() ? 1 : -1;
/**
* @type {number}
*/
this.yDown_ = layer.getYDown() ? 1 : -1;
/**
* @type {number|undefined}
* @private
*/
this.renderedResolution_ = undefined;
/**
* @type {number|undefined}
* @private
*/
this.renderedTop_ = undefined;
/**
* @type {number|undefined}
* @private
*/
this.renderedRight_ = undefined;
/**
* @type {number|undefined}
* @private
*/
this.renderedBottom_ = undefined;
/**
* @type {number|undefined}
* @private
*/
this.renderedLeft_ = undefined;
/**
* @type {number|undefined}
* @private
*/
this.renderedZ_ = undefined;
/**
* @type {goog.math.Size}
* @private
*/
this.containerSize_ = null;
};
goog.inherits(ol.renderer.TileLayerRenderer, ol.renderer.LayerRenderer);
/**
* @param {number} resolution
* @return {Array.<number>}
*/
ol.renderer.TileLayerRenderer.prototype.getPreferredResAndZ_ = function(resolution) {
var minDiff = Number.POSITIVE_INFINITY;
var candidate, diff, z, r;
for (var i=0, ii=this.layerResolutions_.length; i<ii; ++i) {
// assumes sorted resolutions
candidate = this.layerResolutions_[i];
diff = Math.abs(resolution - candidate);
if (diff < minDiff) {
z = i;
r = candidate;
minDiff = diff;
} else {
break;
}
}
return [r, z];
};
/**
* @return {goog.math.Size}
*/
ol.renderer.TileLayerRenderer.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_;
};
/**
* Tiles rendered at the current resolution;
* @type {Object}
*/
ol.renderer.TileLayerRenderer.prototype.renderedTiles_ = {};
/**
* Render the layer.
*
* @param {!ol.Loc} center
* @param {number} resolution
*/
ol.renderer.TileLayerRenderer.prototype.draw = function(center, resolution) {
if (resolution !== this.renderedResolution_) {
this.changeResolution_(center, resolution);
}
var pair = this.getPreferredResAndZ_(resolution);
var tileResolution = pair[0];
var tileZ = pair[1];
var scale = resolution / tileResolution;
var pxMapSize = this.getContainerSize_();
var xRight = this.xRight_;
var yDown = this.yDown_;
var halfMapWidth = (resolution * pxMapSize.width) / 2;
var halfMapHeight = (resolution * pxMapSize.height) / 2;
var centerX = center.getX();
var centerY = center.getY();
var mapMinX = centerX - halfMapWidth;
var mapMaxY = centerY + halfMapHeight;
var pxOffsetX = Math.round((mapMinX - this.tileOrigin_[0]) / resolution);
var pxOffsetY = Math.round((this.tileOrigin_[1] - mapMaxY) / resolution);
// this gives us the desired size in fractional pixels
var pxTileWidth = this.tileSize_[0] / scale;
var pxTileHeight = this.tileSize_[1] / scale;
// this is the index of the top left tile
var leftTileX = Math.floor(xRight * pxOffsetX / pxTileWidth);
var topTileY = Math.floor(yDown * pxOffsetY / pxTileHeight);
var pxMinX;
if (xRight > 0) {
pxMinX = Math.round(leftTileX * pxTileWidth) - pxOffsetX;
} else {
pxMinX = Math.round((-leftTileX-1) * pxTileWidth) - pxOffsetX;
}
var pxMinY;
if (yDown > 0) {
pxMinY = Math.round(topTileY * pxTileHeight) - pxOffsetY;
} else {
pxMinY = Math.round((-topTileY-1) * pxTileHeight) - pxOffsetY;
}
var pxTileLeft = pxMinX;
var pxTileTop = pxMinY;
var numTilesWide = Math.ceil(pxMapSize.width / pxTileWidth);
var numTilesHigh = Math.ceil(pxMapSize.height / pxTileHeight);
// assume a buffer of zero for now
if (pxMinX < 0) {
numTilesWide += 1;
}
if (pxMinY < 0) {
numTilesHigh += 1;
}
var tileX, tileY, tile, img, pxTileRight, pxTileBottom, xyz, append;
var fragment = document.createDocumentFragment();
var newTiles = false;
for (var i=0; i<numTilesWide; ++i) {
pxTileTop = pxMinY;
tileX = leftTileX + (i * xRight);
if (scale !== 1) {
pxTileRight = Math.round(pxMinX + ((i+1) * pxTileWidth));
} else {
pxTileRight = pxTileLeft + pxTileWidth;
}
for (var j=0; j<numTilesHigh; ++j) {
append = false;
tileY = topTileY + (j * yDown);
xyz = tileX + "," + tileY + "," + tileZ;
if (scale !== 1) {
pxTileBottom = Math.round(pxMinY + ((j+1) * pxTileHeight));
} else {
pxTileBottom = pxTileTop + pxTileHeight;
}
img = null;
tile = this.renderedTiles_[xyz];
if (!tile) {
tile = this.layer_.getTileForXYZ(tileX, tileY, tileZ);
if (tile) {
if (!tile.isLoaded() && !tile.isLoading()) {
tile.load();
}
this.renderedTiles_[xyz] = tile;
img = tile.getImg();
goog.dom.appendChild(fragment, img);
newTiles = true;
}
} else {
img = tile.getImg();
}
if (img) {
img.style.top = pxTileTop + "px";
img.style.left = pxTileLeft + "px";
if (scale !== 1) {
img.style.height = (pxTileRight - pxTileLeft) + "px";
img.style.width = (pxTileBottom - pxTileTop) + "px";
}
}
pxTileTop = pxTileBottom;
}
pxTileLeft = pxTileRight;
}
if (newTiles) {
this.target_.appendChild(fragment);
}
this.renderedResolution_ = resolution;
this.renderedTop_ = topTileY;
this.renderedRight_ = tileX;
this.renderedBottom_ = tileY;
this.renderedLeft_ = leftTileX;
this.renderedZ_ = tileZ;
this.removeInvisibleTiles_();
};
/**
* Get rid of tiles outside the rendered extent.
*/
ol.renderer.TileLayerRenderer.prototype.removeInvisibleTiles_ = function() {
var index, prune, x, y, z, tile;
var xRight = (this.xRight_ > 0);
var yDown = (this.yDown_ > 0);
var top = this.renderedTop_;
var right = this.renderedRight_;
var bottom = this.renderedBottom_;
var left = this.renderedLeft_;
for (var xyz in this.renderedTiles_) {
index = xyz.split(",");
x = +index[0];
y = +index[1];
z = +index[2];
prune = this.renderedZ_ !== z ||
// beyond on the left side
(xRight ? x < left : x > left) ||
// beyond on the right side
(xRight ? x > right : x < right) ||
// above
(yDown ? y < top : y > top) ||
// below
(yDown ? y > bottom : y < bottom);
if (prune) {
tile = this.renderedTiles_[xyz];
delete this.renderedTiles_[xyz];
this.target_.removeChild(tile.getImg());
}
}
};
/**
* Deal with changes in resolution.
* TODO: implement the animation
*
* @param {ol.Loc} center New center.
* @param {number} resolution New resolution.
*/
ol.renderer.TileLayerRenderer.prototype.changeResolution_ = function(center, resolution) {
this.renderedTiles_ = {};
goog.dom.removeChildren(this.target_);
};
/**
* 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);