Y-SLD/assets/playkit/js/map.js

3 lines
88 KiB
JavaScript
Raw Normal View History

2024-03-01 11:23:55 +00:00
function simpleheat(e){return this instanceof simpleheat?(this._canvas=e="string"==typeof e?document.getElementById(e):e,this._ctx=e.getContext("2d"),this._width=e.width,this._height=e.height,this._max=1,void(this._data=[])):new simpleheat(e)}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.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.section_id=jQuery("#dd_section_id").val(),t.unique_id=uniqId("cl"),selectedLayers.push(t),layerDialog(t),renderLayer(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(""),$(".l
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 q=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=q(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 q(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(q(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=q(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=j(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}}