@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 13.3 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{fromValues as t}from"../../../../../geometry/support/aaBoundingRect.js";import{tilePixelRatio as i}from"../constants.js";import{ShaderProgramType as e}from"../enums.js";import{translateAnchor as a,offsetLine as o,distanceFromToPolylineWithinThreshold as r,pointInPolygon as n}from"../GeometryUtils.js";import{VTLBackgroundMaterial as s}from"../shaders/VTLBackgroundMaterial.js";import{VTLCircleMaterial as l}from"../shaders/VTLCircleMaterial.js";import{VTLFillMaterial as h,VTLOutlineMaterial as u}from"../shaders/VTLFillMaterial.js";import{VTLLineMaterial as p}from"../shaders/VTLLineMaterial.js";import{VTLIconMaterial as g,VTLTextMaterial as c}from"../shaders/VTLSymbolMaterial.js";import y from"./Filter.js";import{StyleLayerType as P,StyleDefinition as f,RotationAlignment as D}from"./StyleDefinition.js";import m from"./StyleProperty.js";import{thinLineHalfWidthThreshold as d}from"../../webgl/definitions.js";var _;!function(t){t[t.BUTT=0]="BUTT",t[t.ROUND=1]="ROUND",t[t.SQUARE=2]="SQUARE",t[t.UNKNOWN=4]="UNKNOWN"}(_||(_={}));class L{constructor(t,i,e,a,o,r){this.layer=t,this.feature=i,this.bounds=e,this.normalizationRatio=a,this.normalizationOffsetX=o,this.normalizationOffsetY=r}}class T{constructor(t,i,e,a){switch(this.type=t,this.typeName=i.type,this.id=i.id,this.source=i.source,this.sourceLayer=i["source-layer"],this.minzoom=i.minzoom,this.maxzoom=i.maxzoom,this.filter=i.filter,this.layout=i.layout,this.paint=i.paint,this.z=e,this.uid=a,t){case P.BACKGROUND:this._layoutDefinition=f.backgroundLayoutDefinition,this._paintDefinition=f.backgroundPaintDefinition;break;case P.FILL:this._layoutDefinition=f.fillLayoutDefinition,this._paintDefinition=f.fillPaintDefinition;break;case P.LINE:this._layoutDefinition=f.lineLayoutDefinition,this._paintDefinition=f.linePaintDefinition;break;case P.SYMBOL:this._layoutDefinition=f.symbolLayoutDefinition,this._paintDefinition=f.symbolPaintDefinition;break;case P.CIRCLE:this._layoutDefinition=f.circleLayoutDefinition,this._paintDefinition=f.circlePaintDefinition}this._layoutProperties=this._parseLayout(this.layout),this._paintProperties=this._parsePaint(this.paint)}getFeatureFilter(){return void 0!==this._featureFilter?this._featureFilter:this._featureFilter=y.createFilter(this.filter)}getLayoutProperty(t){return this._layoutProperties[t]}getPaintProperty(t){return this._paintProperties[t]}getLayoutValue(t,i,e){let a;const o=this._layoutProperties[t];return o&&(a=o.getValue(i,e)),void 0===a&&(a=this._layoutDefinition[t].default),a}getPaintValue(t,i,e){let a;const o=this._paintProperties[t];return o&&(a=o.getValue(i,e)),void 0===a&&(a=this._paintDefinition[t].default),a}isPainterDataDriven(){const t=this._paintProperties;if(t)for(const i in t)if(t[i].isDataDriven)return!0;return!1}isIntersectingFeature(t,i,e,a,o,r,n){return!1}getFeatureInflatedBounds(t,i,e,a){return null}_parseLayout(t){const i={};for(const e in t){const a=this._layoutDefinition[e];a&&(i[e]=new m(a,t[e]))}return i}_parsePaint(t){const i={};for(const e in t){const a=this._paintDefinition[e];a&&(i[e]=new m(a,t[e]))}return i}computeAttributesKey(t,i,e,a){let o=0,r=0;for(const n of i){let t=3;if(!n||n!==a){const i=e[n],{isLayout:a,isOptional:o}=i,r=a?this.getLayoutProperty(n):this.getPaintProperty(n);t=r?.interpolator?2:r?.isDataDriven?1:o&&!r?3:0}r|=t<<o,o+=2}return r<<3|t}}class V extends T{constructor(t,i,a,o){super(t,i,a,o),this.backgroundMaterial=new s(this.computeAttributesKey(e.BACKGROUND,s.ATTRIBUTES,s.ATTRIBUTES_INFO))}}class v extends T{constructor(t,i,a,o){super(t,i,a,o);const r=this.getPaintProperty("fill-color"),n=this.getPaintProperty("fill-opacity"),s=this.getPaintProperty("fill-pattern");this.hasDataDrivenColor=r?.isDataDriven,this.hasDataDrivenOpacity=n?.isDataDriven,this.hasDataDrivenFill=this.hasDataDrivenColor||this.hasDataDrivenOpacity||s?.isDataDriven;const l=this.getPaintProperty("fill-outline-color");this.outlineUsesFillColor=!l,this.hasDataDrivenOutlineColor=l?.isDataDriven,this.hasDataDrivenOutline=l?l.isDataDriven:!!r&&r.isDataDriven,this.hasDataDrivenOutline=(l?this.hasDataDrivenOutlineColor:this.hasDataDrivenColor)||this.hasDataDrivenOpacity,this.fillMaterial=new h(this.computeAttributesKey(e.FILL,h.ATTRIBUTES,h.ATTRIBUTES_INFO)),this.outlineMaterial=new u(this.computeAttributesKey(e.OUTLINE,this.outlineUsesFillColor?u.ATTRIBUTES_FILL:u.ATTRIBUTES_OUTLINE,this.outlineUsesFillColor?u.ATTRIBUTES_INFO_FILL:u.ATTRIBUTES_INFO_OUTLINE),this.outlineUsesFillColor)}getFeatureInflatedBounds(t,i,e,a){const o=R(t);if(!o)return null;const r=this.getPaintValue("fill-translate",i,t),n=a*Math.max(r[0],r[1]);return o[0]-=n,o[2]-=n,o[1]+=n,o[3]+=n,o}isIntersectingFeature(t,e,o,s,l,h,u){const p=s.getGeometry();if(!p)return!1;const g=i/u.normalizationRatio;t=t/u.normalizationRatio+u.normalizationOffsetX,e=e/u.normalizationRatio+u.normalizationOffsetY;const c=a(this.getPaintValue("fill-translate",l,s),this.getPaintValue("fill-translate-anchor",l,s),h,i);t-=g*c.x,e-=g*c.y;return!!n(t,e,p)||r(t,e,p,g*o)}}class x extends T{constructor(t,i,a,o){super(t,i,a,o);const r=this.getPaintProperty("line-pattern");if(this.lineMaterial=new p(this.computeAttributesKey(e.LINE,p.ATTRIBUTES,p.ATTRIBUTES_INFO,r?"line-dasharray":"")),this.hasDataDrivenLine=this.getPaintProperty("line-blur")?.isDataDriven||this.getPaintProperty("line-color")?.isDataDriven||this.getPaintProperty("line-gap-width")?.isDataDriven||this.getPaintProperty("line-offset")?.isDataDriven||this.getPaintProperty("line-opacity")?.isDataDriven||this.getPaintProperty("line-pattern")?.isDataDriven||this.getPaintProperty("line-dasharray")?.isDataDriven||this.getLayoutProperty("line-cap")?.isDataDriven||this.getPaintProperty("line-width")?.isDataDriven,this.canUseThinTessellation=!1,!this.hasDataDrivenLine){const t=this.getPaintProperty("line-width");if(!t||"number"==typeof t&&.5*t<d){const t=this.getPaintProperty("line-offset");(!t||"number"==typeof t&&0===t)&&(this.canUseThinTessellation=!0)}}}getDashKey(t,i){let e;switch(i){case _.BUTT:e="Butt";break;case _.ROUND:e="Round";break;case _.SQUARE:e="Square";break;default:e="Butt"}return`dasharray-[${t.toString()}]-${e}`}getFeatureInflatedBounds(t,i,e,a){const o=R(t);if(!o)return null;const r=this.getPaintValue("line-translate",i,t),n=a*Math.max(r[0],r[1]);o[0]-=n,o[2]-=n,o[1]+=n,o[3]+=n;const s=a*Math.abs(this.getPaintValue("line-offset",i,t)||0),l=a*(this.getPaintValue("line-width",i,t)/2);return o[0]-=s+l,o[1]-=s+l,o[2]+=s+l,o[3]+=s+l,o}isIntersectingFeature(t,e,n,s,l,h,u){let p=s.getGeometry();if(!p)return!1;const g=i/u.normalizationRatio;t=t/u.normalizationRatio+u.normalizationOffsetX,e=e/u.normalizationRatio+u.normalizationOffsetY;const c=a(this.getPaintValue("line-translate",l,s),this.getPaintValue("line-translate-anchor",l,s),h,i);t-=g*c.x,e-=g*c.y;const y=g*this.getPaintValue("line-offset",l,s)||0;0!==y&&(p=o(p,-y));const P=this.getPaintValue("line-width",l,s);return r(t,e,p,g*(n+P/2))}}class I extends T{constructor(t,i,a,o){super(t,i,a,o),this.iconMaterial=new g(this.computeAttributesKey(e.ICON,g.ATTRIBUTES,g.ATTRIBUTES_INFO)),this.textMaterial=new c(this.computeAttributesKey(e.TEXT,c.ATTRIBUTES,c.ATTRIBUTES_INFO)),this.hasDataDrivenIcon=this.getPaintProperty("icon-color")?.isDataDriven||this.getPaintProperty("icon-halo-blur")?.isDataDriven||this.getPaintProperty("icon-halo-color")?.isDataDriven||this.getPaintProperty("icon-halo-width")?.isDataDriven||this.getPaintProperty("icon-opacity")?.isDataDriven||this.getLayoutProperty("icon-size")?.isDataDriven,this.hasDataDrivenText=this.getPaintProperty("text-color")?.isDataDriven||this.getPaintProperty("text-halo-blur")?.isDataDriven||this.getPaintProperty("text-halo-color")?.isDataDriven||this.getPaintProperty("text-halo-width")?.isDataDriven||this.getPaintProperty("text-opacity")?.isDataDriven||this.getLayoutProperty("text-size")?.isDataDriven}}class A extends T{constructor(t,i,a,o){super(t,i,a,o),this.circleMaterial=new l(this.computeAttributesKey(e.CIRCLE,l.ATTRIBUTES,l.ATTRIBUTES_INFO))}getFeatureInflatedBounds(t,e,a,o){const r=R(t);if(!r)return null;const n=this.getPaintValue("circle-translate",e,t),s=Math.max(n[0],n[1]);r[0]-=s,r[2]-=s,r[1]+=s,r[3]+=s;const l=o*(i*(this.getPaintValue("circle-radius",e,t)+this.getPaintValue("circle-stroke-width",e,t))/2);return r[0]-=l,r[1]-=l,r[2]+=l,r[3]+=l,r}isIntersectingFeature(t,e,o,r,n,s,l){const h=r.getGeometry();if(!h)return!1;const u=i/l.normalizationRatio;t=t/l.normalizationRatio+l.normalizationOffsetX,e=e/l.normalizationRatio+l.normalizationOffsetY,o*=u;const p=a(this.getPaintValue("circle-translate",n,r),this.getPaintValue("circle-translate-anchor",n,r),s,u),g=u*(this.getPaintValue("circle-radius",n,r)+this.getPaintValue("circle-stroke-width",n,r));let c,y;for(const i of h)if(i)for(const a of i){c=a.x+p.x,y=a.y+p.y;if(Math.sqrt((t-c)*(t-c)+(e-y)*(e-y))-o<=g)return!0}return!1}}class U{constructor(t,i,e){let a;this.allowOverlap=t.getLayoutValue("icon-allow-overlap",i),this.ignorePlacement=t.getLayoutValue("icon-ignore-placement",i),this.keepUpright=t.getLayoutValue("icon-keep-upright",i),this.optional=t.getLayoutValue("icon-optional",i),this.rotationAlignment=t.getLayoutValue("icon-rotation-alignment",i),this.rotationAlignment===D.AUTO&&(this.rotationAlignment=e?D.MAP:D.VIEWPORT),a=t.getLayoutProperty("icon-anchor"),a?.isDataDriven?this._anchorProp=a:this.anchor=t.getLayoutValue("icon-anchor",i),a=t.getLayoutProperty("icon-offset"),a?.isDataDriven?this._offsetProp=a:this.offset=t.getLayoutValue("icon-offset",i),a=t.getLayoutProperty("icon-padding"),a?.isDataDriven?this._paddingProp=a:this.padding=t.getLayoutValue("icon-padding",i),a=t.getLayoutProperty("icon-rotate"),a?.isDataDriven?this._rotateProp=a:this.rotate=t.getLayoutValue("icon-rotate",i),a=t.getLayoutProperty("icon-size"),a?.isDataDriven?this._sizeProp=a:this.size=t.getLayoutValue("icon-size",i)}update(t,i){this._anchorProp&&(this.anchor=this._anchorProp.getValue(t,i)),this._offsetProp&&(this.offset=this._offsetProp.getValue(t,i)),this._paddingProp&&(this.padding=this._paddingProp.getValue(t,i)),this._rotateProp&&(this.rotate=this._rotateProp.getValue(t,i)),this._sizeProp&&(this.size=this._sizeProp.getValue(t,i))}}class O{constructor(t,i,e){let a;this.allowOverlap=t.getLayoutValue("text-allow-overlap",i),this.ignorePlacement=t.getLayoutValue("text-ignore-placement",i),this.keepUpright=t.getLayoutValue("text-keep-upright",i),this.optional=t.getLayoutValue("text-optional",i),this.rotationAlignment=t.getLayoutValue("text-rotation-alignment",i),this.rotationAlignment===D.AUTO&&(this.rotationAlignment=e?D.MAP:D.VIEWPORT),a=t.getLayoutProperty("text-anchor"),a?.isDataDriven?this._anchorProp=a:this.anchor=t.getLayoutValue("text-anchor",i),a=t.getLayoutProperty("text-justify"),a?.isDataDriven?this._justifyProp=a:this.justify=t.getLayoutValue("text-justify",i),a=t.getLayoutProperty("text-letter-spacing"),a?.isDataDriven?this._letterSpacingProp=a:this.letterSpacing=t.getLayoutValue("text-letter-spacing",i),a=t.getLayoutProperty("text-line-height"),a?.isDataDriven?this._lineHeightProp=a:this.lineHeight=t.getLayoutValue("text-line-height",i),a=t.getLayoutProperty("text-max-angle"),a?.isDataDriven?this._maxAngleProp=a:this.maxAngle=t.getLayoutValue("text-max-angle",i),a=t.getLayoutProperty("text-max-width"),a?.isDataDriven?this._maxWidthProp=a:this.maxWidth=t.getLayoutValue("text-max-width",i),a=t.getLayoutProperty("text-offset"),a?.isDataDriven?this._offsetProp=a:this.offset=t.getLayoutValue("text-offset",i),a=t.getLayoutProperty("text-padding"),a?.isDataDriven?this._paddingProp=a:this.padding=t.getLayoutValue("text-padding",i),a=t.getLayoutProperty("text-rotate"),a?.isDataDriven?this._rotateProp=a:this.rotate=t.getLayoutValue("text-rotate",i),a=t.getLayoutProperty("text-size"),a?.isDataDriven?this._sizeProp=a:this.size=t.getLayoutValue("text-size",i),a=t.getLayoutProperty("text-writing-mode"),a?.isDataDriven?this._writingModeProp=a:this.writingMode=t.getLayoutValue("text-writing-mode",i)}update(t,i){this._anchorProp&&(this.anchor=this._anchorProp.getValue(t,i)),this._justifyProp&&(this.justify=this._justifyProp.getValue(t,i)),this._letterSpacingProp&&(this.letterSpacing=this._letterSpacingProp.getValue(t,i)),this._lineHeightProp&&(this.lineHeight=this._lineHeightProp.getValue(t,i)),this._maxAngleProp&&(this.maxAngle=this._maxAngleProp.getValue(t,i)),this._maxWidthProp&&(this.maxWidth=this._maxWidthProp.getValue(t,i)),this._offsetProp&&(this.offset=this._offsetProp.getValue(t,i)),this._paddingProp&&(this.padding=this._paddingProp.getValue(t,i)),this._rotateProp&&(this.rotate=this._rotateProp.getValue(t,i)),this._sizeProp&&(this.size=this._sizeProp.getValue(t,i)),this._writingModeProp&&(this.writingMode=this._writingModeProp.getValue(t,i))}}function R(i){const e=i?.getGeometry();if(null==e)return null;let a=1/0,o=1/0,r=-1/0,n=-1/0;for(const t of e)if(t)for(const i of t)a=Math.min(a,i.x),o=Math.min(o,i.y),r=Math.max(r,i.x),n=Math.max(n,i.y);return t(a,o,r,n)}export{V as BackgroundStyleLayer,_ as CapType,A as CircleStyleLayer,v as FillStyleLayer,U as IconLayout,L as IndexItem,x as LineStyleLayer,T as StyleLayer,I as SymbolStyleLayer,O as TextLayout};