Changeset 8604
- Timestamp:
- 01/08/09 10:05:24 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/topp/editing/lib/OpenLayers/Handler/Path.js
r8595 r8604 69 69 * Add temporary geometries 70 70 */ 71 createFeature: function() { 71 createFeature: function(pixel) { 72 var lonlat = this.control.map.getLonLatFromPixel(pixel); 73 this.point = new OpenLayers.Feature.Vector( 74 new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) 75 ); 72 76 this.line = new OpenLayers.Feature.Vector( 73 new OpenLayers.Geometry.LineString()); 74 this.point = new OpenLayers.Feature.Vector( 75 new OpenLayers.Geometry.Point()); 77 new OpenLayers.Geometry.LineString([this.point.geometry]) 78 ); 76 79 this.layer.addFeatures([this.line, this.point], {silent: true}); 77 80 }, … … 87 90 88 91 /** 89 * Method: destroyPoint92 * Method: removePoint 90 93 * Destroy the temporary point. 91 94 */ 92 destroyPoint: function() {95 removePoint: function() { 93 96 if(this.point) { 94 this.layer. destroyFeatures([this.point]);97 this.layer.removeFeatures([this.point]); 95 98 } 96 99 }, … … 101 104 * the behavior of LinearRing that disregards adding duplicate points. 102 105 */ 103 addPoint: function() { 104 this.line.geometry.addComponent(this.point.geometry.clone(), 105 this.line.geometry.components.length); 106 addPoint: function(pixel) { 107 this.layer.removeFeatures([this.point]); 108 var lonlat = this.control.map.getLonLatFromPixel(pixel); 109 this.point = new OpenLayers.Feature.Vector( 110 new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) 111 ); 112 this.line.geometry.addComponent( 113 this.point.geometry, this.line.geometry.components.length 114 ); 106 115 this.callback("point", [this.point.geometry, this.getGeometry()]); 116 this.drawFeature(); 107 117 }, 108 118 … … 123 133 * Modify the existing geometry given the new point 124 134 */ 125 modifyFeature: function( ) {126 var index = this.line.geometry.components.length - 1;127 var target = this.line.geometry.components[index];128 t arget.x = this.point.geometry.x;129 t arget.y = this.point.geometry.y;130 this. callback("modify", [target, this.point.geometry]);131 this. line.geometry.components[index].clearBounds();135 modifyFeature: function(pixel) { 136 var lonlat = this.control.map.getLonLatFromPixel(pixel); 137 this.point.geometry.x = lonlat.lon; 138 this.point.geometry.y = lonlat.lat; 139 this.callback("modify", [this.point.geometry, this.point.geometry.clone()]); 140 this.point.geometry.clearBounds(); 141 this.drawFeature(); 132 142 }, 133 143 … … 177 187 this.destroyFeature(); 178 188 } 179 this.createFeature(); 189 this.createFeature(evt.xy); 190 } else if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) { 191 this.addPoint(evt.xy); 180 192 } 181 193 this.mouseDown = true; 182 194 this.lastDown = evt.xy; 183 var lonlat = this.control.map.getLonLatFromPixel(evt.xy);184 this.point.geometry.x = lonlat.lon;185 this.point.geometry.y = lonlat.lat;186 this.point.geometry.clearBounds();187 if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) {188 this.addPoint();189 }190 this.drawFeature();191 195 this.drawing = true; 192 196 return false; … … 206 210 mousemove: function (evt) { 207 211 if(this.drawing) { 208 var lonlat = this.map.getLonLatFromPixel(evt.xy);209 this.point.geometry.x = lonlat.lon;210 this.point.geometry.y = lonlat.lat;211 this.point.geometry.clearBounds();212 212 if(this.mouseDown && this.freehandMode(evt)) { 213 this.addPoint( );213 this.addPoint(evt.xy); 214 214 } else { 215 this.modifyFeature( );215 this.modifyFeature(evt.xy); 216 216 } 217 this.drawFeature();218 217 } 219 218 return true; … … 235 234 if(this.drawing) { 236 235 if(this.freehandMode(evt)) { 237 if(this.persist) { 238 this.destroyPoint(); 239 } 236 this.removePoint(); 240 237 this.finalize(); 241 238 } else { 242 239 if(this.lastUp == null) { 243 this.addPoint( );240 this.addPoint(evt.xy); 244 241 } 245 242 this.lastUp = evt.xy; … … 265 262 var index = this.line.geometry.components.length - 1; 266 263 this.line.geometry.removeComponent(this.line.geometry.components[index]); 267 if(this.persist) { 268 this.destroyPoint(); 269 } 264 this.removePoint(); 270 265 this.finalize(); 271 266 } sandbox/topp/editing/lib/OpenLayers/Handler/Polygon.js
r8595 r8604 52 52 * Add temporary geometries 53 53 */ 54 createFeature: function() { 54 createFeature: function(pixel) { 55 var lonlat = this.control.map.getLonLatFromPixel(pixel); 56 this.point = new OpenLayers.Feature.Vector( 57 new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) 58 ); 59 this.line = new OpenLayers.Feature.Vector( 60 new OpenLayers.Geometry.LinearRing([this.point.geometry]) 61 ); 55 62 this.polygon = new OpenLayers.Feature.Vector( 56 new OpenLayers.Geometry.Polygon()); 57 this.line = new OpenLayers.Feature.Vector( 58 new OpenLayers.Geometry.LinearRing()); 59 this.polygon.geometry.addComponent(this.line.geometry); 60 this.point = new OpenLayers.Feature.Vector( 61 new OpenLayers.Geometry.Point()); 63 new OpenLayers.Geometry.Polygon([this.line.geometry]) 64 ); 62 65 this.layer.addFeatures([this.polygon, this.point], {silent: true}); 63 66 }, … … 76 79 * Modify the existing geometry given the new point 77 80 */ 78 modifyFeature: function( ) {79 var index = this.line.geometry.components.length - 2;80 var target = this.line.geometry.components[index];81 t arget.x = this.point.geometry.x;82 t arget.y = this.point.geometry.y;83 this. callback("modify", [target, this.point.geometry]);84 this. line.geometry.components[index].clearBounds();81 modifyFeature: function(pixel) { 82 var lonlat = this.control.map.getLonLatFromPixel(pixel); 83 this.point.geometry.x = lonlat.lon; 84 this.point.geometry.y = lonlat.lat; 85 this.callback("modify", [this.point.geometry, this.point.geometry.clone()]); 86 this.point.geometry.clearBounds(); 87 this.drawFeature(); 85 88 }, 86 89 … … 123 126 var index = this.line.geometry.components.length - 2; 124 127 this.line.geometry.removeComponent(this.line.geometry.components[index]); 125 if(this.persist) { 126 this.destroyPoint(); 127 } 128 this.removePoint(); 128 129 this.finalize(); 129 130 }
