1 2var leafletMap = { 3 localization: {}, 4 isEmpty: function (val) { 5 if (val != 'undefined' && val != null & val != '') { 6 return false; 7 } else { 8 return true; 9 } 10 }, 11 temp: { 12 coordenates: [0,0], 13 address: { 14 _value: null, 15 status: null, 16 get: function(){ return leafletMap.temp.address._value; }, 17 set: function(r){ leafletMap.temp.address._value = r; }, 18 clean: function(){ leafletMap.temp.address.set(null), leafletMap.temp.address.status = null; }, 19 }, 20 search: { 21 _value: null, 22 status: null, 23 get: function(){ return leafletMap.temp.search._value; }, 24 set: function(r){ leafletMap.temp.search._value = r; }, 25 clean: function(){ leafletMap.temp.search.set(null), leafletMap.temp.search.status = null; }, 26 }, 27 gps: { 28 _value: null, 29 status: null, 30 get: function(){ return leafletMap.temp.gps._value; }, 31 set: function(r){ leafletMap.temp.gps._value = r; }, 32 clean: function(){ leafletMap.temp.gps.set(null), leafletMap.temp.gps.status = null; }, 33 }, 34 }, 35 info: { 36 name: 'leaflet-map', 37 coordenates: ['41.5802723', '-8.4069483'], 38 zoom: 13, 39 maxZoom: 18, 40 allowScroll: true, 41 fitZoom: true, 42 //translate: [], 43 riskTranslation: [], 44 hidePopup: false, 45 enableClick: false, 46 myMap: null, 47 cluster: null, 48 showPopupBody: true, 49 }, 50 html: { 51 icon: function (pointerBorderStyle, pointerContentExtraClass, pointerContentStyle, ArrowStyle) { 52 let icon = "<div class='leaflet-pointer-holder'>" 53 + " <div class='pointer-border' " + pointerBorderStyle + ">" 54 + " <div class='pointer-content leaflet-pin " + pointerContentExtraClass + "' " + pointerContentStyle + "></div>" 55 + " <div class='pointer-arrow leaflet-arrow' " + ArrowStyle + "></div>" 56 + ' <img src="themes/dte/css/leaflet/images/marker-icon-2x-trans.png" class="leaflet-marker-pin" alt="">' 57 + ' <img src="themes/dte/css/leaflet/images/marker-icon-2x-gray-trans.png" class="leaflet-marker-pin-alt" alt="">' 58 + " </div>" 59 + " </div>"; 60 return icon; 61 }, 62 popup_model: function (d) { 63 let titleLinked = '<div class="popup-header-title" title="' + d.title + '"><a href="' + d.link + '" target="_blank">' + d.title + '</a></div>'; 64 let titleUnlinked = '<div class="popup-header-title" title="' + d.title + '">' + d.title + '</div>'; 65 let title = (leafletMap.isEmpty(d.link))? titleUnlinked : titleLinked; 66 67 // d.closeIcon = 'icon icon-x' 68 69 let popup = ''; 70 popup += ' <div class="custom-popup-holder popup-large" ' + d.hidePopup + ' >'; 71 popup += ' <div class="custom-popup-content">'; 72 // popup += ' <div class="custom-popup-close"><div class="popup-close-icon"><div class="icon-wrapper-16"><i class="' + d.closeIcon + ' color-primary-100"></i></div></div></div>'; 73 popup += ' <div class="custom-popup-content-element">'; 74 popup += ' <div class="popup-content-header">'; 75 popup += ' ' + title; 76 // popup += ' <div class="popup-header-subtitle" title="' + d.subtitle + '">' + d.subtitle + '</div>'; 77 // popup += ' <div class="popup-header-subtitle" title="' + d.indiceLabel + '">' + d.indiceLabel + " " + d.sqiValue + '</div>'; 78 /*if (leafletMap.info.showPopupBody) { 79 popup += ' </div><div class="poopup-hr"></div>'; 80 popup += ' <div class="popup-content-body">'; 81 popup += ' <div class="popup-body-col w-col-4">'; // 82 popup += ' <div class="popup-col-title"> ' + d.nivelRisco + '</div>'; //NÃvel de Risco 83 popup += ' <div class="popup-col-subtitle">'; 84 popup += ' <div class="mini-level-bars popup" style=" ' + d.iconDisplay.i1 + ' background-color: ' + d.color + ' "></div>'; 85 popup += ' <div class="popup-col-subtitle-text">' + d.sqiLvl + '</div>'; 86 popup += ' </div>'; 87 popup += ' </div>'; 88 popup += ' <div class="poopup-vr"></div>'; 89 popup += ' <div class="popup-body-col w-col-4">'; 90 popup += ' <div class="popup-col-title"> ' + d.ultimaInspecao + '</div>'; //Ãlima Inspeção 91 popup += ' <div class="popup-col-subtitle">'; 92 popup += ' <div class="mini-level-bars popup" style=" ' + d.iconDisplay.i2 + ' background-color: ' + d.color + ' "></div>'; 93 popup += ' <div class="popup-col-subtitle-text">' + d.lastInspection + '</div>'; 94 popup += ' </div>'; 95 popup += ' </div>'; 96 popup += ' <div class="poopup-vr"></div>'; 97 popup += ' <div class="popup-body-col w-col-4">'; 98 popup += ' <div class="popup-col-title"> ' + d.ultimaOcorrencia + '</div>'; // Ãlt. ocorrência 99 popup += ' <div class="popup-col-subtitle">'; 100 popup += ' <div class="mini-level-bars popup" style=" ' + d.iconDisplay.i3 + ' background-color: ' + d.color + ' "></div>'; 101 popup += ' <div class="popup-col-subtitle-text">' + d.lastOcorrence + '</div>'; 102 popup += ' </div>'; 103 popup += ' </div>'; 104 popup += ' </div>'; 105 }*/ 106 popup += ' </div>'; 107 popup += ' <div class="custom-popup-content-arrow">'; 108 popup += ' <div class="popup-arrow-icon"></div>'; 109 popup += ' </div>'; 110 popup += ' </div>'; 111 popup += ' </div>'; 112 return popup; 113 }, 114 //popup: function (color, link, title, subtitle, sqiLvl, lastInspection, lastOcorrence, closeIcon, displayIcons, indiceLabel, sqiValue) { 115 popup: function (color, link, title) { 116 117 color = (leafletMap.isEmpty(color)) ? 'black' : color; 118 title = (leafletMap.isEmpty(title)) ? '-' : title;
119 // subtitle = (leafletMap.isEmpty(subtitle)) ? '-' : subtitle; 120 // sqiLvl = (leafletMap.isEmpty(sqiLvl)) ? 'N/D' : sqiLvl; 121 // lastInspection = (leafletMap.isEmpty(lastInspection)) ? 'N/D' : lastInspection; 122 // lastOcorrence = (leafletMap.isEmpty(lastOcorrence)) ? 'N/D' : lastOcorrence; 123 124 // displayIcons = (Array.isArray(displayIcons)) ? displayIcons : [true, false, false]; 125 126 // let iconDisplay = { 127 // i1: (displayIcons[0]) ? ' display: unset; ' : '', 128 // i2: (displayIcons[1]) ? ' display: unset; ' : '', 129 // i3: (displayIcons[2]) ? ' display: unset; ' : '', 130 // }; 131 132 let popupStyle = ""; 133 let hide = leafletMap.info.hidePopup ? ' "display: none;" ' : ''; 134 135 if (!leafletMap.info.showPopupBody) { 136 popupStyle = "style='height: 120px; " + hide + "'"; 137 } else { 138 popupStyle = "style='" + hide + "'"; 139 } 140 141 let data = { 142 hidePopup: popupStyle, 143 // closeIcon: closeIcon, 144 title: title, 145 link: link, 146 // subtitle: subtitle, 147 // indiceLabel: indiceLabel, 148 // sqiValue: sqiValue, 149 // iconDisplay: iconDisplay, 150 color: color, 151 // sqiLvl: sqiLvl, 152 // lastInspection: lastInspection, 153 // lastOcorrence: lastOcorrence, 154 // nivelRisco: leafletMap.localization.map_label_nivel_risco, 155 // ultimaInspecao: leafletMap.localization.map_label_ultima_inspecao, 156 // ultimaOcorrencia: leafletMap.localization.map_label_ultima_ocorrencia 157 }; 158 159 let popup = leafletMap.html.popup_model(data); 160 161 162 return popup; 163 }, 164 }, 165 layers: { 166 show: { 167 simple: true, 168 satellite: true, 169 alternative: true, 170 }, 171 simpleLayer: function () { 172 return L.tileLayer('http://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', { 173 attribution: '© <a href="http://www.innovpoint.com">Innovation Point S.A.</a>', 174 detectRetina: true, 175 maxZoom: leafletMap.info.maxZoom, 176 }); 177 }, 178 satelliteLayer: function () { 179 return L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', { 180 attribution: '© <a href="http://www.innovpoint.com">Innovation Point S.A.</a>', 181 detectRetina: true, 182 maxZoom: leafletMap.info.maxZoom, 183 }); 184 }, 185 altLayer: function () { 186 return L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', { 187 attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>', 188 maxZoom: leafletMap.info.maxZoom, 189 id: 'mapbox/streets-v11', 190 accessToken: 'pk.eyJ1IjoidmFsdGluZ29qZXIiLCJhIjoiY2s1eTFqdzhsMDBvYTNrbWxzaDN1b3FtbiJ9.EFxzK2fg7xVU_TIHELbqdA' 191 }); 192 }, 193 }, 194 points: { 195 markers: [], 196 markersLoaded: [], 197 colors: { 198 c0: 'black', 199 c1: '#1e9d8b', 200 c2: '#8bb35e', 201 c3: '#f9c932', 202 c4: '#f4873d', 203 c5: '#d6555d', 204 205 change: function (code, colorVal, sameAsDefined) { 206 if (sameAsDefined) { 207 switch (code) { 208 case 0: 209 leafletMap.points.colors.c0 = colorVal; 210 break; 211 case 1: 212 leafletMap.points.colors.c1 = colorVal; 213 break; 214 case 2: 215 leafletMap.points.colors.c2 = colorVal; 216 break; 217 case 3: 218 leafletMap.points.colors.c3 = colorVal; 219 break; 220 case 4: 221 leafletMap.points.colors.c4 = colorVal; 222 break; 223 case 5: 224 leafletMap.points.colors.c5 = colorVal; 225 break; 226 default: 227 } 228 } else { 229 switch (code) { 230 case 0: 231 leafletMap.points.colors.c1 = colorVal; 232 break; 233 case 1: 234 leafletMap.points.colors.c2 = colorVal; 235 break; 236 case 2: 237 leafletMap.points.colors.c3 = colorVal; 238 break; 239 case 3: 240 leafletMap.points.colors.c4 = colorVal; 241 break; 242 case 4: 243 leafletMap.points.colors.c5 = colorVal; 244 break; 245 case 5: 246 leafletMap.points.colors.c0 = colorVal; 247 break; 248 default: 249 } 250 } 251 252 }, 253 getByValue: function (val) { 254 let returnValue = 0; 255 if (val >= 1 && val <= 1.5) { 256 returnValue = 1; 257 } else if (val > 1.5 && val <= 2.5) { 258 returnValue = 2; 259 } else if (val > 2.5 && val <= 3.5) { 260 returnValue = 3; 261 } else if (val > 3.5 && val <= 4.3) { 262 returnValue = 4; 263 } else if (val > 4.3 && val <= 5) { 264 returnValue = 5; 265 } 266 267 return returnValue; 268 }, 269 getByCode: function (code) { 270 switch (code) { 271 case 1: return leafletMap.points.colors.c1; 272 case 2: return leafletMap.points.colors.c2; 273 case 3: return leafletMap.points.colors.c3; 274 case 4: return leafletMap.points.colors.c4; 275 case 5: return leafletMap.points.colors.c5; 276 default: return leafletMap.points.colors.c0; 277 } 278 } 279 280 }, 281 getTranslatedRiskByIndex: function (val) { 282 try { 283 switch (val) { 284 case 0: return (!isNullOrUndefined(leafletMap.info.riskTranslation[val])) ? leafletMap.info.riskTranslation[val] : "Muito baixo"; 285 case 1: return (!isNullOrUndefined(leafletMap.info.riskTranslation[val])) ? leafletMap.info.riskTranslation[val] : "Baixo"; 286 case 2: return (!isNullOrUndefined(leafletMap.info.riskTranslation[val])) ? leafletMap.info.riskTranslation[val] : "Moderado"; 287 case 3: return (!isNullOrUndefined(leafletMap.info.riskTranslation[val])) ? leafletMap.info.riskTranslation[val] : "Alto"; 288 case 4: return (!isNullOrUndefined(leafletMap.info.riskTranslation[val])) ? leafletMap.info.riskTranslation[val] : "Muito alto"; 289 default: return ""; 290 } 291 } catch (e) { 292 return ""; 293 } 294 295 296 }, 297 popup: [], 298 values: [], 299 class: [], 300 Latitude: [], 301 Longitude: [], 302 currentCoordenate: [], 303 totalCoordenates: function () { return this.Latitude.length; }, 304 loopParallel: function () { return (this.Latitude.length == this.colors.length) }, 305 totalMarkers: function () { return this.markers.length; }, 306 getCoordenate: function (i) { return [this.Latitude[i], this.Longitude[i]]; }, 307 308 }, 309 setConfig: function (name, coordenates, zoom, maxZoom) { 310 if (!Array.isArray(coordenates)) { throw 'coordenates needs to be array [int Latitude, int Longitude]'; return false; } 311 this.info.name = name;
312 this.info.coordenates = coordenates; 313 this.info.zoom = zoom; 314 this.info.maxZoom = maxZoom; 315 }, 316 317 setLocalization: function ( loc ) { 318 319 //console.log("localization"); 320 //console.log(loc); 321 322 // this.localization = loc; 323 this.localization = loc; 324 325 }, 326 populate: function (type, value, coordenates, popup) { 327 if (!Array.isArray(coordenates)) { throw 'coordenates needs to be array [int Latitude, int Longitude]'; return false; } 328 this.points.values.push(value); 329 this.points.class.push(type); 330 this.points.Latitude.push(coordenates[0]); this.points.Longitude.push(coordenates[1]); 331 332 333 if (!this.isEmpty(popup)) { 334 popup = { 335 link: (leafletMap.isEmpty(popup.link)) ? null : popup.link, 336 title: (leafletMap.isEmpty(popup.title)) ? '-' : popup.title, 337 // subtitle: (leafletMap.isEmpty(popup.subtitle)) ? '-' : popup.subtitle, 338 // sqi: (leafletMap.isEmpty(popup.sqi)) ? 0 : popup.sqi, 339 // lastInspection: (leafletMap.isEmpty(popup.lastInspection)) ? 'N/D' : popup.lastInspection, 340 // lastOcurrence: (leafletMap.isEmpty(popup.lastOcurrence)) ? 'N/D' : popup.lastOcurrence, 341 iconColor: (leafletMap.isEmpty(popup.iconColor)) ? '#fff' : popup.iconColor, 342 // iconBytype: (leafletMap.isEmpty(popup.iconBytype)) ? '' : popup.iconBytype, 343 // sqiValue: (Math.round(sqiValue * 100) / 100), 344 // sqiLabel: sqiLabel 345 346 } 347 } else { 348 popup = { 349 link: null, 350 title: '--', 351 // subtitle: '--', 352 // sqi: 0, 353 // lastInspection: 'N/D', 354 // lastOcurrence: 'N/D', 355 iconColor: '#fff', 356 // iconBytype: '', 357 // sqiValue: "", 358 // sqiLabel: "" 359 } 360 } 361 362 this.points.popup.push(popup); 363 364 365 return true; 366 }, 367 helper: { 368 createMap: function (mainLayer) { 369 mainLayer = (mainLayer == null) ? [leafletMap.layers.satelliteLayer()] : [leafletMap.layers.altLayer()]; 370 371 return L.map(leafletMap.info.name, { 372 layers: mainLayer, 373 zoom: leafletMap.info.zoom, 374 scrollWheelZoom: leafletMap.info.allowScroll, 375 }); 376 }, 377 getCoordenates: function () { return leafletMap.info.coordenates; }, 378 getZoom: function () { return leafletMap.info.zoom; }, 379 createControlLayer: function () { 380 let layers = {}; 381 382 if (leafletMap.layers.show.simple) { layers['Terrain'] = leafletMap.layers.simpleLayer(); } 383 if (leafletMap.layers.show.satellite) { layers['Satellite'] = leafletMap.layers.satelliteLayer(); } 384 if (leafletMap.layers.show.alternative) { layers['Map'] = leafletMap.layers.altLayer(); } 385 386 let controlLayer = L.control.layers(layers, { }); 387 388 return controlLayer; 389 }, 390 createPoints: function (myLeafletMap) { 391 392 for (var i = 0; i < leafletMap.points.totalCoordenates(); i++) { 393 if (leafletMap.points.Latitude.length != leafletMap.points.Longitude.length) { 394 break; 395 } else { 396 /*create custom icons*/ 397 398 //let currentValue = leafletMap.points.values[i]; 399 let colorByCode = leafletMap.points.popup[i].iconColor; 400 let lat = leafletMap.points.Latitude[i]; 401 let long = leafletMap.points.Longitude[i]; 402 403 let customStyle = { 404 pointerBorder: "", 405 pointerContent: "", 406 arrow: "", 407 }; 408 409 // Create a custom HTML with data attributes 410 let iconHtml = leafletMap.html.icon(customStyle.pointerBorder, leafletMap.points.class[i], customStyle.pointerContent, customStyle.arrow); 411 412 // Create a wrapper with data attributes 413 let iconHtmlWithData = `<div data-lat="${lat}" data-long="${long}">${iconHtml}</div>`; 414 415 let customIcon = L.divIcon({ 416 className: "map-marker", 417 iconSize: new L.Point(36, 42), 418 html: iconHtmlWithData, 419 }); 420 421 let marker = L.marker(leafletMap.points.getCoordenate(i), { title: '', icon: customIcon }); 422 423 // Store coordinates in marker options for later reference 424 marker.options.dataLat = lat; 425 marker.options.dataLong = long; 426 427 // Add event to set data attributes after the marker is added to the map 428 marker.on('add', function() { 429 setTimeout(function() { 430 // Find the marker elements that were just added 431 const markerElements = document.querySelectorAll('.leaflet-marker-icon, .leaflet-marker-shadow');
432 markerElements.forEach(function(el) { 433 if (!el.hasAttribute('data-lat')) { 434 el.setAttribute('data-lat', lat); 435 el.setAttribute('data-long', long); 436 } 437 }); 438 }, 100); 439 }); 440 //let marker = L.marker(leafletMap.points.getCoordenate(i), { title: colorByCode.toString().substr(1), icon: customIcon }); 441 442 let popupData = { 443 offset: [-6.5, -20], 444 color: colorByCode, 445 link: leafletMap.points.popup[i].link, 446 title: leafletMap.points.popup[i].title, 447 // subtitle: leafletMap.points.popup[i].subtitle, 448 // sqi: leafletMap.points.sqiRiskToText(leafletMap.points.popup[i].sqi), 449 // lastInspection: leafletMap.points.popup[i].lastInspection, 450 // lastOcurrence: leafletMap.points.popup[i].lastOcurrence, 451 // closeIcon: leafletMap.points.popup[i].iconBytype, 452 IconBarsToDisplay: [true, false, false], 453 // sqiValue: leafletMap.points.popup[i].sqiValue, 454 // sqiLabel: leafletMap.points.popup[i].sqiLabel 455 }; 456/* 457 var popup = leafletMap.html.popup(popupData.color, 458 popupData.link, popupData.title, popupData.subtitle, popupData.sqi, popupData.lastInspection, popupData.lastOcurrence, 459 popupData.closeIcon, popupData.IconBarsToDisplay, popupData.sqiValue, popupData.sqiLabel) 460*/ 461 var popup = leafletMap.html.popup(popupData.color, popupData.link, popupData.title) 462 463 var popupContent = L.popup({ offset: popupData.offset }).setContent(popup); 464 465 466 marker.bindPopup(popupContent).openPopup(); 467 468 leafletMap.points.markers.push(marker); 469 470 } 471 472 } 473 return myLeafletMap; 474 }, 475 createCluster: { 476 defatul: function () { 477 let cluster = L.markerClusterGroup(); 478 for (var i = 0; i < leafletMap.points.totalMarkers(); i++) { 479 let iMark = leafletMap.points.markers[i]; 480 cluster.addLayer(iMark); 481 } 482 return cluster; 483 }, 484 donut: function (myLeafletMap) { 485 let cluster = L.DonutCluster( 486 //the first parameter is markercluster's configuration file 487 { 488 chunkedLoading: true 489 } 490 //the second parameter is DonutCluster's configuration file 491 , { 492 key: 'title', //mandotary, indicates the grouped field, set it in the options of marker 493 sumField: false, //'value', // optional, indicates the value field to sum. set it in the options of marker 494 arcColorDict: { // mandotary, the arc color for each group. 495 '': '#6371B8', 496 }, 497 fillColor: '#6371B8', 498 }); 499 500 var markerCallback = function (map) { 501 leafletMap.points.markersLoaded.push(map.layer); 502 if(leafletMap.points.markersLoaded.length === leafletMap.points.totalMarkers()){ 503 if (leafletMap.info.fitZoom) { 504 try { 505 if(cluster.getBounds() && cluster.getBounds().isValid()){ 506 console.info("valid clusters bounds found"); 507 myLeafletMap.fitBounds(cluster.getBounds()); 508 }else{ 509 console.warn("no valid clusters bounds fallback to portugal"); 510 let portugal = L.latLngBounds([42.260, -8.915], [39.495, -7.000]) 511 myLeafletMap.fitBounds(portugal); 512 } 513 }catch (e){ 514 console.error("error fitting zoom to map", e); 515 } 516 } 517 } 518 }; 519 520 for (var i = 0; i < leafletMap.points.totalMarkers(); i++) { 521 let iMark = leafletMap.points.markers[i];
522 cluster.addLayer(iMark); 523 cluster.on('add', markerCallback); 524 } 525 return cluster; 526 }, 527 }, 528 getAddressInfoByCoordenate: function(coor){ 529 const geocoder = new google.maps.Geocoder(); 530 geocoder.geocode({'latLng': coor}, function (results, status) { 531 if (status == google.maps.GeocoderStatus.OK) { 532 if (results[0]) { 533 return results; 534 }else{ 535 return false; 536 } 537 } 538 }); 539 }, 540 setAddressInfoByCoordenate: function(coor, fn){ 541 const geocoder = new google.maps.Geocoder(); 542 geocoder.geocode({'latLng': coor}, function (results, status) { 543 if (status == google.maps.GeocoderStatus.OK) { 544 if (results[0]) { 545 fn(results); 546 }else{ 547 return false; 548 } 549 } 550 }); 551 }, 552 getCoordenatesBySearch: function(term){ 553 leafletMap.temp.search.status = "processing"; 554 leafletMap.temp.search.set(null); 555 const geocoder = new google.maps.Geocoder(); 556 geocoder.geocode({ 557 'address': term 558 }, function (results, status) { 559 if (status == google.maps.GeocoderStatus.OK) { 560 if (results) { 561 coor = []; 562 coor.push(results[0].geometry.location.lat()); 563 coor.push(results[0].geometry.location.lng()); 564 leafletMap.temp.search.status = "OK"; 565 leafletMap.temp.search.set(coor); 566 } 567 } 568 }); 569 }, 570 getCoordenatesByCurrentLocalization: function(){ 571 leafletMap.temp.gps.status = "processing"; 572 navigator.geolocation.getCurrentPosition(function (position) { 573 coor = []; 574 coor.push(position.coords.latitude); 575 coor.push(position.coords.longitude); 576 leafletMap.temp.gps.status = "OK"; 577 leafletMap.temp.gps.set(coor); 578 }); 579 }, 580 }, 581 removeAllMarks: function(){ 582 try { 583 var loopLimit = (document.querySelectorAll(".leaflet-marker-icon").length * 2) || 10; 584 for (let index = 0; index <= loopLimit; index++) { 585 try { document.querySelector(".leaflet-pane.leaflet-shadow-pane").remove(); } catch (e) {} 586 try { document.querySelector(".leaflet-pane.leaflet-marker-pane div").remove(); } catch (e) {} 587 try { document.querySelector(".leaflet-pane.leaflet-marker-pane img").remove(); } catch (e) {} 588 try { document.querySelector(".leaflet-pane.leaflet-marker-pane svg").remove(); } catch (e) {} 589 } 590 } catch (error) {} 591 }, 592 addMarkerOnClick: function(event, myLeafletMap){ 593 leafletMap.removeAllMarks(); 594 leafletMap.addSimpleMark(myLeafletMap, event.latlng); 595 leafletMap.temp.coordenates = event.latlng; 596 leafletMap.temp.address.status = "processing"; 597 leafletMap.helper.setAddressInfoByCoordenate(event.latlng, function(r){ 598 leafletMap.temp.address.set(r); 599 leafletMap.temp.address.status = "OK"; 600 }); 601 }, 602 addSimpleMark: function (myLeafletMap, coordinates, customIconPath, customIconShadowPath, callback) { 603 try { 604 let newMark = null; 605 if (customIconPath != null && customIconShadowPath != null) { 606 var customIcon = L.icon({ 607 iconUrl: customIconPath, 608 shadowUrl: customIconShadowPath, 609 iconSize: [65, 65], 610 shadowSize: [50, 64], 611 iconAnchor: [21, 63], // point of the icon which will correspond to marker's location 612 shadowAnchor: [4, 62], 613 popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor 614 }); 615 616 newMark = L.marker(coordinates, {icon: customIcon}).addTo(myLeafletMap); 617 } else { 618 newMark = L.marker(coordinates).addTo(myLeafletMap); 619 } 620 621 if (callback != null && typeof callback === "function") { 622 callback(newMark, myLeafletMap); 623 } 624 } catch (e) { 625 console.error("error adding simple mark", e); 626 } 627 }, 628 addClickEvent: function(myLeafletMap, clickEventFunction){ 629 myLeafletMap.addEventListener("click", function(e){ clickEventFunction(e, myLeafletMap); }); 630 }, 631 changeView: function (coordinates, zoom) { 632 if (typeof leafletMap.info.myMap === undefined || !leafletMap) { 633 alert("Mapa não existe, use a função init para criar o mapa primeiro"); 634 } 635
636 leafletMap.info.myMap.setView(coordinates, zoom); 637 leafletMap.info.myMap.setZoom(zoom); 638 }, 639 createMarkers: function (myLeafletMap) { 640 myLeafletMap = this.helper.createPoints(myLeafletMap); 641 let clusters = leafletMap.info.cluster = this.helper.createCluster.donut(myLeafletMap); 642 myLeafletMap.addLayer(clusters); 643 }, 644 init: function (mainLayer) { 645 try { 646 let myLeafletMap = this.helper.createMap(mainLayer); 647 myLeafletMap.setView(this.helper.getCoordenates(), this.helper.getZoom()); 648 this.helper.createControlLayer().addTo(myLeafletMap); 649 650 myLeafletMap = this.helper.createPoints(myLeafletMap); 651 let clusters = leafletMap.info.cluster = this.helper.createCluster.donut(myLeafletMap); 652 myLeafletMap.addLayer(clusters); 653 654 if(this.info.enableClick) { 655 leafletMap.addClickEvent(myLeafletMap, leafletMap.addMarkerOnClick); 656 } 657 leafletMap.info.myMap = myLeafletMap; 658 }catch (e) { 659 console.error("error map init", e); 660 } 661 }, 662 cleanAll: function() { 663 leafletMap.info.myMap.removeLayer(leafletMap.info.cluster) 664 leafletMap.removeAllMarks(); 665 leafletMap.points.markers = []; 666 leafletMap.points.markersLoaded = []; 667 leafletMap.points.popup = []; 668 leafletMap.points.values = []; 669 leafletMap.points.class = []; 670 leafletMap.points.Latitude = []; 671 leafletMap.points.Longitude = []; 672 leafletMap.points.currentCoordenate = []; 673 }, 674 clean: function(lat, long) { 675 try { 676 if (!lat || !long) { 677 console.error("Latitude and longitude are required"); 678 return; 679 } 680 681 // Find the marker index with the given coordinates 682 let markerIndex = -1; 683 for (let i = 0; i < this.points.Latitude.length; i++) { 684 if (this.points.Latitude[i] == lat && this.points.Longitude[i] == long) { 685 markerIndex = i; 686 break; 687 } 688 } 689 690 if (markerIndex === -1) { 691 console.warn("No marker found with coordinates:", lat, long); 692 return; 693 } 694 695 // Remove marker from the map 696 if (this.info.myMap && this.points.markers[markerIndex]) { 697 this.info.myMap.removeLayer(this.points.markers[markerIndex]); 698 } 699 700 // Remove marker data from arrays 701 this.points.markers.splice(markerIndex, 1); 702 this.points.markersLoaded = this.points.markersLoaded.filter(m => 703 m._latlng.lat != lat || m._latlng.lng != long); 704 this.points.popup.splice(markerIndex, 1); 705 this.points.values.splice(markerIndex, 1); 706 this.points.class.splice(markerIndex, 1); 707 this.points.Latitude.splice(markerIndex, 1); 708 this.points.Longitude.splice(markerIndex, 1); 709 710 console.log("Marker cleaned at coordinates:", lat, long); 711 } catch (e) { 712 console.error("Error cleaning marker", e); 713 } 714 }, 715 hideAll: function() { 716 try { 717 const markers = document.querySelectorAll(".leaflet-marker-icon, .leaflet-marker-shadow"); 718 markers.forEach(marker => { 719 marker.classList.add('d-none'); 720 }); 721 console.log("All markers hidden"); 722 } catch (e) { 723 console.error("Error hiding all markers", e); 724 } 725 }, 726 showAll: function() { 727 try { 728 const markers = document.querySelectorAll(".leaflet-marker-icon, .leaflet-marker-shadow"); 729 markers.forEach(marker => { 730 marker.classList.remove('d-none'); 731 }); 732 console.log("All markers shown"); 733 } catch (e) { 734 console.error("Error showing all markers", e); 735 } 736 }, 737 hide: function(lat, long) { 738 try { 739 if (!lat || !long) { 740 console.error("Latitude and longitude are required"); 741 return; 742 } 743 744 const markers = document.querySelectorAll(`.leaflet-marker-icon[data-lat="${lat}"][data-long="${long}"], .leaflet-marker-shadow[data-lat="${lat}"][data-long="${long}"]`);
745 markers.forEach(marker => { 746 marker.classList.add('d-none'); 747 }); 748 console.log("Marker hidden at coordinates:", lat, long); 749 } catch (e) { 750 console.error("Error hiding marker", e); 751 } 752 }, 753 show: function(lat, long) { 754 try { 755 if (!lat || !long) { 756 console.error("Latitude and longitude are required"); 757 return; 758 } 759 760 const markers = document.querySelectorAll(`.leaflet-marker-icon[data-lat="${lat}"][data-long="${long}"], .leaflet-marker-shadow[data-lat="${lat}"][data-long="${long}"]`); 761 markers.forEach(marker => { 762 marker.classList.remove('d-none'); 763 }); 764 console.log("Marker shown at coordinates:", lat, long); 765 } catch (e) { 766 console.error("Error showing marker", e); 767 } 768 }, 769}; 770
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.