UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 4.97 kB
import{clamp as e,nextHighestPowerOfTwo as t}from"../../../../core/mathUtils.js";import{isSome as r,isNone as i}from"../../../../core/maybe.js";import{s}from"../../../../chunks/vec3.js";import{c as o}from"../../../../chunks/vec3f64.js";import{g as n,c as a}from"../../../../chunks/vec4.js";import{f as l}from"../../../../chunks/vec4f64.js";import{projectVectorToVector as u}from"../../../../geometry/projection.js";import{expandWithBuffer as c}from"../../../../geometry/support/aaBoundingBox.js";import{sv3d as h}from"../../../../geometry/support/vectorStacks.js";import{VisualElementResources as m}from"./VisualElementResources.js";import{evaluateElevationAlignmentAtPoint as p}from"../../layers/graphics/elevationAlignmentUtils.js";import{ElevationContext as _}from"../../layers/graphics/ElevationContext.js";import{createTexture as g,DEFAULT_SYMBOL_SIZE_RATIO as d}from"../../support/engineContent/sdfPrimitives.js";import{createPointGeometry as f}from"../../webgl-engine/lib/GeometryUtil.js";import{VertexAttribute as y}from"../../webgl-engine/lib/VertexAttribute.js";import{HUDMaterial as v}from"../../webgl-engine/materials/HUDMaterial.js";class S{constructor(e){this.view=null,this._geometry=null,this._size=3,this._color=l(1,0,1,1),this._pixelSnappingEnabled=!0,this._primitive="square",this._outlineSize=1,this._outlineColor=l(1,1,1,1),this._elevationInfo=null,this._resources=new m({view:e.view,createResources:e=>this._createResources(e),destroyResources:e=>this._destroyResources(e),recreateGeometry:(e,t)=>{e.geometry=this._recreateGeometry(t,e.material)}});let t=!0;for(const r in e)r in this?"attached"===r?t=e[r]??!1:this[r]=e[r]:console.error("Cannot set unknown property",r);this.attached=t}destroy(){this._resources.destroy()}get visible(){return this._resources.visible}set visible(e){this._resources.visible=e}get attached(){return this._resources.attached}set attached(e){this._resources.attached=e}get geometry(){return this._geometry}set geometry(e){this._geometry=e,this._resources.recreateGeometry()}get size(){return this._size}set size(e){if(e!==this._size){const t=this._preferredTextureSize;this._size=e,t<this._preferredTextureSize?r(this._resources)&&this._resources.recreate():this._updateSizeAttribute()}}get color(){return this._color}set color(e){n(e,this._color)||(a(this._color,e),this._updateMaterial())}get pixelSnappingEnabled(){return this._pixelSnappingEnabled}set pixelSnappingEnabled(e){this._pixelSnappingEnabled!==e&&(this._pixelSnappingEnabled=e,this._updateMaterial())}get primitive(){return this._primitive}set primitive(e){this._primitive!==e&&(this._primitive=e,r(this._resources)&&this._resources.recreate())}get outlineSize(){return this._outlineSize}set outlineSize(e){e!==this._outlineSize&&(this._outlineSize=e,this._updateMaterial())}get outlineColor(){return this._outlineColor}set outlineColor(e){n(e,this._outlineColor)||(a(this._outlineColor,e),this._updateMaterial())}get elevationInfo(){return this._elevationInfo}set elevationInfo(e){this._elevationInfo=e,this._resources&&this._resources.recreateGeometry()}_updateMaterial(){const e=this._resources.resources;i(e)||e.material.setParameters(this._materialParameters(e.texture.id))}_updateSizeAttribute(){const e=this._resources.resources,t=this._resources.object;if(i(e)||i(t))return;const r=e.geometry;if(i(r))return;const s=r.getMutableAttribute(y.SIZE).data,o=this._geometrySize;s[0]=o,s[1]=o,t.geometryVertexAttrsUpdated(t.geometries[0])}_materialParameters(e){return{color:this._color,textureIsSignedDistanceField:!0,distanceFieldBoundingBox:x,occlusionTest:!1,outlineColor:this._outlineColor,outlineSize:this._outlineSize,textureId:e,polygonOffset:!1,shaderPolygonOffset:0,drawInSecondSlot:!0,depthEnabled:!1,pixelSnappingEnabled:this.pixelSnappingEnabled}}get _geometrySize(){return this._size/b}_recreateGeometry(e,t){const i=this._createRenderGeometry(t);return r(i)&&e.addGeometry(i),i}_createResources(e){const t=g(this._primitive,this._preferredTextureSize),i=new v(this._materialParameters(t.id)),s=this._recreateGeometry(e,i);return{material:i,texture:t,geometry:s,forEach(e){e(t),e(i),r(this.geometry)&&e(this.geometry)}}}_destroyResources(e){e.geometry=null,e.material.dispose(),e.texture.dispose()}get _preferredTextureSize(){return e(t(2*this._geometrySize),16,128)}calculateMapBounds(e){if(i(this._resources.resources)||i(this._resources.resources.geometry))return!1;const t=this._resources.resources.geometry.vertexAttributes.get(y.POSITION);return u(t.data,this.view.renderCoordsHelper.spatialReference,z,this.view.spatialReference),c(e,z),!0}_createRenderGeometry(e){const t=this.geometry;if(i(t))return null;const{renderCoordsHelper:r,elevationProvider:o}=this.view,n=p(t,o,_.fromElevationInfo(this.elevationInfo),r),a=s(h.get(),t.x,t.y,n),l=h.get();u(a,t.spatialReference,l,r.spatialReference);const c=this._geometrySize;return f(e,null,l,null,[c,c],[0,0,0,1])}}const b=d,x=[b/2,b/2,1-b/2,1-b/2],z=o();export{S as PointVisualElement};