Ticket #1698: sketch.patch
| File sketch.patch, 9.6 kB (added by tschaub, 5 months ago) |
|---|
-
lib/OpenLayers/Handler/Point.js
old new 33 33 layer: null, 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 38 45 */ … … 57 64 lastUp: null, 58 65 59 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 /** 60 76 * Constructor: OpenLayers.Handler.Point 61 77 * Create a new point handler. 62 78 * … … 89 105 } 90 106 // create temporary vector layer for rendering geometry sketch 91 107 // TBD: this could be moved to initialize/destroy - setting visibility here 92 var options = {108 var options = OpenLayers.Util.extend({ 93 109 displayInLayerSwitcher: false, 94 110 // indicate that the temp vector layer will never be out of range 95 111 // without this, resolution properties must be specified at the 96 112 // map-level for this temporary layer to init its resolutions 97 113 // correctly 98 114 calculateInRange: function() { return true; } 99 } ;115 }, this.layerOptions); 100 116 this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); 101 117 this.map.addLayer(this.layer); 102 118 return true; … … 108 124 */ 109 125 createFeature: function() { 110 126 this.point = new OpenLayers.Feature.Vector( 111 new OpenLayers.Geometry.Point()); 127 new OpenLayers.Geometry.Point() 128 ); 129 this.layer.addFeatures([this.point]); 112 130 }, 113 131 114 132 /** … … 123 141 if(this.drawing) { 124 142 this.cancel(); 125 143 } 144 this.destroyFeature(); 126 145 // If a layer's map property is set to null, it means that that layer 127 146 // isn't added to the map. Since we ourself added the layer to the map 128 147 // in activate(), we can assume that if this.layer.map is null it means … … 140 159 * Destroy the temporary geometries 141 160 */ 142 161 destroyFeature: function() { 143 if(this.point) { 144 this.point.destroy(); 145 } 162 this.layer.destroyFeatures(); 146 163 this.point = null; 147 164 }, 148 165 149 166 /** 150 167 * Method: finalize 151 168 * Finish the geometry and call the "done" callback. 169 * 170 * Parameters: 171 * cancel - {Boolean} Call cancel instead of done callback. Default is 172 * false. 152 173 */ 153 finalize: function( ) {154 this.layer.renderer.clear();174 finalize: function(cancel) { 175 var key = cancel ? "cancel" : "done"; 155 176 this.drawing = false; 156 177 this.mouseDown = false; 157 178 this.lastDown = null; 158 179 this.lastUp = null; 159 this.callback("done", [this.geometryClone()]); 160 this.destroyFeature(); 180 this.callback(key, [this.geometryClone()]); 181 if(cancel || !this.persist) { 182 this.destroyFeature(); 183 } 161 184 }, 162 185 163 186 /** … … 165 188 * Finish the geometry and call the "cancel" callback. 166 189 */ 167 190 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(); 191 this.finalize(true); 175 192 }, 176 193 177 194 /** … … 215 232 }, 216 233 217 234 /** 235 * Method: getGeometry 236 * Return the sketch geometry. If <multi> is true, this will return 237 * a multi-part geometry. 238 * 239 * Returns: 240 * {<OpenLayers.Geometry.Point>} 241 */ 242 getGeometry: function() { 243 var geometry = this.point.geometry; 244 if(this.multi) { 245 geometry = new OpenLayers.Geometry.MultiPoint([geometry]); 246 } 247 return geometry; 248 }, 249 250 /** 218 251 * Method: geometryClone 219 252 * Return a clone of the relevant geometry. 220 253 * 221 254 * Returns: 222 * {<OpenLayers.Geometry .Point>}255 * {<OpenLayers.Geometry>} 223 256 */ 224 257 geometryClone: function() { 225 return this. point.geometry.clone();258 return this.getGeometry().clone(); 226 259 }, 227 260 228 261 /** … … 246 279 return true; 247 280 } 248 281 if(this.lastDown == null) { 282 if(this.persist) { 283 this.destroyFeature(); 284 } 249 285 this.createFeature(); 250 286 } 251 287 this.lastDown = evt.xy; -
lib/OpenLayers/Handler/Path.js
old new 73 73 new OpenLayers.Geometry.LineString()); 74 74 this.point = new OpenLayers.Feature.Vector( 75 75 new OpenLayers.Geometry.Point()); 76 this.layer.addFeatures([this.line, this.point]); 76 77 }, 77 78 78 79 /** … … 81 82 */ 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; 88 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 } 96 }, 89 97 90 98 /** 91 99 * Method: addPoint … … 95 103 addPoint: function() { 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 101 109 /** … … 131 139 }, 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 144 157 /** … … 158 171 return false; 159 172 } 160 173 if(this.lastDown == null) { 174 if(this.persist) { 175 this.destroyFeature(); 176 } 161 177 this.createFeature(); 162 178 } 163 179 this.mouseDown = true; … … 214 230 this.mouseDown = false; 215 231 if(this.drawing) { 216 232 if(this.freehandMode(evt)) { 233 if(this.persist) { 234 this.destroyPoint(); 235 } 217 236 this.finalize(); 218 237 } else { 219 238 if(this.lastUp == null) { … … 241 260 if(!this.freehandMode(evt)) { 242 261 var index = this.line.geometry.components.length - 1; 243 262 this.line.geometry.removeComponent(this.line.geometry.components[index]); 263 if(this.persist) { 264 this.destroyPoint(); 265 } 244 266 this.finalize(); 245 267 } 246 268 return false; -
lib/OpenLayers/Handler/Polygon.js
old new 59 59 this.polygon.geometry.addComponent(this.line.geometry); 60 60 this.point = new OpenLayers.Feature.Vector( 61 61 new OpenLayers.Geometry.Point()); 62 this.layer.addFeatures([this.polygon, this.point]); 62 63 }, 63 64 64 65 /** … … 67 68 */ 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 }, 75 73 … … 93 91 this.layer.drawFeature(this.polygon, this.style); 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 108 111 /** … … 118 121 // remove the penultimate point 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 } 123 129 return false;
