@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.78 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{sqlAnd as e}from"../../core/sql.js";import{getJsonType as t}from"../../geometry/support/jsonUtils.js";import{getScale as r}from"../../geometry/support/scaleUtils.js";import{srToRESTValue as i}from"../../geometry/support/spatialReferenceUtils.js";import{getLayerFloorFilterClause as n}from"../../layers/support/floorFilterUtils.js";import{isExportDynamic as s}from"../../layers/support/sublayerUtils.js";function o(e,r){const{dpi:n,gdbVersion:s,geometry:o,geometryPrecision:a,height:m,historicMoment:p,layerOption:f,mapExtent:y,maxAllowableOffset:u,returnFieldName:c,returnGeometry:d,returnUnformattedValues:g,returnZ:x,spatialReference:h,timeExtent:b,tolerance:E,width:O}=e.toJSON(),{dynamicLayers:S,layerDefs:j,layerIds:N}=l(e),$=null!=r?.geometry?r.geometry:null,I={historicMoment:p,geometryPrecision:a,maxAllowableOffset:u,returnFieldName:c,returnGeometry:d,returnUnformattedValues:g,returnZ:x,tolerance:E},R=$?.toJSON()||o;I.imageDisplay=`${O},${m},${n}`,s&&(I.gdbVersion=s),R&&(delete R.spatialReference,I.geometry=JSON.stringify(R),I.geometryType=t(R));const U=h??R?.spatialReference??y?.spatialReference;if(U&&(I.sr=i(U)),I.time=b?[b.start,b.end].join(","):null,y){const{xmin:e,ymin:t,xmax:r,ymax:i}=y;I.mapExtent=`${e},${t},${r},${i}`}return j&&(I.layerDefs=j),S&&!j&&(I.dynamicLayers=S),I.layers="popup"===f?"visible":f,N&&!S&&(I.layers+=`:${N.join(",")}`),I}function l(e){const{mapExtent:t,floors:i,width:o,sublayers:l,layerIds:m,layerOption:p,gdbVersion:f}=e,y=l?.find((e=>null!=e.layer))?.layer?.serviceSublayers,u="popup"===p,c={},d=r({extent:t,width:o,spatialReference:t?.spatialReference}),g=[],x=e=>{const t=0===d,r=0===e.minScale||d<=e.minScale,i=0===e.maxScale||d>=e.maxScale;if(e.visible&&(t||r&&i))if(e.sublayers)e.sublayers.forEach(x);else{if(!1===m?.includes(e.id)||u&&(!e.popupTemplate||!e.popupEnabled))return;g.unshift(e)}};if(l?.forEach(x),l&&!g.length)c.layerIds=[];else{const e=s(g,y,f),t=g.map((e=>{const t=n(i,e);return e.toExportImageJSON(t)}));if(e)c.dynamicLayers=JSON.stringify(t);else{if(l){let e=g.map((({id:e})=>e));m&&(e=e.filter((e=>m.includes(e)))),c.layerIds=e}else m?.length&&(c.layerIds=m);const e=a(i,g);if(null!=e&&e.length){const t={};for(const r of e)r.definitionExpression&&(t[r.id]=r.definitionExpression);Object.keys(t).length&&(c.layerDefs=JSON.stringify(t))}}}return c}function a(t,r){const i=!!t?.length,s=r.filter((e=>null!=e.definitionExpression||i&&null!=e.floorInfo));return s.length?s.map((r=>{const i=n(t,r),s=e(i,r.definitionExpression);return{id:r.id,definitionExpression:s??void 0}})):null}export{o as identifyToIdentifyRESTParameters,l as toDynamicLayersJSON};