aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2021-01-31 19:06:53 +0100
committerhellekin <hellekin@cepheide.org>2021-01-31 20:18:53 +0100
commit288f97605d0af8b027fbfc16703ce4856176dd8c (patch)
treed9cb3fec7feac32e02c22aacdc17c8e54930aef3
parentfa9e4ea45d75e3e6c72ab51aa6e19b212e25ff60 (diff)
downloadincommon-map-288f97605d0af8b027fbfc16703ce4856176dd8c.tar.gz
[FEATURE] Add print button
Using `leaflet-easyprint`, we can add a button to print a current view of the map. This commit adds the functionality, without customization. Source: https://github.com/rowanwins/leaflet-easyPrint
-rw-r--r--app/javascript/controllers/map_controller.js10
-rw-r--r--package.json1
-rw-r--r--yarn.lock18
3 files changed, 29 insertions, 0 deletions
diff --git a/app/javascript/controllers/map_controller.js b/app/javascript/controllers/map_controller.js
index 005599e..57bafa5 100644
--- a/app/javascript/controllers/map_controller.js
+++ b/app/javascript/controllers/map_controller.js
@@ -18,6 +18,7 @@ import "leaflet-providers"
import "leaflet.markercluster/dist/leaflet.markercluster.js"
import 'leaflet-extra-markers'
+import 'leaflet-easyprint'
export default class extends Controller {
static targets = [ "container" ]
@@ -65,6 +66,15 @@ export default class extends Controller {
L.DomEvent.on(window, 'hashchange', this.doSomethingCool);
+ /* Show a button to print the map */
+ L.easyPrint({
+ title: 'Print this map',
+ position: 'bottomright',
+ filename: `incommon-map-detail`,
+ exportOnly: true,
+ sizeModes: ['A4Portrait', 'A4Landscape']
+ }).addTo(this.map);
+
// Allow calling the mapController from elsewhere.
this.element[this.identifier] = this
}
diff --git a/package.json b/package.json
index cdf02a1..48fd106 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
"fork-awesome": "^1.1.7",
"leaflet": "^1.7.1",
"leaflet-defaulticon-compatibility": "^0.1.1",
+ "leaflet-easyprint": "^2.1.9",
"leaflet-extra-markers": "^1.2.1",
"leaflet-providers": "^1.11.0",
"leaflet.markercluster": "^1.4.1",
diff --git a/yarn.lock b/yarn.lock
index fdbce3e..023c201 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2674,6 +2674,11 @@ dom-serializer@0:
domelementtype "^2.0.1"
entities "^2.0.0"
+dom-to-image@^2.5.2:
+ version "2.6.0"
+ resolved "https://registry.yarnpkg.com/dom-to-image/-/dom-to-image-2.6.0.tgz#8a503608088c87b1c22f9034ae032e1898955867"
+ integrity sha1-ilA2CAiMh7HCL5A0rgMuGJiVWGc=
+
domain-browser@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.2.0.tgz#3d31f50191a6749dd1375a7f522e823d42e54eda"
@@ -3107,6 +3112,11 @@ file-loader@^4.2.0:
loader-utils "^1.2.3"
schema-utils "^2.5.0"
+file-saver@^1.3.3:
+ version "1.3.8"
+ resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-1.3.8.tgz#e68a30c7cb044e2fb362b428469feb291c2e09d8"
+ integrity sha512-spKHSBQIxxS81N/O21WmuXA2F6wppUCsutpzenOeZzOCCJ5gEfcbqJP983IrpLXzYmXnMUa6J03SubcNPdKrlg==
+
file-uri-to-path@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
@@ -4294,6 +4304,14 @@ leaflet-defaulticon-compatibility@^0.1.1:
resolved "https://registry.yarnpkg.com/leaflet-defaulticon-compatibility/-/leaflet-defaulticon-compatibility-0.1.1.tgz#ab72257b3da66fb48dab69a10c3824012a15a20a"
integrity sha512-vDBFdlUAwjSEGep9ih8kfJilf6yN8V9zTbF5NC/1ZwLeGko3RUQepspPnGCRMFV51dY3Lb3hziboicrFz+rxQA==
+leaflet-easyprint@^2.1.9:
+ version "2.1.9"
+ resolved "https://registry.yarnpkg.com/leaflet-easyprint/-/leaflet-easyprint-2.1.9.tgz#ed395c7e1e377a5cdd944f7cc07216feae9db833"
+ integrity sha1-7Tlcfh43elzdlE98wHIW/q6duDM=
+ dependencies:
+ dom-to-image "^2.5.2"
+ file-saver "^1.3.3"
+
leaflet-extra-markers@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/leaflet-extra-markers/-/leaflet-extra-markers-1.2.1.tgz#dcea9e0ab3850c4724afa6eda8dda8fa743739fa"