@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 10.2 kB
JavaScript
import{ShaderProgramType as t}from"../enums.js";import{VTLBackgroundMaterial as i}from"../shaders/VTLBackgroundMaterial.js";import{VTLCircleMaterial as e}from"../shaders/VTLCircleMaterial.js";import{VTLFillMaterial as a,VTLOutlineMaterial as o}from"../shaders/VTLFillMaterial.js";import{VTLLineMaterial as r}from"../shaders/VTLLineMaterial.js";import{VTLIconMaterial as s,VTLTextMaterial as n}from"../shaders/VTLSymbolMaterial.js";import h from"./Filter.js";import{StyleLayerType as l,StyleDefinition as p,RotationAlignment as u}from"./StyleDefinition.js";import g from"./StyleProperty.js";import{THIN_LINE_HALF_WIDTH_THRESHOLD as y}from"../../webgl/definitions.js";var D;!function(t){t[t.BUTT=0]="BUTT",t[t.ROUND=1]="ROUND",t[t.SQUARE=2]="SQUARE",t[t.UNKNOWN=4]="UNKNOWN"}(D||(D={}));class P{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 l.BACKGROUND:this._layoutDefinition=p.backgroundLayoutDefinition,this._paintDefinition=p.backgroundPaintDefinition;break;case l.FILL:this._layoutDefinition=p.fillLayoutDefinition,this._paintDefinition=p.fillPaintDefinition;break;case l.LINE:this._layoutDefinition=p.lineLayoutDefinition,this._paintDefinition=p.linePaintDefinition;break;case l.SYMBOL:this._layoutDefinition=p.symbolLayoutDefinition,this._paintDefinition=p.symbolPaintDefinition;break;case l.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=h.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}_parseLayout(t){const i={};for(const e in t){const a=this._layoutDefinition[e];a&&(i[e]=new g(a,t[e]))}return i}_parsePaint(t){const i={};for(const e in t){const a=this._paintDefinition[e];a&&(i[e]=new g(a,t[e]))}return i}computeAttributesKey(t,i,e,a){let o=0,r=0;for(const s of i){let t=3;if(!s||s!==a){const i=e[s],{isLayout:a,isOptional:o}=i,r=a?this.getLayoutProperty(s):this.getPaintProperty(s);t=r?.interpolator?2:r?.isDataDriven?1:o&&!r?3:0}r|=t<<o,o+=2}return r<<3|t}}class c extends P{constructor(e,a,o,r){super(e,a,o,r),this.backgroundMaterial=new i(this.computeAttributesKey(t.BACKGROUND,i.ATTRIBUTES,i.ATTRIBUTES_INFO))}}class f extends P{constructor(i,e,r,s){super(i,e,r,s);const n=this.getPaintProperty("fill-color"),h=this.getPaintProperty("fill-opacity"),l=this.getPaintProperty("fill-pattern");this.hasDataDrivenColor=n?.isDataDriven,this.hasDataDrivenOpacity=h?.isDataDriven,this.hasDataDrivenFill=this.hasDataDrivenColor||this.hasDataDrivenOpacity||l?.isDataDriven;const p=this.getPaintProperty("fill-outline-color");this.outlineUsesFillColor=!p,this.hasDataDrivenOutlineColor=p?.isDataDriven,this.hasDataDrivenOutline=p?p.isDataDriven:!!n&&n.isDataDriven,this.hasDataDrivenOutline=(p?this.hasDataDrivenOutlineColor:this.hasDataDrivenColor)||this.hasDataDrivenOpacity,this.fillMaterial=new a(this.computeAttributesKey(t.FILL,a.ATTRIBUTES,a.ATTRIBUTES_INFO)),this.outlineMaterial=new o(this.computeAttributesKey(t.OUTLINE,this.outlineUsesFillColor?o.ATTRIBUTES_FILL:o.ATTRIBUTES_OUTLINE,this.outlineUsesFillColor?o.ATTRIBUTES_INFO_FILL:o.ATTRIBUTES_INFO_OUTLINE),this.outlineUsesFillColor)}}class _ extends P{constructor(i,e,a,o){super(i,e,a,o);const s=this.getPaintProperty("line-pattern");if(this.lineMaterial=new r(this.computeAttributesKey(t.LINE,r.ATTRIBUTES,r.ATTRIBUTES_INFO,s?"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<y){const t=this.getPaintProperty("line-offset");(!t||"number"==typeof t&&0===t)&&(this.canUseThinTessellation=!0)}}}getDashKey(t,i){let e;switch(i){case D.BUTT:e="Butt";break;case D.ROUND:e="Round";break;case D.SQUARE:e="Square";break;default:e="Butt"}return`dasharray-[${t.toString()}]-${e}`}}class L extends P{constructor(i,e,a,o){super(i,e,a,o),this.iconMaterial=new s(this.computeAttributesKey(t.ICON,s.ATTRIBUTES,s.ATTRIBUTES_INFO)),this.textMaterial=new n(this.computeAttributesKey(t.TEXT,n.ATTRIBUTES,n.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 d extends P{constructor(i,a,o,r){super(i,a,o,r),this.circleMaterial=new e(this.computeAttributesKey(t.CIRCLE,e.ATTRIBUTES,e.ATTRIBUTES_INFO))}}class T{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===u.AUTO&&(this.rotationAlignment=e?u.MAP:u.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 m{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===u.AUTO&&(this.rotationAlignment=e?u.MAP:u.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))}}export{c as BackgroundStyleLayer,D as CapType,d as CircleStyleLayer,f as FillStyleLayer,T as IconLayout,_ as LineStyleLayer,P as StyleLayer,L as SymbolStyleLayer,m as TextLayout};