pos-gis/public/js/esri-leaflet.js

5 lines
37 KiB
JavaScript
Raw Permalink Normal View History

2024-10-07 06:13:42 +00:00
/*! Esri-Leaflet - v0.0.1-beta.5 - 2014-06-16
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
* Apache License*/
L.esri={VERSION:"0.0.1-beta.5",Layers:{},Services:{},Controls:{},Tasks:{},Util:{},Support:{CORS:!!(window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest),pointerEvents:""===document.documentElement.style.pointerEvents}},function(L){function a(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function b(a){return c(a[0],a[a.length-1])||a.push(a[0]),a}function c(a,b){for(var c=0;c<a.length;c++)if(a[c]!==b[c])return!1;return!0}function d(a){var b,c=0,d=0,e=a.length,f=a[d];for(d;e-1>d;d++)b=a[d+1],c+=(b[0]-f[0])*(b[1]+f[1]),f=b;return c>=0}function e(a,b,c,d){var e=(d[0]-c[0])*(a[1]-c[1])-(d[1]-c[1])*(a[0]-c[0]),f=(b[0]-a[0])*(a[1]-c[1])-(b[1]-a[1])*(a[0]-c[0]),g=(d[1]-c[1])*(b[0]-a[0])-(d[0]-c[0])*(b[1]-a[1]);if(0!==g){var h=e/g,i=f/g;if(h>=0&&1>=h&&i>=0&&1>=i)return!0}return!1}function f(a,b){for(var c=0;c<a.length-1;c++)for(var d=0;d<b.length-1;d++)if(e(a[c],a[c+1],b[d],b[d+1]))return!0;return!1}function g(a,b){for(var c=!1,d=-1,e=a.length,f=e-1;++d<e;f=d)(a[d][1]<=b[1]&&b[1]<a[f][1]||a[f][1]<=b[1]&&b[1]<a[d][1])&&b[0]<(a[f][0]-a[d][0])*(b[1]-a[d][1])/(a[f][1]-a[d][1])+a[d][0]&&(c=!c);return c}function h(a,b){var c=f(a,b),d=g(a,b[0]);return!c&&d?!0:!1}function i(a){for(var c=[],e=[],f=0;f<a.length;f++){var g=b(a[f].slice(0));if(!(g.length<4))if(d(g)){var i=[g];c.push(i)}else e.push(g)}for(;e.length;){for(var j=e.pop(),k=!1,l=c.length-1;l>=0;l--){var m=c[l][0];if(h(m,j)){c[l].push(j),k=!0;break}}k||c.push([j.reverse()])}return 1===c.length?{type:"Polygon",coordinates:c[0]}:{type:"MultiPolygon",coordinates:c}}function j(a){var c=[],e=a.slice(0),f=b(e.shift().slice(0));if(f.length>=4){d(f)||f.reverse(),c.push(f);for(var g=0;g<e.length;g++){var h=b(e[g].slice(0));h.length>=4&&(d(h)&&h.reverse(),c.push(h))}}return c}function k(a){for(var b=[],c=0;c<a.length;c++)for(var d=j(a[c]),e=d.length-1;e>=0;e--){var f=d[e].slice(0);b.push(f)}return b}L.esri.Util.extentToBounds=function(a){var b=new L.LatLng(a.ymin,a.xmin),c=new L.LatLng(a.ymax,a.xmax);return new L.LatLngBounds(b,c)},L.esri.Util.boundsToExtent=function(a){return{xmin:a.getSouthWest().lng,ymin:a.getSouthWest().lat,xmax:a.getNorthEast().lng,ymax:a.getNorthEast().lat,spatialReference:{wkid:4326}}},L.esri.Util.arcgisToGeojson=function(b,c){var d={};return"number"==typeof b.x&&"number"==typeof b.y&&(d.type="Point",d.coordinates=[b.x,b.y]),b.points&&(d.type="MultiPoint",d.coordinates=b.points.slice(0)),b.paths&&(1===b.paths.length?(d.type="LineString",d.coordinates=b.paths[0].slice(0)):(d.type="MultiLineString",d.coordinates=b.paths.slice(0))),b.rings&&(d=i(b.rings.slice(0))),(b.geometry||b.attributes)&&(d.type="Feature",d.geometry=b.geometry?L.esri.Util.arcgisToGeojson(b.geometry):null,d.properties=b.attributes?a(b.attributes):null,b.attributes&&(d.id=b.attributes[c]||b.attributes.OBJECTID||b.attributes.FID)),d},L.esri.Util.geojsonToArcGIS=function(b,c){c=c||"OBJECTID";var d,e={wkid:4326},f={};switch(b.type){case"Point":f.x=b.coordinates[0],f.y=b.coordinates[1],f.spatialReference=e;break;case"MultiPoint":f.points=b.coordinates.slice(0),f.spatialReference=e;break;case"LineString":f.paths=[b.coordinates.slice(0)],f.spatialReference=e;break;case"MultiLineString":f.paths=b.coordinates.slice(0),f.spatialReference=e;break;case"Polygon":f.rings=j(b.coordinates.slice(0)),f.spatialReference=e;break;case"MultiPolygon":f.rings=k(b.coordinates.slice(0)),f.spatialReference=e;break;case"Feature":b.geometry&&(f.geometry=L.esri.Util.geojsonToArcGIS(b.geometry,c)),f.attributes=b.properties?a(b.properties):{},b.id&&(f.attributes[c]=b.id);break;case"FeatureCollection":for(f=[],d=0;d<b.features.length;d++)f.push(L.esri.Util.geojsonToArcGIS(b.features[d],c));break;case"GeometryCollection":for(f=[],d=0;d<b.geometries.length;d++)f.push(L.esri.Util.geojsonToArcGIS(b.geometries[d],c))}return f},L.esri.Util.responseToFeatureCollection=function(a,b){var c;if(b)c=b;else if(a.objectIdFieldName)c=a.objectIdFieldName;else if(a.fields){for(var d=0;d<=a.fields.length-1;d++)if("esriFieldTypeOID"===a.fields[d].type){c=a.fields[d].name;break}}else c="OBJECTID";var e={type:"FeatureColl
c=e.concat(f)}else c=this._timeIndex.between(a,b);for(var g=c.length-1;g>=0;g--)d.push(c[g].id);return d},_buildTimeIndexes:function(a){var b,c;if(this.options.timeField.start&&this.options.timeField.end){var d=[],e=[];for(b=a.length-1;b>=0;b--)c=a[b],d.push({id:c.id,value:new Date(c.properties[this.options.timeField.start])}),e.push({id:c.id,value:new Date(c.properties[this.options.timeField.end])});this._startTimeIndex.bulkAdd(d),this._endTimeIndex.bulkAdd(e)}else{var f=[];for(b=a.length-1;b>=0;b--)c=a[b],f.push({id:c.id,value:new Date(c.properties[this.options.timeField])});this._timeIndex.bulkAdd(f)}},_featureWithinTimeRange:function(a){if(!this.options.from||!this.options.to)return!0;var b=+this.options.from.valueOf(),c=+this.options.to.valueOf();if("string"==typeof this.options.timeField){var d=+a.properties[this.options.timeField];return d>=b&&c>=d}if(this.options.timeField.start&&this.options.timeField.end){var e=+a.properties[this.options.timeField.start],f=+a.properties[this.options.timeField.end];return e>=b&&c>=e||f>=b&&c>=f}},authenticate:function(a){return this._service.authenticate(a),this},metadata:function(a,b){return this._service.metadata(a,b),this},query:function(){return this._service.query()},addFeature:function(a,b,c){return this._service.addFeature(a,function(a,d){this.refresh(),b.call(c,a,d)},this),this},updateFeature:function(a,b,c){return this._service.updateFeature(a,function(a,d){this.refresh(),b.call(c,a,d)},this)},deleteFeature:function(a,b,c){return this._service.deleteFeature(a,function(a,d){this.removeLayers([d.objectId]),b.call(c,a,d)},this)}}),a.prototype._query=function(a){for(var b,c,d,e=0,f=this.values.length-1;f>=e;)if(d=b=(e+f)/2|0,c=this.values[Math.round(b)],+c.value<+a)e=b+1;else{if(!(+c.value>+a))return b;f=b-1}return~f},a.prototype.sort=function(){this.values.sort(function(a,b){return+b.value-+a.value}).reverse(),this.dirty=!1},a.prototype.between=function(a,b){this.dirty&&this.sort();var c=this._query(a),d=this._query(b);return 0===c&&0===d?[]:(c=Math.abs(c),d=0>d?Math.abs(d):d+1,this.values.slice(c,d))},a.prototype.bulkAdd=function(a){this.dirty=!0,this.values=this.values.concat(a)}}(L),L.esri.Layers.FeatureLayer=L.esri.Layers.FeatureManager.extend({statics:{EVENTS:"click dblclick mouseover mouseout mousemove contextmenu popupopen popupclose"},initialize:function(a,b){L.esri.Layers.FeatureManager.prototype.initialize.call(this,a,b),b=L.setOptions(this,b),this._layers={},this._leafletIds={},this._key="c"+(1e9*Math.random()).toString(36).replace(".","_")},onAdd:function(a){return L.esri.Layers.FeatureManager.prototype.onAdd.call(this,a)},onRemove:function(a){for(var b in this._layers)a.removeLayer(this._layers[b]);return L.esri.Layers.FeatureManager.prototype.onRemove.call(this,a)},createLayers:function(a){for(var b=a.length-1;b>=0;b--){var c,d=a[b],e=this._layers[d.id];if(e&&!this._map.hasLayer(e)&&this._map.addLayer(e),e&&e.setLatLngs){var f=L.GeoJSON.geometryToLayer(d,this.options.pointToLayer,L.GeoJSON.coordsToLatLng,this.options);e.setLatLngs(f.getLatLngs())}e||(c=L.GeoJSON.geometryToLayer(d,this.options.pointToLayer,L.GeoJSON.coordsToLatLng,this.options),c.feature=d,c.defaultOptions=c.options,c._leaflet_id=this._key+"_"+d.id,this._leafletIds[c._leaflet_id]=d.id,c.on(L.esri.Layers.FeatureLayer.EVENTS,this._propagateEvent,this),this._popup&&c.bindPopup&&c.bindPopup(this._popup(c.feature,c)),this.options.onEachFeature&&this.options.onEachFeature(c.feature,c),this._layers[c.feature.id]=c,this.resetStyle(c.feature.id),(!this.options.timeField||this.options.timeField&&this._featureWithinTimeRange(d))&&this._map.addLayer(c))}},cellEnter:function(a,b){var c=this._cellCoordsToKey(b),d=this._cache[c];if(d)for(var e=d.length-1;e>=0;e--){var f=this.getFeature(d[e]);this._map.hasLayer(f)||this._map.addLayer(f)}},cellLeave:function(a,b){var c=this._cellCoordsToKey(b),d=this._cache[c];if(d)for(var e=d.length-1;e>=0;e--){var f=this.getFeature(d[e]);this._map.hasLayer(f)&&this._map.removeLayer(f)}},addLayers:function(a){for(var b=a.length-1;b>=0;b--){var c=this._layers[a[b]];c&&this._m