@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.32/esri/copyright.txt for details.
*/
import{fromValues as t}from"../../../../../geometry/support/aaBoundingRect.js";import{ShaderProgramType as i}from"../enums.js";import{translateAnchor as e,pointInPolygon as a,distanceFromToPolylineWithinThreshold as o,offsetLine as r}from"../GeometryUtils.js";import{VTLBackgroundMaterial as n}from"../shaders/VTLBackgroundMaterial.js";import{VTLCircleMaterial as s}from"../shaders/VTLCircleMaterial.js";import{VTLFillMaterial as l,VTLOutlineMaterial as h}from"../shaders/VTLFillMaterial.js";import{VTLLineMaterial as u}from"../shaders/VTLLineMaterial.js";import{VTLIconMaterial as p,VTLTextMaterial as g}from"../shaders/VTLSymbolMaterial.js";import c from"./Filter.js";import{StyleLayerType as y,StyleDefinition as P,RotationAlignment as f}from"./StyleDefinition.js";import D from"./StyleProperty.js";import{thinLineHalfWidthThreshold as m}from"../../webgl/definitions.js";const d=8;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 y.BACKGROUND:this._layoutDefinition=P.backgroundLayoutDefinition,this._paintDefinition=P.backgroundPaintDefinition;break;case y.FILL:this._layoutDefinition=P.fillLayoutDefinition,this._paintDefinition=P.fillPaintDefinition;break;case y.LINE:this._layoutDefinition=P.lineLayoutDefinition,this._paintDefinition=P.linePaintDefinition;break;case y.SYMBOL:this._layoutDefinition=P.symbolLayoutDefinition,this._paintDefinition=P.symbolPaintDefinition;break;case y.CIRCLE:this._layoutDefinition=P.circleLayoutDefinition,this._paintDefinition=P.circlePaintDefinition}this._layoutProperties=this._parseLayout(this.layout),this._paintProperties=this._parsePaint(this.paint)}getFeatureFilter(){return void 0!==this._featureFilter?this._featureFilter:this._featureFilter=c.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 D(a,t[e]))}return i}_parsePaint(t){const i={};for(const e in t){const a=this._paintDefinition[e];a&&(i[e]=new D(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,e,a,o){super(t,e,a,o),this.backgroundMaterial=new n(this.computeAttributesKey(i.BACKGROUND,n.ATTRIBUTES,n.ATTRIBUTES_INFO))}}class v extends T{constructor(t,e,a,o){super(t,e,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 u=this.getPaintProperty("fill-outline-color");this.outlineUsesFillColor=!u,this.hasDataDrivenOutlineColor=u?.isDataDriven,this.hasDataDrivenOutline=u?u.isDataDriven:!!r&&r.isDataDriven,this.hasDataDrivenOutline=(u?this.hasDataDrivenOutlineColor:this.hasDataDrivenColor)||this.hasDataDrivenOpacity,this.fillMaterial=new l(this.computeAttributesKey(i.FILL,l.ATTRIBUTES,l.ATTRIBUTES_INFO)),this.outlineMaterial=new h(this.computeAttributesKey(i.OUTLINE,this.outlineUsesFillColor?h.ATTRIBUTES_FILL:h.ATTRIBUTES_OUTLINE,this.outlineUsesFillColor?h.ATTRIBUTES_INFO_FILL:h.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,i,r,n,s,l,h){const u=n.getGeometry();if(!u)return!1;const p=d/h.normalizationRatio;t=t/h.normalizationRatio+h.normalizationOffsetX,i=i/h.normalizationRatio+h.normalizationOffsetY;const g=e(this.getPaintValue("fill-translate",s,n),this.getPaintValue("fill-translate-anchor",s,n),l,d);t-=p*g.x,i-=p*g.y;return!!a(t,i,u)||o(t,i,u,p*r)}}class x extends T{constructor(t,e,a,o){super(t,e,a,o);const r=this.getPaintProperty("line-pattern");if(this.lineMaterial=new u(this.computeAttributesKey(i.LINE,u.ATTRIBUTES,u.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<m){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,i,a,n,s,l,h){let u=n.getGeometry();if(!u)return!1;const p=d/h.normalizationRatio;t=t/h.normalizationRatio+h.normalizationOffsetX,i=i/h.normalizationRatio+h.normalizationOffsetY;const g=e(this.getPaintValue("line-translate",s,n),this.getPaintValue("line-translate-anchor",s,n),l,d);t-=p*g.x,i-=p*g.y;const c=p*this.getPaintValue("line-offset",s,n)||0;0!==c&&(u=r(u,-c));const y=this.getPaintValue("line-width",s,n);return o(t,i,u,p*(a+y/2))}}class I extends T{constructor(t,e,a,o){super(t,e,a,o),this.iconMaterial=new p(this.computeAttributesKey(i.ICON,p.ATTRIBUTES,p.ATTRIBUTES_INFO)),this.textMaterial=new g(this.computeAttributesKey(i.TEXT,g.ATTRIBUTES,g.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,e,a,o){super(t,e,a,o),this.circleMaterial=new s(this.computeAttributesKey(i.CIRCLE,s.ATTRIBUTES,s.ATTRIBUTES_INFO))}getFeatureInflatedBounds(t,i,e,a){const o=R(t);if(!o)return null;const r=this.getPaintValue("circle-translate",i,t),n=Math.max(r[0],r[1]);o[0]-=n,o[2]-=n,o[1]+=n,o[3]+=n;const s=a*(d*(this.getPaintValue("circle-radius",i,t)+this.getPaintValue("circle-stroke-width",i,t))/2);return o[0]-=s,o[1]-=s,o[2]+=s,o[3]+=s,o}isIntersectingFeature(t,i,a,o,r,n,s){const l=o.getGeometry();if(!l)return!1;const h=d/s.normalizationRatio;t=t/s.normalizationRatio+s.normalizationOffsetX,i=i/s.normalizationRatio+s.normalizationOffsetY,a*=h;const u=e(this.getPaintValue("circle-translate",r,o),this.getPaintValue("circle-translate-anchor",r,o),n,h),p=h*(this.getPaintValue("circle-radius",r,o)+this.getPaintValue("circle-stroke-width",r,o));let g,c;for(const e of l)if(e)for(const o of e){g=o.x+u.x,c=o.y+u.y;if(Math.sqrt((t-g)*(t-g)+(i-c)*(i-c))-a<=p)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===f.AUTO&&(this.rotationAlignment=e?f.MAP:f.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===f.AUTO&&(this.rotationAlignment=e?f.MAP:f.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};