~shikharkohli/sahana-eden/gsoc1

« back to all changes in this revision

Viewing changes to views/gis/unused/unused_add_feature_map.html

  • 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
 
<!-- File to be included in a form which needs to be able to add a new feature to the database via map entry -->
2
 
 
3
 
<div class='message information'>
4
 
You can move around and enlarge/reduce the size of the area you want using the scale on upper left corner of the map.<br>
5
 
By clicking on the map you can mark your location with a pointer..
6
 
</div>
7
 
 
8
 
<div id="outer_map" style="width: 600px; height: 800px; background-color: #FFFFFF"> 
9
 
 <div id='gis_map_toolbar' >
10
 
  <fieldset id='gis_map_toolbar_fieldset' style="border: 1px solid ; padding: 5px; padding-bottom:2px;">
11
 
   <div id="gis_map_toolbar_default">
12
 
    <span title="Expand Map"><a onclick="shn_gis_map_expand()" alt="Full screen map"><div id="gis_map_icon_expand" style="width: 24px; height: 22px;"></div></a></span>
13
 
   </div>
14
 
   <div id="gis_map_toolbar_manipulate">
15
 
    <span title="Navigate"><a onclick="shn_gis_map_control_navigate()" alt="Navigate"><div id="gis_map_icon_select" style="width: 24px; height: 22px;"></div></a></span>
16
 
    <span title="Add Point"><a onclick="shn_gis_map_control_add_point()" alt="Add Point"><div id="gis_map_icon_addpoint" style="width: 24px; height: 22px;"></div></a></span>
17
 
    <span title="Add Line"><a onclick="shn_gis_map_control_add_line()" alt="Add Line"><div id="gis_map_icon_addline" style="width: 24px; height: 22px;"></div></a></span>
18
 
    <span title="Add Area"><a onclick="shn_gis_map_control_add_polygon()" alt="Add Area"><div id="gis_map_icon_addpolygon" style="width: 24px; height: 22px;"></div></a></span>
19
 
    <span title="Toggle Freehand Draw"><a onclick="shn_gis_map_control_freehand()" alt="Toggle Freehand Draw"><div id="gis_map_icon_freehand" style="width: 24px; height: 22px;"></div></a></span>
20
 
    <span title="Mode Description" id="gis_map_icon_descripion"></span>
21
 
   </div>
22
 
  </fieldset>
23
 
 </div>
24
 
 <div style="float: left; width: 100%;">
25
 
 </div>
26
 
 <div id="map" style="border: 2px solid black;  background-color: #FFFFFF">
27
 
 </div> 
28
 
</div>
29
 
    
30
 
<script type="text/javascript">
31
 
    
32
 
    // make map available for easy debugging
33
 
    var map;
34
 
    
35
 
    // make features available
36
 
    var featuresLayer, currentFeature;
37
 
 
38
 
    // Make Controls Available
39
 
    var selectControl;
40
 
    var dragControl;
41
 
    //var modifyControl;
42
 
    var pointControl;
43
 
    var lineControl;
44
 
    var polygonControl;
45
 
    
46
 
    // avoid pink tiles
47
 
    OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
48
 
    OpenLayers.Util.onImageLoadErrorColor = "transparent";
49
 
 
50
 
    // Set Proxy Host
51
 
    OpenLayers.ProxyHost = '/sahana/static/proxy.py?url=';
52
 
 
53
 
    var lon = 79.4;
54
 
    var lat = 6;
55
 
    var zoom = 7;
56
 
 
57
 
    // See - http://crschmidt.net/~crschmidt/spherical_mercator.html#reprojecting-points
58
 
    var proj4326 = new OpenLayers.Projection("EPSG:4326");
59
 
    var projection_current = new OpenLayers.Projection('EPSG:900913');
60
 
    var point = new OpenLayers.LonLat(lon, lat);
61
 
 
62
 
    // Map Options
63
 
    var options = {
64
 
        displayProjection: proj4326,
65
 
        projection: projection_current,
66
 
        units: "m",
67
 
                    maxResolution: 156543.0339,
68
 
                        maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34),
69
 
                        //restrictedExtent: new OpenLayers.Bounds()
70
 
                };
71
 
 
72
 
    // Start Map
73
 
    function initMap()
74
 
    {
75
 
    map = new OpenLayers.Map('map', options);
76
 
var mapnik = new OpenLayers.Layer.TMS( "OpenStreetMap (Mapnik)", "http://tile.openstreetmap.org/", {type: 'png', getURL: osm_getTileURL, displayOutsideMaxExtent: true } );
77
 
map.addLayer(mapnik);
78
 
var wmslayer1 = new OpenLayers.Layer.WMS( "VMap0",
79
 
"http://labs.metacarta.com/wms/vmap0",
80
 
{layers:'basic', isBaseLayer:'true', wrapDateLine:'true'});
81
 
map.addLayer(wmslayer1);
82
 
featuresLayer = new OpenLayers.Layer.Vector("Feature");map.addLayer(featuresLayer);
83
 
    map.addControl(new OpenLayers.Control.LayerSwitcher());
84
 
    map.addControl(new OpenLayers.Control.PanZoomBar());
85
 
    map.addControl(new OpenLayers.Control.ScaleLine());
86
 
    map.addControl(new OpenLayers.Control.MousePosition());
87
 
    map.addControl(new OpenLayers.Control.OverviewMap({mapOptions: options}));
88
 
   
89
 
    // Add control to add new Points to the map.
90
 
    pointControl = new OpenLayers.Control.DrawFeature(featuresLayer, OpenLayers.Handler.Point);
91
 
    pointControl.featureAdded = shn_gis_map_add_geometry;
92
 
    map.addControl(pointControl);
93
 
    // Add control to add new Lines to the map.
94
 
    lineControl = new OpenLayers.Control.DrawFeature(featuresLayer, OpenLayers.Handler.Path);
95
 
    lineControl.featureAdded = shn_gis_map_add_geometry;
96
 
    map.addControl(lineControl);
97
 
    // Add control to add new Polygons to the map.
98
 
    polygonControl = new OpenLayers.Control.DrawFeature(featuresLayer, OpenLayers.Handler.Polygon);
99
 
    polygonControl.featureAdded = shn_gis_map_add_geometry;
100
 
    map.addControl(polygonControl);
101
 
shn_gis_map_control_navigate();    // Center the map.
102
 
    map.setCenter(point.transform(proj4326, map.getProjectionObject()), zoom);
103
 
    }
104
 
    window.onload(initMap());
105
 
    function shn_gis_map_add_geometry(feature){
106
 
    
107
 
        var fcopy = feature.clone();
108
 
        // need for later.
109
 
        var fcopygeom = fcopy.geometry.clone();
110
 
        var lonlat = fcopy.geometry.getBounds().getCenterLonLat();
111
 
        var proj_current = map.getProjectionObject();
112
 
        lonlat.transform(proj_current, proj4326);
113
 
        var lon_new = lonlat.lon;
114
 
        var lat_new = lonlat.lat;
115
 
        var wkt_new = fcopy.geometry.transform(proj_current, proj4326).toString();
116
 
        var type_new = featureTypeStr(fcopy);
117
 
        
118
 
        // Update form fields
119
 
        var x_gps = document.getElementById("gps_x");
120
 
        var y_gps = document.getElementById("gps_y");
121
 
        if( x_gps != null && y_gps != null){
122
 
            x_gps.value = lon_new;
123
 
            y_gps.value = lat_new;
124
 
        }
125
 
 
126
 
        // store x,y coords in hidden variables named loc_x, loc_y
127
 
        // must be set via calling page
128
 
        var x_point = document.getElementsByName("loc_x");
129
 
        var y_point = document.getElementsByName("loc_y");
130
 
        if(x_point != null && y_point != null){
131
 
            x_point[0].value = lon_new;
132
 
            y_point[0].value = lat_new;
133
 
        }
134
 
        // store type
135
 
        var loc_type = document.getElementsByName("loc_type");
136
 
        if(loc_type != null){
137
 
            loc_type[0].value = type_new;
138
 
        }
139
 
        // store wkt value
140
 
        var wkt_point = document.getElementsByName("loc_wkt");
141
 
        if(wkt_point != null){
142
 
            wkt_point[0].value = wkt_new;
143
 
        }
144
 
        
145
 
        // Remove last plot from layer
146
 
        featuresLayer.destroyFeatures(featuresLayer.features);
147
 
        
148
 
        // Add icon.  
149
 
        add_Feature(featuresLayer, 'newFeature', fcopygeom, '/sahana/static/img/marker.png');
150
 
    }
151
 
    // Add marker to map
152
 
    function add_Feature(layer, feature_id, geom, iconURL){
153
 
        // Set icon dims
154
 
        var icon_img = new Image();
155
 
        icon_img.src = iconURL;
156
 
        var max_w = 25;
157
 
        var max_h = 35;
158
 
        var width = icon_img.width;
159
 
        var height = icon_img.height;
160
 
        if(width > max_w){
161
 
            height = ((max_w / width) * height);
162
 
            width = max_w;
163
 
        }
164
 
        if(height > max_h){
165
 
            width = ((max_h / height) * width);
166
 
            height = max_h;
167
 
        }
168
 
        // http://www.nabble.com/Markers-vs-Features--td16497389.html
169
 
        var style_marker = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
170
 
        //style_mark.pointRadius = 12;
171
 
        style_marker.graphicWidth = width;
172
 
        style_marker.graphicHeight = height;
173
 
        style_marker.graphicXOffset = -(width / 2);
174
 
        style_marker.graphicYOffset = -height;
175
 
        style_marker.externalGraphic = iconURL;
176
 
        style_marker.graphicOpacity = 1;
177
 
        // Create Feature Vector + Props
178
 
        var featureVec = new OpenLayers.Feature.Vector(geom, null, style_marker);
179
 
        featureVec.fid = feature_id;
180
 
        // Add Feature.
181
 
        layer.addFeatures([featureVec]);
182
 
    }
183
 
    // General functions usable by all Layers
184
 
    
185
 
    // returns string type of a feature
186
 
    // return point if not line or poly ....danger....
187
 
    function featureTypeStr(feature){
188
 
        var type = 'point';
189
 
        var geotype = feature.geometry.CLASS_NAME;
190
 
        if(geotype == 'OpenLayers.Geometry.LineString'){
191
 
            type = 'line';
192
 
        } else if(geotype == 'OpenLayers.Geometry.Polygon'){
193
 
            type = 'poly';
194
 
        }
195
 
        return type;
196
 
    }
197
 
    // create geometries from point coords.
198
 
    function coordToGeom(coords, type){
199
 
        var geom = coords[0]
200
 
        if(type == 'point'){
201
 
            geom = coords[0]; // =  Array(new OpenLayers.Geometry.Point(lon, lat));
202
 
        } else if(type == 'line'){
203
 
            geom = new OpenLayers.Geometry.LineString(coords);
204
 
        } else if(type == 'poly'){
205
 
            geom = new OpenLayers.Geometry.Polygon(new Array(new OpenLayers.Geometry.LinearRing(coords)));
206
 
        } 
207
 
        return geom;
208
 
    }
209
 
    // Report Errors to a DIV
210
 
    function ReportErrors(div,text) {
211
 
         $(div).innerHTML = text;
212
 
    }
213
 
    // For KML layers
214
 
    function onFeatureUnselect(feature) {
215
 
        map.removePopup(feature.popup);
216
 
        feature.popup.destroy();
217
 
        feature.popup = null;
218
 
    }
219
 
    // For OSM File layers
220
 
    function on_feature_hover(feature) {
221
 
            var text ="<ul>";
222
 
            var type ="way";
223
 
            if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
224
 
                type = "node";
225
 
            }    
226
 
            text += "<li>" + feature.osm_id + ": <a href='http://www.openstreetmap.org/api/0.5/"+type + "/" + feature.osm_id + "'>API</a></li>";
227
 
            for (var key in feature.attributes) {
228
 
                text += "<li>" + key + ": " + feature.attributes[key] + "</li>";
229
 
            }
230
 
            text += "</ul>";
231
 
            $("status_osm").innerHTML = text;
232
 
    }
233
 
            function osm_getTileURL(bounds) {
234
 
            var res = this.map.getResolution();
235
 
            var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
236
 
            var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
237
 
            var z = this.map.getZoom();
238
 
            var limit = Math.pow(2, z);
239
 
            if (y < 0 || y >= limit) {
240
 
                return OpenLayers.Util.getImagesLocation() + "404.png";
241
 
            } else {
242
 
                x = ((x % limit) + limit) % limit;
243
 
                return this.url + z + "/" + x + "/" + y + "." + this.type;
244
 
            }
245
 
        }
246
 
       // Activate Control for navigating around the maps.
247
 
   function shn_gis_map_control_navigate(){
248
 
        shn_gis_map_control_deactivate_all();
249
 
        document.getElementById('gis_map_icon_select').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/move_feature_on.png)";
250
 
        document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Navigate';
251
 
    }
252
 
    // Activate Control for selecting features.
253
 
    function shn_gis_map_control_select(){
254
 
        shn_gis_map_control_deactivate_all();
255
 
        document.getElementById('gis_map_icon_select').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/move_feature_on.png)";
256
 
        document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Select';
257
 
        selectControl.activate();
258
 
    }
259
 
    // Activate Control for dragging features.
260
 
    function shn_gis_map_control_drag(){
261
 
        shn_gis_map_control_deactivate_all();
262
 
        document.getElementById('gis_map_icon_drag').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/pan_on.png)";
263
 
        document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Drag';
264
 
        dragControl.activate();
265
 
    }
266
 
    // Activate Control for modifying features.
267
 
    function shn_gis_map_control_modify(){
268
 
        shn_gis_map_control_deactivate_all();
269
 
        //document.getElementById('gis_map_icon_modify').style.backgroundImage = "url()";
270
 
        //document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Modify';
271
 
        //modifyControl.activate();
272
 
    }
273
 
    // Activate Control for adding point features.
274
 
    function shn_gis_map_control_add_point(){
275
 
        shn_gis_map_control_deactivate_all();
276
 
        document.getElementById('gis_map_icon_addpoint').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/draw_point_on.png)";
277
 
        document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Add Point';
278
 
        pointControl.activate();
279
 
    }
280
 
    // Activate Control for adding line features.
281
 
    function shn_gis_map_control_add_line(){
282
 
        shn_gis_map_control_deactivate_all();
283
 
        document.getElementById('gis_map_icon_addline').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/draw_line_on.png)";
284
 
        document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Add line';
285
 
        lineControl.activate();
286
 
    }
287
 
    // Activate Control for adding polygon features.
288
 
    function shn_gis_map_control_add_polygon(){
289
 
        shn_gis_map_control_deactivate_all();
290
 
        document.getElementById('gis_map_icon_addpolygon').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/draw_polygon_on.png)";
291
 
        document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Add Area';
292
 
        polygonControl.activate();
293
 
    }
294
 
    // Activate Control for drawing features freehand.
295
 
    function shn_gis_map_control_freehand(){
296
 
        if(lineControl.handler.freehand){
297
 
            document.getElementById('gis_map_icon_freehand').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/freehand_off.png)";
298
 
            document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Freehand OFF';
299
 
            lineControl.handler.freehand = false;
300
 
            polygonControl.handler.freehand = false;
301
 
        } else{
302
 
            document.getElementById('gis_map_icon_freehand').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/freehand_on.png)";
303
 
            document.getElementById('gis_map_icon_descripion').innerHTML = 'Mode: Freehand ON';
304
 
            lineControl.handler.freehand = true;
305
 
            polygonControl.handler.freehand = true;
306
 
        }
307
 
    }
308
 
    // Deactivate all other controls
309
 
    function shn_gis_map_control_deactivate_all(){
310
 
        // Turn off navigate
311
 
        var nav = document.getElementById('gis_map_icon_select')
312
 
        if(nav != null){
313
 
            nav.style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/move_feature_off.png)";
314
 
        }
315
 
        // Turn off select
316
 
        if(selectControl != null){
317
 
            selectControl.unselectAll();
318
 
            selectControl.deactivate();
319
 
            document.getElementById('gis_map_icon_select').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/move_feature_off.png)";
320
 
        }
321
 
        // Turn off drag
322
 
        if(dragControl != null){
323
 
            dragControl.deactivate();
324
 
            document.getElementById('gis_map_icon_drag').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/pan_off.png)";
325
 
        }
326
 
        // Turn off modify
327
 
        //if(modifyControl != null){
328
 
        //modifyControl.deactivate();
329
 
        //}
330
 
        // Drop features/popups in progress from a create feature.
331
 
        if(currentFeature != null && ((pointControl != null && pointControl.active) || (lineControl != null && lineControl.active) || (polygonControl != null && polygonControl.active))){
332
 
            if(currentFeature.popup != null){
333
 
                currentFeature.popup.hide();
334
 
                currentFeature.popup.destroy(currentFeature.popup);
335
 
            }
336
 
            featuresLayer.removeFeatures([currentFeature]);
337
 
            currentFeature.destroy();
338
 
            currentFeature = null;
339
 
        }
340
 
        // Hide any popup showing and deactivate current feature.
341
 
        if(currentFeature != null){
342
 
            if(currentFeature.popup != null){
343
 
                currentFeature.popup.hide();
344
 
            }
345
 
            currentFeature = null;
346
 
        }
347
 
        // Turn off point add
348
 
        if(pointControl != null){
349
 
            pointControl.deactivate();
350
 
            document.getElementById('gis_map_icon_addpoint').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/draw_point_off.png)";
351
 
        }
352
 
        // Turn off line add
353
 
        if(lineControl != null){
354
 
            lineControl.deactivate();
355
 
            document.getElementById('gis_map_icon_addline').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/draw_line_off.png)";
356
 
        }
357
 
        // Turn off polygon add
358
 
        if(polygonControl != null){
359
 
            polygonControl.deactivate();
360
 
            document.getElementById('gis_map_icon_addpolygon').style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/draw_polygon_off.png)";
361
 
        }
362
 
    }
363
 
    function shn_gis_map_expand()
364
 
    {
365
 
        var omap = document.getElementById("outer_map");
366
 
        var amap = document.getElementById("map");
367
 
        var tmap = document.getElementById("gis_map_toolbar");
368
 
        var fmap = document.getElementById("gis_map_toolbar_fieldset");
369
 
        var expd = document.getElementById("gis_map_icon_expand");
370
 
        // If currently small, make big
371
 
        if(omap.style.position != 'fixed'){
372
 
            expd.style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/map_resize_in_c.png)";
373
 
            amap.style.width = '100%';
374
 
            amap.style.height = '100%';
375
 
            omap.style.position = 'fixed';
376
 
            omap.style.top = '0px';
377
 
            omap.style.left = '0px';
378
 
            omap.style.width = '100%';
379
 
            omap.style.height = '100%';
380
 
            omap.style.marginLeft = '0px';
381
 
            fmap.style.border = '0px none';
382
 
            tmap.style.margin = '0px';
383
 
        }
384
 
        // If currently big, make small
385
 
        else {
386
 
            expd.style.backgroundImage = "url(/sahana/static/mfbase/openlayers/theme/default/img/map_resize_out_c.png)";
387
 
            amap.style.width = '760px';
388
 
            amap.style.height = '600px';
389
 
            omap.style.position = 'relative';
390
 
            omap.style.top = 'auto';
391
 
            omap.style.left = 'auto';
392
 
            omap.style.width = 'auto';
393
 
            omap.style.height = 'auto';
394
 
            omap.style.marginLeft = '10px';
395
 
            fmap.style.border = '1px solid';
396
 
            tmap.style.margin = '10px 10px 10px 0px';
397
 
        }
398
 
    }
399
 
    // On Creating a new feature Display a popup box to enter details.
400
 
    function shn_gis_map_create_feature(feature){
401
 
        // If adding a new popup before an old one is completed, kill old popup (current feature is set to null at end of process)
402
 
        if(currentFeature != null){
403
 
            currentFeature.popup.hide();
404
 
            featuresLayer.removeFeatures([currentFeature]);
405
 
            currentFeature.popup.destroy(currentFeature.popup);
406
 
            currentFeature.destroy();
407
 
        }
408
 
        // Generate Popup + Props
409
 
        var fc_id = null;
410
 
        var fc_lonlat = feature.geometry.getBounds().getCenterLonLat();
411
 
        var fc_size = null;
412
 
        var fc_contentHTML = "<div class='gis_openlayers_popupbox' id='popup_'><form method='post' action='index.php?mod=admin&amp;act=gis_database_classes_edit' id='form0' name='form0'><input name='seq' value='seq_3' type='hidden' />   <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__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__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__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__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__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__popup_desc' tabindex=11 ></textarea></span>  </div>  <div class='gis_openlayers_popupbox_footer'>      <span><a onclick='shn_gis_popup_new_cancel(&#39popup_&#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_&#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>";
413
 
        var fc_anchor = null;
414
 
        var fc_closeBox = true; // Bad can close without create...
415
 
        var fc_closeBoxCallback = shn_gis_popup_new_cancel;
416
 
        var framedCloud = new OpenLayers.Popup.FramedCloud(fc_id, fc_lonlat, fc_size, fc_contentHTML, fc_anchor, fc_closeBox, fc_closeBoxCallback);
417
 
        framedCloud.autoSize = true;
418
 
        framedCloud.minSize = new OpenLayers.Size(460,270);
419
 
        // Add Popup
420
 
        feature.popup = framedCloud;
421
 
        map.addPopup(feature.popup);
422
 
        feature.popup.show();
423
 
        currentFeature = feature;
424
 
    }
425
 
    // Supports feature select control.
426
 
    function onFeatureSelect_1(feature){
427
 
        // Set global for back referencing
428
 
        currentFeature = feature;
429
 
        if (feature.popup.map == null) {
430
 
            map.addPopup(feature.popup);
431
 
            feature.popup.show();
432
 
        } else {
433
 
            feature.popup.toggle();
434
 
        }
435
 
    }
436
 
    // Supports feature select control.
437
 
    function onFeatureUnselect_1(feature) {
438
 
        feature.popup.hide();
439
 
    }
440
 
    // Supports feature select control.
441
 
    function onPopupClose(evt) {
442
 
        onFeatureUnselect_1(currentFeature);
443
 
    }
444
 
    var xmlHttp
445
 
    function shn_gis_popup_unable()
446
 
    {
447
 
        alert ("The module that created this feature does not support this action here. Navigate to the module manually to perform this action.");
448
 
    }
449
 
    function shn_gis_popup_print()
450
 
    {
451
 
        if (xmlHttp.readyState == 4){
452
 
            var textDoc = xmlHttp.responseText;
453
 
            currentFeature.popup.setContentHTML(textDoc);
454
 
        }
455
 
    }
456
 
    function shn_gis_popup_refresh_print()
457
 
    {
458
 
        if (xmlHttp.readyState == 4){
459
 
            var textDoc = xmlHttp.responseText;
460
 
            if(textDoc == '<delete />'){
461
 
                currentFeature.popup.hide();
462
 
                featuresLayer.removeFeatures([currentFeature]);
463
 
                currentFeature.popup.destroy(currentFeature.popup);
464
 
                currentFeature.destroy();
465
 
                //featuresLayer.redraw();
466
 
            } else{
467
 
                currentFeature.popup.setContentHTML(textDoc);
468
 
            }
469
 
        }
470
 
    }
471
 
    function shn_gis_popup_new_print()
472
 
    {
473
 
        if (xmlHttp.readyState == 4){
474
 
            var textDoc = xmlHttp.responseText;
475
 
            
476
 
            var geom = currentFeature.geometry.clone();
477
 
                  
478
 
            currentFeature.popup.hide();
479
 
            featuresLayer.removeFeatures([currentFeature]);
480
 
            currentFeature.popup.destroy(currentFeature.popup);
481
 
            currentFeature.destroy();
482
 
            currentFeature = null;
483
 
            //featuresLayer.redraw();
484
 
            if(!(textDoc == 'fail' || textDoc == '')){ 
485
 
                var uuidpos = textDoc.search('<uuid />');
486
 
                var iconURLPos = textDoc.search('<icon />');
487
 
                
488
 
                var uuid = textDoc.substring(0, uuidpos);
489
 
                var iconURL = textDoc.substring((uuidpos + 8), iconURLPos);
490
 
                var html = textDoc.substring((iconURLPos + 8));
491
 
 
492
 
                add_Feature_with_popup(featuresLayer, uuid, geom, html, iconURL);
493
 
            } else{
494
 
                alert("Failed to create new Feature.");   
495
 
            }
496
 
        }
497
 
    }
498
 
    // Called by link in popup box
499
 
    function shn_gis_popup_new_ok(id){
500
 
        xmlHttp = GetXmlHttpObject();
501
 
        if (xmlHttp==null){
502
 
            alert ("Your browser does not support AJAX!");
503
 
            return;
504
 
        }
505
 
        // Clone to stop any effects on the current feature.
506
 
        var cfcopy = currentFeature.clone();
507
 
        // returns string type of a feature
508
 
        // return point if not line or poly ....danger....
509
 
        var type = featureTypeStr(cfcopy);
510
 
        // Transform for db.
511
 
        var lonlat = cfcopy.geometry.getBounds().getCenterLonLat().clone();
512
 
        var proj_current = map.getProjectionObject();
513
 
        lonlat.transform(proj_current, proj4326);
514
 
        var lat = lonlat.lat;
515
 
        var lon = lonlat.lon;
516
 
        var wkt = cfcopy.geometry.transform(proj_current, proj4326).toString();
517
 
        var name  = document.getElementById(id + '_popup_name').value;
518
 
        var desc  = document.getElementById(id + '_popup_desc').value;
519
 
        var auth  = document.getElementById(id + '_popup_auth').value;
520
 
        var furl  = document.getElementById(id + '_popup_url').value;
521
 
        var add   = document.getElementById(id + '_popup_add').value;
522
 
        var edate = document.getElementById(id + '_popup_edate').value;
523
 
        // Send to db
524
 
        var url = 'index.php?act=gis_popup_new_ok&mod=xst&stream=text';
525
 
        url = url + "&type=" + type + "&center_lat=" + lat + "&center_lon=" + lon + "&wkt=" + wkt + "&name=" + name + "&desc=" + desc + "&auth=" + auth + "&url=" + furl + "&add=" + add + "&date=" + edate;
526
 
        url = url + "&sid=" + Math.random();
527
 
        xmlHttp.onreadystatechange = shn_gis_popup_new_print;
528
 
        xmlHttp.open("GET", url, true);
529
 
        xmlHttp.send(null);
530
 
    }
531
 
    // Called by link in popup box
532
 
    function shn_gis_popup_new_cancel(){
533
 
        currentFeature.popup.hide();
534
 
        featuresLayer.removeFeatures([currentFeature]);
535
 
        currentFeature.popup.destroy(currentFeature.popup);
536
 
        currentFeature.destroy();
537
 
        currentFeature = null;
538
 
    }
539
 
    // Called by link in popup box
540
 
    function shn_gis_popup_refresh(id)
541
 
    {
542
 
        xmlHttp = GetXmlHttpObject();
543
 
        if (xmlHttp == null){
544
 
            alert ("Your browser does not support AJAX!");
545
 
            return;
546
 
        }
547
 
 
548
 
        var url = 'index.php?act=gis_popup_refresh&mod=xst&stream=text&id=' + id;
549
 
        url = url +"&sid=" + Math.random();
550
 
        xmlHttp.onreadystatechange = shn_gis_popup_refresh_print;
551
 
        xmlHttp.open("GET", url, true);
552
 
        xmlHttp.send(null);
553
 
    }
554
 
    // Called by link in popup box
555
 
    function shn_gis_popup_delete(id)
556
 
    {
557
 
        xmlHttp = GetXmlHttpObject();
558
 
        if (xmlHttp == null){
559
 
            alert ();
560
 
            return;
561
 
        }
562
 
        ok = confirm("Are you sure you wish to Delete Feature from system");
563
 
        if(ok){
564
 
            var url = 'index.php?act=gis_popup_delete&mod=xst&stream=text&id=' + id;
565
 
            url = url +"&sid=" + Math.random();
566
 
            xmlHttp.onreadystatechange = shn_gis_popup_refresh_print;
567
 
            xmlHttp.open("GET", url, true);
568
 
            xmlHttp.send(null);
569
 
        }
570
 
    }
571
 
     // Called by dragControl after editing a Features position
572
 
    function shn_gis_popup_edit_position(feature, pixel)
573
 
    {
574
 
        xmlHttp = GetXmlHttpObject();
575
 
        if (xmlHttp==null){
576
 
            alert ("Your browser does not support AJAX!");
577
 
            return;
578
 
        }
579
 
        currentFeature = feature;
580
 
        // Move features popup to new location
581
 
        feature.popup.lonlat = feature.geometry.getBounds().getCenterLonLat();
582
 
        // Need id before clone
583
 
        var id  = feature.fid.substring(6)
584
 
        // Clone to stop any effects on the current feature.
585
 
        var cfcopy = feature.clone();
586
 
        // Transform for db.
587
 
        var lonlat = cfcopy.geometry.getBounds().getCenterLonLat().clone();
588
 
        var proj_current = map.getProjectionObject();
589
 
        lonlat.transform(proj_current, proj4326);
590
 
        var lat = lonlat.lat;
591
 
        var lon = lonlat.lon;
592
 
        var wkt = cfcopy.geometry.transform(proj_current, proj4326).toString();
593
 
        // Send to db
594
 
        var url='index.php?act=gis_popup_edit_position&mod=xst&stream=text&id=' + id;
595
 
        url = url + "&center_lat=" + lat + "&center_lon=" + lon + "&wkt=" + wkt;
596
 
        url = url +"&sid=" + Math.random();
597
 
        //xmlHttp.onreadystatechange = shn_gis_popup_print;
598
 
        xmlHttp.open("GET", url, true);
599
 
        xmlHttp.send(null);
600
 
    }
601
 
    // Called by link in popup box
602
 
    function shn_gis_popup_edit_details(id)
603
 
    {
604
 
        xmlHttp = GetXmlHttpObject();
605
 
        if (xmlHttp==null){
606
 
            alert ("Your browser does not support AJAX!");
607
 
            return;
608
 
        }
609
 
        var url='index.php?act=gis_popup_edit_details&mod=xst&stream=text&id=' + id;
610
 
        url = url +"&sid=" + Math.random();
611
 
        xmlHttp.onreadystatechange = shn_gis_popup_print;
612
 
        xmlHttp.open("GET", url, true);
613
 
        xmlHttp.send(null);
614
 
    }
615
 
    function shn_gis_popup_edit_details_ok(id)
616
 
    {
617
 
        xmlHttp = GetXmlHttpObject();
618
 
        if (xmlHttp==null){
619
 
            alert ("Your browser does not support AJAX!");
620
 
            return;
621
 
        }
622
 
        var name  = document.getElementById(id + '_popup_name').value;
623
 
        var desc  = document.getElementById(id + '_popup_desc').value;
624
 
        var auth  = document.getElementById(id + '_popup_auth').value;
625
 
        var furl   = document.getElementById(id + '_popup_url').value;
626
 
        var add   = document.getElementById(id + '_popup_add').value;
627
 
        var edate  = document.getElementById(id + '_popup_edate').value;
628
 
        var url = 'index.php?act=gis_popup_edit_details_ok&mod=xst&stream=text&id=' + id;
629
 
        url = url + "&name=" + name + "&desc=" + desc + "&auth=" + auth + "&url=" + furl + "&add=" + add + "&date=" + edate;
630
 
        url = url +"&sid=" + Math.random();
631
 
        xmlHttp.onreadystatechange = shn_gis_popup_print;
632
 
        xmlHttp.open("GET", url, true);
633
 
        xmlHttp.send(null);
634
 
    }
635
 
    function GetXmlHttpObject(){
636
 
        var xmlHttp=null;
637
 
        try{
638
 
            // Firefox, Opera 8.0+, Safari
639
 
            xmlHttp=new XMLHttpRequest();
640
 
        }
641
 
        catch (e){
642
 
            // Internet Explorer
643
 
            try{
644
 
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
645
 
            }
646
 
            catch (e){
647
 
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
648
 
            }
649
 
        }
650
 
        return xmlHttp;
651
 
    }
652
 
    </script>
653
 
 
654
 
<div id="center"></div>
655
 
<div id="south">
656
 
{{include 'gis/ol_status.html'}}
657
 
</div>