Change the inhertance of MultiPoint/multipoint.

This commit is contained in:
Marc Jansen
2012-06-21 15:55:37 +02:00
parent 0374d1abc7
commit 745ae25b6b
2 changed files with 16 additions and 28 deletions

View File

@@ -2,13 +2,9 @@ goog.provide('ol.geom.multipoint');
goog.require('ol.geom.MultiPoint'); goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.point'); goog.require('ol.geom.point');
goog.require('ol.geom.collection');
goog.require('ol.projection'); goog.require('ol.projection');
///**
// * @typedef {ol.MultiPointLike|Array.<number>|Object} point Point.
// */
//ol.PointLike;
/** /**
* @export * @export
* @param {Array.<ol.PointLike>} opt_arg Point. * @param {Array.<ol.PointLike>} opt_arg Point.
@@ -45,7 +41,7 @@ ol.geom.multipoint = function(opt_arg){
var mp = new ol.geom.MultiPoint(points); var mp = new ol.geom.MultiPoint(points);
return mp; return mp;
}; };
goog.inherits(ol.geom.multipoint, ol.geom.geometry); goog.inherits(ol.geom.multipoint, ol.geom.collection);
/** /**
* @export * @export
@@ -56,7 +52,7 @@ ol.geom.MultiPoint.prototype.points = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
var points = [], var points = [],
allValid = false; allValid = false;
goog.array.every(opt_arg, function(spec){ allValid = goog.array.every(opt_arg, function(spec){
var p = ol.geom.point(spec); var p = ol.geom.point(spec);
if (p instanceof ol.geom.Point) { if (p instanceof ol.geom.Point) {
points.push(p); points.push(p);
@@ -68,11 +64,11 @@ ol.geom.MultiPoint.prototype.points = function(opt_arg){
if (!allValid) { if (!allValid) {
points = []; points = [];
} }
this.setPoints(points); this.setComponents(points);
return this; return this;
} }
else { else {
return this.getPoints(); return this.getComponents();
} }
}; };
@@ -84,8 +80,7 @@ ol.geom.MultiPoint.prototype.points = function(opt_arg){
* @return {ol.geom.MultiPoint} The MultiPoint instance. * @return {ol.geom.MultiPoint} The MultiPoint instance.
*/ */
ol.geom.MultiPoint.prototype.add = function(point, opt_index){ ol.geom.MultiPoint.prototype.add = function(point, opt_index){
var index = this.points_.length, var index = this.getPoints().length,
allValid = false,
p = ol.geom.point(point); p = ol.geom.point(point);
if (arguments.length == 2 && goog.isDef(opt_index)) { if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index; index = opt_index;
@@ -102,7 +97,7 @@ ol.geom.MultiPoint.prototype.add = function(point, opt_index){
* @return {ol.geom.MultiPoint} The MultiPoint instance. * @return {ol.geom.MultiPoint} The MultiPoint instance.
*/ */
ol.geom.MultiPoint.prototype.addAll = function(points, opt_index){ ol.geom.MultiPoint.prototype.addAll = function(points, opt_index){
var index = this.points_.length, var index = this.getPoints().length,
p; p;
if (arguments.length == 2 && goog.isDef(opt_index)) { if (arguments.length == 2 && goog.isDef(opt_index)) {
@@ -126,8 +121,7 @@ ol.geom.MultiPoint.prototype.addAll = function(points, opt_index){
* @return {ol.geom.MultiPoint} The MultiPoint instance. * @return {ol.geom.MultiPoint} The MultiPoint instance.
*/ */
ol.geom.MultiPoint.prototype.remove = function(points){ ol.geom.MultiPoint.prototype.remove = function(points){
var pointArr = [], var pointArr = [];
allValid = false;
if (!goog.isArray(points)) { if (!goog.isArray(points)) {
pointArr.push(points); pointArr.push(points);
} else { } else {

View File

@@ -1,27 +1,21 @@
goog.provide('ol.geom.MultiPoint'); goog.provide('ol.geom.MultiPoint');
goog.require('goog.array'); goog.require('goog.array');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Collection');
goog.require('ol.Projection');
/** /**
* Creates ol.geom.MultiPoint objects. * Creates ol.geom.MultiPoint objects.
* *
* @extends {ol.geom.Geometry} * @extends {ol.geom.Collection}
* @param {Array.<ol.geom.Point>} points An array of points. * @param {Array.<ol.geom.Point>} points An array of points.
* *
* @constructor * @constructor
*/ */
ol.geom.MultiPoint = function(points) { ol.geom.MultiPoint = function(points) {
/** this.setComponents(points);
* @private
* @type {Array.<ol.geom.Point>}
*/
this.points_ = points;
}; };
goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry); goog.inherits(ol.geom.MultiPoint, ol.geom.Collection);
/** /**
* Sets the MultiPoint's points. * Sets the MultiPoint's points.
@@ -29,7 +23,7 @@ goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry);
* @return {Array.<ol.geom.Point>} An array of points. * @return {Array.<ol.geom.Point>} An array of points.
*/ */
ol.geom.MultiPoint.prototype.getPoints = function() { ol.geom.MultiPoint.prototype.getPoints = function() {
return this.points_; return this.getComponents();
}; };
/** /**
@@ -38,7 +32,7 @@ ol.geom.MultiPoint.prototype.getPoints = function() {
* @param {Array.<ol.geom.Point>} points An array of points. * @param {Array.<ol.geom.Point>} points An array of points.
*/ */
ol.geom.MultiPoint.prototype.setPoints = function(points) { ol.geom.MultiPoint.prototype.setPoints = function(points) {
this.points_ = points; this.setComponents(points);
}; };
/** /**
@@ -48,7 +42,7 @@ ol.geom.MultiPoint.prototype.setPoints = function(points) {
* @param {number} index The index where to add. * @param {number} index The index where to add.
*/ */
ol.geom.MultiPoint.prototype.addPoint = function(point, index) { ol.geom.MultiPoint.prototype.addPoint = function(point, index) {
goog.array.insertAt(this.points_,point,index); this.addComponent(point, index);
}; };
/** /**
@@ -57,5 +51,5 @@ ol.geom.MultiPoint.prototype.addPoint = function(point, index) {
* @param {ol.geom.Point} point A point to be removed. * @param {ol.geom.Point} point A point to be removed.
*/ */
ol.geom.MultiPoint.prototype.removePoint = function(point) { ol.geom.MultiPoint.prototype.removePoint = function(point) {
goog.array.remove(this.points_, point); this.removeComponent(point);
}; };