From 064950f789cb3cb801c44e0c7c9f116e7115ee63 Mon Sep 17 00:00:00 2001 From: kenara <4996484+kenara@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:21:44 +0000 Subject: [PATCH 1/7] Update lib.js Did this after encountering the follow error: Puppeteer old Headless deprecation warning: In the near future `headless: true` will default to the new Headless mode for Chrome instead of the old Headless implementation. For more information, please see https://developer.chrome.com/articles/new-headless/. Consider opting in early by passing `headless: "new"` to `puppeteer.launch()` If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose. Error opening browser {} TypeError: Cannot read properties of null (reading 'newPage') --- src/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.js b/src/lib.js index 2af571b..52ff2fb 100644 --- a/src/lib.js +++ b/src/lib.js @@ -48,7 +48,7 @@ class Browser { args: [...chrome.args, "--no-sandbox", "--disable-setuid-sandbox"], defaultViewport: chrome.defaultViewport, executablePath: await chrome.executablePath, - headless: true, + headless: new, ignoreHTTPSErrors: true, }); } From 738873cac6f01a6c260b38a75129f0b8652070f7 Mon Sep 17 00:00:00 2001 From: kenara <4996484+kenara@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:47:54 +0000 Subject: [PATCH 2/7] Update template.html If a popup parameter is set and the geojson string, parsed as an object, is a single item of type Point, render an opened popup. --- src/template.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/template.html b/src/template.html index 0d9b8e3..539de2c 100644 --- a/src/template.html +++ b/src/template.html @@ -110,6 +110,11 @@ }, }); geojsonlayer.addTo(map); + {{#if popup}} + {{#isOnePoint geojson}} + geojsonlayer.bindPopup('{{{ popup }}}').openPopup(); + {{/isOnePoint}} + {{/if}} map.fitBounds(geojsonlayer.getBounds(), {maxZoom: maxZoom}); {{/if}} From a80c8b197816b3f644c0cc36e7e2e8cbc5cc1aa6 Mon Sep 17 00:00:00 2001 From: kenara <4996484+kenara@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:49:14 +0000 Subject: [PATCH 3/7] Update template.html If a popup is rendered, don't show the close button. --- src/template.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/template.html b/src/template.html index 539de2c..1b8ecf4 100644 --- a/src/template.html +++ b/src/template.html @@ -6,6 +6,9 @@ .leaflet-fade-anim, .leaflet-zoom-anim { transition: none; } + .leaflet-popup-close-button { + display: none; + } body { height: 100%; width: 100%; From bae6e29e0ea0ca58c7d03e603cd1d98e64c715c9 Mon Sep 17 00:00:00 2001 From: kenara <4996484+kenara@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:53:10 +0000 Subject: [PATCH 4/7] Update cli.js Add -P or --popup option to render an opened popup instead of a marker when GeoJSON string contains a single point --- src/cli.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cli.js b/src/cli.js index 5333341..fcbd07b 100755 --- a/src/cli.js +++ b/src/cli.js @@ -99,6 +99,10 @@ program "throw error if there is any console.error(...) when rendering the map image", false ) + .option( + "-P, --popup ", + "HTML or text content of popup" + ) .action(function(cmd) { const opts = cmd.opts(); From 68481782040cf557fe2c5081eba1983ef1e26aaf Mon Sep 17 00:00:00 2001 From: kenara <4996484+kenara@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:55:13 +0000 Subject: [PATCH 5/7] Update lib.js Add Handlebars custom helper for use with popup option --- src/lib.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.js b/src/lib.js index 52ff2fb..5b28636 100644 --- a/src/lib.js +++ b/src/lib.js @@ -2,6 +2,24 @@ const fs = require('fs'); const http = require('http'); const https = require("https"); const Handlebars = require('handlebars'); + +Handlebars.registerHelper('isOnePoint', function(jsonString, options) { + let obj; + try { + obj = JSON.parse(jsonString); + } catch (e) { + console.error('Error parsing JSON:', e); + return options.inverse(this); // Handle parse error or incorrect format + } + + // Check if the object is indeed an object, not an array, and has the required keys + if (typeof obj === 'object' && obj !== null && !Array.isArray(obj) && obj.type === "Point" && obj.coordinates) { + return options.fn(this); // Execute the block if condition is met + } + + return options.inverse(this); // Execute the else block if conditions are not met +}); + const path = require('path'); const child_process = require("child_process"); From 428deeaf76d205d1d0e76d23da2d3bb765a32461 Mon Sep 17 00:00:00 2001 From: kenara <4996484+kenara@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:08:44 +0000 Subject: [PATCH 6/7] Update README.md Add popup option --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 85bd16b..25fad55 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ All parameters have a short and long version. The short version can be used only | k | markerIconOptions | set marker icon options ([a json options object](https://leafletjs.com/reference-1.6.0.html#icon-option)) *see note | `undefined` (leaflet's default marker) | | S | style | style to apply to each feature ([a json options object](https://leafletjs.com/reference-1.6.0.html#path-option)) *see note | `undefined` (leaflet's default) | | e | haltOnConsoleError | throw error if there is any `console.error(...)` when rendering the map image | `false` | +| P | popup | render opened popup instead of marker icon for single point map | `undefined` | + * Note on markerIconOptions: it's also accepted a markerIconOptions attribute in the geojson feature, for example `{"type":"Point","coordinates":[-105.01621,39.57422],"markerIconOptions":{"iconUrl":"https://leafletjs.com/examples/custom-icons/leaf-red.png"}}` From aaee6382038973f3454fe90a8b6bce3350c37349 Mon Sep 17 00:00:00 2001 From: kenara <4996484+kenara@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:43:42 +0000 Subject: [PATCH 7/7] Update template.html Don't show the market icon if showing popup instead. --- src/template.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/template.html b/src/template.html index 1b8ecf4..26625f6 100644 --- a/src/template.html +++ b/src/template.html @@ -20,6 +20,12 @@ height: 100%; width: 100%; } +{{#if popup}} {{#isOnePoint geojson}} +.leaflet-marker-icon, +.leaflet-marker-shadow { + display: none; + } +{{/isOnePoint}} {{/if}}