From 61ec0e89451db66969fe910bf25d0ff68bbbfebf Mon Sep 17 00:00:00 2001 From: "Kamata, Ryo" Date: Thu, 12 Oct 2023 15:05:24 +0900 Subject: [PATCH] =?UTF-8?q?=E5=8D=B0=E5=88=B7=E6=99=82=E3=81=AB=E3=82=A2?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=83=93=E3=83=A5=E3=83=BC=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=81=8C=E8=A1=A8=E7=A4=BA=E3=81=95=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=20CSS=20=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=81=AA=E3=81=A9=E3=82=92=E3=81=97=E3=81=9F=20(#386)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add @media print CSS to remove unnecessary html element close #384 * Control
when printing --- src/lib/CustomAttributionControl.ts | 20 ++++++++++++++++++++ src/style.css | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/src/lib/CustomAttributionControl.ts b/src/lib/CustomAttributionControl.ts index 0e9e5dc5..666cf4f3 100644 --- a/src/lib/CustomAttributionControl.ts +++ b/src/lib/CustomAttributionControl.ts @@ -35,6 +35,8 @@ class CustomAttributionControl implements IControl { private _attribHTML; private styleId; private styleOwner; + private printQuery; + private onMediaPrintChange; constructor(options = {}) { this.options = options; @@ -190,6 +192,12 @@ class CustomAttributionControl implements IControl { } } + @media print { + .maplibregl-ctrl-attrib-button { + display: none!important; + } + } + .maplibregl-ctrl-attrib a { color: rgba(0,0,0,.75); text-decoration: none; @@ -218,6 +226,16 @@ class CustomAttributionControl implements IControl { shadow.appendChild(style); shadow.appendChild(this._shadowContainer); + this.printQuery = window.matchMedia('print'); + this.onMediaPrintChange = (e) => { + if (e.matches) { + // force open + this._shadowContainer.setAttribute('open', ''); + this._shadowContainer.classList.remove('maplibregl-compact-show'); + } + }; + this.printQuery.addEventListener('change', this.onMediaPrintChange); + return this._container; } @@ -233,6 +251,8 @@ class CustomAttributionControl implements IControl { this._map = undefined; this._compact = undefined; this._attribHTML = undefined; + + this.printQuery.removeEventListener('change', this.onMediaPrintChange); } _setElementTitle(element, title) { diff --git a/src/style.css b/src/style.css index 307c7bae..3e288fb2 100644 --- a/src/style.css +++ b/src/style.css @@ -129,3 +129,9 @@ display: block!important; } /* End: CSS for Attribution */ + +@media print { + .maplibregl-control-container button { + display: none; + } +}