Y-SLD/assets/playkit/js/draw_boundary-096ca890ae.js

3 lines
76 KiB
JavaScript

function toWKT(e){var t,r,a=[];if(e instanceof L.Polygon||e instanceof L.Polyline){for(var n=e.getLatLngs(),i=0;i<n.length;i++)n[i],a.push(n[i].lng+" "+n[i].lat),0===i&&(t=n[i].lng,r=n[i].lat);if(e instanceof L.Polygon)return"POLYGON(("+a.join(",")+","+t+" "+r+"))";if(e instanceof L.Polyline)return"LINESTRING("+a.join(",")+")"}else if(e instanceof L.Marker)return"POINT("+e.getLatLng().lng+" "+e.getLatLng().lat+")"}function renderLayer(e,t){if("undefined"==typeof featureGroup[e.unique_id]&&(featureGroup[e.unique_id]=new Array),2==e.type&&"undefined"!=typeof e.cluster&&1==e.cluster?featureGroup[e.unique_id][e.name]=new L.MarkerClusterGroup:featureGroup[e.unique_id][e.name]=new L.FeatureGroup,"undefined"!=typeof e.settings?1==e.settings.active?(add_current_layer_text(e),featureGroup[e.unique_id][e.name].addTo(mymap)):e.settings.active=0:(featureGroup[e.unique_id][e.name].addTo(mymap),e.settings=new Object,e.settings.active=1),1==e.settings.active&&(activeLayers.push({id:e._id,order:0}),order_current_active_layers()),"phantom"==page&&($.inArray(e._id,active_ids)!==-1?featureGroup[e.unique_id][e.name].addTo(mymap):1==e.settings.active&&mymap.removeLayer(featureGroup[e.unique_id][e.name])),"undefined"!=typeof page&&"user_farm"==page&&1==e.settings.active&&jQuery("#chk_"+e.unique_id).prop("checked","checked"),"undefined"!=typeof page&&"manage"==page&&(jQuery("#active-layers-container").append(Mustache.render(tmpl.activeLayer,{t:e,type:layerType[e.type]})),0==e.settings.active&&jQuery("#at-"+e.unique_id+" a.dropdown-toggle span").addClass("label-danger").removeClass("label-primary"),jQuery(".help-active-popup-hover").popover({title:"Active & In-Active",content:'<div class="row"><div class="col-md-12"><p>This feature allows you to initially hide a layer. This can be used to achieve a desired layer presentation as well as to provide faster map loading for larger layers.</p></div></div>',html:!0,trigger:"hover",container:"body"}),jQuery(".at_active_chk").bootstrapSwitch({size:"mini",onSwitchChange:function(t,r){t.preventDefault();var a=jQuery(this).parents("ul:first"),n=a.attr("data-id"),i=getIndex(selectedLayers,"unique_id",n);selectedLayers[i].settings||"undefined"!=typeof selectedLayers[i].settings||(selectedLayers[i].settings=new Object),r===!0?(selectedLayers[i].settings.active=1,jQuery("#at-"+e.unique_id+" a.dropdown-toggle span").removeClass("label-danger").addClass("label-primary"),mymap.addLayer(featureGroup[n][selectedLayers[i].name])):(selectedLayers[i].settings.active=0,jQuery("#at-"+e.unique_id+" a.dropdown-toggle span").addClass("label-danger").removeClass("label-primary"),mymap.removeLayer(featureGroup[n][selectedLayers[i].name])),calculateBounds()}})),1==e.type||4==e.type){var r={format:"image/png",layers:e.Name,transparent:!0,crs:L.CRS.EPSG4326,unique_id:e.unique_id,srs1:e.SRS,layer_type:e.type};"undefined"!=typeof e.geometry_area&&(r.geometry=e.geometry_area),"undefined"!=typeof e.time&&(r.time=e.time),L.tileLayer.betterWms(e.url,r).addTo(featureGroup[e.unique_id][e.name])}else 2==e.type?""==t?"phantom"==page?filterGlobalData():(e.cache_timer||"undefined"!=typeof e.cache_timer||(e.cache_timer=15),t={datasource:e.connection_id,sql_layer_name:e.name,query_box:e.query,_token:jQuery('[name="_token"]').val(),cache_key:e.cache_key,cache_timer:e.cache_timer,type:2,map_id:map.id},ajaxRequest("map/layer/json","post","json",t,function(t){"200"==t.status?processSQLJSON(t,e):showMsg(t.status,t.msg)})):processSQLJSON(t,e):3==e.type;overlayers_controls(e),overlays[e.name]=featureGroup[e.unique_id][e.name],layerSelector.addOverlay(featureGroup[e.unique_id][e.name],e.name),3==e.type&&jQuery("#at-"+e.unique_id).find(".style-at-layer").remove(),calculateBounds()}function getPopupContent(e,t){return $.each(e.features,function(e,r){$.each(r.properties,function(e,r){t=t.replace("&lt;"+e+"&gt;",r)})}),t}function processSQLJSON(e,t){t=defaultLayerStyle(t),3==e.more_data.sql_type?processheatmapJSON(e,t):(clearLayersAndControls(e,t),jQuery.each(e.result,function(e,r){L.geoJson(r,{onEachFeature:function(e,r){if(r instanceof L.Marker){var a=!1;"nr"==t.style.type?$.each(t.style.custom,function(n,i){if(between(e.properties[t.style.field],i.val))return a=!0,custom_marker_icon(i.style,r),!1}):"g"==t.style.type&&$.each(t.style.custom,function(n,i){if(e.properties[t.style.field]==i.val)return a=!0,custom_marker_icon(i.style,r),!1}),0==a&&custom_marker_icon(t.style.marker,r)}r.on("click",function(a){var n=getSQLPopupContent(e.properties,t.pc);r.bindPopup(n)})},style:function(e,r){return t.style.polygon}}).addTo(featureGroup[t.unique_id][t.name])}),1==t.settings.active&&add_sql_legend(t,!0),"phantom"==page&&add_sql_legend(t,!0))}function initLayer(){selectedLayers.sort(sort_value_layer),selectedBaseLayers.length>0&&jQuery("#visiable-layers").find(".baselayers-control").removeClass("hide"),jQuery.each(selectedBaseLayers,function(e,t){if(layerSelector.addBaseLayer(baseLayers.mymap[t.name],t.name),baselayers_controls(t.name),"undefined"!=typeof page&&"manage"==page){var r=jQuery("#base_layer_selection").find('input:checkbox[data-name="'+t.name+'"]');r.length>0&&(r.prop("checked","checked"),baseLayerMap(r,!1))}}),jQuery.each(selectedLayers,function(e,t){renderLayer(t,"")});var e={type:5,id:map.id,_token:jQuery('[name="_token"]').val()};ajaxRequest("map/layer/json","post","json",e,function(e){"200"==e.status?processFreeHand(e):showMsg(e.status,e.msg)});var e={type:6,id:map.id,_token:jQuery('[name="_token"]').val()};ajaxRequest("map/layer/json","post","json",e,function(e){"200"==e.status?processFreeHand(e):showMsg(e.status,e.msg)});var e={type:3,id:map.id,_token:jQuery('[name="_token"]').val()};ajaxRequest("map/layer/json","post","json",e,function(e){"200"==e.status?processFreeHand(e):showMsg(e.status,e.msg)});var e={type:"farm_boundary",id:map.id,_token:jQuery('[name="_token"]').val()};if(ajaxRequest("map/layer/json","post","json",e,function(e){"200"==e.status?isEmpty(e.result)||custom_boundary(e,"farm","boundary"):showMsg(e.status,e.msg)}),"undefined"!=typeof page&&"user_farm"==page){var e={type:"draw_boundary",id:map.id,_token:jQuery('[name="_token"]').val()};ajaxRequest("map/layer/json","post","json",e,function(e){"200"==e.status?isEmpty(e.result)||custom_boundary(e,"draw",e.name):showMsg(e.status,e.msg)})}}function processFreeHand(e){jQuery.each(e.result,function(e,r){index=getIndex(selectedLayers,"unique_id",e),t=selectedLayers[index],"undefined"==typeof featureGroup[t.unique_id]&&(featureGroup[t.unique_id]=new Array),featureGroup[t.unique_id][t.name]=new L.FeatureGroup,"undefined"!=typeof t.settings?1==t.settings.active?featureGroup[t.unique_id][t.name].addTo(mymap):t.settings.active=0:(featureGroup[t.unique_id][t.name].addTo(mymap),t.settings=new Object,t.settings.active=1),L.geoJson(r,{onEachFeature:function(e,r){selectedLayers[index].layer=r,1==t.settings.active&&drawingGroup.addLayer(r),featureGroup[t.unique_id][t.name].addLayer(r),r instanceof L.Marker&&r.setIcon(L.AwesomeMarkers.icon(selectedLayers[index].style.marker)),r.bindPopup(selectedLayers[index].pc)},style:function(e,r){return t.style.polygon},pointToLayer:function(e,r){return"undefined"!=typeof t.radius?L.circle(r,parseInt(t.radius,10)):L.marker(r)}})}),calculateBounds()}function custom_boundary(e,t,r){featureGroup[t]=new Array,featureGroup[t][r]=new L.FeatureGroup,"manage"==page&&featureGroup[t][r].addTo(mymap),jQuery.each(e.result,function(e,a){L.geoJson(a,{onEachFeature:function(e,a){featureGroup[t][r].addLayer(a)},style:function(e,t){return e.style},pointToLayer:function(e,t){return"undefined"!=typeof e.properties.radius?L.circle(t,parseInt(e.properties.radius,10)):L.marker(t)}})}),"boundary"==r&&mymap.fitBounds(featureGroup[t][r].getBounds())}function calculateBounds(){}function extend_bounds(e){}function getLayersIndex(e){var t=selectedLayers.length;for(i=0;i<t;i++)if(selectedLayers[i].unique_id==e)return i}function getIndex(e,t,r){var a=e.length;for(i=0;i<a;i++)if(e[i][t]==r)return i}function getSQLPopupContent(e,t){return $.each(e,function(e,r){"image"==e?(r='<a href="'+baseURL+r+'" target="_blank"><img src="'+baseURL+r+'" style="width:50px" /></a>',t=t.replace("&lt;"+e+"&gt;",r)):t=t.replace("&lt;"+e+"&gt;",r)}),t}function defaultSettings(){map.settings=""!=map.settings?JSON.parse(map.settings):new Object,"undefined"==typeof map.settings.width&&(map.settings.width=500),"undefined"==typeof map.settings.height&&(map.settings.height=500),"undefined"==typeof map.settings.zoom&&(map.settings.zoom=6),"undefined"==typeof map.settings.fullscreen&&(map.settings.fullscreen=1),"undefined"==typeof map.settings.https&&(map.settings.https=1)}function assingSettings(){}function saveMapData(e,t){var r=selectedLayers.length,a=new Array;for(i=0;i<r;i++){var n=jQuery.extend(!0,{},selectedLayers[i]);3!=n.type&&5!=n.type&&6!=n.type||(n.layer instanceof L.Circle&&(n.radius=n.layer.getRadius()),"undefined"!=typeof n.layer&&(n.layer=n.layer.toGeoJSON())),a.push(n)}var o={selectedLayers:a,selectedBaseLayers:selectedBaseLayers};jQuery("#action_type").val(e);var s=JSON.stringify(o);jQuery("#layer_json").val(s),jQuery("#section_id_hidden").val(jQuery("#dd_section_id").val());var l=jQuery("#layer-form, #map-settings-form").serialize();ajaxRequest("/developer/map/save","post","json",l,function(e){200==e.status?(jQuery("#map_id").val(e.map_id),t(e)):showMsg("error",e.msg)})}function sortLayers(){var e=new Array;$("#visiable-layers div.dropdown-menu .custom-control-layers").find("li").each(function(t){var r=$(this).attr("data-key");e[t]=r,t++}),$.each(e,function(e,t){var r=getIndex(selectedLayers,"unique_id",t);selectedLayers[r].order=e+1})}function overlayers_controls(e){var t="map-overlayer-controls-tmpl";"undefined"!=typeof ct_theme&&(t=ct_theme+t);var r=document.getElementById(t).innerHTML;Mustache.parse(r),(2!=e.type||"nr"!=e.style.type&&"g"!=e.style.type)&&("undefined"!=typeof page&&"user_farm"==page||$("<li/>").attr("data-key",e.unique_id).attr("data-name",e.name).addClass("overlay_control_"+e.unique_id).html(Mustache.render(r,e)).appendTo("#visiable-layers div.dropdown-menu .custom-control-layers").find('input[type="checkbox"]').bootstrapSwitch({size:"mini",onSwitchChange:function(e,t){e.preventDefault();var r=jQuery(this).parents("li:first"),a=r.attr("data-key"),n=r.attr("data-name"),i=getIndex(selectedLayers,"unique_id",a);selectedLayers[i];t===!0?mymap.addLayer(featureGroup[a][n]):mymap.removeLayer(featureGroup[a][n])}})),"undefined"!=typeof page&&"manage"==page&&$("#visiable-layers div.dropdown-menu .custom-control-layers").sortable({stop:sortLayers}).disableSelection()}function addSubOverLayer(e){var t=jQuery('li[data-key="'+e.unique_id+'"]'),r=document.getElementById("map-overlayer-sub-controls-tmpl").innerHTML;$.each(e.style.custom,function(a,n){$("<li/>").attr("data-key",e.unique_id).attr("data-name",e.name).attr("data-val",n.val).html(Mustache.render(r,{val:n.val,t:e})).appendTo(t.find("ul")).find('input[type="checkbox"]').bootstrapSwitch({size:"mini",onSwitchChange:function(e,t){e.preventDefault();var r=jQuery(this).parents("li:first"),a=r.attr("data-key"),n=r.attr("data-name"),i=r.attr("data-val"),o=getIndex(selectedLayers,"unique_id",a),s=selectedLayers[o],l=featureGroup[a][n].getLayers();$.each(l,function(e,r){r.eachLayer(function(e){"nr"==s.style.type?between(e.feature.properties[s.style.field],i)&&(t===!0?mymap.addLayer(e):mymap.removeLayer(e)):"g"==s.style.type&&e.feature.properties[s.style.field]==i&&(t===!0?mymap.addLayer(e):mymap.removeLayer(e))})})}})}),jQuery(".subcontrol-layer-action").slimScroll({alwaysVisible:!0,height:100}),jQuery(".submenu-overlay-controls").click(function(e){e.preventDefault();var t=jQuery(this);t.toggleClass("in");var r=$(t.attr("href"));return r.hasClass("in")?r.collapse("hide"):r.collapse("show"),!1})}function baselayers_controls(e){var t=document.getElementById("map-baselayer-controls-tmpl").innerHTML;Mustache.parse(t),$("<li/>").attr("data-name",e).addClass("baselayer_control_"+e).html(Mustache.render(t,{name:e})).prependTo("#visiable-layers div.dropdown-menu .baselayers-control-layers").find('input[type="radio"]').bootstrapSwitch({size:"mini",onSwitchChange:function(e,t){e.preventDefault();var r=jQuery(this).parents("li:first"),a=r.attr("data-name");$.each(baseLayers.mymap,function(e,t){mymap.removeLayer(baseLayers.mymap[e])}),t===!0&&mymap.addLayer(baseLayers.mymap[a])}})}function removeOverlayerControl(e){jQuery("#visiable-layers").find(".overlay_control_"+e).remove()}function applyLiveStyle(e){var t=jQuery('#map-sidebar-container [name="my_unique_id"]').val(),r=getIndex(selectedLayers,"unique_id",t),a={};jQuery("#layer-polygon-styling input").each(function(){var e=jQuery(this);a[e.attr("name")]=e.val()});var n={};if(jQuery("#layer-marker-styling .default-marker-style select").each(function(){var e=jQuery(this);n[e.attr("data-name")]=e.val()}),2==selectedLayers[r].type){var i=featureGroup[selectedLayers[r].unique_id][selectedLayers[r].name].getLayers();$.each(i,function(e,t){t.eachLayer(function(e){e instanceof L.Marker?custom_marker_icon(n,e):(e instanceof L.Polyline||e instanceof L.Polygon||e instanceof L.Rectangle||e instanceof L.Circle)&&e.setStyle(a)})})}else if(3==selectedLayers[r].type){var o=selectedLayers[r].layer;o instanceof L.Marker?custom_marker_icon(n,o):(o instanceof L.Polyline||o instanceof L.Polygon||o instanceof L.Rectangle||o instanceof L.Circle)&&o.setStyle(a)}selectedLayers[r].style.polygon=a,selectedLayers[r].style.marker=n}function defaultLayerStyle(e){var t=new Object,r=new Object;"undefined"==typeof e.style&&(e.style=new Object),"undefined"!=typeof e.style.polygon?t=e.style.polygon:e.style.polygon=new Object,"undefined"!=typeof e.style.marker?r=e.style.marker:e.style.marker=new Object,"undefined"==typeof t.color&&(t.color="#ccc"),"undefined"==typeof t.opacity&&(t.opacity=1),"undefined"==typeof t.fillOpacity&&(t.fillOpacity=1),"undefined"==typeof t.fillColor&&(t.fillColor="#ccc"),"undefined"==typeof t.weight&&(t.weight=1),"undefined"==typeof r.icon&&(r.icon=""),"undefined"==typeof r.color&&(r.color="blue"),e.style.polygon=t,e.style.marker=r;var a=getIndex(selectedLayers,"unique_id",e.unique_id);return selectedLayers[a].style=e.style,e}function getLayerIndex1(e){var t=selectedLayers.length;for(i=0;i<t;i++)if(3==selectedLayers[i].type&&selectedLayers[i].layer==e)return i}function between(e,t){e=parseFloat(e);var r=t.split("-");return e>=r[0]&&e<=r[1]}function getMarkerStyle(e){if(""==e.markerColor){var t=jQuery("#default_style_marker_color").val();""!=t?e.markerColor=t:e.markerColor="blue"}if(""==e.icon){var r=jQuery("#default_style_marker_icon").val();""!=r?e.icon=r:e.icon=""}return e}function isEmpty(e){if(null==e)return!0;if(e.length>0)return!1;if(0===e.length)return!0;if("object"!=typeof e)return!0;for(var t in e)if(hasOwnProperty.call(e,t))return!1;return!0}function custom_marker_icon(e,t){var r=e.icon;if(r.indexOf(".png")!==-1){var a=baseURL+"assets/img/markers/"+e.markerColor+"-"+e.icon,n=L.Icon.extend({options:{iconUrl:a}});t.setIcon(new n)}else t.setIcon(L.AwesomeMarkers.icon(e))}function tinyMCEInit_Popup(e){tinyMCE.init({selector:e,theme:"modern",plugins:[],toolbar1:"insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages",toolbar2:"print preview media | forecolor backcolor emoticons | mapshapes",image_advtab:!0,relative_urls:!1,remove_script_host:!1,convert_urls:!0,autosave_ask_before_unload:!1,extended_valid_elements:"a[onclick|style|href|title|id|class|target]",setup:function(e){e.on("change",function(t){var r=jQuery(e.targetElm),a=getIndex(selectedLayers,"unique_id",r.attr("data-uniqueid"));selectedLayers[a].pc=e.getContent()})}})}function runFilterElementJS(){if(jQuery(".datepicker").length>0&&jQuery(".datepicker").datepicker({format:"yyyy-mm-dd",autoclose:!0}),jQuery(".input-daterange").length>0&&$(".input-daterange input.form-control").each(function(){$self1=$(this),$self1.daterangepicker({format:"YYYY-MM-DD",autoclose:!0,ranges:{Today:[moment(),moment()],Yesterday:[moment().subtract(1,"days"),moment().subtract(1,"days")],"Last 7 Days":[moment().subtract(6,"days"),moment()],"Last 30 Days":[moment().subtract(29,"days"),moment()],"This Month":[moment().startOf("month"),moment().endOf("month")],"Last Month":[moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")]}}).on("apply.daterangepicker",function(e,t){var r=$self1.attr("data-startname"),a=$self1.attr("data-endname");$self1.parents(".input-daterange:first").find('[name="'+r+'"]').val(t.startDate.format("YYYY-MM-DD")),$self1.parents(".input-daterange:first").find('[name="'+a+'"]').val(t.endDate.format("YYYY-MM-DD"))})}),jQuery(".dbisunique").length>0){var e=jQuery("select.dbisunique");e.each(function(){jQuery(this).select2({placeholder:"Select Filter",width:"100%"})})}}function filterGlobalData(){$.each(selectedLayers,function(e,t){if(2==t.type){var r=jQuery("#global_filter").serializeArray();r.push({name:"type",value:2}),r.push({name:"datasource",value:t.connection_id}),r.push({name:"layer_id",value:t._id}),r.push({name:"map_id",value:map.id}),r.push({name:"_token",value:jQuery('[name="_token"]').val()}),r.push({name:"sql_layer_name",value:t.name}),r.push({name:"query_box",value:t.query}),r.push({name:"cache_key",value:t.cache_key}),r.push({name:"cache_timer",value:0}),ajaxRequest("map/layer/json","post","json",r,function(e){"200"==e.status?processSQLJSON(e,t):showMsg(e.status,e.msg)})}})}function clearLayersAndControls(e,t){layer=featureGroup[t.unique_id][t.name],layer&&layer.clearLayers()}function getSQLFeatureData(e){var t=featureGroup[e.unique_id][e.name].getLayers(),r=new Array,a=0;return $.each(t,function(t,n){"undefined"!=typeof e.cluster&&1==e.cluster?r[a++]=n.feature.properties:n.eachLayer(function(e){r[a++]=e.feature.properties})}),r}function processheatmapJSON(e,t){"undefined"==typeof heatmap[t.unique_id]?heatmap[t.unique_id]=L.heatLayer(e.result,{radius:30}).addTo(featureGroup[t.unique_id][t.name]):heatmap[t.unique_id].setLatLngs(e.result).setOptions({radius:30}).redraw()}function deleteLayer(e){var t=getLayersIndex(e);3==selectedLayers[t].type&&drawingGroup.removeLayer(selectedLayers[t].layer),jQuery("#at-"+e).remove(),selectedLayers.splice(t,1),saveMapData("map",function(e){showMsg("success","Map saved successfully.")}),featureGroup[selectedLayers[t].unique_id][selectedLayers[t].name].clearLayers(),layerSelector.removeLayer(featureGroup[selectedLayers[t].unique_id][selectedLayers[t].name])}function add_sql_legend(e,t){1==t&&(2!=e.type||"nr"!=e.style.type&&"g"!=e.style.type||(legend[e.unique_id]=L.control({position:"bottomright"}),legend[e.unique_id].onAdd=function(t){var r=L.DomUtil.create("div","info mapfig-legend");return r.innerHTML+='<h6 class="map-legend-title">'+e.name+"</h6>",$.each(e.style.custom,function(e,t){var a=t.style.icon;if(a.indexOf(".png")!==-1){var n=baseURL+"assets/img/markers/"+t.style.markerColor+"-"+t.style.icon;r.innerHTML+='<div class="map-legend"><img src="'+n+'" height="20"/><div class="legend-text">'+t.val+"</div></div>"}else r.innerHTML+='<div class="map-legend"><i class="fa fa-map-marker" style="color:'+t.style.markerColor+' !important"></i><div class="legend-text">'+t.val+"</div></div>"}),r},mymap.addControl(legend[e.unique_id])))}function user_sidebar_chk(){"undefined"!=typeof page&&"user_farm"==page&&jQuery(".custom-theme-sidebar,#current-active-layer").on("change",'input[type="checkbox"]',function(e){e.preventDefault();var t=jQuery(this),r=t.is(":checked"),a=t.parents("li:first"),n=a.attr("data-key"),i=a.attr("data-name"),o=getIndex(selectedLayers,"unique_id",n),s=selectedLayers[o];if("undefined"==typeof s)return void(r===!0?mymap.addLayer(featureGroup[n][i]):mymap.removeLayer(featureGroup[n][i]));if(r===!0)activeLayers.push({id:s._id,order:0}),order_current_active_layers(),t.hasClass("active-layer-chk")||add_current_layer_text(s),mymap.addLayer(featureGroup[s.unique_id][s.name]),featureGroup[s.unique_id][s.name].bringToFront(),add_sql_legend(s,!0);else{var o=getIndex(activeLayers,"id",s._id);activeLayers.splice(o,1),t.hasClass("active-layer-chk")||jQuery("#user-farm-at-layers-"+s.unique_id).remove(),mymap.removeLayer(featureGroup[s.unique_id][s.name]),"undefined"!=typeof legend[n]&&legend[s.unique_id].removeFrom(mymap)}})}function add_current_layer_text(e){if("undefined"!=typeof page&&"user_farm"==page){var t=document.getElementById("user-farm-active-layers-tmpl").innerHTML;Mustache.parse(t),jQuery("#current-active-layer ul").prepend(Mustache.render(t,e))}}function order_current_active_layers(){activeLayers.sort(sort_value_layer);var e=activeLayers.length;for(i=0;i<e;i++)activeLayers[i].order=activeLayers[i].order+1}function fromWKT2Json(e){var t={},r=function(e){var t=[],r=e.replace(/\)|\(/gi,"").split(",");return r.forEach(function(e){var r=e.trim().split(" "),a=parseFloat(r[0],10),n=parseFloat(r[1],10);t[t.length]=[a,n]}),t};t.POINT=function(e){var t=e.replace(/\)|\(/gi,"").trim().split(" ");return{type:"point",x:parseFloat(t[0],10),y:parseFloat(t[1],10)}},t.MULTILINESTRING=function(e){e=e.replace(/(\(\()|(\)\))/gi,"");var t=[],a=e.split("),");return a.forEach(function(e){t[t.length]=r(e)}),{type:"polyline",paths:t}},t.POLYGON=function(e){var r=t.MULTILINESTRING(e);return{type:"polygon",rings:r.paths}},t.MULTIPOLYGON=function(e){},t.MULTIPOINT=function(e){return{type:"multipoint",points:r(e)}},t.LINESTRING=function(e){return t.MULTIPOINT(e)};var a=e.split("("),n=a.shift().trim(),i="("+a.join("(").trim();return t[n](i)}function field_form_collection(e){var t={farm_id:farm_id,field_id:e};ajaxRequest("user/field/task/form","get","html",t,function(e){jQuery("#field-task-form-container .card-block").html(e),field_tasks_init()})}function ajaxLoadSucess(){jQuery("#main-loader").addClass("hide")}function WMSLayers(e,r,a){var n=e.attr("data-gsid"),i=e.attr("data-layername"),o=getIndex(DBLayerType,"id",a),s=gslayers[DBLayerType[o].tmpl+"_"+n][0],l=getDetailsByAttr(s.layers,"Name",i);l=l[0];var u,c=l.Name.split(":");u=1==a?c.length>1?s.url+c[0]+"/wms":s.url+"/wms":s.url;var y=l.l_id;if(e.is(":checked"))1==r&&(t=l,t.id=s.id,t.unique_id=y,t.type=a,t.name=l.Title,t.url=u,t.pc="",t.section_id=jQuery("#dd_section_id").val(),selectedLayers.push(t)),renderLayer(t,"");else{jQuery("#at-"+y).remove();var o=getLayersIndex(y);selectedLayers.splice(o,1),featureGroup[y][l.Title].clearLayers(),layerSelector.removeLayer(featureGroup[y][l.Title]),removeOverlayerControl(y)}calculateBounds()}function clearMap(){jQuery.each(selectedLayers,function(e,t){$self=jQuery("#layer_selection_"+t.gs.id).find('input:checkbox[data-layername="'+t.gs.layers.Name+'"]');var r=$self.attr("data-gsid"),a=$self.attr("data-layername"),n=getDetailsByAttr(layers,"id",r);n=n[0];var i=getDetailsByAttr(n.layers,"Name",a);i=i[0];var o="gs_"+i.Name+"_"+n.id;layerSelector.removeLayer(featureGroup[o][i.Title]),featureGroup[o][i.Title].clearLayers()})}function tinyMCEInit_Popup(e){tinyMCE.init({selector:e,theme:"modern",plugins:[],toolbar1:"insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages",toolbar2:"print preview media | forecolor backcolor emoticons | mapshapes",image_advtab:!0,relative_urls:!1,remove_script_host:!1,convert_urls:!0,autosave_ask_before_unload:!1,extended_valid_elements:"a[onclick|style|href|title|id|class|target]",setup:function(e){e.on("change",function(t){var r=jQuery(e.targetElm),a=getIndex(selectedLayers,"unique_id",r.attr("data-uniqueid"));selectedLayers[a].pc=e.getContent()})}})}function baseLayerMap(e,t){var r=e.attr("data-name"),a=e.val();if(e.is(":checked")){if(t===!0){layerSelector.addBaseLayer(baseLayers.mymap[r],r);var n=new Object;n.id=a,n.name=r,selectedBaseLayers.push(n),baselayers_controls(r)}}else{layerSelector.removeLayer(baseLayers.mymap[r]);var i=getIndex(selectedBaseLayers,"id",a);selectedBaseLayers.splice(i,1),jQuery('#custom_layers [data-name="'+r+'"]').remove()}selectedBaseLayers.length>0&&jQuery("#visiable-layers").find(".baselayers-control").removeClass("hide")}function makeFasterTree(e){var t=new Array;$.each(db.columns,function(e,r){var a=new Object;a.text=e,a.href=e,a.tags=r.length,a.nodes=new Array,$.each(r,function(e,t){var r=new Object;r.text=t.column_name,r.href=t.column_name,a.nodes.push(r)}),t.push(a)});var r={bootstrap2:!1,showTags:!1,levels:1,data:t,onNodeSelected:function(e,t){"undefined"==typeof t.parentId?$(this).treeview("toggleNodeExpanded",[t.nodeId,{silent:!0}]):jQuery("#query_box").val(jQuery("#query_box").val()+" "+t.href)}};$("#"+e).treeview(r),jQuery("#table_tree_container").slimScroll({height:400}),jQuery("#query-help-text-btn").slimScroll({height:400})}function getGeoLayer(e,t){var r=e.attr("data-id"),a=e.attr("data-wk");e.find(".loading").removeClass("hide"),0==e.find("ul").length&&ajaxRequest("developer/geoserver/layers/json","get","json",{id:r,type:t,wk:a},function(a){if(e.find(".loading").addClass("hide"),200==a.status){gslayers[t+"_"+r]=a.result;var n=document.getElementById("geoserver-layers-tmpl").innerHTML;Mustache.parse(n),e.find(".box-body").html(Mustache.render(n,{geolayers:a.result}));var i=getIndex(DBLayerType,"tmpl",t),o=getDetailsByType(selectedLayers,"id",r,"type",DBLayerType[i].id),s=jQuery("#"+t+'-container [data-id="'+r+'"]');jQuery.each(o,function(e,t){s.find('[data-layername="'+t.Name+'"]').prop("checked",!0)}),jQuery(".scroller").slimScroll({railVisible:!0,alwaysVisible:!0}),$('.gs-collapse input[type="checkbox"].layer_chk').each(function(){jQuery(this).bootstrapSwitch({size:"mini",onSwitchChange:function(e,t){var r=jQuery(e.target);WMSLayers(r,!0,1)}})}),$('.wms-collapse input[type="checkbox"].layer_chk').each(function(){jQuery(this).bootstrapSwitch({size:"mini",onSwitchChange:function(e,t){var r=jQuery(e.target);WMSLayers(r,!0,4)}})})}else showMsg(a.error,a.msg)})}function deleteLayer(e){var t=getLayersIndex(e);3==selectedLayers[t].type&&drawingGroup.removeLayer(selectedLayers[t].layer),jQuery("#at-"+e).remove(),featureGroup[selectedLayers[t].unique_id][selectedLayers[t].name].clearLayers(),layerSelector.removeLayer(featureGroup[selectedLayers[t].unique_id][selectedLayers[t].name]),selectedLayers.splice(t,1)}function editATLayer(e){var t=getLayersIndex(e);currentIndex=t,1==selectedLayers[t].type||4==selectedLayers[t].type?layerDialog(selectedLayers[t]):2==selectedLayers[t].type?layerDialog(selectedLayers[t]):3==selectedLayers[t].type&&layerDialog(selectedLayers[t])}function editSQLATLayer(e){var t=getLayersIndex(e);if(currentIndex=t,1==selectedLayers[t].type)layerDialog(selectedLayers[t]);else if(2==selectedLayers[t].type){var r=document.getElementById("sql-layer-modal-tmpl").innerHTML;Mustache.parse(r),jQuery("#sql_layer_form").html(Mustache.render(r,{ds:ds})),jQuery("#sql-layer-modal").modal("show"),jQuery("#query_box").val(selectedLayers[t].query),jQuery("#query_box").val(selectedLayers[t].query),jQuery("#sql_layer_name").val(selectedLayers[t].name),jQuery("#sql_datasource").val(selectedLayers[t].connection_id),jQuery("#sql_unique_id").val(selectedLayers[t].unique_id),jQuery("#sql_datasource").trigger("change"),validateForm(jQuery("#sql_layer_form")),sqlFormChange=!1,SQLModeModal(selectedLayers[t].sqlMode)}else 3==selectedLayers[t].type&&layerDialog(selectedLayers[t])}function editCacheLayer(e){var t=getLayersIndex(e);currentIndex=t;var r=jQuery("#cache_settings_form");if(1==selectedLayers[t].type||3==selectedLayers[t].type){var a="Cache settings not avaliable for Geoserver layers.";3==selectedLayers[t].type&&(a="Cache settings not avaliable for FreeHand layers.");var n=document.getElementById("no-settings-msg-modal-tmpl").innerHTML;Mustache.parse(n),r.html(Mustache.render(n,{msg:a})),jQuery("#cache-settings-modal").modal("show"),jQuery("#cache-settings-modal .btn.btn-success").addClass("hide")}else if(2==selectedLayers[t].type){var i=document.getElementById("sql-layer-cache-modal-tmpl").innerHTML;Mustache.parse(i),r.html(Mustache.render(i,{ds:ds})),jQuery("#cache-settings-modal").modal("show"),r.find('[name="cache_timer"]').val(selectedLayers[t].cache_timer),r.find('[name="unique_id"]').val(selectedLayers[t].unique_id),validateForm(jQuery("#cache_settings_form")),jQuery("#cache-settings-modal .btn.btn-success").removeClass("hide")}}function editStyleLayer(e){var t=getLayersIndex(e);currentIndex=t;var r=jQuery("#style_settings_form");if(1==selectedLayers[t].type){var a=document.getElementById("geoserver-style-modal-tmpl").innerHTML;Mustache.parse(a),r.html(Mustache.render(a)),jQuery("#style-settings-modal").modal("show"),jQuery("#style-settings-modal .btn.btn-success").addClass("hide")}else if(2==selectedLayers[t].type){var n=document.getElementById("sql-layer-style-modal-tmpl").innerHTML;return Mustache.parse(n),jQuery("#map-sidebar-container").html(Mustache.render(n,{t:selectedLayers[t]})),jQuery(".control-sidebar").toggleClass("control-sidebar-open"),jQuery("#layer_polygon_fill_color,#layer_polygon_color").colorpicker({theme:"bootstrap"}).on("changeColor",function(e){applyLiveStyle()}),jQuery("#layer-polygon-styling input").change(function(){applyLiveStyle()}),jQuery("#layer-marker-styling select").change(function(){applyLiveStyle()}),void jQuery(".sidebar_hide").toggleClass("hide")}else 3==selectedLayers[t].type&&(jQuery("#layer_polygon_fill_color,#layer_polygon_color").colorpicker({theme:"bootstrap"}).on("changeColor",function(e){applyLiveStyle()}),jQuery("#layer-polygon-styling input").change(function(){applyLiveStyle()}))}function sqlFormEvent(){jQuery(".sql-layers-btn").click(function(){currentIndex=-1;var e=(jQuery(this).val(),document.getElementById("sql-layer-modal-tmpl").innerHTML);Mustache.parse(e),jQuery("#sql_layer_form").html(Mustache.render(e,{ds:ds})),jQuery("#sql-layer-modal").modal("show"),validateForm(jQuery("#sql_layer_form")),SQLModeModal()}),jQuery("#sql-layer-modal").on("change","#sql_datasource",function(){var e=jQuery(this).val();currentIndex!=-1&&selectedLayers[currentIndex].connection_id!=e&&setupEditor(),ajaxRequest("db/table/"+e,"get","json",{},function(e){200==e.status?(db.tables=e.tables,db.columns=e.columns,makeFasterTree("tree_5"),jQuery("#drag_table").html(""),jQuery("#drag_table").append(Mustache.render(table_tmpl,e)),currentIndex!=-1&&(jQuery("#drag_table").val(selectedLayers[currentIndex].table_name),jQuery("#drag_table").trigger("change")),jQuery("#drag_table").select2({width:"100%"})):showMsg("error",e.error)})}),jQuery("#sql-layer-modal").on("change","#drag_table",function(){var e=jQuery(this).val();if(jQuery("#drag_geometry_column").html(Mustache.render(column_tmpl,{columns:db.columns[e]})),jQuery("#drag_other_column").html(Mustache.render(column_tmpl,{columns:db.columns[e]})),currentIndex!=-1&&(jQuery("#drag_geometry_column").val(selectedLayers[currentIndex].geometry_col),"undefined"!=typeof selectedLayers[currentIndex].other_col&&selectedLayers[currentIndex].other_col.length>0))for(var t in selectedLayers[currentIndex].other_col){var r=selectedLayers[currentIndex].other_col[t];$("#drag_other_column").find("option[value="+r+"]").prop("selected","selected")}jQuery("#drag_other_column, #drag_geometry_column").select2({width:"100%"})}),jQuery("#sql-layer-modal").on("change","#geohelm_tags",function(){var e=jQuery(this).val();jQuery("#query_box").val(jQuery("#query_box").val()+e)}),jQuery("#sql-layer-save-btn").click(function(e){e.preventDefault();var r=jQuery(this);if(jQuery("#sql_layer_form").validate().form())if(sqlFormChange===!0){r.button("loading");var a=jQuery("#sql_layer_form").serialize();ajaxRequest("developer/map/sql/layer/save","post","json",a,function(e){if(r.button("reset"),200==e.status){sqlMode=jQuery("#sql-mode-switch").bootstrapSwitch("state");var a=jQuery("#sql_unique_id").val(),n=-1;""!=a?(n=getLayersIndex(a),t=selectedLayers[n]):(t=new Object,t.unique_id=uniqId("pg"),t.pc="",t.type=2,t.cache_timer=15),t.connection_id=jQuery("#sql_datasource").val(),
t.section_id=jQuery("#dd_section_id").val(),1==sqlMode?(t.query=jQuery("#query_box").val(),t.sqlMode=!0):t.query=e.query,t.table_name=jQuery("#drag_table").val(),t.geometry_col=jQuery("#drag_geometry_column").val(),t.other_col=jQuery("#drag_other_column").val(),t.name=jQuery("#sql_layer_name").val(),t.properties=e.columns,n!=-1?(selectedLayers[n]=t,mymap.removeLayer(featureGroup[t.unique_id][t.name]),mymap.addLayer(featureGroup[t.unique_id][t.name]),processSQLJSON(e,t)):(selectedLayers.push(t),renderLayer(t,e)),jQuery("#sql-layer-modal").modal("hide")}else showMsg(e.status,e.msg)})}else jQuery("#sql-layer-modal").modal("hide")}),jQuery("#geoserver-layer-save-btn").click(function(e){e.preventDefault();jQuery(this);if(jQuery("#geoserver_layer_form").validate().form()){var r=jQuery("#geoserver_unique_id").val(),a=-1;""!=r?(a=getLayersIndex(r),t=selectedLayers[a]):(t=new Object,t.unique_id=uniqId("pg"),t.pc="",t.type=2),t.name=jQuery("#geoserver_layer_name").val(),a!=-1?(selectedLayers[a]=t,jQuery("#at-"+t.unique_id+" span").html(t.name)):(selectedLayers.push(t),renderLayer(t,data)),jQuery("#geoserver-layer-modal").modal("hide")}}),jQuery("#sql-layer-modal").on("change","#sql_datasource, #drag_sql_datasource",function(){sqlFormChange=!0}),jQuery("#sql-layer-modal").on("change","#query_box, #drag_geometry_column,#drag_other_column,#drag_table",function(){sqlFormChange=!0})}function SQLModeModal(e){jQuery("#drag_sql_datasource,#sql_datasource").select2({width:"100%"}),$("#sql-mode-switch").on("switchChange.bootstrapSwitch",function(e,t){sqlFormChange=!0,e.preventDefault(),jQuery("#sql_mode").val(!0),t===!0?(jQuery("#sql-mode-container").show(),jQuery("#drag-drop-container").hide()):(jQuery("#sql-mode-container").hide(),jQuery("#drag-drop-container").show())}),jQuery("#sql-mode-switch").bootstrapSwitch("state",e,!1)}function setupEditor(){jQuery("#query_box").val(""),jQuery("#drag_table").val(""),jQuery("#drag_geometry_column").val(""),jQuery("#drag_other_column").val("")}function drawing_event(){var e=function(){mymap.on("draw:drawstart",function(e){draw_editStart(e)}),mymap.on("draw:deletestart",function(e){draw_editStart(e)}),mymap.on("draw:editstop",function(e){draw_editStop(e)}),mymap.on("draw:drawstop",function(e){draw_editStop(e)}),mymap.on("draw:deletestop",function(e){draw_editStop(e)}),mymap.on("moveend",function(e){updateMapCenter()}),mymap.on("draw:created",function(e){var t=new Object;t.lt=e.layerType;var r=e.layer;drawingGroup.addLayer(r),r.on("click",function(){var e=getLayerIndex1(r);editMode?(layerDialog(selectedLayers[e]),setTimeout(function(){mymap.closePopup()},50)):r.bindPopup(selectedLayers[e].pc)}),style={};r instanceof L.Marker?(style.marker=new Object,style.marker.icon="",style.marker.color="",t.marker=!0,t.polygon=!1):(r instanceof L.MultiPolygon||r instanceof L.Polyline||r instanceof L.Rectangle||r instanceof L.Circle)&&(style.polygon=new Object,style.polygon.color="#ff0000",style.polygon.opacity=.5,style.polygon.weight=5,style.polygon.fillColor="#ff0000",style.polygon.fillOpacity=.5,r.setStyle(style.polygon),t.marker=!1,t.polygon=!0),t.layer=r,t.style=style,t.type=3,t.name="Layer Name",t.location="",t.pc="",t.unique_id=uniqId("cl"),t.drawing=1,layerDialog(t),renderLayer(t),t.section_id=jQuery("#dd_section_id").val(),selectedLayers.push(t)}),mymap.on("draw:editstart",function(e){draw_editStart(),editMode=!0}),mymap.on("draw:editstop",function(e){editMode=!1,draw_editStop(e)}),mymap.on("draw:deleted",function(e){var t=e.layers;t.eachLayer(function(e){(e instanceof L.MultiPolygon||e instanceof L.Polyline||e instanceof L.Rectangle||e instanceof L.Circle||e instanceof L.Marker)&&deleteLayer(e.feature.properties.unique_id)})})};e(),$(".leaflet-draw.leaflet-control").hide(),$("#mapid > #data").show(),$("#draw-polyline,#draw-polygon,#draw-rectangle,#draw-marker, #edit-edit,#edit-remove, #draw-circle").click(function(e){if("#"==$(this).attr("href")){e.preventDefault();var t=$(this).attr("id");$(".leaflet-draw-"+t)[0].click()}})}function draw_editStart(e){var t=0;setTimeout(function(){info=$(".leaflet-draw-tooltip").text().replace("Click cancel to undo changes.",""),$("#control-tip-info").html(info),$("#control-tip-buttons").text(""),$(".leaflet-draw-actions li").each(function(e){var r=$(this);if("block"==r.parent().css("display")){var a=r.text(),n="";n=/cancel/i.test(a)?"remove":/save/i.test(a)?"save":"trash",Actions='<a href="#" onClick="return tipButtonsclick('+t++ +');" class="button-top drawing-icon pin-right unround button quiet icon close pad1 inline"><i class="fa fa-'+n+'"></i> '+r.text()+"</a>",$("#control-tip-buttons").prepend(Actions)}})},100)}function draw_editStop(e){$("#control-tip-info").html('Select the Shape to draw on Map or <a href="#" class="btn btn-primary btn-xs" onClick="$(\'#data-importer\').click(); return false;" style="color:white;">click here to import</a> gpx, json or kml.'),$("#control-tip-buttons").text("")}function updateMapCenter(){canter=mymap.getCenter(),$("input[name=latitude]").val(canter.lat),$("input[name=longitude]").val(canter.lng),$("#mapcenter").val("["+canter.lat+","+canter.lng+"]")}function layerDialog(e){var t=document.getElementById("cl-style-modal-tmpl").innerHTML;if(Mustache.parse(t),jQuery("#map-sidebar-container").html(Mustache.render(t,{t:e,type:layerType[e.type]})),sidebar_toggle(!0),tinyMCEInit_Popup('#cs-layer-popup [name="pc"]'),2==e.type||3==e.type){if("nr"==e.style.type||"g"==e.style.type){var r=featureGroup[e.unique_id][e.name].getLayers(),a=new Array,n=0;if($.each(r,function(e,t){t.eachLayer(function(e){a[n++]=e.feature.properties})}),"nr"==e.style.type){var i=_.max(a,function(t){return t[e.style.field]}),o=document.getElementById(e.style.type+"-style-selection").innerHTML;Mustache.parse(o),jQuery("#style_column_name").val(e.style.field),jQuery("#style_data_type").val(e.style.type),jQuery("#attribute-input-field").html(Mustache.render(o,{max:i[e.style.field]}));$.each(e.style.custom,function(t,r){var a=document.getElementById(e.style.type+"-column-style-selection").innerHTML;Mustache.parse(a);var n=Mustache.render(a,{});jQuery("#attribute-input-field table tbody").append(n);var i=jQuery("#attribute-input-field table tbody tr:last");i.find("input").val(r.val),i.find('select[data-name="markerColor"]').val(r.style.markerColor),i.find('select[data-name="icon"]').val(r.style.icon)})}else if("g"==e.style.type){var i=_.groupBy(a,function(t){return parseFloat(t[e.style.field])}),o=document.getElementById(e.style.type+"-style-selection").innerHTML;Mustache.parse(o),jQuery("#style_column_name").val(e.style.field),jQuery("#style_data_type").val(e.style.type),jQuery("#attribute-input-field").html(Mustache.render(o,{max:i[e.style.field]}));$.each(e.style.custom,function(t,r){var a=document.getElementById(e.style.type+"-column-style-selection").innerHTML;Mustache.parse(a);var n=Mustache.render(a,{});jQuery("#attribute-input-field table tbody").append(n);var i=jQuery("#attribute-input-field table tbody tr:last");i.find("input").val(r.val),i.find('select[data-name="markerColor"]').val(r.style.markerColor),i.find('select[data-name="icon"]').val(r.style.icon)})}}jQuery("#layer_polygon_fill_color,#layer_polygon_color").colorpicker({theme:"bootstrap"}).on("changeColor",function(e){applyLiveStyle()}),jQuery("#layer-polygon-styling input").change(function(){applyLiveStyle()}),jQuery("#layer-marker-styling .default-marker-style select").change(function(){applyLiveStyle()}),jQuery("#layer-marker-styling").on("click",".numeric-range",function(){var e=jQuery(this).parents("tr:first"),t=e.clone();t.find("input").val(""),e.after(t)}),jQuery("#layer-marker-styling .custom-marker-style #style_data_type, #layer-marker-styling .custom-marker-style #style_column_name").change(function(){var e=jQuery("#style_column_name").val(),t=jQuery("#style_data_type").val();if(""!=e&&""!=t){jQuery("#attribute-input-field").html("");var r=jQuery('#map-sidebar-container [name="my_unique_id"]').val(),a=getIndex(selectedLayers,"unique_id",r),n=featureGroup[selectedLayers[a].unique_id][selectedLayers[a].name].getLayers(),i=new Array,o=0;if($.each(n,function(e,t){t.eachLayer(function(e){i[o++]=e.feature.properties})}),"nr"==t){var s=_.max(i,function(t){return parseFloat(t[e])}),l=document.getElementById(t+"-style-selection").innerHTML;if(Mustache.parse(l),jQuery("#attribute-input-field").html(Mustache.render(l,{max:s[e]})),0==jQuery("#attribute-input-field table tboday tr").length){var l=document.getElementById("nr-column-style-selection").innerHTML;Mustache.parse(l);var u=Mustache.render(l,{});jQuery("#attribute-input-field table tbody").append(u)}}else{var s=_.groupBy(i,function(t){return t[e]}),l=document.getElementById(t+"-style-selection").innerHTML;Mustache.parse(l),jQuery("#attribute-input-field").html(Mustache.render(l,{max:s[e]})),$.each(s,function(e,t){var r=document.getElementById("g-column-style-selection").innerHTML;Mustache.parse(r);var a=Mustache.render(r,{attr:e});jQuery("#attribute-input-field table tbody").append(a)})}}});var s=new Array,l=0;jQuery("#attribute-input-field").on("change","table input, table select",function(){var e=jQuery('#map-sidebar-container [name="my_unique_id"]').val(),t=getIndex(selectedLayers,"unique_id",e),r=featureGroup[selectedLayers[t].unique_id][selectedLayers[t].name].getLayers(),a=jQuery("#style_column_name").val(),n=jQuery("#style_data_type").val();s=new Array,l=0,jQuery("#attribute-numeric-table tbody tr").each(function(){var e=jQuery(this),t=e.find("input:text").val(),i={};e.find("select").each(function(){i[jQuery(this).attr("data-name")]=jQuery(this).val()}),s[l]=new Object,s[l].val=t,s[l].style=i,l++,i=getMarkerStyle(i),$.each(r,function(e,r){r.eachLayer(function(e){"nr"==n?between(e.feature.properties[a],t)&&e.setIcon(L.AwesomeMarkers.icon(i)):"g"==n&&e.feature.properties[a]==t&&e.setIcon(L.AwesomeMarkers.icon(i))})})}),"undefined"==typeof selectedLayers[t].style.custom&&(selectedLayers[t].style.custom=new Object),selectedLayers[t].style.custom=s,selectedLayers[t].style.type=n,selectedLayers[t].style.field=a}),e.style.marker&&"undefined"!=typeof e.style.marker&&(jQuery('#layer-marker-styling select[name="marker_color"]').val(e.style.marker.markerColor),jQuery('#layer-marker-styling select[name="marker_icon"]').val(e.style.marker.icon))}jQuery("#cs-layer-info input").change(function(){var e=jQuery(this),t=jQuery('#map-sidebar-container [name="my_unique_id"]').val(),r=getIndex(selectedLayers,"unique_id",t);selectedLayers[r][e.attr("name")]=e.val(),jQuery("#at-"+selectedLayers[r].unique_id+" span.at-text").html(selectedLayers[r].name)}),3==e.type&&(autocomplete=new google.maps.places.Autocomplete(document.getElementById("autoFillAddress"),{types:["geocode"]}),google.maps.event.addListener(autocomplete,"place_changed",function(e){lat=autocomplete.getPlace().geometry.location.lat(),lng=autocomplete.getPlace().geometry.location.lng();var t=jQuery("#style_settings_form").find('[name="my_unique_id"]').val(),r=getIndex(selectedLayers,"unique_id",t);selectedLayers[r].layer.setLatLng([lat,lng]),selectedLayers[r].location=jQuery("#autoFillAddress").val(),mymap.setView([lat,lng],mymap.getZoom())}))}function tipButtonsclick(e){var t=void 0;return $(".leaflet-draw-actions").each(function(e){"block"==$(this).css("display")&&(t=$(this))}),t&&t.find("a")[e].click(),!1}function getDetailsByType(e,t,r,a,n){var o=[],s=e.length;for(i=0;i<s;i++)e[i][t]==r&&e[i][a]==n&&o.push(e[i]);return o}function initiateUpload(){if(""==$("#data-importer").val())return void(globalLastFileFormat="");var e=$("form#layer-form input[type=file]").val().split(".");globalLastFileFormat=e[e.length-1];var t=new FormData($("form#layer-form")[0]);$.ajax({url:baseURL+"developer/map/file/upload",type:"POST",xhr:function(){var e=$.ajaxSettings.xhr();return e.upload&&e.upload.addEventListener("progress",function(e){e.lengthComputable},!1),e},success:function(e){try{if(jsonData=JSON.parse(e),!(jsonData.status=200))return void alert("Invalid File");if("json"==jsonData.format)jQuery.each(jsonData.result,function(e,t){L.geoJson(t,{onEachFeature:function(e,t){t.on("click",function(a){var n=getSQLPopupContent(e.properties,r.pc),i=t.getBounds(),o=L.popup();o.setLatLng(i.getCenter()),o.setContent(n),mymap.openPopup(o)})}}).addTo(mymap)});else if("kml"==jsonData.format||"gpx"==jsonData.format){var e=new Object,t=new Object,r=JSON.parse(JSON.stringify(toGeoJSON[globalLastFileFormat.toLowerCase()]((new DOMParser).parseFromString(jsonData.kmlData,"text/xml")),null,4));t.mapfig=r.features,e.geoJSON=t,L.geoJson(t,{onEachFeature:function(e,t){t.on("click",function(a){var n=getSQLPopupContent(e.properties,r.pc),i=t.getBounds(),o=L.popup();o.setLatLng(i.getCenter()),o.setContent(n),mymap.openPopup(o)})}}).addTo(mymap)}$("form#layer-form input[type=file]").val("")}catch(a){return void alert("Invalid File","error")}},error:function(e){alert("Error While Uploading the file","error")},data:t,cache:!1,contentType:!1,processData:!1}),$("form#data-importer-form input[type=file]").val("")}function manage_custom_layers(){jQuery("#add-custom-layer").click(function(e){e.preventDefault(),jQuery("#add-custom-layer-modal").modal({backdrop:"static",keyboard:!1})}),$("#add-custom-layer-modal").on("hidden.bs.modal",function(){$(".modal-backdrop").remove()}),jQuery("#upload-form-layer-btn").click(function(){jQuery("#upload-layer-form").submit()})}function sidebar_toggle(e){return 1==e?(jQuery(".sidebar_hide").removeClass("hide"),void jQuery(".control-sidebar").addClass("open")):(jQuery(".sidebar_hide").removeClass("hide"),void jQuery(".control-sidebar").removeClass("open"))}!function(e,t){"object"==typeof exports&&exports&&"string"!=typeof exports.nodeName?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):(e.Mustache={},t(e.Mustache))}(this,function(e){function t(e){return"function"==typeof e}function r(e){return m(e)?"array":typeof e}function a(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function n(e,t){return null!=e&&"object"==typeof e&&t in e}function i(e,t){return h.call(e,t)}function o(e){return!i(g,e)}function s(e){return String(e).replace(/[&<>"'`=\/]/g,function(e){return v[e]})}function l(t,r){function n(){if(g&&!v)for(;h.length;)delete f[h.pop()];else h=[];g=!1,v=!1}function i(e){if("string"==typeof e&&(e=e.split(L,2)),!m(e)||2!==e.length)throw new Error("Invalid tags: "+e);s=new RegExp(a(e[0])+"\\s*"),l=new RegExp("\\s*"+a(e[1])),d=new RegExp("\\s*"+a("}"+e[1]))}if(!t)return[];var s,l,d,p=[],f=[],h=[],g=!1,v=!1;i(r||e.tags);for(var w,k,x,q,M,S,I=new y(t);!I.eos();){if(w=I.pos,x=I.scanUntil(s))for(var T=0,C=x.length;T<C;++T)q=x.charAt(T),o(q)?h.push(f.length):v=!0,f.push(["text",q,w,w+1]),w+=1,"\n"===q&&n();if(!I.scan(s))break;if(g=!0,k=I.scan(Q)||"name",I.scan(_),"="===k?(x=I.scanUntil(j),I.scan(j),I.scanUntil(l)):"{"===k?(x=I.scanUntil(d),I.scan(b),I.scanUntil(l),k="&"):x=I.scanUntil(l),!I.scan(l))throw new Error("Unclosed tag at "+I.pos);if(M=[k,x,w,I.pos],f.push(M),"#"===k||"^"===k)p.push(M);else if("/"===k){if(S=p.pop(),!S)throw new Error('Unopened section "'+x+'" at '+w);if(S[1]!==x)throw new Error('Unclosed section "'+S[1]+'" at '+w)}else"name"===k||"{"===k||"&"===k?v=!0:"="===k&&i(x)}if(S=p.pop())throw new Error('Unclosed section "'+S[1]+'" at '+I.pos);return c(u(f))}function u(e){for(var t,r,a=[],n=0,i=e.length;n<i;++n)t=e[n],t&&("text"===t[0]&&r&&"text"===r[0]?(r[1]+=t[1],r[3]=t[3]):(a.push(t),r=t));return a}function c(e){for(var t,r,a=[],n=a,i=[],o=0,s=e.length;o<s;++o)switch(t=e[o],t[0]){case"#":case"^":n.push(t),i.push(t),n=t[4]=[];break;case"/":r=i.pop(),r[5]=t[2],n=i.length>0?i[i.length-1][4]:a;break;default:n.push(t)}return a}function y(e){this.string=e,this.tail=e,this.pos=0}function d(e,t){this.view=e,this.cache={".":this.view},this.parent=t}function p(){this.cache={}}var f=Object.prototype.toString,m=Array.isArray||function(e){return"[object Array]"===f.call(e)},h=RegExp.prototype.test,g=/\S/,v={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"},_=/\s*/,L=/\s+/,j=/\s*=/,b=/\s*\}/,Q=/#|\^|\/|>|\{|&|=|!/;y.prototype.eos=function(){return""===this.tail},y.prototype.scan=function(e){var t=this.tail.match(e);if(!t||0!==t.index)return"";var r=t[0];return this.tail=this.tail.substring(r.length),this.pos+=r.length,r},y.prototype.scanUntil=function(e){var t,r=this.tail.search(e);switch(r){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,r),this.tail=this.tail.substring(r)}return this.pos+=t.length,t},d.prototype.push=function(e){return new d(e,this)},d.prototype.lookup=function(e){var r,a=this.cache;if(a.hasOwnProperty(e))r=a[e];else{for(var i,o,s=this,l=!1;s;){if(e.indexOf(".")>0)for(r=s.view,i=e.split("."),o=0;null!=r&&o<i.length;)o===i.length-1&&(l=n(r,i[o])),r=r[i[o++]];else r=s.view[e],l=n(s.view,e);if(l)break;s=s.parent}a[e]=r}return t(r)&&(r=r.call(this.view)),r},p.prototype.clearCache=function(){this.cache={}},p.prototype.parse=function(e,t){var r=this.cache,a=r[e];return null==a&&(a=r[e]=l(e,t)),a},p.prototype.render=function(e,t,r){var a=this.parse(e),n=t instanceof d?t:new d(t);return this.renderTokens(a,n,r,e)},p.prototype.renderTokens=function(e,t,r,a){for(var n,i,o,s="",l=0,u=e.length;l<u;++l)o=void 0,n=e[l],i=n[0],"#"===i?o=this.renderSection(n,t,r,a):"^"===i?o=this.renderInverted(n,t,r,a):">"===i?o=this.renderPartial(n,t,r,a):"&"===i?o=this.unescapedValue(n,t):"name"===i?o=this.escapedValue(n,t):"text"===i&&(o=this.rawValue(n)),void 0!==o&&(s+=o);return s},p.prototype.renderSection=function(e,r,a,n){function i(e){return o.render(e,r,a)}var o=this,s="",l=r.lookup(e[1]);if(l){if(m(l))for(var u=0,c=l.length;u<c;++u)s+=this.renderTokens(e[4],r.push(l[u]),a,n);else if("object"==typeof l||"string"==typeof l||"number"==typeof l)s+=this.renderTokens(e[4],r.push(l),a,n);else if(t(l)){if("string"!=typeof n)throw new Error("Cannot use higher-order sections without the original template");l=l.call(r.view,n.slice(e[3],e[5]),i),null!=l&&(s+=l)}else s+=this.renderTokens(e[4],r,a,n);return s}},p.prototype.renderInverted=function(e,t,r,a){var n=t.lookup(e[1]);if(!n||m(n)&&0===n.length)return this.renderTokens(e[4],t,r,a)},p.prototype.renderPartial=function(e,r,a){if(a){var n=t(a)?a(e[1]):a[e[1]];return null!=n?this.renderTokens(this.parse(n),r,a,n):void 0}},p.prototype.unescapedValue=function(e,t){var r=t.lookup(e[1]);if(null!=r)return r},p.prototype.escapedValue=function(t,r){var a=r.lookup(t[1]);if(null!=a)return e.escape(a)},p.prototype.rawValue=function(e){return e[1]},e.name="mustache.js",e.version="2.2.1",e.tags=["{{","}}"];var w=new p;e.clearCache=function(){return w.clearCache()},e.parse=function(e,t){return w.parse(e,t)},e.render=function(e,t,a){if("string"!=typeof e)throw new TypeError('Invalid template! Template should be a "string" but "'+r(e)+'" was given as the first argument for mustache#render(template, view, partials)');return w.render(e,t,a)},e.to_html=function(r,a,n,i){var o=e.render(r,a,n);return t(i)?void i(o):o},e.escape=s,e.Scanner=y,e.Context=d,e.Writer=p}),function(){function e(e){function t(t,r,a,n,i,o){for(;i>=0&&o>i;i+=e){var s=n?n[i]:i;a=r(a,t[s],s,t)}return a}return function(r,a,n,i){a=_(a,i,4);var o=!x(r)&&v.keys(r),s=(o||r).length,l=e>0?0:s-1;return arguments.length<3&&(n=r[o?o[l]:l],l+=e),t(r,a,n,o,l,s)}}function t(e){return function(t,r,a){r=L(r,a);for(var n=k(t),i=e>0?0:n-1;i>=0&&n>i;i+=e)if(r(t[i],i,t))return i;return-1}}function r(e,t,r){return function(a,n,i){var o=0,s=k(a);if("number"==typeof i)e>0?o=i>=0?i:Math.max(i+s,o):s=i>=0?Math.min(i+1,s):i+s+1;else if(r&&i&&s)return i=r(a,n),a[i]===n?i:-1;if(n!==n)return i=t(c.call(a,o,s),v.isNaN),i>=0?i+o:-1;for(i=e>0?o:s-1;i>=0&&s>i;i+=e)if(a[i]===n)return i;return-1}}function a(e,t){var r=T.length,a=e.constructor,n=v.isFunction(a)&&a.prototype||s,i="constructor";for(v.has(e,i)&&!v.contains(t,i)&&t.push(i);r--;)i=T[r],i in e&&e[i]!==n[i]&&!v.contains(t,i)&&t.push(i)}var n=this,i=n._,o=Array.prototype,s=Object.prototype,l=Function.prototype,u=o.push,c=o.slice,y=s.toString,d=s.hasOwnProperty,p=Array.isArray,f=Object.keys,m=l.bind,h=Object.create,g=function(){},v=function(e){return e instanceof v?e:this instanceof v?void(this._wrapped=e):new v(e)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=v),exports._=v):n._=v,v.VERSION="1.8.3";var _=function(e,t,r){if(void 0===t)return e;switch(null==r?3:r){case 1:return function(r){return e.call(t,r)};case 2:return function(r,a){return e.call(t,r,a)};case 3:return function(r,a,n){return e.call(t,r,a,n)};case 4:return function(r,a,n,i){return e.call(t,r,a,n,i)}}return function(){return e.apply(t,arguments)}},L=function(e,t,r){return null==e?v.identity:v.isFunction(e)?_(e,t,r):v.isObject(e)?v.matcher(e):v.property(e)};v.iteratee=function(e,t){return L(e,t,1/0)};var j=function(e,t){return function(r){var a=arguments.length;if(2>a||null==r)return r;for(var n=1;a>n;n++)for(var i=arguments[n],o=e(i),s=o.length,l=0;s>l;l++){var u=o[l];t&&void 0!==r[u]||(r[u]=i[u])}return r}},b=function(e){if(!v.isObject(e))return{};if(h)return h(e);g.prototype=e;var t=new g;return g.prototype=null,t},Q=function(e){return function(t){return null==t?void 0:t[e]}},w=Math.pow(2,53)-1,k=Q("length"),x=function(e){var t=k(e);return"number"==typeof t&&t>=0&&w>=t};v.each=v.forEach=function(e,t,r){t=_(t,r);var a,n;if(x(e))for(a=0,n=e.length;n>a;a++)t(e[a],a,e);else{var i=v.keys(e);for(a=0,n=i.length;n>a;a++)t(e[i[a]],i[a],e)}return e},v.map=v.collect=function(e,t,r){t=L(t,r);for(var a=!x(e)&&v.keys(e),n=(a||e).length,i=Array(n),o=0;n>o;o++){var s=a?a[o]:o;i[o]=t(e[s],s,e)}return i},v.reduce=v.foldl=v.inject=e(1),v.reduceRight=v.foldr=e(-1),v.find=v.detect=function(e,t,r){var a;return a=x(e)?v.findIndex(e,t,r):v.findKey(e,t,r),void 0!==a&&a!==-1?e[a]:void 0},v.filter=v.select=function(e,t,r){var a=[];return t=L(t,r),v.each(e,function(e,r,n){t(e,r,n)&&a.push(e)}),a},v.reject=function(e,t,r){return v.filter(e,v.negate(L(t)),r)},v.every=v.all=function(e,t,r){t=L(t,r);for(var a=!x(e)&&v.keys(e),n=(a||e).length,i=0;n>i;i++){var o=a?a[i]:i;if(!t(e[o],o,e))return!1}return!0},v.some=v.any=function(e,t,r){t=L(t,r);for(var a=!x(e)&&v.keys(e),n=(a||e).length,i=0;n>i;i++){var o=a?a[i]:i;if(t(e[o],o,e))return!0}return!1},v.contains=v.includes=v.include=function(e,t,r,a){return x(e)||(e=v.values(e)),("number"!=typeof r||a)&&(r=0),v.indexOf(e,t,r)>=0},v.invoke=function(e,t){var r=c.call(arguments,2),a=v.isFunction(t);return v.map(e,function(e){var n=a?t:e[t];return null==n?n:n.apply(e,r)})},v.pluck=function(e,t){return v.map(e,v.property(t))},v.where=function(e,t){return v.filter(e,v.matcher(t))},v.findWhere=function(e,t){return v.find(e,v.matcher(t))},v.max=function(e,t,r){var a,n,i=-1/0,o=-1/0;if(null==t&&null!=e){e=x(e)?e:v.values(e);for(var s=0,l=e.length;l>s;s++)a=e[s],a>i&&(i=a)}else t=L(t,r),v.each(e,function(e,r,a){n=t(e,r,a),(n>o||n===-1/0&&i===-1/0)&&(i=e,o=n)});return i},v.min=function(e,t,r){var a,n,i=1/0,o=1/0;if(null==t&&null!=e){e=x(e)?e:v.values(e);for(var s=0,l=e.length;l>s;s++)a=e[s],i>a&&(i=a)}else t=L(t,r),v.each(e,function(e,r,a){n=t(e,r,a),(o>n||1/0===n&&1/0===i)&&(i=e,o=n)});return i},v.shuffle=function(e){for(var t,r=x(e)?e:v.values(e),a=r.length,n=Array(a),i=0;a>i;i++)t=v.random(0,i),t!==i&&(n[i]=n[t]),n[t]=r[i];return n},v.sample=function(e,t,r){return null==t||r?(x(e)||(e=v.values(e)),e[v.random(e.length-1)]):v.shuffle(e).slice(0,Math.max(0,t))},v.sortBy=function(e,t,r){return t=L(t,r),v.pluck(v.map(e,function(e,r,a){return{value:e,index:r,criteria:t(e,r,a)}}).sort(function(e,t){var r=e.criteria,a=t.criteria;if(r!==a){if(r>a||void 0===r)return 1;if(a>r||void 0===a)return-1}return e.index-t.index}),"value")};var q=function(e){return function(t,r,a){var n={};return r=L(r,a),v.each(t,function(a,i){var o=r(a,i,t);e(n,a,o)}),n}};v.groupBy=q(function(e,t,r){v.has(e,r)?e[r].push(t):e[r]=[t]}),v.indexBy=q(function(e,t,r){e[r]=t}),v.countBy=q(function(e,t,r){v.has(e,r)?e[r]++:e[r]=1}),v.toArray=function(e){return e?v.isArray(e)?c.call(e):x(e)?v.map(e,v.identity):v.values(e):[]},v.size=function(e){return null==e?0:x(e)?e.length:v.keys(e).length},v.partition=function(e,t,r){t=L(t,r);var a=[],n=[];return v.each(e,function(e,r,i){(t(e,r,i)?a:n).push(e)}),[a,n]},v.first=v.head=v.take=function(e,t,r){return null==e?void 0:null==t||r?e[0]:v.initial(e,e.length-t)},v.initial=function(e,t,r){return c.call(e,0,Math.max(0,e.length-(null==t||r?1:t)))},v.last=function(e,t,r){return null==e?void 0:null==t||r?e[e.length-1]:v.rest(e,Math.max(0,e.length-t))},v.rest=v.tail=v.drop=function(e,t,r){return c.call(e,null==t||r?1:t)},v.compact=function(e){return v.filter(e,v.identity)};var M=function(e,t,r,a){for(var n=[],i=0,o=a||0,s=k(e);s>o;o++){var l=e[o];if(x(l)&&(v.isArray(l)||v.isArguments(l))){t||(l=M(l,t,r));var u=0,c=l.length;for(n.length+=c;c>u;)n[i++]=l[u++]}else r||(n[i++]=l)}return n};v.flatten=function(e,t){return M(e,t,!1)},v.without=function(e){return v.difference(e,c.call(arguments,1))},v.uniq=v.unique=function(e,t,r,a){v.isBoolean(t)||(a=r,r=t,t=!1),null!=r&&(r=L(r,a));for(var n=[],i=[],o=0,s=k(e);s>o;o++){var l=e[o],u=r?r(l,o,e):l;t?(o&&i===u||n.push(l),i=u):r?v.contains(i,u)||(i.push(u),n.push(l)):v.contains(n,l)||n.push(l)}return n},v.union=function(){return v.uniq(M(arguments,!0,!0))},v.intersection=function(e){for(var t=[],r=arguments.length,a=0,n=k(e);n>a;a++){var i=e[a];if(!v.contains(t,i)){for(var o=1;r>o&&v.contains(arguments[o],i);o++);o===r&&t.push(i)}}return t},v.difference=function(e){var t=M(arguments,!0,!0,1);return v.filter(e,function(e){return!v.contains(t,e)})},v.zip=function(){return v.unzip(arguments)},v.unzip=function(e){for(var t=e&&v.max(e,k).length||0,r=Array(t),a=0;t>a;a++)r[a]=v.pluck(e,a);return r},v.object=function(e,t){for(var r={},a=0,n=k(e);n>a;a++)t?r[e[a]]=t[a]:r[e[a][0]]=e[a][1];return r},v.findIndex=t(1),v.findLastIndex=t(-1),v.sortedIndex=function(e,t,r,a){r=L(r,a,1);for(var n=r(t),i=0,o=k(e);o>i;){var s=Math.floor((i+o)/2);r(e[s])<n?i=s+1:o=s}return i},v.indexOf=r(1,v.findIndex,v.sortedIndex),v.lastIndexOf=r(-1,v.findLastIndex),v.range=function(e,t,r){null==t&&(t=e||0,e=0),r=r||1;for(var a=Math.max(Math.ceil((t-e)/r),0),n=Array(a),i=0;a>i;i++,e+=r)n[i]=e;return n};var S=function(e,t,r,a,n){if(!(a instanceof t))return e.apply(r,n);var i=b(e.prototype),o=e.apply(i,n);return v.isObject(o)?o:i};v.bind=function(e,t){if(m&&e.bind===m)return m.apply(e,c.call(arguments,1));if(!v.isFunction(e))throw new TypeError("Bind must be called on a function");var r=c.call(arguments,2),a=function(){return S(e,a,t,this,r.concat(c.call(arguments)))};return a},v.partial=function(e){var t=c.call(arguments,1),r=function(){for(var a=0,n=t.length,i=Array(n),o=0;n>o;o++)i[o]=t[o]===v?arguments[a++]:t[o];for(;a<arguments.length;)i.push(arguments[a++]);return S(e,r,this,this,i)};return r},v.bindAll=function(e){var t,r,a=arguments.length;if(1>=a)throw new Error("bindAll must be passed function names");for(t=1;a>t;t++)r=arguments[t],e[r]=v.bind(e[r],e);return e},v.memoize=function(e,t){var r=function(a){var n=r.cache,i=""+(t?t.apply(this,arguments):a);return v.has(n,i)||(n[i]=e.apply(this,arguments)),n[i]};return r.cache={},r},v.delay=function(e,t){var r=c.call(arguments,2);return setTimeout(function(){return e.apply(null,r)},t)},v.defer=v.partial(v.delay,v,1),v.throttle=function(e,t,r){var a,n,i,o=null,s=0;r||(r={});var l=function(){s=r.leading===!1?0:v.now(),o=null,i=e.apply(a,n),o||(a=n=null)};return function(){var u=v.now();s||r.leading!==!1||(s=u);var c=t-(u-s);return a=this,n=arguments,0>=c||c>t?(o&&(clearTimeout(o),o=null),s=u,i=e.apply(a,n),o||(a=n=null)):o||r.trailing===!1||(o=setTimeout(l,c)),i}},v.debounce=function(e,t,r){var a,n,i,o,s,l=function(){var u=v.now()-o;t>u&&u>=0?a=setTimeout(l,t-u):(a=null,r||(s=e.apply(i,n),a||(i=n=null)))};return function(){i=this,n=arguments,o=v.now();var u=r&&!a;return a||(a=setTimeout(l,t)),u&&(s=e.apply(i,n),i=n=null),s}},v.wrap=function(e,t){return v.partial(t,e)},v.negate=function(e){return function(){return!e.apply(this,arguments)}},v.compose=function(){var e=arguments,t=e.length-1;return function(){for(var r=t,a=e[t].apply(this,arguments);r--;)a=e[r].call(this,a);return a}},v.after=function(e,t){return function(){return--e<1?t.apply(this,arguments):void 0}},v.before=function(e,t){var r;return function(){return--e>0&&(r=t.apply(this,arguments)),1>=e&&(t=null),r}},v.once=v.partial(v.before,2);var I=!{toString:null}.propertyIsEnumerable("toString"),T=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];v.keys=function(e){if(!v.isObject(e))return[];if(f)return f(e);var t=[];for(var r in e)v.has(e,r)&&t.push(r);return I&&a(e,t),t},v.allKeys=function(e){if(!v.isObject(e))return[];var t=[];for(var r in e)t.push(r);return I&&a(e,t),t},v.values=function(e){for(var t=v.keys(e),r=t.length,a=Array(r),n=0;r>n;n++)a[n]=e[t[n]];return a},v.mapObject=function(e,t,r){t=L(t,r);for(var a,n=v.keys(e),i=n.length,o={},s=0;i>s;s++)a=n[s],o[a]=t(e[a],a,e);return o},v.pairs=function(e){for(var t=v.keys(e),r=t.length,a=Array(r),n=0;r>n;n++)a[n]=[t[n],e[t[n]]];return a},v.invert=function(e){for(var t={},r=v.keys(e),a=0,n=r.length;n>a;a++)t[e[r[a]]]=r[a];return t},v.functions=v.methods=function(e){var t=[];for(var r in e)v.isFunction(e[r])&&t.push(r);return t.sort()},v.extend=j(v.allKeys),v.extendOwn=v.assign=j(v.keys),v.findKey=function(e,t,r){t=L(t,r);for(var a,n=v.keys(e),i=0,o=n.length;o>i;i++)if(a=n[i],t(e[a],a,e))return a},v.pick=function(e,t,r){var a,n,i={},o=e;if(null==o)return i;v.isFunction(t)?(n=v.allKeys(o),a=_(t,r)):(n=M(arguments,!1,!1,1),a=function(e,t,r){return t in r},o=Object(o));for(var s=0,l=n.length;l>s;s++){var u=n[s],c=o[u];a(c,u,o)&&(i[u]=c)}return i},v.omit=function(e,t,r){if(v.isFunction(t))t=v.negate(t);else{var a=v.map(M(arguments,!1,!1,1),String);t=function(e,t){return!v.contains(a,t)}}return v.pick(e,t,r)},v.defaults=j(v.allKeys,!0),v.create=function(e,t){var r=b(e);return t&&v.extendOwn(r,t),r},v.clone=function(e){return v.isObject(e)?v.isArray(e)?e.slice():v.extend({},e):e},v.tap=function(e,t){return t(e),e},v.isMatch=function(e,t){var r=v.keys(t),a=r.length;if(null==e)return!a;for(var n=Object(e),i=0;a>i;i++){var o=r[i];if(t[o]!==n[o]||!(o in n))return!1}return!0};var C=function(e,t,r,a){if(e===t)return 0!==e||1/e===1/t;if(null==e||null==t)return e===t;e instanceof v&&(e=e._wrapped),t instanceof v&&(t=t._wrapped);var n=y.call(e);if(n!==y.call(t))return!1;switch(n){case"[object RegExp]":case"[object String]":return""+e==""+t;case"[object Number]":return+e!==+e?+t!==+t:0===+e?1/+e===1/t:+e===+t;case"[object Date]":case"[object Boolean]":return+e===+t}var i="[object Array]"===n;if(!i){if("object"!=typeof e||"object"!=typeof t)return!1;var o=e.constructor,s=t.constructor;if(o!==s&&!(v.isFunction(o)&&o instanceof o&&v.isFunction(s)&&s instanceof s)&&"constructor"in e&&"constructor"in t)return!1}r=r||[],a=a||[];for(var l=r.length;l--;)if(r[l]===e)return a[l]===t;if(r.push(e),a.push(t),i){if(l=e.length,l!==t.length)return!1;for(;l--;)if(!C(e[l],t[l],r,a))return!1}else{var u,c=v.keys(e);if(l=c.length,v.keys(t).length!==l)return!1;for(;l--;)if(u=c[l],!v.has(t,u)||!C(e[u],t[u],r,a))return!1}return r.pop(),a.pop(),!0};v.isEqual=function(e,t){return C(e,t)},v.isEmpty=function(e){return null==e||(x(e)&&(v.isArray(e)||v.isString(e)||v.isArguments(e))?0===e.length:0===v.keys(e).length)},v.isElement=function(e){return!(!e||1!==e.nodeType)},v.isArray=p||function(e){return"[object Array]"===y.call(e)},v.isObject=function(e){var t=typeof e;return"function"===t||"object"===t&&!!e},v.each(["Arguments","Function","String","Number","Date","RegExp","Error"],function(e){v["is"+e]=function(t){return y.call(t)==="[object "+e+"]"}}),v.isArguments(arguments)||(v.isArguments=function(e){return v.has(e,"callee")}),"function"!=typeof/./&&"object"!=typeof Int8Array&&(v.isFunction=function(e){return"function"==typeof e||!1}),v.isFinite=function(e){return isFinite(e)&&!isNaN(parseFloat(e));
},v.isNaN=function(e){return v.isNumber(e)&&e!==+e},v.isBoolean=function(e){return e===!0||e===!1||"[object Boolean]"===y.call(e)},v.isNull=function(e){return null===e},v.isUndefined=function(e){return void 0===e},v.has=function(e,t){return null!=e&&d.call(e,t)},v.noConflict=function(){return n._=i,this},v.identity=function(e){return e},v.constant=function(e){return function(){return e}},v.noop=function(){},v.property=Q,v.propertyOf=function(e){return null==e?function(){}:function(t){return e[t]}},v.matcher=v.matches=function(e){return e=v.extendOwn({},e),function(t){return v.isMatch(t,e)}},v.times=function(e,t,r){var a=Array(Math.max(0,e));t=_(t,r,1);for(var n=0;e>n;n++)a[n]=t(n);return a},v.random=function(e,t){return null==t&&(t=e,e=0),e+Math.floor(Math.random()*(t-e+1))},v.now=Date.now||function(){return(new Date).getTime()};var O={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},E=v.invert(O),G=function(e){var t=function(t){return e[t]},r="(?:"+v.keys(e).join("|")+")",a=RegExp(r),n=RegExp(r,"g");return function(e){return e=null==e?"":""+e,a.test(e)?e.replace(n,t):e}};v.escape=G(O),v.unescape=G(E),v.result=function(e,t,r){var a=null==e?void 0:e[t];return void 0===a&&(a=r),v.isFunction(a)?a.call(e):a};var B=0;v.uniqueId=function(e){var t=++B+"";return e?e+t:t},v.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var $=/(.)^/,A={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},F=/\\|'|\r|\n|\u2028|\u2029/g,D=function(e){return"\\"+A[e]};v.template=function(e,t,r){!t&&r&&(t=r),t=v.defaults({},t,v.templateSettings);var a=RegExp([(t.escape||$).source,(t.interpolate||$).source,(t.evaluate||$).source].join("|")+"|$","g"),n=0,i="__p+='";e.replace(a,function(t,r,a,o,s){return i+=e.slice(n,s).replace(F,D),n=s+t.length,r?i+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'":a?i+="'+\n((__t=("+a+"))==null?'':__t)+\n'":o&&(i+="';\n"+o+"\n__p+='"),t}),i+="';\n",t.variable||(i="with(obj||{}){\n"+i+"}\n"),i="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+i+"return __p;\n";try{var o=new Function(t.variable||"obj","_",i)}catch(s){throw s.source=i,s}var l=function(e){return o.call(this,e,v)},u=t.variable||"obj";return l.source="function("+u+"){\n"+i+"}",l},v.chain=function(e){var t=v(e);return t._chain=!0,t};var P=function(e,t){return e._chain?v(t).chain():t};v.mixin=function(e){v.each(v.functions(e),function(t){var r=v[t]=e[t];v.prototype[t]=function(){var e=[this._wrapped];return u.apply(e,arguments),P(this,r.apply(v,e))}})},v.mixin(v),v.each(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=o[e];v.prototype[e]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!==e&&"splice"!==e||0!==r.length||delete r[0],P(this,r)}}),v.each(["concat","join","slice"],function(e){var t=o[e];v.prototype[e]=function(){return P(this,t.apply(this._wrapped,arguments))}}),v.prototype.value=function(){return this._wrapped},v.prototype.valueOf=v.prototype.toJSON=v.prototype.value,v.prototype.toString=function(){return""+this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return v})}.call(this);var legend=new Array,activeLayers=new Array;jQuery(document).ready(function(){L.TileLayer.BetterWMS=L.TileLayer.WMS.extend({onAdd:function(e){L.TileLayer.WMS.prototype.onAdd.call(this,e)},onRemove:function(e){L.TileLayer.WMS.prototype.onRemove.call(this,e),e.off("click",this.getFeatureInfo,this)},getFeatureInfo:function(e){},getFeatureInfoUrl:function(e){var t=this._map.latLngToContainerPoint(e,this._map.getZoom()),r=this._map.getSize(),a=this.wmsParams.layer_type,n="application/json";4==a&&(n="text/html");var i={request:"GetFeatureInfo",service:"WMS",srs:"EPSG:4326",styles:this.wmsParams.styles,transparent:this.wmsParams.transparent,version:this.wmsParams.version,format:this.wmsParams.format,height:r.y,width:r.x,layers:this.wmsParams.layers,query_layers:this.wmsParams.layers,info_format:n};return i["1.3.0"===i.version?"i":"x"]=t.x,i["1.3.0"===i.version?"j":"y"]=t.y,this._url+L.Util.getParamString(i,this._url,!0)},showGetFeatureInfo:function(e,t,r){if("undefined"!=r){var a=getIndex(selectedLayers,"unique_id",this.wmsParams.unique_id),n="";if(1==selectedLayers[a].type){if(!r.features||0==r.features.length)return;n=getPopupContent(r,selectedLayers[a].pc)}else{if(jQuery(r).find("tr").length<2)return;n=r}L.popup({maxWidth:"auto"}).setLatLng(t).setContent(n).openOn(this._map)}}}),L.tileLayer.betterWms=function(e,t){return new L.TileLayer.BetterWMS(e,t)},L.Icon.Default.imagePath=baseURL+"/assets/plugins/leaflet/images",L.AwesomeMarkers.Icon.prototype.options.prefix="fa"});var heatmap=new Array,pgsql_tmpl,featureGroup=new Array,bounds,layerSelector=new Array,overlays=new Array,mymap,currentBaseMap=new Array,marker_content_tmpl,popupContentId=new Array,tmpl={},db={},table_tmpl=document.getElementById("table-tmpl").innerHTML;Mustache.parse(table_tmpl);var column_tmpl=document.getElementById("column-tmpl").innerHTML;Mustache.parse(column_tmpl);var currentIndex=-1,drawingGroup,editMode=!1;jQuery(document).ready(function(){$.fn.button.Constructor.DEFAULTS={loadingText:'<i class="fa fa-spin fa-spinner"></i> Processing...…'},$(".gs-collapse").on("expanded",function(){var e=jQuery(this);getGeoLayer(e,"gs")}),$(".wms-collapse").on("expanded",function(){var e=jQuery(this);getGeoLayer(e,"wms")}),drawingGroup=new L.FeatureGroup,marker_content_tmpl=document.getElementById("marker-content-tmpl").innerHTML,Mustache.parse(marker_content_tmpl),tmpl.activeLayer=document.getElementById("active-layers-tmpl").innerHTML,Mustache.parse(tmpl.activeLayer),defaultSettings();var e=new L.Control.Draw({edit:{featureGroup:drawingGroup}});mymap=L.map("mapid",{}).setView([51.505,-.09],13),e.addTo(mymap),drawingGroup.addTo(mymap),drawing_event(),selectedBaseLayers.length>0?layername=selectedBaseLayers[0].name:$.each(baseLayers.mymap,function(e,t){layername=e}),$("#share-modal").on("shown.bs.modal",function(){var e=baseURL;map.settings.https||1==map.settings.https||(e=baseURL.replace("s://","://"));var t='<iframe src="'+e+"map/embed/"+map.random_token+'" height="'+map.settings.height+'" width="'+map.settings.width+'"></iframe>';jQuery("#ds_iframe_code").val(t),jQuery("#ds_share_url").val(e+"map/share/"+map.random_token),jQuery("#ds_json_url").val(e+"map/json/"+map.random_token)}),currentBaseMap=isGoogle()?L.tileLayer("https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}",{maxZoom:20,subdomains:["mt0","mt1","mt2","mt3"]}).addTo(mymap):L.tileLayer(baseLayers.mymap[layername]._url,{maxZoom:18,attribution:baseLayers.mymap[layername].options.attribution,id:baseLayers.mymap[layername].options.id}).addTo(mymap),layerSelector=L.control.layers({},{}),mymap.on("baselayerchange",function(e,t){}),mymap.addControl(layerSelector),jQuery("#active-layers-container").on("click",".delete-at-layer",function(){var e=jQuery(this);swal({title:"Are you sure?",text:"This will remove layer from current map.",type:"warning",showCancelButton:!0,confirmButtonColor:"#DD6B55",confirmButtonText:"Yes, delete it!",cancelButtonText:"No, cancel plx!",closeOnConfirm:!0,closeOnCancel:!0},function(t){if(t){var r=e.parents("ul:first").attr("data-id");deleteLayer(r)}})}),jQuery("#active-layers-container").on("click",".geometry-area-limit",function(){var e=jQuery(this),t=e.parents("ul:first").attr("data-id"),r=document.getElementById("geometry-area-limit-tmpl").innerHTML;Mustache.parse(r);var a=getIndex(selectedLayers,"unique_id",t),n=_.where(selectedLayers,{type:3});jQuery("#geometry-area-limit-form-body").html(Mustache.render(r,{unique_id:t,t:a,f:n})),jQuery("#geometry-area-limit-modal").modal("show"),validateForm(jQuery("#geometry-area-limit-form")),jQuery("#geometry_area_dd").click(function(){var e=jQuery(this).val();"custom"==e?jQuery("#cg_area").show():jQuery("#cg_area").hide()}),jQuery("#geometry-area-limit-submit").click(function(){var e=jQuery("#geometry-area-limit-form");if(e.validate().form()){var t=e.find('[name="unique_id"]').val(),r=getIndex(selectedLayers,"unique_id",t),a=e.find('[name="geometry_area"]').val();if("custom"==a){var n=getIndex(selectedLayers,"unique_id",a);selectedLayers[r].geometry_area=jQuery("#custom_geometry_area").val()}else{var n=getIndex(selectedLayers,"unique_id",a),i=selectedLayers[n].layer.getBounds();selectedLayers[r].bouding_box=i._southWest.lat+","+i._southWest.lng+",",selectedLayers[r].bouding_box+=i._northEast.lat+","+i._northEast.lng,selectedLayers[r].geometry_area=toWKT(selectedLayers[n].layer)}jQuery("#geometry-area-limit-modal").modal("hide")}})}),jQuery("#active-layers-container").on("click",".edit-at-layer",function(){var e=jQuery(this),t=e.parents("ul:first").attr("data-id");editATLayer(t)}),jQuery("#active-layers-container").on("click",".edit-query-at-layer",function(){var e=jQuery(this),t=e.parents("ul:first").attr("data-id");editSQLATLayer(t)}),jQuery("#active-layers-container").on("click",".cache-at-layer",function(){var e=jQuery(this),t=e.parents("ul:first").attr("data-id");editCacheLayer(t)}),jQuery("#active-layers-container").on("click",".style-at-layer",function(e){var t=jQuery(this),r=t.parents("ul:first").attr("data-id");editStyleLayer(r)}),jQuery("#cache-settings-modal").on("click","#cache-settings-save-btn",function(e){e.preventDefault();var t=jQuery("#cache_settings_form");if(t.validate().form()){var r=t.find('[name="unique_id"]').val(),a=getIndex(selectedLayers,"unique_id",r),n=t.find('[name="cache_timer"]').val();selectedLayers[a].cache_timer=n,jQuery("#cahe-settings-modal").modal("hide"),saveMapData("settings",function(){showMsg("success","Cache settings save successfully.")})}}),jQuery("#layer-tmpl").change(function(){var e=jQuery(this).val(),e=document.getElementById(e).innerHTML;Mustache.parse(e),jQuery("#layer-render-tmpl").html(Mustache.render(e))}),jQuery(".layer_chk").change(function(){var e=jQuery(this);WMSLayers(e,!0)}),jQuery("#layer-submit").click(function(){var e=jQuery("#layer-form").serialize();ajaxRequest("/developer/connection/save","post","json",e,function(e){if(200==e.status&&""==e.table_name){var t=document.getElementById("table-tmpl").innerHTML;Mustache.parse(t),jQuery("#tables_div").html(Mustache.render(t,{tables:e.result}))}else 200==e.status&&""!=e.table_name&&(jQuery.each(e.result,function(e,t){featureGroup=new L.FeatureGroup,featureGroup.addTo(mymap),L.geoJson(t,{onEachFeature:function(e,t){}}).addTo(featureGroup),mymap.fitBounds(featureGroup.getBounds())}),jQuery("#layer-modal").modal("hide"))})}),jQuery("#save-your-map").click(function(e){e.preventDefault();var t=jQuery(this);t.button("loading"),saveMapData("map",function(e){t.button("reset"),showMsg(e.action,e.msg)})}),jQuery(".close-right-sidebar").click(function(){jQuery(".sidebar_hide").hasClass("hide")&&(jQuery(".sidebar_hide").toggleClass("hide"),jQuery(".control-sidebar").toggleClass("control-sidebar-open"))}),jQuery("#settings-menu-open").click(function(e){e.stopPropagation(),e.preventDefault();var t=document.getElementById("map-settings-sidebar-tmpl").innerHTML;Mustache.parse(t),jQuery("#map-sidebar-container").html(Mustache.render(t,{}));var r=document.getElementById("map-settings-tmpl").innerHTML;Mustache.parse(r),jQuery("#setting_tab_2").html(Mustache.render(r,{settings:map.settings,bg_layers:bglayersrow})),"undefined"!=typeof map.settings.base_layer&&jQuery("#map_base_layers").val(map.settings.base_layer),jQuery(".sidebar_hide").hasClass("hide")||(jQuery(".sidebar_hide").toggleClass("hide"),jQuery(".control-sidebar").toggleClass("control-sidebar-open")),tinyMCEInit_Popup(".popup-content-textarea");var a=jQuery("#map-settings-form");validateForm(a),map.settings.fullscreen&&1==map.settings.fullscreen&&a.find('[name="fullscreen"]').prop("checked",!0),map.settings.https&&1==map.settings.https&&a.find('[name="https"]').prop("checked",!0),jQuery(".map_settings_chk").bootstrapSwitch({size:"small"})}),jQuery(".control-sidebar").on("click","#save-settings-btn",function(e){if(jQuery("#map-settings-form").validate().form()){e.preventDefault();var t=jQuery(this);t.button("loading"),saveMapData("settings",function(e){t.button("reset"),map.settings=e.settings,showMsg("success","Settings saved successfully.")})}}),jQuery(".control-sidebar").on("click",".save-settings",function(e){e.preventDefault();var t=jQuery(this);jQuery("#style_settings_form").validate().form()&&(t.button("loading"),saveMapData("style",function(e){t.button("reset"),showMsg("success","Style saved successfully.")}))}),jQuery(".control-sidebar").on("click","#save_popup_content",function(){var e=jQuery("#layer-form").serialize();ajaxRequest("/developer/map/save","post","json",e,function(e){200==e.status?(jQuery("#map_id").val(e.map_id),window.location=baseURL+"/developer/map/edit/"+e.map_id):showMsg("error",e.msg)})}),sqlFormEvent(),assingSettings(),manage_custom_layers()}),jQuery(document).ready(function(){jQuery("#main-loader").removeClass("hide"),initLayer(),$('input[type="checkbox"].bg_layer_chk').each(function(){jQuery(this).bootstrapSwitch({size:"mini",onSwitchChange:function(e,t){e.preventDefault();var r=jQuery(e.target);baseLayerMap(r,!0)}})}),jQuery(".make-switch").bootstrapSwitch({size:"mini"});var e=getDetailsByAttr(selectedLayers,"type",2);0==e.length&&ajaxLoadSucess()}).ajaxStop(function(){ajaxLoadSucess()});var sqlFormChange=!1,autocomplete,globalLastFileFormat="";