OpenLayers OpenLayers

Changeset 5828

Show
Ignore:
Timestamp:
01/20/08 15:33:54 (1 year ago)
Author:
crschmidt
Message:

Add support for reprojection of vector formats when loading data. This allows
for the definition of a 'projection' option on a layer. IF this projection
object exists, it will be used to create the format's internal/external
projection options, making it such that any data loaded will be reprojected
to the map's projection automatically. r=pagameba (Closes #1273, #1225, #1269)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Layer/GML.js

    r5776 r5828  
    2929      */ 
    3030    format: null, 
     31 
     32    /** 
     33     * APIProperty: formatOptions 
     34     * {Object} Hash of options which should be passed to the format when it is 
     35     * created. Must be passed in the constructor. 
     36     */ 
     37    formatOptions: null,  
    3138     
    3239    /** 
     
    128135            doc = request.responseText; 
    129136        } 
    130  
    131         var gml = this.format ? new this.format() : new OpenLayers.Format.GML(); 
     137         
     138        var options = {}; 
     139         
     140        OpenLayers.Util.extend(options, this.formatOptions); 
     141        if (this.map && !this.projection.equals(this.map.getProjectionObject())) { 
     142            options.externalProjection = this.projection; 
     143            options.internalProjection = this.map.getProjectionObject(); 
     144        }     
     145         
     146        var gml = this.format ? new this.format(options) : new OpenLayers.Format.GML(options); 
    132147        this.addFeatures(gml.read(doc)); 
    133148        this.events.triggerEvent("loadend"); 
  • trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js

    r5715 r5828  
    3030     */ 
    3131    features: null, 
     32     
     33    /** 
     34     * APIProperty: formatOptions 
     35     * {Object} Hash of options which should be passed to the format when it is 
     36     * created. Must be passed in the constructor. 
     37     */ 
     38    formatOptions: null,  
    3239 
    3340    /**  
     
    7077        this.location = location; 
    7178        this.features = []; 
    72         this.events.triggerEvent("loadstart"); 
    73         OpenLayers.loadURL(location, null, this, this.parseData); 
    7479    }, 
    7580 
     
    8792        this.features = null; 
    8893    }, 
     94 
     95    /** 
     96     * Method: loadRSS 
     97     * Start the load of the RSS data. Don't do this when we first add the layer, 
     98     * since we may not be visible at any point, and it would therefore be a waste. 
     99     */ 
     100    loadRSS: function() { 
     101        if (!this.loaded) { 
     102            this.events.triggerEvent("loadstart"); 
     103            OpenLayers.loadURL(this.location, null, this, this.parseData); 
     104            this.loaded = true; 
     105        }     
     106    },     
     107     
     108    /** 
     109     * Method: moveTo 
     110     * If layer is visible and RSS has not been loaded, load RSS.  
     111     *  
     112     * Parameters: 
     113     * bounds - {Object}  
     114     * zoomChanged - {Object}  
     115     * minor - {Object}  
     116     */ 
     117    moveTo:function(bounds, zoomChanged, minor) { 
     118        OpenLayers.Layer.Markers.prototype.moveTo.apply(this, arguments); 
     119        if(this.visibility && !this.loaded){ 
     120            this.events.triggerEvent("loadstart"); 
     121            this.loadRSS(); 
     122        } 
     123    }, 
    89124         
    90125    /** 
     
    114149        } 
    115150        
    116         var format = new OpenLayers.Format.GeoRSS(); 
     151        var options = {}; 
     152         
     153        OpenLayers.Util.extend(options, this.formatOptions); 
     154         
     155        if (this.map && !this.projection.equals(this.map.getProjectionObject())) { 
     156            options.externalProjection = this.projection; 
     157            options.internalProjection = this.map.getProjectionObject(); 
     158        }     
     159         
     160        var format = new OpenLayers.Format.GeoRSS(options); 
    117161        var features = format.read(doc); 
    118162         
  • trunk/openlayers/lib/OpenLayers/Layer/Text.js

    r5614 r5828  
    5454     */ 
    5555    features: null, 
     56     
     57    /** 
     58     * APIProperty: formatOptions 
     59     * {Object} Hash of options which should be passed to the format when it is 
     60     * created. Must be passed in the constructor. 
     61     */ 
     62    formatOptions: null,  
    5663 
    5764    /**  
     
    7380        OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments); 
    7481        this.features = new Array(); 
    75         if (this.location != null) { 
    76  
    77             var onFail = function(e) { 
    78                 this.events.triggerEvent("loadend"); 
    79             }; 
    80  
    81             this.events.triggerEvent("loadstart"); 
    82             OpenLayers.loadURL(this.location, null,  
    83                                this, this.parseData, onFail); 
    84         } 
    8582    }, 
    8683 
     
    9996    }, 
    10097     
     98    /** 
     99     * Method: loadText 
     100     * Start the load of the Text data. Don't do this when we first add the layer, 
     101     * since we may not be visible at any point, and it would therefore be a waste. 
     102     */ 
     103    loadText: function() { 
     104        if (!this.loaded) { 
     105            if (this.location != null) { 
     106 
     107                var onFail = function(e) { 
     108                    this.events.triggerEvent("loadend"); 
     109                }; 
     110 
     111                this.events.triggerEvent("loadstart"); 
     112                OpenLayers.loadURL(this.location, null,  
     113                                   this, this.parseData, onFail); 
     114                this.loaded = true; 
     115            } 
     116        }     
     117    },     
     118     
     119    /** 
     120     * Method: moveTo 
     121     * If layer is visible and Text has not been loaded, load Text.  
     122     *  
     123     * Parameters: 
     124     * bounds - {Object}  
     125     * zoomChanged - {Object}  
     126     * minor - {Object}  
     127     */ 
     128    moveTo:function(bounds, zoomChanged, minor) { 
     129        OpenLayers.Layer.Markers.prototype.moveTo.apply(this, arguments); 
     130        if(this.visibility && !this.loaded){ 
     131            this.events.triggerEvent("loadstart"); 
     132            this.loadText(); 
     133        } 
     134    }, 
    101135     
    102136    /** 
     
    108142    parseData: function(ajaxRequest) { 
    109143        var text = ajaxRequest.responseText; 
    110         var parser = new OpenLayers.Format.Text(); 
     144         
     145        var options = {}; 
     146         
     147        OpenLayers.Util.extend(options, this.formatOptions); 
     148         
     149        if (this.map && !this.projection.equals(this.map.getProjectionObject())) { 
     150            options.externalProjection = this.projection; 
     151            options.internalProjection = this.map.getProjectionObject(); 
     152        }     
     153         
     154        var parser = new OpenLayers.Format.Text(options); 
    111155        features = parser.read(text); 
    112156        for (var i = 0; i < features.length; i++) { 
  • trunk/openlayers/lib/OpenLayers/Layer/WFS.js

    r5614 r5828  
    5454     */ 
    5555    featureClass: null, 
     56     
     57    /** 
     58      * APIProperty: format 
     59      * {<OpenLayers.Format>} The format you want the data to be parsed with. 
     60      * Must be passed in the constructor. Should be a class, not an instance. 
     61      */ 
     62    format: null, 
     63 
     64    /**  
     65     * Property: formatObject 
     66     * {<OpenLayers.Format>} Internally created/managed format object, used by 
     67     * the Tile to parse data. 
     68     */ 
     69    formatObject: null, 
     70 
     71    /** 
     72     * APIProperty: formatOptions 
     73     * {Object} Hash of options which should be passed to the format when it is 
     74     * created. Must be passed in the constructor. 
     75     */ 
     76    formatOptions: null,  
    5677 
    5778    /** 
     
    147168        if (this.vectorMode) { 
    148169            OpenLayers.Layer.Vector.prototype.setMap.apply(this, arguments); 
     170             
     171            var options = { 
     172              'extractAttributes': this.extractAttributes 
     173            }; 
     174             
     175            OpenLayers.Util.extend(options, this.formatOptions); 
     176            if (this.map && !this.projection.equals(this.map.getProjectionObject())) { 
     177                options.externalProjection = this.projection; 
     178                options.internalProjection = this.map.getProjectionObject(); 
     179            }     
     180             
     181            this.formatObject = this.format ? new this.format(options) : new OpenLayers.Format.GML(options); 
    149182        } else {     
    150183            OpenLayers.Layer.Markers.prototype.setMap.apply(this, arguments); 
  • trunk/openlayers/lib/OpenLayers/Tile/WFS.js

    r5777 r5828  
    134134            } 
    135135            if (this.layer.vectorMode) { 
    136                 var gml = new OpenLayers.Format.GML({ 
    137                     'extractAttributes': this.layer.options.extractAttributes 
    138                 }); 
    139                 this.layer.addFeatures(gml.read(doc)); 
     136                this.layer.addFeatures(this.formatObject.read(doc)); 
    140137            } else { 
    141138                var resultFeatures = OpenLayers.Ajax.getElementsByTagNameNS( 
  • trunk/openlayers/tests/Layer/test_GeoRSS.html

    r4356 r5828  
    2222        t.eq( layer.location, georss_txt, "layer.location is correct" ); 
    2323        var markers; 
     24        layer.loadRSS(); 
    2425        t.delay_call( 1, function() {   
    2526            t.eq( layer.markers.length, 40, "marker length is correct" ); 
     
    4445        t.eq( layer.location, atom_xml, "layer.location is correct" ); 
    4546        var markers; 
     47        layer.loadRSS(); 
    4648        t.delay_call( 1, function() {   
    4749            t.eq( layer.markers.length, 2, "marker length is correct" ); 
     
    154156        map.setCenter(new OpenLayers.LonLat(0,0),0); 
    155157        var defaultIcon = OpenLayers.Marker.defaultIcon(); 
    156         t.delay_call( 1, function() { 
     158        layer.loadRSS(); 
     159        otherLayer.loadRSS(); 
     160        t.delay_call( 2, function() { 
    157161            t.ok(layer.markers[0].icon, "The layer has a icon"); 
    158162            t.eq(layer.markers[0].icon.url, defaultIcon.url, "The layer without icon has the default icon."); 
  • trunk/openlayers/tests/Layer/test_Text.html

    r5489 r5828  
    2222         
    2323        layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile }); 
     24        layer.loadText(); 
    2425        t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" ); 
    2526        t.eq( layer.location, datafile, "layer.location is correct" );