UNPKG

@arcgis/map-components

Version:
378 lines (377 loc) • 20.9 kB
import { c as w } from "../../chunks/runtime.js"; import { makeAccessorController as c, reEmitEvent as t, accessorSupport as v } from "@arcgis/components-controllers/accessor"; import { watch as a } from "@arcgis/core/core/reactiveUtils.js"; import d from "@arcgis/core/views/SceneView.js"; import m from "@arcgis/core/WebScene.js"; import { LitElement as l, createEvent as r, noShadowRoot as p } from "@arcgis/lumina"; import { c as h, p as n, e as o, i as g } from "../../chunks/component-utils.js"; import { css as y } from "@lit/reactive-element/css-tag.js"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. v4.32.13 */ const u = y`@layer{arcgis-scene{display:block;height:100%;.esri-view{height:100%;width:100%}}}`, f = c(m, {}), _ = c(d, {}); class b extends l { constructor() { super(...arguments), this._camera = void 0, this._center = void 0, this._extent = void 0, this._itemId = void 0, this._scale = void 0, this._viewpoint = void 0, this._zoom = void 0, this._cameraFov = void 0, this._cameraHeading = void 0, this._cameraPosition = void 0, this._cameraTilt = void 0, this._map = f(this, { editConstructorProperties: this._editMapProperties }), this.view = _(this, { editConstructorProperties: this._editViewProperties }), this.allLayerViews = this.view.allLayerViews, this.alphaCompositingEnabled = this.view.alphaCompositingEnabled, this.analyses = this.view.analyses, this.autoDestroyDisabled = !1, this.basemap = this._map.basemap, this.basemapView = this.view.basemapView, this.clippingArea = this.view.clippingArea, this.constraints = this.view.constraints, this.displayFilterDisabled = this.view.displayFilterEnabled, this.environment = this.view.environment, this.fatalError = this.view.fatalError, this.floors = this.view.floors, this.graphics = this.view.graphics, this.ground = this._map.ground, this.groundView = this.view.groundView, this.highlights = this.view.highlights, this.highlightOptions = this.view.highlightOptions, this.layerViews = this.view.layerViews, this.magnifier = this.view.magnifier, this.map = this.view.map, this.navigation = this.view.navigation, this.padding = this.view.padding, this.popup = this.view.popup, this.popupDisabled = this.view.popupEnabled, this.qualityProfile = this.view.qualityProfile, this.ready = this.view.ready, this.spatialReference = this.view.spatialReference, this.suspended = this.view.suspended, this.theme = this.view.theme, this.timeExtent = this.view.timeExtent, this.updating = this.view.updating, this.viewingMode = this.view.viewingMode, this.arcgisViewChange = r(), this.arcgisViewClick = t(() => this.view, "click"), this.arcgisViewDoubleClick = t(() => this.view, "double-click"), this.arcgisViewDrag = t(() => this.view, "drag"), this.arcgisViewHold = t(() => this.view, "hold"), this.arcgisViewImmediateClick = t(() => this.view, "immediate-click"), this.arcgisViewImmediateDoubleClick = t(() => this.view, "immediate-double-click"), this.arcgisViewKeyDown = t(() => this.view, "key-down"), this.arcgisViewKeyUp = t(() => this.view, "key-up"), this.arcgisViewLayerviewCreate = t(() => this.view, "layerview-create"), this.arcgisViewLayerviewCreateError = t(() => this.view, "layerview-create-error"), this.arcgisViewLayerviewDestroy = t(() => this.view, "layerview-destroy"), this.arcgisViewMouseWheel = t(() => this.view, "mouse-wheel"), this.arcgisViewPointerDown = t(() => this.view, "pointer-down"), this.arcgisViewPointerEnter = t(() => this.view, "pointer-enter"), this.arcgisViewPointerLeave = t(() => this.view, "pointer-leave"), this.arcgisViewPointerMove = t(() => this.view, "pointer-move"), this.arcgisViewPointerUp = t(() => this.view, "pointer-up"), this.arcgisViewReadyChange = r(); } static { this.properties = { _map: 16, view: 32, allLayerViews: 0, alphaCompositingEnabled: 5, analyses: 0, autoDestroyDisabled: 5, basemap: 1, basemapView: 0, camera: 0, cameraFov: 9, cameraHeading: 9, cameraPosition: 1, cameraTilt: 9, center: 1, clippingArea: 0, constraints: 0, displayFilterDisabled: 5, environment: 0, extent: 0, fatalError: 0, floors: 0, gamepad: 32, graphics: 0, ground: 1, groundView: 0, highlights: 0, highlightOptions: 0, interacting: 32, itemId: 3, layerViews: 0, magnifier: 0, map: 0, navigating: 32, navigation: 0, padding: 0, performanceInfo: 32, popup: 0, popupDisabled: 5, qualityProfile: 1, ready: 4, resolution: 32, scale: 9, spatialReference: 0, stationary: 32, suspended: 7, theme: 0, timeExtent: 0, updating: 7, viewingMode: 1, viewpoint: 0, zoom: 9 }; } static { this.shadowRootOptions = p; } static { this.styles = u; } /** The [camera](https://developers.arcgis.com/javascript/latest/api-reference/esri-Camera.html) allows to set the observation point from which the visible portion (or perspective) * of the view is determined. When set in the constructor, this property overrides the * [center](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#center), * [extent](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#extent), * [scale](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#scale), * [viewpoint](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#viewpoint), and * [zoom](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#zoom) properties. * * Setting the camera immediately changes the current view. For animating the view, see this component's * [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. */ get camera() { return this.view.camera ?? this._camera; } set camera(i) { this._camera = i, this.ready && !h(this.camera, i) && (this.view.camera = i); } /** * The diagonal field of view (fov) angle for the camera. The range of angles must be between 1 and 170 degrees. * * Setting the camera fov immediately changes the current view. For animating the view, see this component's * [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-Camera.html#fov) */ get cameraFov() { return this.view.camera?.fov ?? this._cameraFov; } set cameraFov(i) { this.ready && i != null && this._mutateCamera((e) => { e.fov = i; }), this._cameraFov = i; } /** * The compass heading of the camera in degrees. * * Setting the camera heading immediately changes the current view. For animating the view, see this component's * [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-Camera.html#heading) */ get cameraHeading() { return this.view.camera?.heading ?? this._cameraHeading; } set cameraHeading(i) { this.ready && i != null && this._mutateCamera((e) => { e.heading = i; }), this._cameraHeading = i; } /** * The position of the camera defined by a map point. It can be a string with the format `"<longitude>, <latitude>, <elevation>"` * or a [Point](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html) instance. * * Setting the camera position immediately changes the current view. For animating the view, see this component's * [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-Camera.html#position) * */ get cameraPosition() { return this.view.camera?.position ?? this._cameraPosition; } set cameraPosition(i) { if (this.ready) { const e = n(this.view.camera?.position, i); e && this._mutateCamera((s) => { s.position = e; }); } else this._cameraPosition = i; } /** * The tilt of the camera in degrees with respect to the surface as projected down from the camera position. * * Setting the camera tilt immediately changes the current view. For animating the view, see this component's * [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-Camera.html#tilt) */ get cameraTilt() { return this.view.camera?.tilt ?? this._cameraTilt; } set cameraTilt(i) { this.ready && i != null && this._mutateCamera((e) => { e.tilt = i; }), this._cameraTilt = i; } /** * Represents the center point of the view. It can be a string with the format `"<longitude>, <latitude>"` * or a [Point](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html) instance. * * Setting the center immediately changes the current view. For animating the view, see this component's * [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#center) */ get center() { return this.view.center ?? this._center; } set center(i) { const e = o(i, this.ready ? this.view : void 0); e && (this.ready && (this.view.center = e), this._center = e); } /** * The extent represents the visible portion of a map within the view as an instance of * [Extent](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Extent.html). * * Setting the extent immediately changes the view without animation. To animate * the view, see this component's [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * When the view is rotated, the extent does not update to include the newly visible portions of the map. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#extent) */ get extent() { return this.view.extent ?? this._extent; } set extent(i) { this.ready && i && !this.extent?.equals(i) && (this.view.extent = i), this._extent = i; } /** Gamepad input specific configuration settings. */ get gamepad() { return this.ready ? this.view.input.gamepad : void 0; } /** Indication whether the view is being interacted with (for example when panning or by an interactive tool). */ get interacting() { return this.view.interacting; } /** * The ID of a [WebScene](https://developers.arcgis.com/javascript/latest/api-reference/esri-WebScene.html) item from either * [ArcGIS Online](https://www.arcgis.com/home/index.html) or [ArcGIS Enterprise portal](https://enterprise.arcgis.com/en/portal/latest/administer/windows/what-is-portal-for-arcgis-.htm). * * To configure the portal url you must set the [config.portalUrl](https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#portalUrl) property before the Scene component loads. * */ get itemId() { return this._map.portalItem?.id ?? this._itemId; } set itemId(i) { this._itemId = i, this.ready ? v.reCreate(this._map, this).then(() => { this.view.map = this._map; }).catch(console.error) : this.view.ready != null && (this._map.destroy(), this._map = new m(this._editMapProperties({ portalItem: { id: this._itemId } })), this.view.map = this._map); } /** Indication whether the view is being navigated (for example when panning). */ get navigating() { return this.view.navigating; } /** * This property contains performance information of the view, e.g. global memory usage and additional * details for layers about memory consumption and number of features. */ get performanceInfo() { return this.view.performanceInfo; } /** * Represents the current value of one pixel in the unit of the view's * [spatialReference](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#spatialReference). * The resolution is calculated by dividing the view's [extent width](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Extent.html#width) * by [its width](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#width). */ get resolution() { return this.view.resolution; } /** * Represents the map scale at the center of the view. * * Setting the scale immediately changes the view. For animating * the view, see this component's [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#scale) */ get scale() { return this.view.scale ?? this._scale; } set scale(i) { this.ready && (this.view.scale = i), this._scale = i; } /** Indication whether the view is animating, being navigated with or resizing. */ get stationary() { return this.view.stationary; } /** * Represents the current view as a [Viewpoint](https://developers.arcgis.com/javascript/latest/api-reference/esri-Viewpoint.html) * or point of observation on the view. * * Setting the viewpoint immediately changes the current view. For animating * the view, see this component's [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#viewpoint) */ get viewpoint() { return this.view.viewpoint ?? this._viewpoint; } set viewpoint(i) { this.ready && g(this.viewpoint, i) && (this.view.viewpoint = i), this._viewpoint = i; } /** * Represents the level of detail (LOD) at the center of the view. * * Setting the zoom immediately changes the current view. For animating the view, see this component's [goTo()](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#goTo) method. * Setting this property in conjunction with [center](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#center) * is a convenient way to set the initial extent of the view. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#zoom) */ get zoom() { return this.view.zoom ?? this._zoom; } set zoom(i) { this.ready && (this.view.zoom = i), this._zoom = i; } // #endregion // #region Public Methods /** Adds a layer to the [map's](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#map) `layers` collection. */ async addLayer(i, e) { this.map?.add(i, e); } /** Adds a layer or array of layers to the [map's](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#map) `layers` collection. */ async addLayers(i, e) { this.map?.addMany(i, e); } /** Adds a table to the [map's](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#map) `tables` collection. */ async addTable(i) { this.map?.tables.add(i); } /** Adds a table or array of tables to the [map's](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#map) `tables` collection. */ async addTables(i, e) { this.map?.tables.addMany(i, e); } /** Closes the [popup](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#popup). */ async closePopup() { this.view?.closePopup(); } /** Destroys the Scene component, and any associated resources, including its * [map](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#map), * [popup](https://developers.arcgis.com/javascript/latest/references/map-components/arcgis-scene/#popup), * and removes components or other UI DOM elements added to it. */ async destroy() { await this.manager.destroy(); } /** Sets the view to a given target. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#goTo) */ async goTo(i, e) { return await this.view?.goTo(i, e); } /** Returns [hit test results](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#HitTestResult) * from each layer that intersects the specified screen coordinates. * * ``` * arcgisScene.addEventListener("arcgisViewClick", (event) => { * arcgisScene.hitTest(event.detail).then((response) => { * const result = response.results[0]; * if (result?.type === "graphic") { * const { longitude, latitude } = result.mapPoint; * console.log("Hit graphic at (" + longitude + ", " + latitude + ")", result.graphic); * } else { * console.log("Did not hit any graphic"); * } * }); * }); * ``` * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#hitTest) */ async hitTest(i, e) { return await this.view?.hitTest(i, e); } /** * Opens the popup based on input options. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#openPopup) */ async openPopup(i) { await this.view?.openPopup(i); } /** Creates a screenshot of the current view. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#takeScreenshot) */ async takeScreenshot(i) { return await this.view?.takeScreenshot(i); } /** * Converts the given screen point to a [map point](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html). */ toMap(i, e) { return this.view.toMap(i, e); } /** * Converts the given [map point](https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Point.html) to a screen point. */ toScreen(i) { return this.view.toScreen(i); } /** Call this method to clear any fatal errors resulting from a lost WebGL context. */ async tryFatalErrorRecovery() { this.view?.tryFatalErrorRecovery(); } /** * Gets the analysis view created for the given analysis object. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#whenAnalysisView) */ async whenAnalysisView(i) { return await this.view?.whenAnalysisView(i); } /** Gets the layer view created on the view for the given layer. * * [Read more](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#whenLayerView) */ async whenLayerView(i) { return await this.view?.whenLayerView(i); } // #endregion // #region Lifecycle load() { this.el.childElem = document.createElement("div"), this.el.append(this.el.childElem), this.view.container ??= this.el.childElem; } loaded() { this.manager.onLifecycle(() => [ a(() => this.view.stationary, () => { this.arcgisViewChange.emit(); }, { initial: !0 }), a(() => this.view.ready, () => this.arcgisViewReadyChange.emit(), { initial: this.view.ready }) ]); } // #endregion // #region Private Methods _editMapProperties(i) { this.map && (this._map = this.map), this.itemId && (i.portalItem = { id: this.itemId }); const { basemap: e, ...s } = i; return e || (i = s), i; } async _editViewProperties(i) { await this.manager.use(this._map), this.view.ui || (i.ui = { components: ["attribution"] }), i.map ??= this._map; const e = o(this.center, void 0); e && (i.center = e), this.viewpoint && (i.viewpoint = this.viewpoint), this.scale !== void 0 && (i.scale = this.scale), this.extent && (i.extent = this.extent), this.camera && (i.camera = this.camera); const s = n(void 0, this.cameraPosition); return s && (i.camera ??= {}, i.camera.position = s), this.cameraHeading != null && (i.camera ??= {}, i.camera.heading = this.cameraHeading), this.cameraTilt != null && (i.camera ??= {}, i.camera.tilt = this.cameraTilt), this.cameraFov != null && (i.camera ??= {}, i.camera.fov = this.cameraFov), this.zoom !== void 0 && (i.zoom = this.zoom), i; } _mutateCamera(i) { const e = this.view.camera.clone(); i(e), h(this.view.camera, e) || (this.view.camera = e); } } w("arcgis-scene", b); export { b as ArcgisScene };