[OpenLayers-Commits] r2327 - sandbox/vector-2.4/lib/OpenLayers/Feature

commits at openlayers.org commits at openlayers.org
Mon Mar 5 12:51:34 EST 2007


Author: tschaub
Date: 2007-03-05 12:51:24 -0500 (Mon, 05 Mar 2007)
New Revision: 2327

Added:
   sandbox/vector-2.4/lib/OpenLayers/Feature/Vector.js
Log:
adding Feature/Vector.js

Added: sandbox/vector-2.4/lib/OpenLayers/Feature/Vector.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/Feature/Vector.js	                        (rev 0)
+++ sandbox/vector-2.4/lib/OpenLayers/Feature/Vector.js	2007-03-05 17:51:24 UTC (rev 2327)
@@ -0,0 +1,249 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+// TRASH THIS
+OpenLayers.State = {
+    /** states */
+    UNKNOWN: 'Unknown',
+    INSERT: 'Insert',
+    UPDATE: 'Update',
+    DELETE: 'Delete'
+}
+
+/**
+ * @class
+ * 
+ * @requires OpenLayers/Util.js
+ */
+OpenLayers.Feature = OpenLayers.Class.create();
+OpenLayers.Feature.prototype =
+  OpenLayers.Class.inherit( OpenLayers.Feature, {
+
+    /** @type String */
+    fid: null,
+    
+    /** @type OpenLayers.Geometry */
+    geometry:null,
+
+    /** @type array */
+    attributes: null,
+
+    /** @type strinng */
+    state: null,
+    
+    /** 
+     * @constructor
+     * 
+     * @param {OpenLayers.Layer} layer
+     * @param {OpenLayers.Geometry} geometry
+     * @param {Object} data
+     */
+    initialize: function(layer, geometry, data) {
+        OpenLayers.Feature.prototype.initialize.apply(this, [layer, null, data]);
+        this.lonlat = null;
+        this.setGeometry(geometry);
+        this.state = null;
+    },
+    
+        
+   /**
+    * @returns An exact clone of this OpenLayers.Feature
+    * @type OpenLayers.Feature
+    */
+    clone: function (obj) {
+        if (obj == null) {
+            obj = new OpenLayers.Feature(null, this.geometry.clone(), this.data);
+        } 
+        
+        // catch any randomly tagged-on properties
+        OpenLayers.Util.applyDefaults(obj, this);
+        
+        return obj;
+    },
+
+    /**
+     * 
+     */
+    destroy: function() {
+        this.geometry = null;
+        OpenLayers.Feature.prototype.destroy.apply(this, arguments);
+    },
+    
+    /**
+     * HACK - we need to rewrite this for non-point geometry
+     * @returns null - we need to rewrite this for non-point geometry
+     * @type Boolean
+     */
+    onScreen:function() {
+        return null;
+    },
+    
+    /**
+     *
+     * HACK - we need to decide if all vector features should be able to
+     * create markers
+     * 
+     * @returns null
+     * 
+     * @type OpenLayers.Marker
+     */
+    createMarker: function() {
+        return null;
+    },
+
+    /**
+     * HACK - we need to decide if all vector features should be able to
+     * delete markers
+     * 
+     * If user overrides the createMarker() function, s/he should be able
+     *   to also specify an alternative function for destroying it
+     */
+    destroyMarker: function() {
+        // pass
+    },
+
+    /**
+     * HACK - we need to decide if all vector features should be able to
+     * create popups
+     * 
+     * @returns null
+     */
+    createPopup: function() {
+        return null;
+    },
+
+    /**
+     * Set a feature id to the feature
+     *
+     * @param {String} feature id to set
+     */
+    setFid: function(fid) {
+        this.fid = fid;
+    },
+
+    /**
+     * Set a geometry to the feature
+     *
+     * @param {OpenLayers.Geometry} geometry to set
+     */
+    setGeometry: function(geometry) {
+        if(geometry){
+            this.geometry = geometry;
+            this.geometry.feature = this;
+            this._setGeometryFeatureReference(this.geometry, this);
+        }
+    },
+    
+    /**
+     * Sets recursively the reference to the feature in the geometry
+     *
+     * @param {OpenLayers.Geometry}
+     * @param {OpenLayers.Feature}
+     */
+    _setGeometryFeatureReference: function(geometry, feature) {
+        geometry.feature = feature;
+        if (geometry.components) {
+            for (var i = 0; i < geometry.components.length; i++) {
+                this._setGeometryFeatureReference(geometry.components[i], feature);
+            }
+        }
+    },
+    
+    /**
+     * Adds attributes an attributes object to the feature.
+     * (should not be in geometry but in feature class)
+     *
+     * @param {Attributes} attributes
+     */
+    setAttributes: function(attributes) {
+        this.attributes=attributes;
+    },
+
+    /**
+     * Takes an lonLat point and returns true if the feature is at this location.
+     * @param {OpenLayers.LonLat} lonlat
+     * @param toleranceLon Optional tolerance in Geometric Coords
+     * @param toleranceLat Optional tolerance in Geographic Coords
+     * @return Boolean
+     */
+    atPoint: function(lonlat,toleranceLon,toleranceLat){
+        var atPoint=false;
+        if(this.geometry){
+            atPoint=this.geometry.atPoint(lonlat,toleranceLon,toleranceLat);
+        }
+        return atPoint;
+    },
+
+    /**
+     * Set geometry style
+     *
+     * @param {OpenLayers.Style} attributes to remove, can be an array
+     */
+    setStyle: function(style) {
+        this.style = style;
+    },
+
+    /**
+     * Get the current geometry style
+     * 
+     */    
+    getStyle: function() {
+        return style;
+    },
+    
+    /**
+     *
+     * HACK - we need to decide if all vector features should be able to
+     * delete popups
+     */
+    destroyPopup: function() {
+        // pass
+    },
+    
+    /**
+     * Sets the new state
+     * @param {String} state
+     */
+    toState: function(state) {
+        if (state == OpenLayers.State.UPDATE) {
+            switch (this.state) {
+                case OpenLayers.State.UNKNOWN:
+                case OpenLayers.State.DELETE:
+                    this.state = state;
+                    break;
+                case OpenLayers.State.UPDATE:
+                case OpenLayers.State.INSERT:
+                    break;
+            }
+        } else if (state == OpenLayers.State.INSERT) {
+            switch (this.state) {
+                case OpenLayers.State.UNKNOWN:
+                    break;
+                default:
+                    this.state = state;
+                    break;
+            }
+        } else if (state == OpenLayers.State.DELETE) {
+            switch (this.state) {
+                case OpenLayers.State.INSERT:
+                    // the feature should be destroyed
+                    break;
+                case OpenLayers.State.DELETE:
+                    break;
+                case OpenLayers.State.UNKNOWN:
+                case OpenLayers.State.UPDATE:
+                    this.state = state;
+                    break;
+            }
+        } else if (state == OpenLayers.State.UNKNOWN) {
+            this.state = state;
+        }
+    },
+    
+    destroy: function() {
+    
+    },
+    
+    CLASS_NAME: "OpenLayers.Feature.Vector"
+});



More information about the Commits mailing list