Ticket #1698: sketch.2.patch
| File sketch.2.patch, 10.4 kB (added by tschaub, 2 years ago) |
|---|
-
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], {silent: true}); 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; -
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 /** 76 * Property: layerOptions 77 * {Object} Any optional properties to be set on the sketch layer. 78 */ 79 layerOptions: null, 80 81 /** 60 82 * Constructor: OpenLayers.Handler.Point 61 83 * Create a new point handler. 62 84 * … … 89 111 } 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 95 117 // without this, resolution properties must be specified at the 96 118 // map-level for this temporary layer to init its resolutions 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); 102 124 return true; … … 108 130 */ 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 114 138 /** … … 123 147 if(this.drawing) { 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 128 153 // in activate(), we can assume that if this.layer.map is null it means … … 140 165 * Destroy the temporary geometries 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; 147 172 }, … … 149 174 /** 150 175 * Method: finalize 151 176 * Finish the geometry and call the "done" callback. 177 * 178 * Parameters: 179 * cancel - {Boolean} Call cancel instead of done callback. Default is 180 * false. 152 181 */ 153 finalize: function( ) {154 this.layer.renderer.clear();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 163 194 /** … … 165 196 * Finish the geometry and call the "cancel" callback. 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 177 202 /** … … 215 240 }, 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 228 269 /** … … 246 287 return true; 247 288 } 248 289 if(this.lastDown == null) { 290 if(this.persist) { 291 this.destroyFeature(); 292 } 249 293 this.createFeature(); 250 294 } 251 295 this.lastDown = evt.xy; … … 253 297 var lonlat = this.map.getLonLatFromPixel(evt.xy); 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; 258 303 }, -
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], {silent: true}); 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; … … 165 181 var lonlat = this.control.map.getLonLatFromPixel(evt.xy); 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(); 170 187 } … … 215 232 this.mouseDown = false; 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 { 220 240 if(this.lastUp == null) { … … 242 262 if(!this.freehandMode(evt)) { 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 } 247 270 return false;
