Skip to content

Commit

Permalink
feature: Separate printRenderMode for better labeling in printed maps (
Browse files Browse the repository at this point in the history
…origo-map#1542)

* Separate printRenderMode for better labeling in printed maps

* fix: remove unrelated changes

* fix: undo changed functions and fix event names
  • Loading branch information
sweco-sedalh authored Jan 25, 2023
1 parent de584ee commit 3b2eb6b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
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 @@ -395,13 +395,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 @@ -644,6 +654,7 @@ const Viewer = function Viewer(targetOption, options = {}) {
getUrlParams,
getViewerOptions,
removeGroup,
removeLayer,
removeOverlays,
setStyle,
zoomToExtent,
Expand Down

0 comments on commit 3b2eb6b

Please sign in to comment.