~shikharkohli/sahana-eden/gsoc1

« back to all changes in this revision

Viewing changes to views/gis/ol_controls_features.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
 
// Supports feature create controls (Point, Line & Polygon)
2
 
// On Creating a new feature, display a popup box to enter details.
3
 
function shn_gis_map_create_feature(feature){
4
 
    // If adding a new popup before an old one is completed, kill old popup (current feature is set to null at end of process)
5
 
    if(currentFeature != null){
6
 
        currentFeature.popup.hide();
7
 
        featuresLayer.removeFeatures([currentFeature]);
8
 
        currentFeature.popup.destroy(currentFeature.popup);
9
 
        currentFeature.destroy();
10
 
    }
11
 
    // Generate Popup + Props
12
 
    var fc_id = null;
13
 
    var fc_lonlat = feature.geometry.getBounds().getCenterLonLat();
14
 
    var fc_size = null;
15
 
    var fc_contentHTML = "<div class='gis_openlayers_popupbox' id='popup_0'><form method='post' action='{{=URL(r=request, c='gis', f='feature', args=['create'], vars=dict(format='json'))}}' id='form0' name='form0'> <div class='gis_openlayers_popupbox_header'> <div class='gis_openlayers_popupbox_header_r'> <div class='gis_openlayers_popupbox_author'><label for='gis_popup_author' >Author:</label> <input type='text' name='gis_popup_author' id='popup_0_popup_auth' size='15' maxlength='60' tabindex=8 /></div>       <div class='gis_openlayers_popupbox_date'><label for='gis_popup_date' >Date:</label> <input type='text' name='gis_popup_date' id='popup_0_popup_edate' size='15' tabindex=9 /></div></div><div class='gis_openlayers_popupbox_header_l'> <div class='gis_openlayers_popupbox_name'><label for='gis_popup_name'>Name:</label> <span><input type='text' name='gis_popup_name' id='popup_0_popup_name' size='10' maxlength='60' tabindex=6 /></span> ()</div>       <div class='gis_openlayers_popupbox_url'><label for='gis_popup_name'>Url:</label> <input type='text' name='gis_popup_url' id='popup_0_popup_url' size='40' maxlength='100' tabindex=7 /></div>     </div>      <div class='gis_openlayers_popupbox_address'><b>Address:</b> <input type='text' name='gis_popup_address' id='popup_0_popup_add' size='55' maxlength='200' tabindex=10 /></div>   </div>   <div class='gis_openlayers_popupbox_body'>     <span class='gis_openlayers_popupbox_text'><textarea rows='5' cols='70' name='gis_popup_desc' id='popup_0_popup_desc' tabindex=11 ></textarea></span>  </div>  <div class='gis_openlayers_popupbox_footer'>      <span><a onclick='shn_gis_popup_new_cancel(&#39popup_0&#39)' alt='cancel'><div class='gis_openlayers_popupbox_edit_cancel' style='width: 17px; height: 17px;'></div><span>cancel</span></a></span> <span><a onclick='shn_gis_popup_new_ok(&#39popup_0&#39)' alt='ok'><div class='gis_openlayers_popupbox_edit_ok' style='width: 17px; height: 17px;'></div><span>ok</span></a></span>   </div>  <div style='clear: both;'></div></form></div>";
16
 
    var fc_anchor = null;
17
 
    var fc_closeBox = true; // Bad can close without create...
18
 
    var fc_closeBoxCallback = shn_gis_popup_new_cancel;
19
 
    var framedCloud = new OpenLayers.Popup.FramedCloud(fc_id, fc_lonlat, fc_size, fc_contentHTML, fc_anchor, fc_closeBox, fc_closeBoxCallback);
20
 
    framedCloud.autoSize = true;
21
 
    framedCloud.minSize = new OpenLayers.Size(460,270);
22
 
    // Add Popup
23
 
    feature.popup = framedCloud;
24
 
    map.addPopup(feature.popup);
25
 
    feature.popup.show();
26
 
    currentFeature = feature;
27
 
}
28
 
// Called by closeBox in Popup
29
 
function shn_gis_popup_new_cancel(){
30
 
    currentFeature.popup.hide();
31
 
    featuresLayer.removeFeatures([currentFeature]);
32
 
    currentFeature.popup.destroy(currentFeature.popup);
33
 
    currentFeature.destroy();
34
 
    currentFeature = null;
35
 
}
36
 
 
37
 
// Supports selectControl for All Feature Layers
38
 
function onFeatureUnselect(event) {
39
 
    var feature = event.feature;
40
 
    if (feature.popup) {
41
 
        map.removePopup(feature.popup);
42
 
        feature.popup.destroy();
43
 
        delete feature.popup;
44
 
    }
45
 
}
46
 
 
47
 
// Supports Internal FeatureGroup Layers
48
 
function onFeatureSelect(event) {
49
 
    var feature = event.feature;
50
 
    if (feature.popup == null) {
51
 
        popup = feature.makePopup();
52
 
        feature.popup = popup
53
 
        map.addPopup(popup);
54
 
        popup.show();
55
 
    } else {
56
 
        feature.popup.toggle();
57
 
    }
58
 
}
59
 
 
60
 
// Supports toolbar selectControl for Draft Features
61
 
function onFeatureControlSelect(feature){
62
 
    // Set global for back referencing
63
 
    currentFeature = feature;
64
 
    if (feature.popup.map == null) {
65
 
        map.addPopup(feature.popup);
66
 
        feature.popup.show();
67
 
    } else {
68
 
        feature.popup.toggle();
69
 
    }
70
 
}
71
 
function onFeatureControlUnselect(feature) {
72
 
    if (feature.popup != null) {
73
 
        feature.popup.hide();
74
 
    }
75
 
}
76
 
 
77
 
// Add marker to map (called by ol_layers_features.js)
78
 
function add_Feature_with_popup(layer, feature_id, geom, popupContentHTML, iconURL) {
79
 
    // Set icon dims
80
 
    var icon_img = new Image();
81
 
    icon_img.src = iconURL;
82
 
    var max_w = 25;
83
 
    var max_h = 35;
84
 
    var width = icon_img.width;
85
 
    var height = icon_img.height;
86
 
    if(width > max_w){
87
 
        height = ((max_w / width) * height);
88
 
        width = max_w;
89
 
    }
90
 
    if(height > max_h){
91
 
        width = ((max_h / height) * width);
92
 
        height = max_h;
93
 
    }
94
 
    // http://www.nabble.com/Markers-vs-Features--td16497389.html
95
 
    var style_marker = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
96
 
    style_marker.graphicWidth = width;
97
 
    style_marker.graphicHeight = height;
98
 
    style_marker.graphicXOffset = -(width / 2);
99
 
    style_marker.graphicYOffset = -height;
100
 
    style_marker.externalGraphic = iconURL;
101
 
    style_marker.graphicOpacity = 1;
102
 
    // Create Feature Vector
103
 
    var featureVec = new OpenLayers.Feature.Vector(geom, null, style_marker);
104
 
    featureVec.fid = feature_id;
105
 
    // Create Popup
106
 
    var fc_id = null;
107
 
    var fc_lonlat = featureVec.geometry.getBounds().getCenterLonLat();
108
 
    var fc_size = null;
109
 
    var fc_contentHTML = popupContentHTML;
110
 
    var fc_anchor = null;
111
 
    var fc_closeBox = true;
112
 
    var fc_closeBoxCallback = onPopupClose;
113
 
    var makePopup = function(){
114
 
        var framedCloud = new OpenLayers.Popup.FramedCloud(fc_id, fc_lonlat, fc_size, fc_contentHTML, fc_anchor, fc_closeBox, fc_closeBoxCallback);
115
 
        framedCloud.autoSize = true;
116
 
        framedCloud.minSize = new OpenLayers.Size(460,270);
117
 
        return framedCloud;
118
 
    }
119
 
    // Add Popup
120
 
    featureVec.popup = null;
121
 
    featureVec.makePopup = makePopup;
122
 
 
123
 
    // Add Feature
124
 
    layer.addFeatures([featureVec]);
125
 
}
126
 
// Supports add_Feature_with_popup()
127
 
function onPopupClose(evt) {
128
 
    //currentFeature.popup.hide();
129
 
    popupControl.unselectAll();
130
 
}