OpenLayers OpenLayers

Changeset 2020

Show
Ignore:
Timestamp:
12/06/06 22:47:42 (2 years ago)
Author:
camerons
Message:

#434 Now querying multiple layers works based on querying layers below the top using BoundingBox queries. Still need to address point queries, and aggregate geometries.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/vector/lib/OpenLayers/BaseTypes.js

    r2013 r2020  
    488488                this.top=(top>this.top)?top:this.top; 
    489489            }else{ 
    490               this.right=(left<this.left)?left:this.left; 
    491               this.top=(bottom<this.bottom)?bottom:this.bottom
     490              this.right=(left>this.right)?left:this.right; 
     491              this.top=(bottom>this.top)?bottom:this.top
    492492            } 
    493493        } 
  • sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js

    r2009 r2020  
    2828     
    2929    /** 
     30     * Register for mousedown events 
     31     */ 
     32    turnOn: function() { 
     33 
     34        this.setLayer(); 
     35         
     36        this.defaultMouseDown = this.defaultMouseDown.bindAsEventListener(this); 
     37        this.map.events.register( "mousedown", this, this.defaultMouseDown); 
     38    }, 
     39 
     40    /** 
     41     * 
     42     */ 
     43    turnOff: function() { 
     44        this.map.events.unregister( "mousedown", this, this.defaultMouseDown); 
     45    }, 
     46     
     47    /** 
    3048     * Render an array of attributes into a popup. 
    3149     * @param attributes Attributes array to render 
    3250     */ 
    3351    setContent: function(attributes) { 
    34        // Clear previous popup 
    35        this.div.innerHTML=""; 
    36          
     52        // Clear previous popup 
     53        this.div.innerHTML=""; 
     54         
    3755        //configure main div 
    3856        this.div.style.position = "absolute"; 
     
    5068 
    5169        this.innerDiv = document.createElement("div"); 
    52        this.innerDiv.innerHTML="<b>Attribute List</b><br/>" 
     70        this.innerDiv.innerHTML="<b>Attribute List</b><br/>" 
    5371        this.innerDiv.id = "layersDiv"; 
    5472        this.innerDiv.style.paddingTop = "2px"; 
     
    5775        this.innerDiv.style.paddingRight = "2px"; 
    5876        this.innerDiv.style.backgroundColor = this.activeColor; 
    59        this.div.appendChild(this.innerDiv);     
     77        this.div.appendChild(this.innerDiv);     
    6078 
    6179        Rico.Corner.round(this.div, {corners: "tl bl", 
     
    6583 
    6684        Rico.Corner.changeOpacity(this.innerDiv, 0.75); 
    67          
     85         
    6886        attribs=attributes.getAttributes(); 
    6987        for (var i = 0; i < attribs.length; i++) { 
     
    85103            this.innerDiv.appendChild(attributeDiv); 
    86104        } 
    87          
     105         
    88106        // minimize button div 
    89107        var imgLocation = OpenLayers.Util.getImagesLocation(); 
     
    105123        this.div.appendChild(this.minimizeDiv); 
    106124 
    107        // Stop MouseEvents from propogating through this popup 
     125        // Stop MouseEvents from propogating through this popup 
    108126        OpenLayers.Event.observe(this.div, "mouseup", this.ignoreEvent); 
    109127        OpenLayers.Event.observe(this.div, "mousedown", this.ignoreEvent); 
     
    130148    }, 
    131149 
     150    /** 
     151     * Add the Geometry that has been selected to the Event. 
     152     * The top geometry layer is selected first, this is done using 
     153     * SVG/VML feature selection and is accurate. If a feature is not 
     154     * found, features in layers below are progressively queried using 
     155     * the BoundingBox of the feature. (Ie, it is not very accurate). 
     156     * See http://trac.openlayers.org/ticket/434 for more info. 
     157     * 
     158     * @param {Event} evt 
     159     */ 
     160    setEventContext: function(evt) { 
     161        // calculate the mouse position 
     162        var lonlat = this.map.getLonLatFromLayerPx(evt.xy); 
     163        evt.point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat); 
     164 
     165        // For the top layer, query the SVG/VML feature 
     166        if(map.layers.length>0){ 
     167            evt.targetGeometry = map.layers[map.layers.length-1].renderer.getGeometryFromEvent(evt); 
     168        } 
     169        // For remaining layers, query features based on feature bounds. 
     170        // Exit loop when a feature is found. 
     171        for(var i=map.layers.length-1;(!evt.targetGeometry&&(i>=0));i--){ 
     172            if(map.layers[i].getVisibility()&&map.layers[i].isVector){ 
     173                for(var f=0;!evt.targetGeometry&&(f<map.layers[i].features.length);f++){ 
     174                    if(map.layers[i].features[f].atPoint(lonlat)){ 
     175                        evt.targetGeometry=map.layers[i].features[f].geometry; 
     176                    } 
     177                     
     178                } 
     179            } 
     180        } 
     181         
     182        // reset evt.point if modes are activated. 
     183        if (this.editingModes) { 
     184            for (var i = 0; i < this.editingModes.length; i++) { 
     185                var snappingCoordinates =  
     186                    this.editingModes[i].calculatePoint(evt.point, evt.targetGeometry, this.geometry, this.layer); 
     187 
     188                if (snappingCoordinates) { 
     189                    evt.point = snappingCoordinates;                     
     190                    break; 
     191                } 
     192            } 
     193        } 
     194    }, 
     195 
    132196    /** Hide all the contents of the control, shrink the size,  
    133197     *   add the maximize icon 
  • sandbox/vector/lib/OpenLayers/Feature.js

    r2010 r2020  
    6060    initialize: function(layer, geometry, data) { 
    6161        this.layer = layer; 
    62        this.setGeometry(geometry); 
     62        this.setGeometry(geometry); 
    6363        this.data = (data != null) ? data : new Object(); 
    6464        this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");  
     
    169169     */ 
    170170    setGeometry: function(geometry) { 
    171        if(geometry){ 
    172            this.geometry = geometry; 
    173            this.geometry.feature = this; 
    174            this._setGeometryFeatureReference(this.geometry, this); 
    175        
     171        if(geometry){ 
     172            this.geometry = geometry; 
     173            this.geometry.feature = this; 
     174            this._setGeometryFeatureReference(this.geometry, this); 
     175       
    176176    }, 
    177177     
     
    217217 
    218218    /** 
     219     * Takes an lonLat point and returns true if the feature is at this location. 
     220     * @param {OpenLayers.LonLat} lonlat 
     221     * @return Boolean 
     222     */ 
     223    atPoint: function(lonlat){ 
     224        var atPoint=false; 
     225        if(this.geometry){ 
     226            atPoint=this.geometry.atPoint(lonlat); 
     227        } 
     228        return atPoint; 
     229    }, 
     230 
     231    /** 
    219232     * Set geometry style 
    220233     * 
  • sandbox/vector/lib/OpenLayers/Geometry.js

    r2013 r2020  
    1414    /** @type OpenLayers.Bounds */ 
    1515    bounds: null, 
    16      
    17    /**  
    18     * Cross reference back to the feature that owns this geometry so 
    19     * that that the feature can be identified after the geometry has been 
    20     * selected by a mouse click. 
    21     * @type OpenLayers.Feature */ 
    22    feature: null, 
     16     
     17    /**  
     18    * Cross reference back to the feature that owns this geometry so 
     19    * that that the feature can be identified after the geometry has been 
     20    * selected by a mouse click. 
     21    * @type OpenLayers.Feature */ 
     22    feature: null, 
    2323     
    2424    /** 
     
    3030        this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+ "_"); 
    3131    }, 
    32      
    33     /** 
    34      * Set the bounds for this Geometry. 
    35      * @param {OpenLayers.Bounds} bounds 
    36      */ 
    37     setBounds: function(bounds){ 
    38         this.bounds=bounds; 
    39     }, 
    40      
    41     /** 
    42      * Extend the existing bounds to include the new bounds. If existing 
    43      * bounds=null, then set a new Bounds. 
    44      * @param {Object} bounds 
    45      */ 
    46     extendBounds: function(bounds){ 
    47         if(!this.bounds){ 
    48             this.setBounds(bounds); 
    49         }else{ 
    50             this.bounds.extendBounds(bounds); 
    51         } 
    52     }, 
    53      
    54     /** 
    55      * Get the bounds for this Geometry. The bounds will be null if not it has 
    56      * not been set. 
    57      * Once the bounds is set, it is not calculated again, this makes queries 
    58      * faster. 
    59      * @return {OpenLayers.Bounds} 
    60      */ 
    61     getBounds: function(){ 
    62         return this.bounds; 
    63     }, 
    6432     
     33    /** 
     34     * Set the bounds for this Geometry. 
     35     * @param {OpenLayers.Bounds} bounds 
     36     */ 
     37    setBounds: function(bounds){ 
     38        this.bounds=bounds; 
     39    }, 
     40     
     41    /** 
     42     * Extend the existing bounds to include the new bounds. If existing 
     43     * bounds=null, then set a new Bounds. 
     44     * @param {Object} bounds 
     45     */ 
     46    extendBounds: function(bounds){ 
     47        if(!this.bounds){ 
     48            this.setBounds(bounds); 
     49        }else{ 
     50            this.bounds.extendBounds(bounds); 
     51        } 
     52    }, 
     53     
     54    /** 
     55     * Get the bounds for this Geometry. The bounds will be null if not it has 
     56     * not been set. 
     57     * Once the bounds is set, it is not calculated again, this makes queries 
     58     * faster. 
     59     * @return {OpenLayers.Bounds} 
     60     */ 
     61    getBounds: function(){ 
     62        return this.bounds; 
     63    }, 
     64     
     65    /** 
     66     * Takes an lonLat point and returns true if the geometry is at this location. 
     67     * This is only an approximation based on the bounds of the geometry. 
     68     * @param {OpenLayers.LonLat} lonlat 
     69     * @return Boolean 
     70     */ 
     71    atPoint: function(lonlat){ 
     72        var atPoint=false; 
     73        if(this.bounds){ 
     74            atPoint=(this.bounds.bottom<=lonlat.lat) 
     75                && (lonlat.lat<=this.bounds.top) 
     76                && (this.bounds.left<=lonlat.lon) 
     77                && (lonlat.lon<=this.bounds.right); 
     78        } 
     79        return atPoint; 
     80    }, 
     81 
    6582    CLASS_NAME: "OpenLayers.Geometry" 
    6683}; 
  • sandbox/vector/lib/OpenLayers/Geometry/Aggregate.js

    r1982 r2020  
    4646    }, 
    4747 
     48//  /** 
     49//   * Takes an lonLat point and returns true if the feature is at this location. 
     50//   * @param {OpenLayers.LonLat} lonlat 
     51//   * @return Boolean 
     52//   */ 
     53//  atPoint: function(lonlat){ 
     54//      var atPoint=false; 
     55//      var bounds; 
     56//      if(this.components){ 
     57//          for(var i=0;!atPoint&&(i<this.components.length);i++){ 
     58//              atPoint=this.components[i].atPoint(lonlat); 
     59//          } 
     60//      }else{ 
     61//          // The following code is probably not required as 
     62//          // agregate geometries will always have components. Right? 
     63//          // Cameron Shorter. 
     64//          if(this.bounds){ 
     65//              atPoint=(this.bounds.bottom<=lonlat.lat) 
     66//                  && (lonlat.lat<=this.bounds.top) 
     67//                  && (this.bounds.left<=lonlat.lon) 
     68//                  && (lonlat.lon<=this.bounds.right); 
     69//          } 
     70//      } 
     71//      return atPoint; 
     72//  }, 
     73 
    4874    CLASS_NAME: "OpenLayers.Geometry.Aggregate" 
    4975}); 
  • sandbox/vector/lib/OpenLayers/Parser/GML.js

    r2015 r2020  
    9595                polygon = this.parsePolygonNode(polygons[i],geom); 
    9696                geom.addComponents(polygon); 
    97                geom.extendBounds(polygon.getBounds()); 
     97                geom.extendBounds(polygon.getBounds()); 
    9898            } 
    9999        } 
     
    184184        var rings = []; 
    185185        var p; 
    186        var polyBounds; 
     186        var polyBounds; 
    187187        for (var i = 0; i < linearRings.length; i++) { 
    188188            p = this.parseCoords(linearRings[i]); 
    189            ring1=new OpenLayers.Geometry.LinearRing(p.points); 
    190            ring1.extendBounds(p.bounds); 
    191            if(polyBounds){ 
    192                polyBounds.extend(p.bounds); 
    193            }else{ 
    194                polyBounds=p.bounds; 
    195            
     189            ring1=new OpenLayers.Geometry.LinearRing(p.points); 
     190            ring1.extendBounds(p.bounds); 
     191            if(polyBounds){ 
     192                polyBounds.extend(p.bounds); 
     193            }else{ 
     194                polyBounds=p.bounds; 
     195           
    196196            rings.push(ring1); 
    197197        } 
     
    247247                y=parseFloat(nums[i+1]); 
    248248                p.points.push(new OpenLayers.Geometry.Point(x,y)); 
    249                  
    250                if(!p.bounds){ 
    251                    p.bounds=new OpenLayers.Bounds(x,y,x,y); 
    252                }else{ 
    253                    p.bounds.extendBounds(x,y); 
    254                
     249                 
     250                if(!p.bounds){ 
     251                    p.bounds=new OpenLayers.Bounds(x,y,x,y); 
     252                }else{ 
     253                    p.bounds.extendBounds(x,y); 
     254               
    255255            } 
    256256        }