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

印刷時にアトリビューションが表示されるように CSS の修正などをした #386

Merged
merged 2 commits into from
Oct 12, 2023
Merged
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
20 changes: 20 additions & 0 deletions src/lib/CustomAttributionControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class CustomAttributionControl implements IControl {
private _attribHTML;
private styleId;
private styleOwner;
private printQuery;
private onMediaPrintChange;

constructor(options = {}) {
this.options = options;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@
display: block!important;
}
/* End: CSS for Attribution */

@media print {
.maplibregl-control-container button {
display: none;
}
}