adding features

This commit is contained in:
Mike Adair
2012-06-20 13:33:20 -04:00
parent d5f9f9e8a4
commit 4ea2fe3701
8 changed files with 332 additions and 2 deletions

89
src/api/feature.js Normal file
View File

@@ -0,0 +1,89 @@
goog.provide('ol.feature');
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 attrs;
/** @type {ol.geom.Geometry|undefined} */
var geom;
/** @type {string|undefined} */
var type;
if (arguments.length == 1) {
if (opt_arg instanceof ol.Feature) {
return opt_arg;
}
else if (goog.isObject(opt_arg)) {
attrs = opt_arg['attrs'];
geom = opt_arg['geom'];
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(attrs)) {
feature.setAttributes(attrs);
}
if (goog.isDef(geom)) {
feature.setGeometry(geom);
}
}
return feature;
};
/**
* @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;
};
/**
* @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);
};
/**
* @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();
}
};