mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-17 14:26:35 +00:00
Add markers-updated to ha-locations-editor (#10601)
This commit is contained in:
parent
87c2046ab5
commit
a6b98fc3c3
@ -26,6 +26,7 @@ declare global {
|
|||||||
// for fire event
|
// for fire event
|
||||||
interface HASSDomEvents {
|
interface HASSDomEvents {
|
||||||
"location-updated": { id: string; location: [number, number] };
|
"location-updated": { id: string; location: [number, number] };
|
||||||
|
"markers-updated": undefined;
|
||||||
"radius-updated": { id: string; radius: number };
|
"radius-updated": { id: string; radius: number };
|
||||||
"marker-clicked": { id: string };
|
"marker-clicked": { id: string };
|
||||||
}
|
}
|
||||||
@ -281,6 +282,7 @@ export class HaLocationsEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
this._circles = circles;
|
this._circles = circles;
|
||||||
this._locationMarkers = locationMarkers;
|
this._locationMarkers = locationMarkers;
|
||||||
|
fireEvent(this, "markers-updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
|
@ -2,13 +2,16 @@ import "@material/mwc-button/mwc-button";
|
|||||||
import "@polymer/paper-input/paper-input";
|
import "@polymer/paper-input/paper-input";
|
||||||
import type { PaperInputElement } from "@polymer/paper-input/paper-input";
|
import type { PaperInputElement } from "@polymer/paper-input/paper-input";
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import type { LocalizeFunc } from "../common/translations/localize";
|
import type { LocalizeFunc } from "../common/translations/localize";
|
||||||
import { createCurrencyListEl } from "../components/currency-datalist";
|
import { createCurrencyListEl } from "../components/currency-datalist";
|
||||||
import "../components/map/ha-locations-editor";
|
import "../components/map/ha-locations-editor";
|
||||||
import type { MarkerLocation } from "../components/map/ha-locations-editor";
|
import type {
|
||||||
|
HaLocationsEditor,
|
||||||
|
MarkerLocation,
|
||||||
|
} from "../components/map/ha-locations-editor";
|
||||||
import { createTimezoneListEl } from "../components/timezone-datalist";
|
import { createTimezoneListEl } from "../components/timezone-datalist";
|
||||||
import {
|
import {
|
||||||
ConfigUpdateValues,
|
ConfigUpdateValues,
|
||||||
@ -25,6 +28,7 @@ import type { HaRadio } from "../components/ha-radio";
|
|||||||
|
|
||||||
const amsterdam: [number, number] = [52.3731339, 4.8903147];
|
const amsterdam: [number, number] = [52.3731339, 4.8903147];
|
||||||
const mql = matchMedia("(prefers-color-scheme: dark)");
|
const mql = matchMedia("(prefers-color-scheme: dark)");
|
||||||
|
const locationMarkerId = "location";
|
||||||
|
|
||||||
@customElement("onboarding-core-config")
|
@customElement("onboarding-core-config")
|
||||||
class OnboardingCoreConfig extends LitElement {
|
class OnboardingCoreConfig extends LitElement {
|
||||||
@ -46,6 +50,8 @@ class OnboardingCoreConfig extends LitElement {
|
|||||||
|
|
||||||
@state() private _timeZone?: string;
|
@state() private _timeZone?: string;
|
||||||
|
|
||||||
|
@query("ha-locations-editor", true) private map!: HaLocationsEditor;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<p>
|
<p>
|
||||||
@ -268,7 +274,7 @@ class OnboardingCoreConfig extends LitElement {
|
|||||||
private _markerLocation = memoizeOne(
|
private _markerLocation = memoizeOne(
|
||||||
(location: [number, number]): MarkerLocation[] => [
|
(location: [number, number]): MarkerLocation[] => [
|
||||||
{
|
{
|
||||||
id: "location",
|
id: locationMarkerId,
|
||||||
latitude: location[0],
|
latitude: location[0],
|
||||||
longitude: location[1],
|
longitude: location[1],
|
||||||
location_editable: true,
|
location_editable: true,
|
||||||
@ -304,6 +310,15 @@ class OnboardingCoreConfig extends LitElement {
|
|||||||
const values = await detectCoreConfig(this.hass);
|
const values = await detectCoreConfig(this.hass);
|
||||||
|
|
||||||
if (values.latitude && values.longitude) {
|
if (values.latitude && values.longitude) {
|
||||||
|
this.map.addEventListener(
|
||||||
|
"markers-updated",
|
||||||
|
() => {
|
||||||
|
this.map.fitMarker(locationMarkerId);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
once: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
this._location = [Number(values.latitude), Number(values.longitude)];
|
this._location = [Number(values.latitude), Number(values.longitude)];
|
||||||
}
|
}
|
||||||
if (values.elevation) {
|
if (values.elevation) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user