From 4508a88c2c5745a9083d479e829c9f5fa392ec5f Mon Sep 17 00:00:00 2001 From: Yannick Schaus Date: Mon, 7 Dec 2020 14:44:58 +0100 Subject: [PATCH] Add options to oh-map-page & fix initial positioning (#599) Fixes #588. Allows to select a tile provider from http://leaflet-extras.github.io/leaflet-providers/preview/ Close #589. Signed-off-by: Yannick Schaus --- bundles/org.openhab.ui/web/package-lock.json | 5 ++ bundles/org.openhab.ui/web/package.json | 1 + .../assets/definitions/widgets/map/index.js | 20 +++++- .../web/src/components/widgets/map/index.js | 1 + .../components/widgets/map/oh-map-page.vue | 63 ++++++++++++++---- .../src/pages/settings/pages/map/map-edit.vue | 66 ++++++++++++++++++- 6 files changed, 141 insertions(+), 15 deletions(-) diff --git a/bundles/org.openhab.ui/web/package-lock.json b/bundles/org.openhab.ui/web/package-lock.json index 65740c578..6247b6763 100644 --- a/bundles/org.openhab.ui/web/package-lock.json +++ b/bundles/org.openhab.ui/web/package-lock.json @@ -10952,6 +10952,11 @@ "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.7.1.tgz", "integrity": "sha512-/xwPEBidtg69Q3HlqPdU3DnrXQOvQU/CCHA1tcDQVzOwm91YMYaILjNp7L4Eaw5Z4sOYdbBz6koWyibppd8Zqw==" }, + "leaflet-providers": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/leaflet-providers/-/leaflet-providers-1.11.0.tgz", + "integrity": "sha512-eu/28vrWZqxv9+fXze/4ZwbjHgaWjyeLS5fDtk95W/myDBRAyaAca/5an6WFSheYyhohuLy94vpBLuGHFXiJog==" + }, "left-pad": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", diff --git a/bundles/org.openhab.ui/web/package.json b/bundles/org.openhab.ui/web/package.json index 58a25ac79..fd44f6201 100644 --- a/bundles/org.openhab.ui/web/package.json +++ b/bundles/org.openhab.ui/web/package.json @@ -67,6 +67,7 @@ "framework7-vue": "^5.7.12", "later-again": "^0.1.1", "leaflet": "^1.7.1", + "leaflet-providers": "^1.11.0", "moo": "^0.5.1", "nearley": "^2.19.6", "pkce-challenge": "^2.1.0", diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/widgets/map/index.js b/bundles/org.openhab.ui/web/src/assets/definitions/widgets/map/index.js index f1b673cbb..2f241e1d7 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/widgets/map/index.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/widgets/map/index.js @@ -1,12 +1,30 @@ // definitions for the map page & markers -import { WidgetDefinition, pt, pi, pg, pd } from '../helpers' +import { WidgetDefinition, pt, pb, pi, pg, pd } from '../helpers' import { actionGroup, actionParams } from '../actions' const LabelParam = () => pt('label', 'Label', 'The label on the marker') const ItemParam = () => pi('item', 'Item', 'The Location item this marker will be centered on') const LocationParam = () => pt('location', 'Fixed location', 'The fixed position of the marker if no item is configured or its coordinates are invalid').c('location') +export const OhMapPageDefinition = () => new WidgetDefinition('oh-map-page', 'Map page', 'Displays markers on a map') + .params([ + pt('initialCenter', 'Initial Center', 'The center to use when no markers are present or have valid positions').c('location'), + pt('initialZoom', 'Initial Zoom Level', 'The zoom level to use when no markers are present or have valid positions'), + pb('noZoomOrDrag', 'Disable Zooming & Dragging', 'Disable the ability to zoom and drag'), + pb('noZoomAnimation', 'No Zoom Animation', 'Change zoom levels without animation, can also avoid graphic glitches with persistent tooltips'), + pb('noMarkerZoomAnimation', 'Hide Markers during Zoom Animation').a(), + pt('tileLayerProvider', 'Provider for the background tiles', 'The provider of tiles to use for the background of the map. ' + + 'Use one from Leaflet Providers, ' + + 'Some providers will not work until you set options, like access tokens, in the tileLayerProviderOptions parameter (in Code view). ' + + 'See here for more info. ' + + 'The default is CartoDB, the variant depending on the dark mode setting.'), + pt('overlayTileLayerProvider', 'Provider for the overlay tiles', 'The provider of tiles to use for the overlay layer above the background of the map. ' + + 'Use one from Leaflet Providers, ' + + 'Some providers will not work until you set options, like access tokens, in the overlayTileLayerProviderOptions parameter (in Code view). ' + + 'See here for more info. ') + ]) + export const OhMapMarkerDefinition = () => new WidgetDefinition('oh-map-marker', 'Map Marker', 'An icon on a map', 'map_pin') .paramGroup(pg('marker', 'Marker', 'General marker settings'), [ LabelParam(), diff --git a/bundles/org.openhab.ui/web/src/components/widgets/map/index.js b/bundles/org.openhab.ui/web/src/components/widgets/map/index.js index f2b364844..85ba18793 100644 --- a/bundles/org.openhab.ui/web/src/components/widgets/map/index.js +++ b/bundles/org.openhab.ui/web/src/components/widgets/map/index.js @@ -1,2 +1,3 @@ +export { default as OhMapPage } from './oh-map-page.vue' export { default as OhMapMarker } from './oh-map-marker.vue' export { default as OhMapCircleMarker } from './oh-map-circle-marker.vue' diff --git a/bundles/org.openhab.ui/web/src/components/widgets/map/oh-map-page.vue b/bundles/org.openhab.ui/web/src/components/widgets/map/oh-map-page.vue index f90460e5a..723cf2af5 100644 --- a/bundles/org.openhab.ui/web/src/components/widgets/map/oh-map-page.vue +++ b/bundles/org.openhab.ui/web/src/components/widgets/map/oh-map-page.vue @@ -5,14 +5,12 @@ :zoom="zoom" :center="center" :options="mapOptions" + :zoom-animation="!config.noZoomAnimation" + :marker-zoom-animation="!config.noMarkerZoomAnimation" class="oh-map-page-lmap" :class="{ 'with-tabbar': context.tab }" @update:center="centerUpdate" @update:zoom="zoomUpdate"> - @@ -32,13 +30,17 @@