Add MultiPoint and multipoint.
This commit is contained in:
143
src/api/geom/multipoint.js
Normal file
143
src/api/geom/multipoint.js
Normal file
@@ -0,0 +1,143 @@
|
||||
goog.provide('ol.geom.multipoint');
|
||||
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.point');
|
||||
goog.require('ol.projection');
|
||||
|
||||
///**
|
||||
// * @typedef {ol.MultiPointLike|Array.<number>|Object} point Point.
|
||||
// */
|
||||
//ol.PointLike;
|
||||
|
||||
/**
|
||||
* @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.geometry);
|
||||
|
||||
/**
|
||||
* @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;
|
||||
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.setPoints(points);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getPoints();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @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.points_.length,
|
||||
allValid = false,
|
||||
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.points_.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 = [],
|
||||
allValid = false;
|
||||
if (!goog.isArray(points)) {
|
||||
pointArr.push(points);
|
||||
} else {
|
||||
pointArr = points;
|
||||
}
|
||||
|
||||
goog.array.every(pointArr, function(p){
|
||||
this.removePoint(p);
|
||||
return true;
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
};
|
||||
@@ -15,6 +15,7 @@ goog.require("ol.Tile");
|
||||
goog.require("ol.TileSet");
|
||||
goog.require("ol.geom.geometry");
|
||||
goog.require("ol.geom.point");
|
||||
goog.require("ol.geom.multipoint");
|
||||
goog.require('ol.layer.XYZ');
|
||||
goog.require('ol.layer.OSM');
|
||||
goog.require('ol.renderer.TileLayerRenderer');
|
||||
|
||||
61
src/ol/geom/MultiPoint.js
Normal file
61
src/ol/geom/MultiPoint.js
Normal file
@@ -0,0 +1,61 @@
|
||||
goog.provide('ol.geom.MultiPoint');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.Projection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.MultiPoint objects.
|
||||
*
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.MultiPoint = function(points) {
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.geom.Point>}
|
||||
*/
|
||||
this.points_ = points;
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* Sets the MultiPoint's points.
|
||||
*
|
||||
* @return {Array.<ol.geom.Point>} An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.getPoints = function() {
|
||||
return this.points_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the MultiPoint's points.
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.setPoints = function(points) {
|
||||
this.points_ = 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) {
|
||||
goog.array.insertAt(this.points_,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) {
|
||||
goog.array.remove(this.points_, point);
|
||||
};
|
||||
Reference in New Issue
Block a user