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

Separate printRenderMode for better labeling in printed maps #1542

Merged
merged 4 commits into from
Jan 25, 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
30 changes: 30 additions & 0 deletions src/controls/print/print-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,18 @@ const PrintComponent = function PrintComponent(options = {}) {
printMapComponent.dispatch('change:togglePrintLegend', { showPrintLegend });
},
close() {
// 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) => {
l.setVisible(true);
l.unset('hidden-for-print');
});

if (suppressNewDPIMethod === false) {
printResize.resetLayers();
printResize.setResolution(150);
}

// Restore scales
if (!supressResolutionsRecalculation) {
const viewerResolutions = viewer.getResolutions();
Expand Down Expand Up @@ -528,6 +536,28 @@ const PrintComponent = function PrintComponent(options = {}) {
map.setTarget(printMapComponent.getId());
this.removeViewerControls();
await printMapComponent.addPrintControls();

// GH-1537: temporarily add layers for print and hide their original versions
viewer.getLayersByProperty('printRenderMode', 'image').forEach((layer) => {
if (layer.getVisible() && !layer.get('added-for-print') && !layer.get('hidden-for-print')) {
// hide the original, tiled, layer
layer.setVisible(false);
layer.set('hidden-for-print', true);

// create a duplicate of the layer with a different renderMode
const { map: _, type, name, sourceName, ...properties } = layer.getProperties();
const newLayer = viewer.addLayer({
...properties,
source: sourceName,
renderMode: 'image',
type: type === 'AGS_TILE' ? 'AGS_MAP' : type,
name: `${name}-forPrint`,
visible: true
}, layer);
newLayer.set('added-for-print', true);
}
});

if (!supressResolutionsRecalculation) {
updateResolutions();
}
Expand Down
15 changes: 13 additions & 2 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,23 @@ const Viewer = function Viewer(targetOption, options = {}) {
}
};

const addLayer = function addLayer(layerProps) {
const addLayer = function addLayer(layerProps, insertBefore) {
const layer = Layer(layerProps, this);
addLayerStylePicker(layerProps);
map.addLayer(layer);
if (insertBefore) {
map.getLayers().insertAt(map.getLayers().getArray().indexOf(insertBefore), layer);
} else {
map.addLayer(layer);
}
this.dispatch('addlayer', {
layerName: layerProps.name
});
return layer;
};

const removeLayer = function removeLayer(layer) {
this.dispatch('removelayer', { layerName: layer.get('name') });
map.removeLayer(layer);
};

const addLayers = function addLayers(layersProps) {
Expand Down Expand Up @@ -636,6 +646,7 @@ const Viewer = function Viewer(targetOption, options = {}) {
getUrlParams,
getViewerOptions,
removeGroup,
removeLayer,
removeOverlays,
setStyle,
zoomToExtent,
Expand Down