From 7d0badd134c7f4481ab2cf198f6c5e2aeadca75c Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Sun, 16 Jan 2022 15:35:27 +0000 Subject: [PATCH] Add bounds command capability --- CHANGELOG.md | 1 + README.md | 2 ++ worldmap/worldmap.js | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1c9553..92a6521 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Change Log for Node-RED Worldmap + - v2.25.0 - Add bounds command to set overall map bounds. - v2.24.3 - Fix geojson incorrect fill. - v2.24.2 - Changes to drawing colours to be more visible. - v2.24.1 - Fix ellipse accuracy. diff --git a/README.md b/README.md index c18178c..215f574 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ map web page for plotting "things" on. ### Updates +- v2.25.0 - Add bounds command to set overall map bounds. - v2.24.3 - Fix geojson incorrect fill. - v2.24.2 - Changes to drawing colours to be more visible. - v2.24.1 - Fix ellipse accuracy @@ -388,6 +389,7 @@ Optional properties include - **lat** - move map to specified latitude. - **lon** - move map to specified longitude. - **zoom** - move map to specified zoom level (1 - world, 13 to 20 max zoom depending on map). + - **bounds** - if set to an array `[ [ lat(S), lon(W) ], [lat(N), lon(E)] ]` - sets the overall map bounds. - **layer** - set map to specified base layer name - `{"command":{"layer":"Esri"}}` - **search** - search markers on map for name containing `string`. If not found in existing markers, will then try geocoding looking using Nominatim. An empty string `""` clears the search results. - `{"command":{"search":"Winchester"}}` - **showlayer** - show the named overlay(s) - `{"command":{"showlayer":"foo"}}` or `{"command":{"showlayer":["foo","bar"]}}` diff --git a/worldmap/worldmap.js b/worldmap/worldmap.js index 5c10548..d01267f 100644 --- a/worldmap/worldmap.js +++ b/worldmap/worldmap.js @@ -2622,6 +2622,11 @@ function doCommand(cmd) { map.touchZoom.enable(); } } + if (cmd.hasOwnProperty("bounds")) { // Move/Zoom map to new bounds + if (cmd.bounds.length === 2 && cmd.bounds[0].length === 2 && cmd.bounds[1].length === 2) { + map.fitBounds(cmd.bounds); + } + } } // handle any incoming GEOJSON directly - may style badly