;(function($,_,undefined){"use strict";ips.controller.register('communitymap.front.markers.markerform',{map:null,popup:null,marker:null,infowindow:null,bounds:null,initialize:function(){this.setupMap();this.setup();this.setupEvents();},setup:function(){const icon=L.AwesomeMarkers.icon({prefix:'fa',icon:'map-marker',color:'darkblue'});this.infowindow=new L.Popup();this.marker=new L.Marker(this.bounds.getCenter(),{draggable:true,opacity:0.0,icon:icon}).bindPopup(this.infowindow).addTo(this.map);if($('#communitymap_marker_form input[name="marker_lat"]').val()!=0){Debug.log('Setting initial marker');Debug.log('Lat: '+$('#communitymap_marker_form input[name="marker_lat"]').val());Debug.log('Lng: '+$('#communitymap_marker_form input[name="marker_lon"]').val());this.marker.setLatLng(new L.LatLng(parseFloat($('#communitymap_marker_form input[name="marker_lat"]').val()),parseFloat($('#communitymap_marker_form input[name="marker_lon"]').val())));this.marker.setOpacity(1);this.infowindow.setContent('<h4>'+($('#elInput_marker_title').val()||'')+'</h4>'+$('#elInput_marker_location').val());this.marker.openPopup();this.map.flyTo(this.marker.getLatLng(),8);}
else{this.map.panTo(this.bounds.getCenter());this.map.setZoom(this.map.getZoom()+1);}},setupEvents:function(){const that=this;this.marker.on('dragend',function(e){const coords=e.target.getLatLng();that.findMarkerPosition(coords.lat,coords.lng);});this.map.on('click',function(e){Debug.log(e.latlng);that.findMarkerPosition(e.latlng.lat,e.latlng.lng);});$('#elInput_marker_location').autocomplete({minLength:3,source:function(request,response){ips.getAjax()({url:ips.getSetting('baseURL')+'index.php?app=communitymap&module=communitymap&controller=ajax&do=locationSearch',type:'get',dataType:'json',data:{q:request.term},success:function(data){response($.map(data.results,function(item){return{value:item.formatted,resultType:item.result_type,latLng:{lat:item.lat,lng:item.lon},country:item.country_code??''};}));}});},select:function(event,ui){$('#communitymap_marker_form input[name="marker_lat"]').val(parseFloat(ui.item.latLng.lat).toFixed(6));$('#communitymap_marker_form input[name="marker_lon"]').val(parseFloat(ui.item.latLng.lng).toFixed(6));$('#communitymap_marker_form input[name="marker_country"]').val(ui.item.country);that.marker.setLatLng(new L.LatLng(parseFloat($('#communitymap_marker_form input[name="marker_lat"]').val()),parseFloat($('#communitymap_marker_form input[name="marker_lon"]').val())),8);that.marker.setOpacity(1);that.map.flyTo(that.marker.getLatLng(),8);that.infowindow.setContent('<h4>'+($('#elInput_marker_title').val()||'')+'</h4>'+ui.item.value);that.marker.openPopup();}}).autocomplete("instance")._renderItem=function(ul,item){let icon="";const featureIcons={unknown:"map-marker",amenity:"map-marker",building:"building",street:"road",suburb:"building",district:"building",postcode:"building",city:"building",county:"building",state:"building"}
if(featureIcons[item.resultType]){icon="<span class='ipsType_large'><i class='fa fa-"+featureIcons[item.resultType]+"'></i></span> ";}
const o=item.value.toLowerCase().indexOf(this.term.toLowerCase());if(o>=0){item.value=item.value.substring(0,o)+"<strong>"+item.value.substring(o,o+this.term.length)+"</strong>"+item.value.substring(o+this.term.length);}
return $("<li>").append("<div>"+icon+item.value+"</div>").appendTo(ul);};},setupMap:function(){const southWest=new L.LatLng(56.83,-7.14);const northEast=new L.LatLng(74.449,37.466);this.bounds=new L.LatLngBounds(southWest,northEast);const mapServices={};const baseMaps={};const defaultMaps=ips.getSetting('communitymap_defaultMaps');let defaultMap='';$.each(defaultMaps.basemaps,function(id,name){try{const key=name.toLowerCase().replace('.','');const prettyName=name.replace('.',' ');baseMaps[prettyName]=mapServices[key]=L.tileLayer.provider(name);if(defaultMap===''){defaultMap=key;}}
catch(e){Debug.log(e.message);}});this.map=L.map('mapCanvas',{zoom:7,layers:[mapServices[defaultMap]],attributionControl:true,crs:L.CRS.EPSG3857});this.map.fitBounds(this.bounds);L.control.layers(baseMaps).addTo(this.map);},findMarkerPosition:function(lat,lng){const that=this;$('#communitymap_marker_form input[name="marker_lat"]').val(parseFloat(lat).toFixed(6));$('#communitymap_marker_form input[name="marker_lon"]').val(parseFloat(lng).toFixed(6));this.marker.setLatLng([lat,lng]);this.marker.setOpacity(1);ips.getAjax()({url:ips.getSetting('baseURL')+'index.php?app=communitymap&module=communitymap&controller=ajax&do=reverseLookup',type:'get',dataType:'json',data:{lat:lat,lng:lng},success:function(data){$('#communitymap_marker_form input[name="marker_country"]').val('');const item=data.results[0];if(item.result_type!=='unknown'){let location=item.formatted;location=location.replace(/(^\s*,)|(,\s*$)/g,'');$('#elInput_marker_location').val(location);that.infowindow.setContent('<h4>'+($('#elInput_marker_title').val()||'')+'</h4>'+location);}
else{$('#elInput_marker_location').val('');that.infowindow.setContent('<h4>'+$('#elInput_marker_title').val()+'</h4>');}
if(item.country_code){$('#communitymap_marker_form input[name="marker_country"]').val(item.country_code);}
that.marker.openPopup();}});}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('communitymap.front.markers.markerview',{map:null,popup:null,marker:null,infowindow:null,bounds:null,initialize:function(){this.setup();},setup:function(){this.setupMap();var icon=L.AwesomeMarkers.icon({prefix:'fa',icon:'map-marker',color:'darkblue'});this.marker=new L.Marker(new L.LatLng(parseFloat($(this.scope).attr('data-lat').replace(',','.')),parseFloat($(this.scope).attr('data-lon').replace(',','.'))),{icon:icon}).addTo(this.map);var popupOptions={autoPan:true,minWidth:320};var popupLoading=L.DomUtil.create('div','ipsLoading');popupLoading.style.height="70px";this.marker.bindPopup(popupLoading,(popupOptions||{}));var self=this;ips.getAjax()(ips.getSetting('baseURL')+'index.php?app=communitymap&module=communitymap&controller=ajax&do=getPopup&id='+$(this.scope).attr('data-id')).done(function(res){self.marker.getPopup().setContent(res);self.marker.getPopup().update();self.map.fire('popupopen',{popup:self.marker.getPopup()});});this.marker.openPopup();this.map.flyTo(this.marker.getLatLng(),ips.getSetting('communitymap_defaultzoom'));this.map.once('zoomend',function(){if(self.marker._popup.isOpen()){self.marker._popup._adjustPan();}});},setupMap:function(){var southWest=new L.LatLng(56.83,-7.14);var northEast=new L.LatLng(74.449,37.466);this.bounds=new L.LatLngBounds(southWest,northEast);var mapServices={};var baseMaps={};var defaultMaps=ips.getSetting('communitymap_defaultMaps');var defaultMap='';$.each(defaultMaps.basemaps,function(id,name){try{var key=name.toLowerCase().replace('.','');var prettyName=name.replace('.',' ');baseMaps[prettyName]=mapServices[key]=L.tileLayer.provider(name);if(defaultMap==''){defaultMap=key;}}
catch(e){Debug.log(e.message);}});this.map=L.map('mapCanvas',{zoom:ips.getSetting('communitymap_defaultzoom'),layers:[mapServices[defaultMap]],attributionControl:true,crs:L.CRS.EPSG3857});this.map.attributionControl.addAttribution('Powered by <a href="https://www.geoapify.com/" target="_blank">Geoapify</a>');this.map.fitBounds(this.bounds);L.control.layers(baseMaps).addTo(this.map);}});}(jQuery,_));;