~shikharkohli/sahana-eden/gsoc1

« back to all changes in this revision

Viewing changes to views/gis/ol_layers_georss.js

  • Committer: Shikhar Kohli
  • Date: 2010-08-11 18:40:09 UTC
  • mfrom: (802.1.156 eden)
  • Revision ID: shikharkohli@gmail.com-20100811184009-yy8zag5dowlam0ip
Merge trunk and update (a bit) of JS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var georssLayers = new Array();
2
 
{{for layer in georss_layers:}}
3
 
  {{name = re.sub('\W', '_', layer)}}
4
 
    iconURL = "{{=URL(r=request, c='default', f='download', args=georss_layers[layer].marker)}}";
5
 
    icon_img.src = iconURL;
6
 
    width = icon_img.width;
7
 
    height = icon_img.height;
8
 
    if(width > max_w){
9
 
        height = ((max_w / width) * height);
10
 
        width = max_w;
11
 
    }
12
 
    if(height > max_h){
13
 
        width = ((max_h / height) * width);
14
 
        height = max_h;
15
 
    }
16
 
    style_marker.graphicWidth = width;
17
 
    style_marker.graphicHeight = height;
18
 
    style_marker.graphicXOffset = -(width / 2);
19
 
    style_marker.graphicYOffset = -height;
20
 
    style_marker.externalGraphic = iconURL;
21
 
    var georssLayer{{=name}} = new OpenLayers.Layer.GML( "{{=layer}}", "{{=georss_layers[layer].url}}", {
22
 
        strategies: [ new OpenLayers.Strategy.Cluster({distance: {{=cluster_distance}}, threshold: {{=cluster_threshold}}}) ],
23
 
        format: OpenLayers.Format.GeoRSS, style: style_marker,
24
 
        formatOptions: {
25
 
            // adds the thumbnail attribute to the feature
26
 
            createFeatureFromItem: function(item) {
27
 
                var feature = OpenLayers.Format.GeoRSS.prototype.createFeatureFromItem.apply(this, arguments);
28
 
                //feature.attributes.thumbnail =
29
 
                //        this.getElementsByTagNameNS(
30
 
                //        item, "*", "thumbnail")[0].getAttribute("url");
31
 
                return feature;
32
 
            }
33
 
        },
34
 
      {{if georss_layers[layer].projection == 4326:}}
35
 
        projection: proj4326});
36
 
      {{else:}}
37
 
        projection: new OpenLayers.Projection('EPSG:{{=georss_layers[layer].projection}}')});
38
 
      {{pass}} 
39
 
    {{if georss_layers[layer].visibility:}}
40
 
      georssLayer{{=name}}.setVisibility(true);
41
 
    {{else:}}
42
 
      georssLayer{{=name}}.setVisibility(false);
43
 
    {{pass}}
44
 
    map.addLayer(georssLayer{{=name}});
45
 
    georssLayers.push(georssLayer{{=name}});
46
 
    georssLayer{{=name}}.events.on({ "featureselected": onGeorssFeatureSelect, "featureunselected": onFeatureUnselect });
47
 
{{pass}}
48
 
{{if georss_layers:}}
49
 
allLayers = allLayers.concat(georssLayers);
50
 
 
51
 
function onGeorssFeatureSelect(event) {
52
 
    var feature = event.feature;
53
 
    var selectedFeature = feature;
54
 
    if (undefined == feature.attributes.description) {
55
 
        var popup = new OpenLayers.Popup.FramedCloud("chicken", 
56
 
        feature.geometry.getBounds().getCenterLonLat(),
57
 
        new OpenLayers.Size(200,200),
58
 
        "<h2>" + feature.attributes.title + "</h2>",
59
 
        null, true, onPopupClose);
60
 
    } else {
61
 
        var popup = new OpenLayers.Popup.FramedCloud("chicken",
62
 
        feature.geometry.getBounds().getCenterLonLat(),
63
 
        new OpenLayers.Size(200,200),
64
 
        "<h2>" + feature.attributes.title + "</h2>" + feature.attributes.description,
65
 
        null, true, onPopupClose);
66
 
    };
67
 
    feature.popup = popup;
68
 
    popup.feature = feature;
69
 
    map.addPopup(popup);
70
 
}
71
 
 
72
 
{{pass}}