@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.34 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{_ as o}from"../../../chunks/tslib.es6.js";import e from"../../../core/Accessor.js";import t from"../../../core/Collection.js";import{watch as r,syncAndInitial as s}from"../../../core/reactiveUtils.js";import{property as i}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as n}from"../../../core/accessorSupport/decorators/subclass.js";import{getConfig as d}from"./constants.js";import c from"../../support/AnchorElementViewModel.js";let a=class extends e{constructor(o){super(o),this._hoveredPoints=new t}initialize(){this.addHandles(r((()=>this._hoveredPoints.toArray().map((({anchor:o,element:e})=>({screenLocation:o.screenLocation,element:e})))),(o=>{for(const{screenLocation:e,element:t}of o)e&&(t.style.transform=`translate(${e.x}px, ${e.y}px)`)}),s))}destroy(){this._hoveredPoints.drain((o=>this._destroyHoveredPoint(o)))}update(o){const e=this.view,t=this._hoveredPoints,r=o.length;for(;this._hoveredPoints.length>r;)this._destroyHoveredPoint(this._hoveredPoints.pop());for(;this._hoveredPoints.length<r;){const o=this._makeHoveredPoint();t.push(o),e.surface?.appendChild(o.element)}for(let s=0;s<r;++s){const e=t.at(r-1-s),i=o[s];this._updateHoveredPoint(e,i)}}_makeHoveredPoint(){const{size:o,borderStyle:e,borderColor:t,borderWidth:r,boxShadow:s}=d().hoveredPointsStyle,i=this.view,n=new c({view:i,screenLocationEnabled:!0}),a=document.createElement("div"),p=a.style;return p.position="absolute",p.top="0",p.left="0",p.contain="strict",p.boxSizing="border-box",p.width=`${o}px`,p.height=`${o}px`,p.marginTop=`-${o/2}px`,p.marginLeft=`-${o/2}px`,p.border=`${e} ${r}px ${t}`,p.borderRadius=`${o}px`,p.boxShadow=s,{anchor:n,element:a}}_updateHoveredPoint({anchor:o,element:e},t){o.screenLocationEnabled=!0,o.location=t.hoveredPoint;const r=e.style;r.display="block",r.background=t.color.toCss()}_destroyHoveredPoint({anchor:o,element:e}){o.destroy(),this.view.surface?.removeChild(e)}};o([i()],a.prototype,"view",void 0),o([i()],a.prototype,"_hoveredPoints",void 0),a=o([n("esri.widgets.ElevationProfile.support.HoveredPoints")],a);export{a as HoveredPoints};