1/* (c) Copyright 2024 MiKa (http://wp-osm-plugin.hyumika.com) 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License as published by 5 the Free Software Foundation; either version 2 of the License, or 6 (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16*/ 17 18// This namespace covers the eventhandler in the metabox to 19// generate the shortcodes 20var MetaboxEventhandler = { 21 22 AddMarker: function osm_AddMarker(a_mapname, a_post_id) { 23 a_mapname.on('click', function(evt) { 24 jQuery( document ).ready( function( $ ) { 25 26 var lonlat = ol.proj.transform(evt.coordinate, "EPSG:3857", "EPSG:4326"); 27 var lon = lonlat[0].toFixed(4); 28 var lat = lonlat[1].toFixed(4); 29 var attr = ""; 30 MarkerId = ""; 31 32 33 if($('#osm_add_marker_show_attribution').prop('checked') == true) { 34 attr = 1; 35 } 36 else { 37 attr = 0; 38 } 39 40 MarkerNameField = ""; 41 MarkerTextField = ""; 42 43 MarkerId = 1; 44 45 //MarkerName = $('#osm_add_marker_name').val(); 46 MarkerIcon = $('#marker_icon:checked').val(); 47 MarkerName = MarkerIcon; 48 MarkerTextField = $('#osm_add_marker_text').val(); 49 50 MarkerTextField = MarkerTextField.replace(/(\r\n|\n|\r)/gm, ""); 51 MarkerTextField = MarkerTextField.replace(/(\')/gm, "'"); 52 53 osm_ajax_object.MarkerLat = lat; 54 osm_ajax_object.MarkerLon = lon; 55 osm_ajax_object.MarkerId = MarkerId; 56 osm_ajax_object.MarkerName = MarkerName; 57 osm_ajax_object.MarkerText = MarkerTextField; 58 osm_ajax_object.MarkerIcon = MarkerIcon; 59 osm_ajax_object.post_id = a_post_id; 60 61 WarningTxt = "</br> <span style=\"color:red\"> <b>Warning:</b> Display attribution / credit in the map (checkbox at 3. map controls) is not enabled, it may violate the license of data or map and have legal consequences! </span> </b>" 62 63 GenTxt = "<br> Marker_Id: "+ MarkerId + "<br>Marker_Name: " + MarkerName + "<br>Marker_LatLon: "+lat+","+lon+ " <br>Icon: " + MarkerIcon + "<br> Marker_Text:<br>"+ MarkerTextField + "<br><b>4. Press [Save marker and generate shortcode]!</b>"; 64 65 if (attr == 0){ 66 GenTxt = WarningTxt + GenTxt; 67 } 68 69 $('#Marker_Div').html(GenTxt); 70 $('#ShortCode_Div').html(""); 71 72 73 /** if there is already a marker, delete the layer with it **/ 74 var layers = a_mapname.getLayers().getArray(); 75 if (layers.length > 1){ 76 a_mapname.removeLayer(layers[1]) 77 } 78 MarkerIconUrl = osm_ajax_object.plugin_url + "/icons/"+MarkerIcon; 79 osm_addMarkerLayer(a_mapname, Number(lon), Number(lat), MarkerIconUrl, -16, -41, ""); 80 } ); /** JQuery **/ 81 82 }); 83 }, 84 85 SetGeotag: function osm_setGeotagEvent(a_mapname, a_post_id) { 86 a_mapname.on('click', function(evt) { 87 88jQuery( document ).ready( function( $ ) { 89 90 var lonlat = ol.proj.transform(evt.coordinate, "EPSG:3857", "EPSG:4326"); 91 var lon = lonlat[0].toFixed(4); 92 var lat = lonlat[1].toFixed(4); 93 94 var zoom = a_mapname.getView().getZoom(); 95 96 MarkerField = ""; 97 98 99 var MarkerName = $('#geotag_marker_icon:checked').val(); 100 101 if ($('#geotag_marker_icon:checked').val() != "none"){ 102 MarkerField = " marker=\""+lat+","+lon+"\" marker_name=\"" + MarkerName + "\""; 103 } 104 105 106 osm_ajax_object.lat = lat; 107 osm_ajax_object.lon = lon; 108 osm_ajax_object.post_id = a_post_id; 109 if (MarkerName != "none"){ 110 osm_ajax_object.icon = MarkerName; 111 GenTxt = "Location: "+lat+","+lon+" <br>Icon: " + MarkerName + "<br><b>3. Press [Save] to store!</b>"; 112 } 113 else { 114 GenTxt = "Location: "+lat+","+lon + "<br><b>3. Press [Save] to store!</b>"; 115 } 116 117 $('#Geotag_Div').html(GenTxt); 118 $('#ShortCode_Div').html(""); 119 120 /** if there is already a marker, delete the layer with it **/ 121 var layers = a_mapname.getLayers().getArray(); 122 if (layers.length > 1){ 123 a_mapname.removeLayer(layers[1]) 124 } 125
126 MarkerIconUrl = osm_ajax_object.plugin_url + "/icons/"+MarkerName; 127 osm_addMarkerLayer(a_mapname, Number(lon), Number(lat), MarkerIconUrl, -16, -41, ""); 128 129 } ); /** JQuery **/ 130 131 }); 132 } 133} 134 135function osm_generateTaggedPostsSC(){ 136jQuery( document ).ready( function( $ ) { 137 138 var MarkerField = ""; 139 var ThemeField = ""; 140 var MapTypeField = ""; 141 var Linefield = ""; 142 var PostTypeField =""; 143 var PostType =""; 144 var CatFilterField = ""; 145 var MapBorderField = ""; 146 var MarkerStyleField = ""; 147 var StyleColorField = ""; 148 var TagTypeField = ""; 149 var LatLonField = ""; 150 var ZoomField = ""; 151 152 153 154 //var dropdown = document.getElementById("cat"); 155 //var dropdown = $('#cat').val(); 156 157 158 var MarkerName = $('#tagged_marker_icon:checked').val(); 159 160 var TagFilter = $('#tag_filter').val(); 161 var CategoryFilter = $('#category_parent').val(); 162 163 var ErrorFlag = 0; 164 165 166 if($('#osm_geotag_show_attribution').prop('checked') == true) { 167 $AttrTxt =""; 168 } 169 else { 170 $AttrTxt = "attribution=\"WARNING: Display attribution is not enabled. It may violate the license of data and map and have legal consequences!\""; 171 } 172 173 174 175 if ((CategoryFilter != "-1") && (TagFilter != "")){ 176 CatFilterField = ""; 177 TagFilter =""; 178 ErrorFlag = 1; 179 } 180 else if (CategoryFilter != "-1"){ 181 CatFilterField = " tagged_filter=\"" + CategoryFilter + "\""; 182 } 183 else if (TagFilter != ""){ 184 CatFilterField = " tagged_filter=\"" + TagFilter + "\""; 185 TagTypeField = " tagged_filter_type=\"post_tag\""; 186 } 187 188 if ($('#osm_geotag_map_type').val() != "Mapnik"){ 189 MapTypeField = " type=\"" + $('#osm_geotag_map_type').val() + "\""; 190 } 191 192 PostType = $('#osm_geotag_posttype').val(); 193 PostTypeField = " tagged_type=\""+PostType+"\""; 194 195 if ($('#osm_geotag_posttype').val() != "none"){ 196 MarkerField = " marker_name=\"" + MarkerName + "\""; 197 } 198 199 if($('#tagged_marker_style:checked').val() == "cluster"){ 200 var lonlat = ol.proj.transform(TaggedSC_map.getView().getCenter(), "EPSG:3857", "EPSG:4326"); 201 var lon = lonlat[0].toFixed(4); 202 var lat = lonlat[1].toFixed(4); 203 LatLonField = lat + "," + lon; 204 ZoomField = TaggedSC_map.getView().getZoom(); 205 ZoomField = ZoomField.toFixed(1); 206 } 207 else { 208 LatLonField = "autolat,autolon"; 209 ZoomField = "5"; 210 } 211 212 if (PostType == "actual"){ 213 LatLonField = "0,0"; 214 } 215 216 if (MarkerName == "mic_black_pinother_02.png"){ 217 MapBorderField = " map_border=\"thin solid grey\""; 218 StyleColorField = " tagged_color=\"black\""; 219 } 220 else if (MarkerName == "mic_red_pinother_02.png"){ 221 MapBorderField = " map_border=\"thin solid red\""; 222 StyleColorField = " tagged_color=\"red\""; 223 } 224 else if (MarkerName == "mic_green_pinother_02.png"){ 225 MapBorderField = " map_border=\"thin solid green\""; 226 StyleColorField = " tagged_color=\"green\""; 227 } 228 else if (MarkerName == "mic_blue_pinother_02.png"){ 229 MapBorderField = " map_border=\"thin solid blue\""; 230 StyleColorField = " tagged_color=\"blue\""; 231 } 232 233 if ($('#tagged_marker_style:checked').val() != "standard"){ 234 MarkerStyleField = " tagged_param=\"" + $('#tagged_marker_style:checked').val()+ "\""; 235 } 236 237 if (ErrorFlag > 0){ 238 GenTxt = "[Error]: You must not set category filter and tag filter at the same time! <br> Set Category filter to None or delete tag tilter." 239 } 240 else { 241 GenTxt = "[osm_map_v3 " + $AttrTxt +" map_center=\"" + LatLonField + "\" zoom=\"" + ZoomField + "\" width=\"100%\" height=\"450\" " + PostTypeField + MarkerField + MapTypeField + CatFilterField + MapBorderField + MarkerStyleField + StyleColorField + TagTypeField+"]"; 242 } 243 244 $('#ShortCode_Div').html(GenTxt); 245 } ); /** JQuery **/ 246} 247 248function osm_showTaggedSCmap () { 249 jQuery( document ).ready( function( $ ) { 250 if($('#tagged_marker_style:checked').val() == "cluster"){ 251 document.getElementById("TaggedSC_map").style.display = "block"; 252 TaggedSC_map.updateSize(); 253 } 254 else{ /** standard **/ 255 document.getElementById("TaggedSC_map").style.display = "none"; 256 } 257 258 259} ); /** JQuery **/ 260 } 261 262 function osm_showFileSCmap () { 263 jQuery( document ).ready( function( $ ) { 264 if($('#show_selection_box').prop('checked') == true){ 265 document.getElementById("FileSC_map").style.display = "block"; 266 FileSC_map.updateSize(); 267 } 268 else{ 269 document.getElementById("FileSC_map").style.display = "none"; 270 } 271} ); /** JQuery **/ 272 } 273 274 275function osm_generateFileSC(){ 276 277 var GenTxt = ""; 278 279jQuery( document ).ready( function( $ ) { 280 281 var lon = "autolon"; 282 var lat = "autolat"; 283 var zoom = "autozoom"; 284 285 var FileList_ColorField = ""; 286 var FileList_TypeField = ""; 287 var FileList_MapTypeField = ""; 288 var FileList_FileField = ""; 289 var FileList_TitleField = ""; 290 var FileList_SelectBoxField = ""; 291 var DisplayName = ""; 292 var Controls = ""; 293 var ControlField = ""; 294 var BckgrndImageField= ""; 295 BorderField = ""; 296 fileUrls = []; 297 fileTitles = []; 298 fileColors = []; 299 var NumOfFiles = 0; 300 301 302 if ($('#osm_file_list_map_type').val() != "Mapnik"){ 303 FileList_MapTypeField = " type=\"" + $('#osm_file_list_map_type').val() + "\""; 304 } 305 306 if ($('#osm_file_border').val() != "none"){ 307 BorderField = " map_border=\"thin solid " + $('#osm_file_border').val()+ "\""; 308 } 309 310 311 if($('#file_fullscreen').prop('checked') == true) { 312 Controls = "fullscreen,"; 313 } 314 315 if($('#file_scaleline').prop('checked') == true) { 316 Controls = Controls + "scaleline,"; 317 } 318 319 if($('#file_mouseposition').prop('checked') == true) { 320 Controls = Controls + "mouseposition,"; 321 } 322 323 if($('#file_overviewmap').prop('checked') == true) { 324 Controls = Controls + "overview,"; 325 } 326 327 if($('#osm_file_show_attribution').prop('checked') == true) { 328 Attribution =""; 329 } 330 else { 331 Attribution = "attribution=\"WARNING: Display attribution is not enabled. It may violate the license of data and map and have legal consequences!\""; 332 } 333
334 if (Controls != ""){ 335 Controls = Controls.substr(0, Controls.length-1); 336 ControlField = " control=\"" + Controls + "\""; 337 } 338 else { 339 ControlField =""; 340 } 341 342 if($('#file_bckgrnd_img').prop('checked') == true) { 343 BckgrndImageField = ' bckgrndimg="GDPR_bckgrnd.png" '; 344 } 345 else { 346 BckgrndImageField = ""; 347 } 348 349 350 /** handle multiple form fields in metabox with same input (layers and their files/colors/titles - links still missing (tbc) */ 351 $(".osmFileName").each(function(i,e) { 352 if (jQuery(e).val() != "") { 353 fileUrls.push( jQuery(e).val()); 354 } 355 }); 356 357 $(".osmFileTitle").each(function(i,e) { 358 359 if (jQuery(e).val() != "" && fileUrls[i] != "") { 360 fileTitles.push( jQuery(e).val()); 361 NumOfFiles += 1; 362 } 363 else if ((fileUrls[i] != "") && (typeof fileUrls[i] !== "undefined")) { 364 var filename = fileUrls[i]; 365 var filename = filename.replace(/^.*[\\\/]/, '') 366 fileTitles.push(filename); 367 368 } 369 }); 370 371 $(".osmFileColor").each(function(i,e) { 372 if (jQuery(e).val() != "" && typeof(fileUrls[i]) == "string") { 373 fileColors.push( jQuery(e).val()); 374 } 375 }); 376 377 FileList_FileField = " file_list=\"" + fileUrls.join() + "\""; 378 FileList_ColorField = " file_color_list=\"" + fileColors.join() + "\""; 379 FileList_TitleField = " file_title=\"" + fileTitles.join() + "\""; 380 381 if(($('#show_selection_box').prop('checked') == true) && (NumOfFiles > 1)) { 382 FileList_SelectBoxField = " file_select_box=\"one\""; 383 var lonlat = ol.proj.transform(FileSC_map.getView().getCenter(), "EPSG:3857", "EPSG:4326"); 384 lon = lonlat[0].toFixed(4); 385 lat = lonlat[1].toFixed(4); 386 zoom = FileSC_map.getView().getZoom().toFixed(1); 387 } 388 389 GenTxt = "[osm_map_v3 " + Attribution + " map_center=\"" + lat + "," + lon + "\" zoom=\"" + zoom + "\" width=\"100%\" height=\"450\" " + FileList_FileField + FileList_MapTypeField + FileList_ColorField + DisplayName + ControlField + BorderField + FileList_TitleField + FileList_SelectBoxField + BckgrndImageField +"]"; 390 391 $('#ShortCode_Div').html(GenTxt); 392 393 394} ); /** JQuery **/ 395 396 397 } 398 399 400 401 402function osm_generateAddMarkerSC(){ 403 404 var GenTxt = ""; 405 406jQuery( document ).ready( function( $ ) { 407 408 var zoom = ""; 409 var Attribution = ""; 410 var BorderField = "" ; 411 var MapTypeField = ""; 412 var Controls = ""; 413 var BckgrndImage = ""; 414 415 416 var lonlat = ol.proj.transform(AddMarker_map.getView().getCenter(), "EPSG:3857", "EPSG:4326"); 417 var lon = lonlat[0].toFixed(4); 418 var lat = lonlat[1].toFixed(4); 419 ZoomField = AddMarker_map.getView().getZoom(); 420 zoom = ZoomField.toFixed(1); 421 422 423 if ($('#osm_add_marker_map_type').val() != "Mapnik"){ 424 MapTypeField = " type=\"" + $('#osm_add_marker_map_type').val() + "\""; 425 } 426 427 428 if ($('#osm_add_marker_border').val() != "none"){ 429 BorderField = " map_border=\"thin solid " + $('#osm_add_marker_border').val()+ "\""; 430 } 431 432 if($('#osm_add_marker_fullscreen').prop('checked') == true) { 433 Controls = "fullscreen,"; 434 } 435 436 if($('#osm_add_marker_scaleline').prop('checked') == true) { 437 Controls = Controls + "scaleline,"; 438 } 439 440 if($('#osm_add_marker_mouseposition').prop('checked') == true) { 441 Controls = Controls + "mouseposition,"; 442 } 443 444 if($('#osm_add_marker_overviewmap').prop('checked') == true) { 445 Controls = Controls + "overview,"; 446 } 447 448 if (Controls != ""){ 449 Controls = Controls.substr(0, Controls.length-1); 450 ControlField = " control=\"" + Controls + "\""; 451 } 452 else { 453 ControlField =""; 454 } 455 456 457 if($('#osm_add_marker_bckgrnd_img').prop('checked') == true) { 458 BckgrndImageField = ' bckgrndimg="GDPR_bckgrnd.png" '; 459 } 460 else { 461 BckgrndImageField = ""; 462 } 463 464 if($('#osm_add_marker_show_attribution').prop('checked') == true) { 465 Attribution =""; 466 } 467 else { 468 Attribution = "attribution=\"WARNING: Display attribution is not enabled. It may violate the license of data and map and have legal consequences!\""; 469 } 470 471 472 GenTxt = "[osm_map_v3 " + Attribution + " map_center=\"" + lat + "," + lon + "\" zoom=\"" + zoom + "\" width=\"95%\" height=\"450\" " + BorderField + ' post_markers="1" ' + MapTypeField + ControlField + BckgrndImageField +"]"; 473 474 $('#ShortCode_Div').html(GenTxt); 475 476 477} ); /** JQuery **/ 478 479 480 } 481
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.