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

fix: crash when printing on iOS #1666

Merged
merged 2 commits into from
Feb 3, 2023
Merged
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
16 changes: 14 additions & 2 deletions src/controls/print/print-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ const PrintComponent = function PrintComponent(options = {}) {
const originalGrids = new Map();
const deviceOnIos = isOnIos();

// eslint-disable-next-line no-underscore-dangle
const olPixelRatio = map.pixelRatio_;

if (!Array.isArray(scales) || scales.length === 0) {
scales = originalResolutions.map(currRes => maputils.resolutionToFormattedScale(currRes, viewer.getProjection()));
}
Expand Down Expand Up @@ -337,7 +340,6 @@ const PrintComponent = function PrintComponent(options = {}) {
name: 'printComponent',
onInit() {
this.on('render', this.onRender);

this.addComponent(printSettings);
this.addComponent(printInteractionToggle);
this.addComponent(printToolbar);
Expand Down Expand Up @@ -455,6 +457,11 @@ const PrintComponent = function PrintComponent(options = {}) {
printMapComponent.dispatch('change:togglePrintLegend', { showPrintLegend });
},
close() {
if (deviceOnIos) {
// Reset pixelRatio
// eslint-disable-next-line no-underscore-dangle
map.pixelRatio_ = olPixelRatio;
}
// GH-1537: remove layers temporarily added for print and unhide layers hidden for print
viewer.getLayersByProperty('added-for-print', true).forEach((l) => viewer.removeLayer(l));
viewer.getLayersByProperty('hidden-for-print', true).forEach((l) => {
Expand Down Expand Up @@ -625,9 +632,14 @@ const PrintComponent = function PrintComponent(options = {}) {
if (draganddropControl) draganddropControl.addInteraction();
},
render() {
if (deviceOnIos) {
// If user is on iOS we have to make sure the canvas ain't too heavy and make the browser crash
// eslint-disable-next-line no-underscore-dangle
map.pixelRatio_ = 1;
}
targetElement = document.getElementById(target);
const htmlString = `
<div id="${this.getId()}" class="absolute flex no-wrap fade-in no-margin width-full height-full z-index-ontop-low bg-grey-lightest overflow-auto">
<div id="${this.getId()}" class="absolute flex no-wrap fade-in no-margin width-full height-full z-index-ontop-low bg-grey-lightest overflow-auto" style="touch-action:none">
<div
id="${pageContainerId}"
class="flex column no-shrink margin-top-large margin-x-auto box-shadow bg-white border-box"
Expand Down