OpenLayers OpenLayers

Changeset 8604

Show
Ignore:
Timestamp:
01/08/09 10:05:24 (6 months ago)
Author:
tschaub
Message:

Make sketch components share geometries so listeners can modify geometry properties and have the entire sketch modified.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/topp/editing/lib/OpenLayers/Handler/Path.js

    r8595 r8604  
    6969     * Add temporary geometries 
    7070     */ 
    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        ); 
    7276        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        ); 
    7679        this.layer.addFeatures([this.line, this.point], {silent: true}); 
    7780    }, 
     
    8790 
    8891    /** 
    89      * Method: destroyPoint 
     92     * Method: removePoint 
    9093     * Destroy the temporary point. 
    9194     */ 
    92     destroyPoint: function() { 
     95    removePoint: function() { 
    9396        if(this.point) { 
    94             this.layer.destroyFeatures([this.point]); 
     97            this.layer.removeFeatures([this.point]); 
    9598        } 
    9699    }, 
     
    101104     * the behavior of LinearRing that disregards adding duplicate points. 
    102105     */ 
    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        ); 
    106115        this.callback("point", [this.point.geometry, this.getGeometry()]); 
     116        this.drawFeature(); 
    107117    }, 
    108118     
     
    123133     * Modify the existing geometry given the new point 
    124134     */ 
    125     modifyFeature: function() { 
    126         var index = this.line.geometry.components.length - 1
    127         var target = this.line.geometry.components[index]
    128         target.x = this.point.geometry.x
    129         target.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(); 
    132142    }, 
    133143     
     
    177187                this.destroyFeature(); 
    178188            } 
    179             this.createFeature(); 
     189            this.createFeature(evt.xy); 
     190        } else if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) { 
     191            this.addPoint(evt.xy); 
    180192        } 
    181193        this.mouseDown = true; 
    182194        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(); 
    191195        this.drawing = true; 
    192196        return false; 
     
    206210    mousemove: function (evt) { 
    207211        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(); 
    212212            if(this.mouseDown && this.freehandMode(evt)) { 
    213                 this.addPoint(); 
     213                this.addPoint(evt.xy); 
    214214            } else { 
    215                 this.modifyFeature(); 
     215                this.modifyFeature(evt.xy); 
    216216            } 
    217             this.drawFeature(); 
    218217        } 
    219218        return true; 
     
    235234        if(this.drawing) { 
    236235            if(this.freehandMode(evt)) { 
    237                 if(this.persist) { 
    238                     this.destroyPoint(); 
    239                 } 
     236                this.removePoint(); 
    240237                this.finalize(); 
    241238            } else { 
    242239                if(this.lastUp == null) { 
    243                    this.addPoint(); 
     240                   this.addPoint(evt.xy); 
    244241                } 
    245242                this.lastUp = evt.xy; 
     
    265262            var index = this.line.geometry.components.length - 1; 
    266263            this.line.geometry.removeComponent(this.line.geometry.components[index]); 
    267             if(this.persist) { 
    268                 this.destroyPoint(); 
    269             } 
     264            this.removePoint(); 
    270265            this.finalize(); 
    271266        } 
  • sandbox/topp/editing/lib/OpenLayers/Handler/Polygon.js

    r8595 r8604  
    5252     * Add temporary geometries 
    5353     */ 
    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        ); 
    5562        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        ); 
    6265        this.layer.addFeatures([this.polygon, this.point], {silent: true}); 
    6366    }, 
     
    7679     * Modify the existing geometry given the new point 
    7780     */ 
    78     modifyFeature: function() { 
    79         var index = this.line.geometry.components.length - 2
    80         var target = this.line.geometry.components[index]
    81         target.x = this.point.geometry.x
    82         target.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(); 
    8588    }, 
    8689 
     
    123126            var index = this.line.geometry.components.length - 2; 
    124127            this.line.geometry.removeComponent(this.line.geometry.components[index]); 
    125             if(this.persist) { 
    126                 this.destroyPoint(); 
    127             } 
     128            this.removePoint(); 
    128129            this.finalize(); 
    129130        }