Changeset 7961
- Timestamp:
- 09/05/08 07:32:17 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/camptocamp/unhcr/lib/OpenLayers/Handler/Path.js
r7875 r7961 74 74 this.point = new OpenLayers.Feature.Vector( 75 75 new OpenLayers.Geometry.Point()); 76 this.layer.addFeatures([this.line, this.point], {silent: true}); 76 77 }, 77 78 … … 82 83 destroyFeature: function() { 83 84 OpenLayers.Handler.Point.prototype.destroyFeature.apply(this); 84 if(this.line) {85 this.line.destroy();86 }87 85 this.line = null; 86 }, 87 88 /** 89 * Method: destroyPoint 90 * Destroy the temporary point. 91 */ 92 destroyPoint: function() { 93 if(this.point) { 94 this.layer.destroyFeatures([this.point]); 95 } 88 96 }, 89 97 … … 96 104 this.line.geometry.addComponent(this.point.geometry.clone(), 97 105 this.line.geometry.components.length); 98 this.callback("point", [this.point.geometry ]);106 this.callback("point", [this.point.geometry, this.getGeometry()]); 99 107 }, 100 108 … … 132 140 133 141 /** 134 * Method: geometryClone 135 * Return a clone of the relevant geometry. 142 * Method: getGeometry 143 * Return the sketch geometry. If <multi> is true, this will return 144 * a multi-part geometry. 136 145 * 137 146 * Returns: 138 147 * {<OpenLayers.Geometry.LineString>} 139 148 */ 140 geometryClone: function() { 141 return this.line.geometry.clone(); 149 getGeometry: function() { 150 var geometry = this.line.geometry; 151 if(this.multi) { 152 geometry = new OpenLayers.Geometry.MultiLineString([geometry]); 153 } 154 return geometry; 142 155 }, 143 156 … … 159 172 } 160 173 if(this.lastDown == null) { 174 if(this.persist) { 175 this.destroyFeature(); 176 } 161 177 this.createFeature(); 162 178 } … … 166 182 this.point.geometry.x = lonlat.lon; 167 183 this.point.geometry.y = lonlat.lat; 184 this.point.geometry.clearBounds(); 168 185 if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) { 169 186 this.addPoint(); … … 216 233 if(this.drawing) { 217 234 if(this.freehandMode(evt)) { 235 if(this.persist) { 236 this.destroyPoint(); 237 } 218 238 this.finalize(); 219 239 } else { … … 243 263 var index = this.line.geometry.components.length - 1; 244 264 this.line.geometry.removeComponent(this.line.geometry.components[index]); 265 if(this.persist) { 266 this.destroyPoint(); 267 } 245 268 this.finalize(); 246 269 } sandbox/camptocamp/unhcr/lib/OpenLayers/Handler/Point.js
r7785 r7961 34 34 35 35 /** 36 * Property: multi 37 * {Boolean} Cast features to multi-part geometries before passing to the 38 * layer. Default is false. 39 */ 40 multi: false, 41 42 /** 36 43 * Property: drawing 37 44 * {Boolean} A point is being drawn … … 56 63 */ 57 64 lastUp: null, 65 66 /** 67 * APIProperty: persist 68 * {Boolean} Leave the feature rendered until destroyFeature is called. 69 * Default is false. If set to true, the feature remains rendered until 70 * destroyFeature is called, typically by deactivating the handler or 71 * starting another drawing. 72 */ 73 persist: false, 74 75 /** 76 * Property: layerOptions 77 * {Object} Any optional properties to be set on the sketch layer. 78 */ 79 layerOptions: null, 58 80 59 81 /** … … 90 112 // create temporary vector layer for rendering geometry sketch 91 113 // TBD: this could be moved to initialize/destroy - setting visibility here 92 var options = {114 var options = OpenLayers.Util.extend({ 93 115 displayInLayerSwitcher: false, 94 116 // indicate that the temp vector layer will never be out of range … … 97 119 // correctly 98 120 calculateInRange: function() { return true; } 99 } ;121 }, this.layerOptions); 100 122 this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); 101 123 this.map.addLayer(this.layer); … … 109 131 createFeature: function() { 110 132 this.point = new OpenLayers.Feature.Vector( 111 new OpenLayers.Geometry.Point()); 133 new OpenLayers.Geometry.Point() 134 ); 135 this.layer.addFeatures([this.point], {silent: true}); 112 136 }, 113 137 … … 124 148 this.cancel(); 125 149 } 150 this.destroyFeature(); 126 151 // If a layer's map property is set to null, it means that that layer 127 152 // isn't added to the map. Since we ourself added the layer to the map … … 141 166 */ 142 167 destroyFeature: function() { 143 if(this. point) {144 this. point.destroy();168 if(this.layer) { 169 this.layer.destroyFeatures(); 145 170 } 146 171 this.point = null; … … 150 175 * Method: finalize 151 176 * Finish the geometry and call the "done" callback. 152 */ 153 finalize: function() { 154 this.layer.renderer.clear(); 177 * 178 * Parameters: 179 * cancel - {Boolean} Call cancel instead of done callback. Default is 180 * false. 181 */ 182 finalize: function(cancel) { 183 var key = cancel ? "cancel" : "done"; 155 184 this.drawing = false; 156 185 this.mouseDown = false; 157 186 this.lastDown = null; 158 187 this.lastUp = null; 159 this.callback("done", [this.geometryClone()]); 160 this.destroyFeature(); 188 this.callback(key, [this.geometryClone()]); 189 if(cancel || !this.persist) { 190 this.destroyFeature(); 191 } 161 192 }, 162 193 … … 166 197 */ 167 198 cancel: function() { 168 this.layer.renderer.clear(); 169 this.drawing = false; 170 this.mouseDown = false; 171 this.lastDown = null; 172 this.lastUp = null; 173 this.callback("cancel", [this.geometryClone()]); 174 this.destroyFeature(); 199 this.finalize(true); 175 200 }, 176 201 … … 216 241 217 242 /** 243 * Method: getGeometry 244 * Return the sketch geometry. If <multi> is true, this will return 245 * a multi-part geometry. 246 * 247 * Returns: 248 * {<OpenLayers.Geometry.Point>} 249 */ 250 getGeometry: function() { 251 var geometry = this.point.geometry; 252 if(this.multi) { 253 geometry = new OpenLayers.Geometry.MultiPoint([geometry]); 254 } 255 return geometry; 256 }, 257 258 /** 218 259 * Method: geometryClone 219 260 * Return a clone of the relevant geometry. 220 261 * 221 262 * Returns: 222 * {<OpenLayers.Geometry .Point>}263 * {<OpenLayers.Geometry>} 223 264 */ 224 265 geometryClone: function() { 225 return this. point.geometry.clone();266 return this.getGeometry().clone(); 226 267 }, 227 268 … … 247 288 } 248 289 if(this.lastDown == null) { 290 if(this.persist) { 291 this.destroyFeature(); 292 } 249 293 this.createFeature(); 250 294 } … … 254 298 this.point.geometry.x = lonlat.lon; 255 299 this.point.geometry.y = lonlat.lat; 300 this.point.geometry.clearBounds(); 256 301 this.drawFeature(); 257 302 return false; sandbox/camptocamp/unhcr/lib/OpenLayers/Handler/Polygon.js
r7785 r7961 60 60 this.point = new OpenLayers.Feature.Vector( 61 61 new OpenLayers.Geometry.Point()); 62 this.layer.addFeatures([this.polygon, this.point], {silent: true}); 62 63 }, 63 64 … … 68 69 destroyFeature: function() { 69 70 OpenLayers.Handler.Path.prototype.destroyFeature.apply(this); 70 if(this.polygon) {71 this.polygon.destroy();72 }73 71 this.polygon = null; 74 72 }, … … 94 92 this.layer.drawFeature(this.point, this.style); 95 93 }, 96 94 97 95 /** 98 * Method: geometryClone 99 * Return a clone of the relevant geometry. 96 * Method: getGeometry 97 * Return the sketch geometry. If <multi> is true, this will return 98 * a multi-part geometry. 100 99 * 101 100 * Returns: 102 101 * {<OpenLayers.Geometry.Polygon>} 103 102 */ 104 geometryClone: function() { 105 return this.polygon.geometry.clone(); 103 getGeometry: function() { 104 var geometry = this.polygon.geometry; 105 if(this.multi) { 106 geometry = new OpenLayers.Geometry.MultiPolygon([geometry]); 107 } 108 return geometry; 106 109 }, 107 110 … … 119 122 var index = this.line.geometry.components.length - 2; 120 123 this.line.geometry.removeComponent(this.line.geometry.components[index]); 124 if(this.persist) { 125 this.destroyPoint(); 126 } 121 127 this.finalize(); 122 128 }
