Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add popup option #40

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}`

Expand Down
4 changes: 4 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ program
"throw error if there is any console.error(...) when rendering the map image",
false
)
.option(
"-P, --popup <string>",
"HTML or text content of popup"
)
.action(function(cmd) {
const opts = cmd.opts();

Expand Down
20 changes: 19 additions & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -48,7 +66,7 @@ class Browser {
args: [...chrome.args, "--no-sandbox", "--disable-setuid-sandbox"],
defaultViewport: chrome.defaultViewport,
executablePath: await chrome.executablePath,
headless: true,
headless: new,
ignoreHTTPSErrors: true,
});
}
Expand Down
14 changes: 14 additions & 0 deletions src/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
.leaflet-fade-anim, .leaflet-zoom-anim {
transition: none;
}
.leaflet-popup-close-button {
display: none;
}
body {
height: 100%;
width: 100%;
Expand All @@ -17,6 +20,12 @@
height: 100%;
width: 100%;
}
{{#if popup}} {{#isOnePoint geojson}}
.leaflet-marker-icon,
.leaflet-marker-shadow {
display: none;
}
{{/isOnePoint}} {{/if}}
</style>
<script>
//leafletjs//
Expand Down Expand Up @@ -110,6 +119,11 @@
},
});
geojsonlayer.addTo(map);
{{#if popup}}
{{#isOnePoint geojson}}
geojsonlayer.bindPopup('{{{ popup }}}').openPopup();
{{/isOnePoint}}
{{/if}}
map.fitBounds(geojsonlayer.getBounds(), {maxZoom: maxZoom});
{{/if}}

Expand Down