/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import {LitElement, html, css, PropertyValues} from 'lit';
import {customElement, property, query} from 'lit/decorators.js';
import '@arcgis/map-components/dist/components/arcgis-map';
import '@arcgis/map-components/dist/components/arcgis-legend';
import type {ArcgisMap} from '@arcgis/map-components/dist/components/arcgis-map';
@customElement('arcgis-js-api-calcite-lit-example')
export class ArcGISJSAPICalciteLitExample extends LitElement {
static override styles = css`
:host {
display: flex;
flex-direction: column;
gap: 10px;
height: 100%;
position: relative;
border: solid 1px gray;
padding: 16px;
}
arcgis-map {
display: block;
height: 100%;
}
`;
/**
* The name to say "Hello" to.
*/
@property()
locationLabel = 'Here we are:';
@property({type: Array})
center = [0.0, 0.0];
@property({type: Number})
zoom = 2;
@query('#centerInputBox')
centerInputBox!: HTMLInputElement;
handleArcGISViewChange(evt: Event) {
const target = evt.target as ArcgisMap;
if (target?.center && target.stationary === true) {
this.center = [target.center.longitude, target.center.latitude];
}
}
isValidFloat = (v: number) => {
if (typeof v === 'number' && !isNaN(v) && isFinite(v)) {
return true;
}
return false;
};
getLngLatFromString(str: string): [number, number] | undefined {
if (str && str.includes(',')) {
const [lng, lat] = str.split(',').map((v) => parseFloat(v));
if (this.isValidFloat(lng) && this.isValidFloat(lat)) {
return [lng, lat];
}
return undefined;
}
return undefined;
}
protected override willUpdate(_changedProperties: PropertyValues): void {
if (_changedProperties.has('center')) {
this.dispatchEvent(
new CustomEvent('center-changed', {
detail: _changedProperties.get('center'),
})
);
}
}
override render() {
return html`