OpenLayers OpenLayers

Changeset 7448

Show
Ignore:
Timestamp:
06/25/08 04:32:19 (2 months ago)
Author:
ahocevar
Message:

modified georss-flickr example to make use of Layer.GML with format option instead of adding the features manually after parsing them using Format.GeoRSS.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/georss-flickr.html

    r7148 r7448  
    4747            style.addRules([rule, elseRule]); 
    4848             
    49             // Create a layer with a style map.  Giving the style map keys 
    50             // for "default" and "select" rendering intent. 
    51             markerLayer = new OpenLayers.Layer.Vector("", { 
     49            // Create a GML layer with GeoRSS format and a style map. 
     50            markerLayer = new OpenLayers.Layer.GML("Some images from Flickr", 
     51                                                   "xml/georss-flickr.xml", { 
     52                format: OpenLayers.Format.GeoRSS, 
     53                formatOptions: { 
     54                    // adds the thumbnail attribute to the feature 
     55                    createFeatureFromItem: function(item) { 
     56                        var feature = OpenLayers.Format.GeoRSS.prototype 
     57                                .createFeatureFromItem.apply(this, arguments); 
     58                        feature.attributes.thumbnail = 
     59                                this.getElementsByTagNameNS( 
     60                                item, "*", "thumbnail")[0].getAttribute("url"); 
     61                        return feature; 
     62                    } 
     63                }, 
     64                // Giving the style map keys for "default" and "select" 
     65                // rendering intent, to make the image larger when selected 
    5266                styleMap: new OpenLayers.StyleMap({ 
    5367                    "default": style, 
     
    7690             
    7791            popupControl.activate(); 
    78              
    79             OpenLayers.loadURL("xml/georss-flickr.xml", null, window, afterload); 
    80              
    81         } 
    82          
    83         function afterload(req) { 
    84             // extended version of OpenLayers.Format.GeoRSS.createFeatureFromItem; 
    85             // adds the thumbnail attribute to the feature 
    86             function createFeatureFromItem(item) { 
    87                 var feature = OpenLayers.Format.GeoRSS.prototype 
    88                         .createFeatureFromItem.apply(this, arguments); 
    89                 feature.attributes.thumbnail = 
    90                         this.getElementsByTagNameNS( 
    91                         item, "*", "thumbnail")[0].getAttribute("url"); 
    92                 return feature; 
    93             } 
    94  
    95             var store = new OpenLayers.Format.GeoRSS({ 
    96                     createFeatureFromItem: createFeatureFromItem}); 
    97  
    98             rss = store.read(req.responseText); 
    99  
    100             markerLayer.setName("Some images from Flickr"); 
    101             markerLayer.addFeatures(rss); 
    10292        } 
    10393    </script>