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();
11
// Generate Popup + Props
13
var fc_lonlat = feature.geometry.getBounds().getCenterLonLat();
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('popup_0')' 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('popup_0')' 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>";
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);
23
feature.popup = framedCloud;
24
map.addPopup(feature.popup);
26
currentFeature = feature;
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;
37
// Supports selectControl for All Feature Layers
38
function onFeatureUnselect(event) {
39
var feature = event.feature;
41
map.removePopup(feature.popup);
42
feature.popup.destroy();
47
// Supports Internal FeatureGroup Layers
48
function onFeatureSelect(event) {
49
var feature = event.feature;
50
if (feature.popup == null) {
51
popup = feature.makePopup();
56
feature.popup.toggle();
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);
68
feature.popup.toggle();
71
function onFeatureControlUnselect(feature) {
72
if (feature.popup != null) {
77
// Add marker to map (called by ol_layers_features.js)
78
function add_Feature_with_popup(layer, feature_id, geom, popupContentHTML, iconURL) {
80
var icon_img = new Image();
81
icon_img.src = iconURL;
84
var width = icon_img.width;
85
var height = icon_img.height;
87
height = ((max_w / width) * height);
91
width = ((max_h / height) * width);
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;
107
var fc_lonlat = featureVec.geometry.getBounds().getCenterLonLat();
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);
120
featureVec.popup = null;
121
featureVec.makePopup = makePopup;
124
layer.addFeatures([featureVec]);
126
// Supports add_Feature_with_popup()
127
function onPopupClose(evt) {
128
//currentFeature.popup.hide();
129
popupControl.unselectAll();