| 1 | | var widgets = []; |
|---|
| 2 | | var current_pos = null; |
|---|
| 3 | | var position_marker = null; |
|---|
| 4 | | var widgets_mapstrations = []; |
|---|
| 5 | | |
|---|
| 6 | | function init_position_widget(widget_id, mapstration) |
|---|
| 7 | | { |
|---|
| 8 | | jQuery('#' + widget_id).each(function(i,w){ |
|---|
| 9 | | var widget = jQuery(w); |
|---|
| 10 | | |
|---|
| 11 | | widgets[w.id] = widget; |
|---|
| 12 | | |
|---|
| 13 | | var geodata_btn = jQuery('#' + widget_id + '_geodata_btn', widget); |
|---|
| 14 | | var indicator = jQuery('#' + widget_id + '_indicator', widget); |
|---|
| 15 | | var status_box = jQuery('#' + widget_id + '_status_box', widget); |
|---|
| 16 | | |
|---|
| 17 | | var backend_url = jQuery('input.position_widget_backend_url',widget).attr('value'); |
|---|
| 18 | | var backend_service = jQuery('input.position_widget_backend_service',widget).attr('value'); |
|---|
| 19 | | |
|---|
| 20 | | var input_data = {}; |
|---|
| | 1 | jQuery.fn.extend({ |
|---|
| | 2 | dm2_position_widget: function(mapstraction, options) { |
|---|
| | 3 | options = jQuery.extend(jQuery.midcom_helper_datamanager2_widget_position.defaults, options); |
|---|
| | 4 | return this.each(function() { |
|---|
| | 5 | return new jQuery.midcom_helper_datamanager2_widget_position(this, mapstraction, options); |
|---|
| | 6 | }); |
|---|
| | 7 | }, |
|---|
| | 8 | dm2_pw_new_position: function(point) { |
|---|
| | 9 | return this.trigger("new_position",[point]); |
|---|
| | 10 | }, |
|---|
| | 11 | dm2_pw_clear_alternative_markers: function() { |
|---|
| | 12 | return this.trigger("clear_alternative_markers",[]); |
|---|
| | 13 | }, |
|---|
| | 14 | dm2_pw_set_marker: function(label, info) { |
|---|
| | 15 | return this.trigger("set_marker",[label, info]); |
|---|
| | 16 | }, |
|---|
| | 17 | dm2_pw_init_current_pos: function(lat, lon) |
|---|
| | 18 | { |
|---|
| | 19 | return this.trigger("init_current_pos",[lat, lon]); |
|---|
| | 20 | }, |
|---|
| | 21 | dm2_pw_position_map_to_current: function() { |
|---|
| | 22 | return this.trigger("position_map_to_current",[]); |
|---|
| | 23 | } |
|---|
| | 24 | }); |
|---|
| | 25 | |
|---|
| | 26 | jQuery.midcom_helper_datamanager2_widget_position = function(widget_block, mapstraction, options) { |
|---|
| | 27 | |
|---|
| | 28 | var widget = jQuery(widget_block); |
|---|
| | 29 | var widget_id = widget.attr('id'); |
|---|
| | 30 | |
|---|
| | 31 | mapstraction.addMapTypeControls(); |
|---|
| | 32 | mapstraction.addEventListener('click', new_position); |
|---|
| | 33 | |
|---|
| | 34 | var geodata_btn = jQuery('#' + widget_id + '_geodata_btn', widget); |
|---|
| | 35 | var indicator = jQuery('#' + widget_id + '_indicator', widget); |
|---|
| | 36 | |
|---|
| | 37 | var revgeodata_btn = jQuery('#' + widget_id + '_revgeodata_btn', widget); |
|---|
| | 38 | var revindicator = jQuery('#' + widget_id + '_revindicator', widget); |
|---|
| | 39 | |
|---|
| | 40 | var actions_cam = jQuery('#' + widget_id + '_position_widget_action_cam', widget); |
|---|
| | 41 | |
|---|
| | 42 | var status_box = jQuery('#' + widget_id + '_status_box', widget); |
|---|
| | 43 | |
|---|
| | 44 | var current_pos_icon_url = MIDCOM_STATIC_URL + '/midcom.helper.datamanager2/position/current_position_marker.png' |
|---|
| | 45 | var backend_url = jQuery('input.position_widget_backend_url',widget).attr('value'); |
|---|
| | 46 | var backend_service = jQuery('input.position_widget_backend_service',widget).attr('value'); |
|---|
| | 47 | var input_data = {}; |
|---|
| | 48 | var current_pos = null; |
|---|
| | 49 | var position_marker = null; |
|---|
| | 50 | var alternative_markers = null; |
|---|
| | 51 | var alternative_markers_visible = true; |
|---|
| | 52 | |
|---|
| | 53 | widget.bind("new_position", function(event, point){ |
|---|
| | 54 | new_position(point); |
|---|
| | 55 | }).bind("clear_alternative_markers", function(event, point){ |
|---|
| | 56 | clear_alternative_markers(); |
|---|
| | 57 | }).bind("set_marker", function(event, label, info){ |
|---|
| | 58 | set_marker(label, info); |
|---|
| | 59 | }).bind("init_current_pos", function(event, lat, lon){ |
|---|
| | 60 | init_current_pos(lat, lon); |
|---|
| | 61 | }).bind("position_map_to_current", function(event){ |
|---|
| | 62 | position_map_to_current(); |
|---|
| | 63 | }); |
|---|
| | 64 | |
|---|
| | 65 | indicator.hide(); |
|---|
| | 66 | revindicator.hide(); |
|---|
| | 67 | |
|---|
| | 68 | geodata_btn.bind('click', function(e){ |
|---|
| | 69 | refresh_geodata(); |
|---|
| | 70 | geodata_btn.hide(); |
|---|
| | 71 | indicator.show(); |
|---|
| | 72 | }); |
|---|
| | 73 | revgeodata_btn.bind('click', function(e){ |
|---|
| | 74 | var lat = jQuery('#' + input_data['latitude']['id']).attr('value'); |
|---|
| | 75 | var lon = jQuery('#' + input_data['longitude']['id']).attr('value'); |
|---|
| | 76 | |
|---|
| | 77 | new_position(new LatLonPoint(lat,lon)); |
|---|
| | 78 | |
|---|
| | 79 | revgeodata_btn.hide(); |
|---|
| | 80 | revindicator.show(); |
|---|
| | 81 | }); |
|---|
| | 82 | |
|---|
| | 83 | actions_cam.bind('click', function(e){ |
|---|
| | 84 | clear_alternative_markers(); |
|---|
| | 85 | }); |
|---|
| | 86 | |
|---|
| | 87 | jQuery('.position_widget_input',widget).each(function(i, o){ |
|---|
| | 88 | var jqo = jQuery(o); |
|---|
| | 89 | var key = get_key_name(jqo.attr('name')); |
|---|
| | 90 | input_data[key] = { |
|---|
| | 91 | id: jqo.attr('id'), |
|---|
| | 92 | value: jqo.attr('value') |
|---|
| | 93 | }; |
|---|
| | 94 | |
|---|
| | 95 | if (input_data[key]['value'] == undefined) |
|---|
| | 96 | { |
|---|
| | 97 | input_data[key]['value'] = ''; |
|---|
| | 98 | } |
|---|
| | 99 | }); |
|---|
| | 100 | |
|---|
| | 101 | function disable_tabs() |
|---|
| | 102 | { |
|---|
| | 103 | widget.disableTab(1); |
|---|
| | 104 | widget.disableTab(2); |
|---|
| | 105 | widget.disableTab(3); |
|---|
| | 106 | } |
|---|
| | 107 | function enable_tabs() |
|---|
| | 108 | { |
|---|
| | 109 | widget.enableTab(1); |
|---|
| | 110 | widget.enableTab(2); |
|---|
| | 111 | widget.enableTab(3); |
|---|
| | 112 | } |
|---|
| | 113 | |
|---|
| | 114 | function new_position(point) |
|---|
| | 115 | { |
|---|
| | 116 | current_pos = point; |
|---|
| | 117 | |
|---|
| | 118 | jQuery('#' + input_data['latitude']['id']).attr('value', current_pos.lat); |
|---|
| | 119 | jQuery('#' + input_data['longitude']['id']).attr('value', current_pos.lon); |
|---|
| | 120 | |
|---|
| | 121 | set_marker('Current position', ''); |
|---|
| | 122 | get_reversed_geodata(); |
|---|
| | 123 | } |
|---|
| | 124 | |
|---|
| | 125 | function get_reversed_geodata() |
|---|
| | 126 | { |
|---|
| | 127 | disable_tabs(); |
|---|
| | 128 | clear_alternative_markers(); |
|---|
| | 129 | |
|---|
| | 130 | var opts_str = '?'; |
|---|
| | 131 | jQuery.each(options, function(key,value){ |
|---|
| | 132 | opts_str += 'options[' + key + ']=' + value + '&'; |
|---|
| | 133 | }); |
|---|
| | 134 | |
|---|
| | 135 | opts_str = opts_str.substr(0,opts_str.length-1); |
|---|
| | 136 | |
|---|
| | 137 | var get_params = { |
|---|
| | 138 | service: backend_service, |
|---|
| | 139 | dir: 'reverse', |
|---|
| | 140 | latitude: current_pos.lat, |
|---|
| | 141 | longitude: current_pos.lon |
|---|
| | 142 | }; |
|---|
| | 143 | |
|---|
| | 144 | jQuery.ajax({ |
|---|
| | 145 | type: "GET", |
|---|
| | 146 | url: backend_url + opts_str, |
|---|
| | 147 | data: get_params, |
|---|
| | 148 | dataType: "xml", |
|---|
| | 149 | error: function(request, type, expobj){ |
|---|
| | 150 | parse_error(request.responseText); |
|---|
| | 151 | }, |
|---|
| | 152 | success: function(data){ |
|---|
| | 153 | var parsed = parse_response(data); |
|---|
| | 154 | update_widget_inputs(parsed[0], true); |
|---|
| | 155 | handle_alternatives(parsed); |
|---|
| | 156 | } |
|---|
| | 157 | }); |
|---|
| | 158 | |
|---|
| | 159 | function parse_error(error_string) |
|---|
| | 160 | { |
|---|
| | 161 | indicator.hide(); |
|---|
| | 162 | revindicator.hide(); |
|---|
| | 163 | geodata_btn.show(); |
|---|
| | 164 | revgeodata_btn.show(); |
|---|
| | 165 | enable_tabs(); |
|---|
| | 166 | |
|---|
| | 167 | status_box.html(error_string); |
|---|
| | 168 | } |
|---|
| | 169 | |
|---|
| | 170 | function parse_response(data) |
|---|
| | 171 | { |
|---|
| | 172 | status_box.html(''); |
|---|
| | 173 | |
|---|
| | 174 | var results = []; |
|---|
| | 175 | jQuery('position',data).each(function(idx) { |
|---|
| | 176 | var rel_this = jQuery(this); |
|---|
| | 177 | |
|---|
| | 178 | results[idx] = { |
|---|
| | 179 | latitude: rel_this.find("latitude").text(), |
|---|
| | 180 | longitude: rel_this.find("longitude").text(), |
|---|
| | 181 | distance: { |
|---|
| | 182 | meters: rel_this.find("distance").find("meters").text(), |
|---|
| | 183 | bearing: rel_this.find("distance").find("bearing").text() |
|---|
| | 184 | }, |
|---|
| | 185 | city: rel_this.find("city").text(), |
|---|
| | 186 | region: rel_this.find("region").text(), |
|---|
| | 187 | country: rel_this.find("country").text(), |
|---|
| | 188 | alternate_names: rel_this.find("alternate_names").text(), |
|---|
| | 189 | accuracy: rel_this.find("accuracy").text() |
|---|
| | 190 | }; |
|---|
| | 191 | }); |
|---|
| | 192 | |
|---|
| | 193 | return results; |
|---|
| | 194 | } |
|---|
| | 195 | } |
|---|
| | 196 | |
|---|
| | 197 | function refresh_geodata() |
|---|
| | 198 | { |
|---|
| | 199 | disable_tabs(); |
|---|
| | 200 | clear_alternative_markers(); |
|---|
| | 201 | |
|---|
| | 202 | var opts_str = '?'; |
|---|
| | 203 | jQuery.each(options, function(key,value){ |
|---|
| | 204 | opts_str += 'options[' + key + ']=' + value + '&'; |
|---|
| | 205 | }); |
|---|
| | 206 | |
|---|
| | 207 | opts_str = opts_str.substr(0,opts_str.length-1); |
|---|
| | 208 | |
|---|
| | 209 | var get_params = { |
|---|
| | 210 | service: backend_service, |
|---|
| | 211 | }; |
|---|
| 44 | | jQuery('#' + input_data['latitude']['id']).attr('value',current_pos.lat); |
|---|
| 45 | | jQuery('#' + input_data['longitude']['id']).attr('value',current_pos.lon); |
|---|
| 46 | | |
|---|
| 47 | | set_marker('Current position','',widget_id); |
|---|
| 48 | | get_reversed_geodata(); |
|---|
| 49 | | } |
|---|
| 50 | | |
|---|
| | 254 | status_box.html(error_string); |
|---|
| | 255 | } |
|---|
| | 256 | |
|---|
| | 257 | function parse_response(data) |
|---|
| | 258 | { |
|---|
| | 259 | status_box.html(''); |
|---|
| | 260 | |
|---|
| | 261 | var results = []; |
|---|
| | 262 | jQuery('position',data).each(function(idx) { |
|---|
| | 263 | var rel_this = jQuery(this); |
|---|
| | 264 | |
|---|
| | 265 | results[idx] = { |
|---|
| | 266 | latitude: rel_this.find("latitude").text(), |
|---|
| | 267 | longitude: rel_this.find("longitude").text(), |
|---|
| | 268 | distance: { |
|---|
| | 269 | meters: rel_this.find("distance").find("meters").text(), |
|---|
| | 270 | bearing: rel_this.find("distance").find("bearing").text() |
|---|
| | 271 | }, |
|---|
| | 272 | accuracy: rel_this.find("accuracy").text(), |
|---|
| | 273 | city: rel_this.find("city").text(), |
|---|
| | 274 | region: rel_this.find("region").text(), |
|---|
| | 275 | country: rel_this.find("country").text(), |
|---|
| | 276 | alternate_names: rel_this.find("alternate_names").text(), |
|---|
| | 277 | postalcode: rel_this.find("postalcode").text() |
|---|
| | 278 | }; |
|---|
| | 279 | }); |
|---|
| | 280 | |
|---|
| | 281 | return results; |
|---|
| | 282 | } |
|---|
| | 283 | } |
|---|
| | 284 | |
|---|
| | 285 | function update_widget(location_data) |
|---|
| | 286 | { |
|---|
| | 287 | update_widget_inputs(location_data); |
|---|
| | 288 | |
|---|
| | 289 | current_pos = new LatLonPoint(location_data['latitude'],location_data['longitude']); |
|---|
| | 290 | |
|---|
| | 291 | var info = location_data['city'] + ", " + location_data['country'] + ", " + location_data['postalcode']; |
|---|
| | 292 | var label = 'Current position'; |
|---|
| | 293 | if (input_data['description']) |
|---|
| | 294 | { |
|---|
| | 295 | label = input_data['description']; |
|---|
| | 296 | } |
|---|
| | 297 | else if (location_data['description']) |
|---|
| | 298 | { |
|---|
| | 299 | label = location_data['description']; |
|---|
| | 300 | } |
|---|
| | 301 | |
|---|
| | 302 | set_marker(label, info); |
|---|
| | 303 | } |
|---|
| | 304 | |
|---|
| | 305 | function update_widget_inputs(location_data, skip_lat_lon) |
|---|
| | 306 | { |
|---|
| | 307 | if (skip_lat_lon == undefined) |
|---|
| | 308 | { |
|---|
| | 309 | var skip_lat_lon = false; |
|---|
| | 310 | } |
|---|
| | 311 | |
|---|
| | 312 | enable_tabs(); |
|---|
| 52 | | |
|---|
| 53 | | geodata_btn.bind('click', function(e){ |
|---|
| 54 | | refresh_geodata(); |
|---|
| 55 | | geodata_btn.hide(); |
|---|
| 56 | | indicator.show(); |
|---|
| 57 | | }); |
|---|
| 58 | | |
|---|
| 59 | | function get_reversed_geodata() |
|---|
| 60 | | { |
|---|
| 61 | | var get_params = { |
|---|
| 62 | | service: backend_service, |
|---|
| 63 | | dir: 'reverse', |
|---|
| 64 | | latitude: current_pos.lat, |
|---|
| 65 | | longitude: current_pos.lon |
|---|
| 66 | | }; |
|---|
| 67 | | |
|---|
| 68 | | jQuery.ajax({ |
|---|
| 69 | | type: "GET", |
|---|
| 70 | | url: backend_url, |
|---|
| 71 | | data: get_params, |
|---|
| 72 | | dataType: "xml", |
|---|
| 73 | | error: function(request, type, expobj){ |
|---|
| 74 | | parse_error(request.responseText); |
|---|
| 75 | | }, |
|---|
| 76 | | success: function(data){ |
|---|
| 77 | | var parsed = parse_response(data); |
|---|
| 78 | | update_widget_inputs(parsed); |
|---|
| 79 | | } |
|---|
| 80 | | }); |
|---|
| 81 | | |
|---|
| 82 | | function parse_error(error_string) |
|---|
| 83 | | { |
|---|
| 84 | | indicator.hide(); |
|---|
| 85 | | geodata_btn.show(); |
|---|
| 86 | | |
|---|
| 87 | | status_box.html(error_string); |
|---|
| 88 | | } |
|---|
| 89 | | |
|---|
| 90 | | function parse_response(data) |
|---|
| 91 | | { |
|---|
| 92 | | status_box.html(''); |
|---|
| 93 | | |
|---|
| 94 | | var results = []; |
|---|
| 95 | | jQuery('position',data).each(function(idx) { |
|---|
| 96 | | var rel_this = jQuery(this); |
|---|
| 97 | | |
|---|
| 98 | | results[idx] = { |
|---|
| 99 | | accuracy: rel_this.find("accuracy").text(), |
|---|
| 100 | | city: rel_this.find("city").text(), |
|---|
| 101 | | region: rel_this.find("region").text(), |
|---|
| 102 | | country: rel_this.find("country").text(), |
|---|
| 103 | | accuracy: rel_this.find("accuracy").text() |
|---|
| 104 | | }; |
|---|
| 105 | | }); |
|---|
| 106 | | |
|---|
| 107 | | return results[0]; |
|---|
| 108 | | } |
|---|
| 109 | | } |
|---|
| 110 | | |
|---|
| 111 | | function refresh_geodata() |
|---|
| 112 | | { |
|---|
| 113 | | var get_params = { |
|---|
| 114 | | service: backend_service |
|---|
| 115 | | }; |
|---|
| 116 | | |
|---|
| 117 | | jQuery('.position_widget_input',widget).each(function(i, o){ |
|---|
| 118 | | var jqo = jQuery(o); |
|---|
| 119 | | var key = get_key_name(jqo.attr('name')); |
|---|
| 120 | | input_data[key] = { |
|---|
| 121 | | id: jqo.attr('id'), |
|---|
| 122 | | value: jqo.attr('value') |
|---|
| 123 | | }; |
|---|
| 124 | | |
|---|
| 125 | | if (input_data[key]['value'] == undefined) |
|---|
| | 314 | revindicator.hide(); |
|---|
| | 315 | geodata_btn.show(); |
|---|
| | 316 | revgeodata_btn.show(); |
|---|
| | 317 | |
|---|
| | 318 | jQuery.each(location_data, function(key,value){ |
|---|
| | 319 | if (input_data[key]) |
|---|
| | 320 | { |
|---|
| | 321 | if (skip_lat_lon) |
|---|
| 131 | | get_params[key] = input_data[key]['value']; |
|---|
| 132 | | } |
|---|
| 133 | | }); |
|---|
| 134 | | |
|---|
| 135 | | // jQuery.each(input_data, function(i,o){ |
|---|
| 136 | | // if (o['value'] != '') |
|---|
| 137 | | // { |
|---|
| 138 | | // get_params[i] = o['value']; |
|---|
| 139 | | // } |
|---|
| 140 | | // }); |
|---|
| 141 | | |
|---|
| 142 | | jQuery.ajax({ |
|---|
| 143 | | type: "GET", |
|---|
| 144 | | url: backend_url, |
|---|
| 145 | | data: get_params, |
|---|
| 146 | | dataType: "xml", |
|---|
| 147 | | error: function(request, type, expobj){ |
|---|
| 148 | | parse_error(request.responseText); |
|---|
| 149 | | }, |
|---|
| 150 | | success: function(data){ |
|---|
| 151 | | var parsed = parse_response(data); |
|---|
| 152 | | update_widget(parsed); |
|---|
| 153 | | } |
|---|
| 154 | | }); |
|---|
| 155 | | |
|---|
| 156 | | function parse_error(error_string) |
|---|
| 157 | | { |
|---|
| 158 | | indicator.hide(); |
|---|
| 159 | | geodata_btn.show(); |
|---|
| 160 | | |
|---|
| 161 | | status_box.html(error_string); |
|---|
| 162 | | } |
|---|
| 163 | | |
|---|
| 164 | | function parse_response(data) |
|---|
| 165 | | { |
|---|
| 166 | | status_box.html(''); |
|---|
| 167 | | |
|---|
| 168 | | var results = []; |
|---|
| 169 | | jQuery('position',data).each(function(idx) { |
|---|
| 170 | | var rel_this = jQuery(this); |
|---|
| 171 | | |
|---|
| 172 | | results[idx] = { |
|---|
| 173 | | latitude: rel_this.find("latitude").text(), |
|---|
| 174 | | longitude: rel_this.find("longitude").text(), |
|---|
| 175 | | accuracy: rel_this.find("accuracy").text(), |
|---|
| 176 | | city: rel_this.find("city").text(), |
|---|
| 177 | | region: rel_this.find("region").text(), |
|---|
| 178 | | country: rel_this.find("country").text(), |
|---|
| 179 | | postalcode: rel_this.find("postalcode").text() |
|---|
| 180 | | }; |
|---|
| 181 | | }); |
|---|
| 182 | | |
|---|
| 183 | | return results[0]; |
|---|
| 184 | | } |
|---|
| 185 | | } |
|---|
| 186 | | |
|---|
| 187 | | function update_widget(location_data) |
|---|
| 188 | | { |
|---|
| 189 | | indicator.hide(); |
|---|
| 190 | | geodata_btn.show(); |
|---|
| 191 | | |
|---|
| 192 | | update_widget_inputs(location_data); |
|---|
| 193 | | |
|---|
| 194 | | current_pos = new LatLonPoint(location_data['latitude'],location_data['longitude']); |
|---|
| 195 | | |
|---|
| 196 | | var info = location_data['city'] + ", " + location_data['country'] + ", " + location_data['postalcode']; |
|---|
| 197 | | var label = 'Current position'; |
|---|
| 198 | | if (input_data['description']) |
|---|
| 199 | | { |
|---|
| 200 | | label = input_data['description']; |
|---|
| 201 | | } |
|---|
| 202 | | else if (location_data['description']) |
|---|
| 203 | | { |
|---|
| 204 | | label = location_data['description']; |
|---|
| 205 | | } |
|---|
| 206 | | |
|---|
| 207 | | set_marker(label, info, widget_id); |
|---|
| 208 | | } |
|---|
| 209 | | |
|---|
| 210 | | function update_widget_inputs(location_data) |
|---|
| 211 | | { |
|---|
| 212 | | jQuery.each(location_data, function(key,value){ |
|---|
| 213 | | if (input_data[key]) |
|---|
| 214 | | { |
|---|
| 217 | | else |
|---|
| | 333 | } |
|---|
| | 334 | }); |
|---|
| | 335 | } |
|---|
| | 336 | |
|---|
| | 337 | function get_key_name(key) |
|---|
| | 338 | { |
|---|
| | 339 | var re = /widget_([a-z]*)_([a-z]{5,11})_([a-z]*)/; |
|---|
| | 340 | var reg = re.exec(key); |
|---|
| | 341 | |
|---|
| | 342 | return reg[3]; |
|---|
| | 343 | } |
|---|
| | 344 | |
|---|
| | 345 | function handle_alternatives(items) |
|---|
| | 346 | { |
|---|
| | 347 | var total = items.length; |
|---|
| | 348 | for (var i=1; i<total; i++) |
|---|
| | 349 | { |
|---|
| | 350 | var point = new LatLonPoint(items[i]['latitude'],items[i]['longitude']); |
|---|
| | 351 | var info = items[i]['city'] + ", " + items[i]['country'] + ", " + items[i]['postalcode']; |
|---|
| | 352 | set_alternative_marker('Alternative position', info, point); |
|---|
| | 353 | } |
|---|
| | 354 | } |
|---|
| | 355 | |
|---|
| | 356 | function init_current_pos(lat, lon) |
|---|
| | 357 | { |
|---|
| | 358 | current_pos = new LatLonPoint(lat,lon); |
|---|
| | 359 | set_marker('Current position', ''); |
|---|
| | 360 | } |
|---|
| | 361 | |
|---|
| | 362 | function set_marker(label, info) |
|---|
| | 363 | { |
|---|
| | 364 | if (position_marker != null) |
|---|
| | 365 | { |
|---|
| | 366 | mapstraction.removeMarker(position_marker); |
|---|
| | 367 | } |
|---|
| | 368 | |
|---|
| | 369 | position_marker = new Marker(current_pos); |
|---|
| | 370 | position_marker.setIcon(current_pos_icon_url); |
|---|
| | 371 | |
|---|
| | 372 | //position_marker.draggable = true; |
|---|
| | 373 | //position_marker.draggable_end_event = function(marker){var p = marker.getPoint(); alert(p.lat);}; |
|---|
| | 374 | //position_marker.addEventListener('dragend', function(){alert('drop');}); |
|---|
| | 375 | // jQuery.extend(this, function(){ |
|---|
| | 376 | // var point = position_marker.getPoint(); |
|---|
| | 377 | // dm2_pw_new_position(point); |
|---|
| | 378 | // }); |
|---|
| | 379 | |
|---|
| | 380 | if (label != undefined) |
|---|
| | 381 | { |
|---|
| | 382 | position_marker.setLabel(label); |
|---|
| | 383 | } |
|---|
| | 384 | |
|---|
| | 385 | if ( info != undefined |
|---|
| | 386 | && info != '') |
|---|
| | 387 | { |
|---|
| | 388 | position_marker.setInfoBubble(info); |
|---|
| | 389 | } |
|---|
| | 390 | |
|---|
| | 391 | mapstraction.addMarker(position_marker); |
|---|
| | 392 | |
|---|
| | 393 | // if (info != undefined) |
|---|
| | 394 | // { |
|---|
| | 395 | // position_marker[widget_id].openBubble(); |
|---|
| | 396 | // } |
|---|
| | 397 | } |
|---|
| | 398 | |
|---|
| | 399 | function set_alternative_marker(label, info, pos) |
|---|
| | 400 | { |
|---|
| | 401 | if (! alternative_markers) |
|---|
| | 402 | { |
|---|
| | 403 | alternative_markers = []; |
|---|
| | 404 | } |
|---|
| | 405 | |
|---|
| | 406 | var last_key = alternative_markers.push( new Marker(pos) ); |
|---|
| | 407 | |
|---|
| | 408 | if (label != undefined) |
|---|
| | 409 | { |
|---|
| | 410 | alternative_markers[last_key-1].setLabel(label); |
|---|
| | 411 | } |
|---|
| | 412 | |
|---|
| | 413 | if ( info != undefined |
|---|
| | 414 | && info != '') |
|---|
| | 415 | { |
|---|
| | 416 | alternative_markers[last_key-1].setInfoBubble(info); |
|---|
| | 417 | } |
|---|
| | 418 | |
|---|
| | 419 | mapstraction.addMarker(alternative_markers[last_key-1]); |
|---|
| | 420 | |
|---|
| | 421 | // if (info != undefined) |
|---|
| | 422 | // { |
|---|
| | 423 | // alternative_markers[widget_id][last_key-1].openBubble(); |
|---|
| | 424 | // } |
|---|
| | 425 | } |
|---|
| | 426 | |
|---|
| | 427 | function clear_alternative_markers() |
|---|
| | 428 | { |
|---|
| | 429 | if ( alternative_markers |
|---|
| | 430 | && alternative_markers.length > 0) |
|---|
| | 431 | { |
|---|
| | 432 | var length = alternative_markers.length; |
|---|
| | 433 | for (var i=0; i<length; i++) |
|---|
| | 434 | { |
|---|
| | 435 | mapstraction.removeMarker(alternative_markers[i]); |
|---|
| | 436 | } |
|---|
| | 437 | } |
|---|
| | 438 | } |
|---|
| | 439 | |
|---|
| | 440 | function toggle_alternative_markers() |
|---|
| | 441 | { |
|---|
| | 442 | if (! alternative_markers_visible) |
|---|
| | 443 | { |
|---|
| | 444 | alternative_markers_visible = true; |
|---|
| | 445 | |
|---|
| | 446 | if ( alternative_markers |
|---|
| | 447 | && alternative_markers.length > 0) |
|---|
| | 448 | { |
|---|
| | 449 | var length = alternative_markers.length; |
|---|
| | 450 | for (var i=0; i<length; i++) |
|---|
| 221 | | }); |
|---|
| 222 | | } |
|---|
| 223 | | |
|---|
| 224 | | function get_key_name(key) |
|---|
| 225 | | { |
|---|
| 226 | | //var re = /^\s*(\s*)_(\w{5,11})_(\s*)$/; |
|---|
| 227 | | var re = /widget_([a-z]*)_([a-z]{5,11})_([a-z]*)/; |
|---|
| 228 | | var reg = re.exec(key); |
|---|
| 229 | | // console.log("Reg: "+reg); |
|---|
| 230 | | // console.log("Reg.length: "+reg.length); |
|---|
| 231 | | // console.log("Reg[0]: "+reg[0]+" Reg[1]: "+reg[1]+" Reg[2]: "+reg[2]); |
|---|
| 232 | | |
|---|
| 233 | | return reg[3]; |
|---|
| 234 | | } |
|---|
| 235 | | |
|---|
| 236 | | }); |
|---|
| 237 | | } |
|---|
| 238 | | |
|---|
| 239 | | function init_current_pos(widget_id,lat,lon) |
|---|
| 240 | | { |
|---|
| 241 | | current_pos = new LatLonPoint(lat,lon); |
|---|
| 242 | | set_marker('Current position','',widget_id); |
|---|
| 243 | | } |
|---|
| 244 | | |
|---|
| 245 | | function set_marker(label, info, widget_id) |
|---|
| 246 | | { |
|---|
| 247 | | // console.log("set_marker label: "+label+" info: "+info+" widget_id: "+widget_id); |
|---|
| 248 | | |
|---|
| 249 | | if (position_marker != null) |
|---|
| 250 | | { |
|---|
| 251 | | widgets_mapstrations[widget_id].removeMarker(position_marker); |
|---|
| 252 | | } |
|---|
| 253 | | |
|---|
| 254 | | position_marker = new Marker(current_pos); |
|---|
| 255 | | |
|---|
| 256 | | if (label != undefined) |
|---|
| 257 | | { |
|---|
| 258 | | position_marker.setLabel(label); |
|---|
| 259 | | } |
|---|
| 260 | | |
|---|
| 261 | | if ( info != undefined |
|---|
| 262 | | && info != '') |
|---|
| 263 | | { |
|---|
| 264 | | position_marker.setInfoBubble(info); |
|---|
| 265 | | } |
|---|
| 266 | | |
|---|
| 267 | | widgets_mapstrations[widget_id].addMarker(position_marker); |
|---|
| 268 | | |
|---|
| 269 | | // if (info != undefined) |
|---|
| 270 | | // { |
|---|
| 271 | | // position_marker.openBubble(); |
|---|
| 272 | | // } |
|---|
| 273 | | } |
|---|
| 274 | | |
|---|
| 275 | | function position_map_to_current(widget_id) |
|---|
| 276 | | { |
|---|
| 277 | | //console.log("position_map_to_current widget_id: "+widget_id); |
|---|
| 278 | | //console.log("current_pos: "+current_pos); |
|---|
| 279 | | |
|---|
| 280 | | if (current_pos != null) |
|---|
| 281 | | { |
|---|
| 282 | | widgets_mapstrations[widget_id].resizeTo(400,280); |
|---|
| 283 | | widgets_mapstrations[widget_id].setCenterAndZoom(current_pos, 13); |
|---|
| 284 | | widgets_mapstrations[widget_id].resizeTo(420,300); |
|---|
| 285 | | } |
|---|
| 286 | | } |
|---|
| | 454 | } |
|---|
| | 455 | } |
|---|
| | 456 | else |
|---|
| | 457 | { |
|---|
| | 458 | alternative_markers_visible = false; |
|---|
| | 459 | |
|---|
| | 460 | if ( alternative_markers |
|---|
| | 461 | && alternative_markers.length > 0) |
|---|
| | 462 | { |
|---|
| | 463 | var length = alternative_markers.length; |
|---|
| | 464 | for (var i=0; i<length; i++) |
|---|
| | 465 | { |
|---|
| | 466 | alternative_markers[i].hide(); |
|---|
| | 467 | } |
|---|
| | 468 | } |
|---|
| | 469 | } |
|---|
| | 470 | } |
|---|
| | 471 | |
|---|
| | 472 | function position_map_to_current() |
|---|
| | 473 | { |
|---|
| | 474 | if (current_pos != null) |
|---|
| | 475 | { |
|---|
| | 476 | mapstraction.resizeTo(400,280); |
|---|
| | 477 | mapstraction.setCenterAndZoom(current_pos, 13); |
|---|
| | 478 | mapstraction.resizeTo(420,300); |
|---|
| | 479 | } |
|---|
| | 480 | } |
|---|
| | 481 | |
|---|
| | 482 | }; |
|---|
| | 483 | |
|---|
| | 484 | jQuery.midcom_helper_datamanager2_widget_position.defaults = { |
|---|
| | 485 | maxRows: 20, |
|---|
| | 486 | radius: 5 |
|---|
| | 487 | }; |
|---|