@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 5.73 kB
JavaScript
import{_ as e}from"../../chunks/tslib.es6.js";import{geometryTypes as t}from"../../geometry.js";import r from"../../Graphic.js";import{JSONMap as o}from"../../core/jsonMap.js";import{JSONSupport as s}from"../../core/JSONSupport.js";import{clone as i}from"../../core/lang.js";import{isSome as n,unwrap as a}from"../../core/maybe.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import{reader as l}from"../../core/accessorSupport/decorators/reader.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import{writer as m}from"../../core/accessorSupport/decorators/writer.js";import c from"../../geometry/SpatialReference.js";import{fromJSON as u,isPolygon as f}from"../../geometry/support/jsonUtils.js";import h from"../../layers/support/Field.js";var d;const g=new o({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryEnvelope:"extent",mesh:"mesh","":null});let j=d=class extends s{constructor(e){super(e),this.displayFieldName=null,this.exceededTransferLimit=!1,this.features=[],this.fields=null,this.geometryType=null,this.hasM=!1,this.hasZ=!1,this.queryGeometry=null,this.spatialReference=null}readFeatures(e,t){const o=c.fromJSON(t.spatialReference),s=[];for(let i=0;i<e.length;i++){const t=e[i],a=r.fromJSON(t),p=t.geometry&&t.geometry.spatialReference;n(a.geometry)&&!p&&(a.geometry.spatialReference=o);const l=t.aggregateGeometries,y=a.aggregateGeometries;if(l&&n(y))for(const e in y){const t=y[e],r=l[e]?.spatialReference;n(t)&&!r&&(t.spatialReference=o)}s.push(a)}return s}writeGeometryType(e,t,r,o){if(e)return void g.write(e,t,r,o);const{features:s}=this;if(s)for(const i of s)if(i&&n(i.geometry))return void g.write(i.geometry.type,t,r,o)}readQueryGeometry(e,t){if(!e)return null;const r=!!e.spatialReference,o=u(e);return o&&!r&&t.spatialReference&&(o.spatialReference=c.fromJSON(t.spatialReference)),o}writeSpatialReference(e,t){if(e)return void(t.spatialReference=e.toJSON());const{features:r}=this;if(r)for(const o of r)if(o&&n(o.geometry)&&o.geometry.spatialReference)return void(t.spatialReference=o.geometry.spatialReference.toJSON())}clone(){return new d(this.cloneProperties())}cloneProperties(){return i({displayFieldName:this.displayFieldName,exceededTransferLimit:this.exceededTransferLimit,features:this.features,fields:this.fields,geometryType:this.geometryType,hasM:this.hasM,hasZ:this.hasZ,queryGeometry:this.queryGeometry,spatialReference:this.spatialReference,transform:this.transform})}toJSON(e){const t=this.write();if(t.features&&Array.isArray(e)&&e.length>0)for(let r=0;r<t.features.length;r++){const o=t.features[r];if(o.geometry){const t=e&&e[r];o.geometry=t&&t.toJSON()||o.geometry}}return t}quantize(e){const{scale:[t,r],translate:[o,s]}=e,i=e=>Math.round((e-o)/t),n=e=>Math.round((s-e)/r),p=this.features,l=this._getQuantizationFunction(this.geometryType,i,n);for(let y=0,m=p.length;y<m;y++)l?.(a(p[y].geometry))||(p.splice(y,1),y--,m--);return this.transform=e,this}unquantize(){const{geometryType:e,features:t,transform:r}=this;if(!r)return this;const{translate:[o,s],scale:[i,a]}=r,p=e=>e*i+o,l=e=>s-e*a,y=this._getHydrationFunction(e,p,l);for(const{geometry:m}of t)n(m)&&y&&y(m);return this.transform=null,this}_quantizePoints(e,t,r){let o,s;const i=[];for(let n=0,a=e.length;n<a;n++){const a=e[n];if(n>0){const e=t(a[0]),n=r(a[1]);e===o&&n===s||(i.push([e-o,n-s]),o=e,s=n)}else o=t(a[0]),s=r(a[1]),i.push([o,s])}return i.length>0?i:null}_getQuantizationFunction(e,t,r){return"point"===e?e=>(e.x=t(e.x),e.y=r(e.y),e):"polyline"===e||"polygon"===e?e=>{const o=f(e)?e.rings:e.paths,s=[];for(let i=0,n=o.length;i<n;i++){const e=o[i],n=this._quantizePoints(e,t,r);n&&s.push(n)}return s.length>0?(f(e)?e.rings=s:e.paths=s,e):null}:"multipoint"===e?e=>{const o=this._quantizePoints(e.points,t,r);return o&&o.length>0?(e.points=o,e):null}:"extent"===e?e=>e:null}_getHydrationFunction(e,t,r){return"point"===e?e=>{e.x=t(e.x),e.y=r(e.y)}:"polyline"===e||"polygon"===e?e=>{const o=f(e)?e.rings:e.paths;let s,i;for(let n=0,a=o.length;n<a;n++){const e=o[n];for(let o=0,n=e.length;o<n;o++){const n=e[o];o>0?(s+=n[0],i+=n[1]):(s=n[0],i=n[1]),n[0]=t(s),n[1]=r(i)}}}:"extent"===e?e=>{e.xmin=t(e.xmin),e.ymin=r(e.ymin),e.xmax=t(e.xmax),e.ymax=r(e.ymax)}:"multipoint"===e?e=>{const o=e.points;let s,i;for(let n=0,a=o.length;n<a;n++){const e=o[n];n>0?(s+=e[0],i+=e[1]):(s=e[0],i=e[1]),e[0]=t(s),e[1]=r(i)}}:null}};e([p({type:String,json:{write:!0}})],j.prototype,"displayFieldName",void 0),e([p({type:Boolean,json:{write:{overridePolicy:e=>({enabled:e})}}})],j.prototype,"exceededTransferLimit",void 0),e([p({type:[r],json:{write:!0}})],j.prototype,"features",void 0),e([l("features")],j.prototype,"readFeatures",null),e([p({type:[h],json:{write:!0}})],j.prototype,"fields",void 0),e([p({type:["point","multipoint","polyline","polygon","extent","mesh"],json:{read:{reader:g.read}}})],j.prototype,"geometryType",void 0),e([m("geometryType")],j.prototype,"writeGeometryType",null),e([p({type:Boolean,json:{write:{overridePolicy:e=>({enabled:e})}}})],j.prototype,"hasM",void 0),e([p({type:Boolean,json:{write:{overridePolicy:e=>({enabled:e})}}})],j.prototype,"hasZ",void 0),e([p({types:t,json:{write:!0}})],j.prototype,"queryGeometry",void 0),e([l("queryGeometry")],j.prototype,"readQueryGeometry",null),e([p({type:c,json:{write:!0}})],j.prototype,"spatialReference",void 0),e([m("spatialReference")],j.prototype,"writeSpatialReference",null),e([p({json:{write:!0}})],j.prototype,"transform",void 0),j=d=e([y("esri.rest.support.FeatureSet")],j),j.prototype.toJSON.isDefaultToJSON=!0;const x=j;export{x as default};