MapNotesLayer.js 11 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import"../geometry.js";import t from"../Graphic.js";import"../symbols.js";import r from"../core/Collection.js";import o from"../core/Error.js";import{clone as i}from"../core/lang.js";import{isSome as l,isNone as a}from"../core/maybe.js";import{MultiOriginJSONMixin as n}from"../core/MultiOriginJSONSupport.js";import{setDeepValue as s}from"../core/object.js";import p from"../core/Warning.js";import{property as y}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import{reader as m}from"../core/accessorSupport/decorators/reader.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import{writer as c}from"../core/accessorSupport/decorators/writer.js";import{projectOrLoad as f,canProjectWithoutEngine as d,isLoaded as g,load as b,project as S}from"../geometry/projection.js";import{empty as h,expand as O,equals as w,toExtent as j,NEGATIVE_INFINITY as N}from"../geometry/support/aaBoundingRect.js";import{normalizeCentralMeridian as L}from"../geometry/support/normalizeUtils.js";import{equals as x}from"../geometry/support/spatialReferenceUtils.js";import J from"./FeatureLayer.js";import T from"./GraphicsLayer.js";import v from"./Layer.js";import{findLastObjectIdFromFeatures as C}from"./graphics/objectIdUtils.js";import{BlendLayer as M}from"./mixins/BlendLayer.js";import{OperationalLayer as I}from"./mixins/OperationalLayer.js";import{PortalLayer as R}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as E}from"./mixins/ScaleRangeLayer.js";import D from"./support/Field.js";import _ from"../symbols/SimpleFillSymbol.js";import G from"../symbols/SimpleLineSymbol.js";import P from"../symbols/SimpleMarkerSymbol.js";import F from"../symbols/TextSymbol.js";import B from"../geometry/SpatialReference.js";import k from"../geometry/Extent.js";function z(e){return"markup"===e.featureCollectionType||e.layers.some((e=>null!=e.layerDefinition.visibilityField||!U(e)))}function U({layerDefinition:e,featureSet:t}){const r=e.geometryType??t.geometryType;return H.find((t=>r===t.geometryTypeJSON&&e.drawingInfo?.renderer?.symbol?.type===t.identifyingSymbol.type))}function W(){return new k({xmin:-180,ymin:-90,xmax:180,ymax:90})}const A=new D({name:"OBJECTID",alias:"OBJECTID",type:"oid",nullable:!1,editable:!1}),$=new D({name:"title",alias:"Title",type:"string",nullable:!0,editable:!0});let q=class extends T{constructor(e){super(e),this.visibilityMode="inherited"}initialize(){for(const e of this.graphics)e.sourceLayer=this.layer;this.graphics.on("after-add",(e=>{e.item.sourceLayer=this.layer})),this.graphics.on("after-remove",(e=>{e.item.sourceLayer=null}))}get fullExtent(){const e=this.layer?.spatialReference,t=this.fullBounds;return e?a(t)?f(W(),e).geometry:j(t,e):null}get fullBounds(){const e=this.layer?.spatialReference;if(!e)return null;const t=h();return this.graphics.forEach((r=>{const o=l(r.geometry)?f(r.geometry,e).geometry:null;l(o)&&O(t,"point"===o.type?o:o.extent,t)})),w(t,N)?null:t}get sublayers(){return this.graphics}};e([y({readOnly:!0})],q.prototype,"fullExtent",null),e([y({readOnly:!0})],q.prototype,"fullBounds",null),e([y({readOnly:!0})],q.prototype,"sublayers",null),e([y()],q.prototype,"layer",void 0),e([y()],q.prototype,"layerId",void 0),e([y({readOnly:!0})],q.prototype,"visibilityMode",void 0),q=e([u("esri.layers.MapNotesLayer.MapNotesSublayer")],q);const H=[{geometryType:"polygon",geometryTypeJSON:"esriGeometryPolygon",id:"polygonLayer",layerId:0,title:"Polygons",identifyingSymbol:(new _).toJSON()},{geometryType:"polyline",geometryTypeJSON:"esriGeometryPolyline",id:"polylineLayer",layerId:1,title:"Polylines",identifyingSymbol:(new G).toJSON()},{geometryType:"multipoint",geometryTypeJSON:"esriGeometryMultipoint",id:"multipointLayer",layerId:2,title:"Multipoints",identifyingSymbol:(new P).toJSON()},{geometryType:"point",geometryTypeJSON:"esriGeometryPoint",id:"pointLayer",layerId:3,title:"Points",identifyingSymbol:(new P).toJSON()},{geometryType:"point",geometryTypeJSON:"esriGeometryPoint",id:"textLayer",layerId:4,title:"Text",identifyingSymbol:(new F).toJSON()}];let K=class extends(M(E(I(R(n(v)))))){constructor(e){super(e),this.capabilities={operations:{supportsMapNotesEditing:!0}},this.featureCollections=null,this.featureCollectionJSON=null,this.featureCollectionType="notes",this.legendEnabled=!1,this.listMode="hide-children",this.minScale=0,this.maxScale=0,this.spatialReference=B.WGS84,this.sublayers=new r(H.map((e=>new q({id:e.id,layerId:e.layerId,title:e.title,layer:this})))),this.title="Map Notes",this.type="map-notes",this.visibilityMode="inherited"}readCapabilities(e,t,r){return{operations:{supportsMapNotesEditing:!z(t)&&"portal-item"!==r?.origin}}}readFeatureCollections(e,t,o){if(!z(t))return null;const i=t.layers.map((e=>{const t=new J;return t.read(e,o),t}));return new r({items:i})}readLegacyfeatureCollectionJSON(e,t){return z(t)?i(t.featureCollection):null}get fullExtent(){const e=this.spatialReference,t=h();if(l(this.sublayers))this.sublayers.forEach((({fullBounds:e})=>l(e)?O(t,e,t):t),t);else if(this.featureCollectionJSON?.layers.some((e=>e.layerDefinition.extent))){this.featureCollectionJSON.layers.forEach((r=>{const o=f(r.layerDefinition.extent,e).geometry;l(o)&&O(t,o,t)}))}return w(t,N)?f(W(),e).geometry:j(t,e)}readMinScale(e,t){for(const r of t.layers)if(null!=r.layerDefinition.minScale)return r.layerDefinition.minScale;return 0}readMaxScale(e,t){for(const r of t.layers)if(null!=r.layerDefinition.maxScale)return r.layerDefinition.maxScale;return 0}get multipointLayer(){return this._findSublayer("multipointLayer")}get pointLayer(){return this._findSublayer("pointLayer")}get polygonLayer(){return this._findSublayer("polygonLayer")}get polylineLayer(){return this._findSublayer("polylineLayer")}readSpatialReference(e,t){return t.layers.length?B.fromJSON(t.layers[0].layerDefinition.spatialReference):B.WGS84}readSublayers(e,o,i){if(z(o))return null;const a=[];let n=o.layers.reduce(((e,t)=>Math.max(e,t.layerDefinition.id??-1)),-1)+1;for(const r of o.layers){const{layerDefinition:e,featureSet:o}=r,i=e.id??n++,s=U(r);if(l(s)){const r=new q({id:s.id,title:e.name,layerId:i,layer:this,graphics:o.features.map((({geometry:e,symbol:r,attributes:o,popupInfo:i})=>t.fromJSON({attributes:o,geometry:e,symbol:r,popupTemplate:i})))});a.push(r)}}return new r(a)}writeSublayers(e,t,r,i){const{minScale:n,maxScale:p}=this;if(a(e))return;const y=e.some((e=>e.graphics.length>0));if(!this.capabilities.operations.supportsMapNotesEditing)return void(y&&i?.messages?.push(new o("map-notes-layer:editing-not-supported","New map notes cannot be added to this layer")));const m=[];let u=this.spatialReference.toJSON();e:for(const o of e)for(const e of o.graphics)if(l(e.geometry)){u=e.geometry.spatialReference.toJSON();break e}for(const o of H){const t=e.find((e=>o.id===e.id));this._writeMapNoteSublayer(m,t,o,n,p,u,i)}s("featureCollection.layers",m,t)}get textLayer(){return this._findSublayer("textLayer")}load(e){return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["Feature Collection"]},e)),Promise.resolve(this)}read(e,t){"featureCollection"in e&&(e=i(e),Object.assign(e,e.featureCollection)),super.read(e,t)}async beforeSave(){if(a(this.sublayers))return;let e=null;const t=[];for(const o of this.sublayers)for(const r of o.graphics)if(l(r.geometry)){const o=r.geometry;e?x(o.spatialReference,e)||(d(o.spatialReference,e)||g()||await b(),r.geometry=S(o,e)):e=o.spatialReference,t.push(r)}const r=await L(t.map((e=>e.geometry)));t.forEach(((e,t)=>e.geometry=r[t]))}_findSublayer(e){return a(this.sublayers)?null:this.sublayers?.find((t=>t.id===e))??null}_writeMapNoteSublayer(e,t,r,o,l,n,s){const p=[];if(!a(t)){for(const e of t.graphics)this._writeMapNote(p,e,r.geometryType,s);this._normalizeObjectIds(p,A),e.push({layerDefinition:{name:t.title,drawingInfo:{renderer:{type:"simple",symbol:i(r.identifyingSymbol)}},id:t.layerId,geometryType:r.geometryTypeJSON,minScale:o,maxScale:l,objectIdField:"OBJECTID",fields:[A.toJSON(),$.toJSON()],spatialReference:n},featureSet:{features:p,geometryType:r.geometryTypeJSON}})}}_writeMapNote(e,t,r,o){if(a(t))return;const{geometry:i,symbol:n,popupTemplate:s}=t;if(a(i))return;if(i.type!==r)return void o?.messages?.push(new p("map-notes-layer:invalid-geometry-type",`Geometry "${i.type}" cannot be saved in "${r}" layer`,{graphic:t}));if(a(n))return void o?.messages?.push(new p("map-notes-layer:no-symbol","Skipping map notes with no symbol",{graphic:t}));const y={attributes:{...t.attributes},geometry:i.toJSON(),symbol:n.toJSON()};l(s)&&(y.popupInfo=s.toJSON()),e.push(y)}_normalizeObjectIds(e,t){const r=t.name;let o=C(r,e)+1;const i=new Set;for(const l of e){l.attributes||(l.attributes={});const{attributes:e}=l;(null==e[r]||i.has(e[r]))&&(e[r]=o++),i.add(e[r])}}};e([y({readOnly:!0})],K.prototype,"capabilities",void 0),e([m(["portal-item","web-map"],"capabilities",["layers"])],K.prototype,"readCapabilities",null),e([y({readOnly:!0})],K.prototype,"featureCollections",void 0),e([m(["web-map","portal-item"],"featureCollections",["layers"])],K.prototype,"readFeatureCollections",null),e([y({readOnly:!0,json:{origins:{"web-map":{write:{enabled:!0,target:"featureCollection"}}}}})],K.prototype,"featureCollectionJSON",void 0),e([m(["web-map","portal-item"],"featureCollectionJSON",["featureCollection"])],K.prototype,"readLegacyfeatureCollectionJSON",null),e([y({readOnly:!0,json:{read:!0,write:{enabled:!0,ignoreOrigin:!0}}})],K.prototype,"featureCollectionType",void 0),e([y({readOnly:!0})],K.prototype,"fullExtent",null),e([y({readOnly:!0,json:{origins:{"web-map":{write:{target:"featureCollection.showLegend",overridePolicy(){return{enabled:null!=this.featureCollectionJSON}}}}}}})],K.prototype,"legendEnabled",void 0),e([y({type:["show","hide","hide-children"]})],K.prototype,"listMode",void 0),e([y({type:Number,nonNullable:!0,json:{write:!1}})],K.prototype,"minScale",void 0),e([m(["web-map","portal-item"],"minScale",["layers"])],K.prototype,"readMinScale",null),e([y({type:Number,nonNullable:!0,json:{write:!1}})],K.prototype,"maxScale",void 0),e([m(["web-map","portal-item"],"maxScale",["layers"])],K.prototype,"readMaxScale",null),e([y({readOnly:!0})],K.prototype,"multipointLayer",null),e([y({value:"ArcGISFeatureLayer",type:["ArcGISFeatureLayer"]})],K.prototype,"operationalLayerType",void 0),e([y({readOnly:!0})],K.prototype,"pointLayer",null),e([y({readOnly:!0})],K.prototype,"polygonLayer",null),e([y({readOnly:!0})],K.prototype,"polylineLayer",null),e([y({type:B})],K.prototype,"spatialReference",void 0),e([m(["web-map","portal-item"],"spatialReference",["layers"])],K.prototype,"readSpatialReference",null),e([y({readOnly:!0,json:{origins:{"web-map":{write:{ignoreOrigin:!0}}}}})],K.prototype,"sublayers",void 0),e([m("web-map","sublayers",["layers"])],K.prototype,"readSublayers",null),e([c("web-map","sublayers")],K.prototype,"writeSublayers",null),e([y({readOnly:!0})],K.prototype,"textLayer",null),e([y()],K.prototype,"title",void 0),e([y({readOnly:!0,json:{read:!1}})],K.prototype,"type",void 0),K=e([u("esri.layers.MapNotesLayer")],K);const Q=K;export{Q as default};