Skip to content

Commit 930d1ce

Browse files
authored
Merge pull request #38 from conterra/dev_fixGraphicLayerOrder
Refactor PrintingPreviewDrawer to ensure the graphislayer is always on top
2 parents 1d4ade9 + 2930eeb commit 930d1ce

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

src/main/js/bundles/dn_printingenhanced/PrintingPreviewDrawer.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,25 @@ const _differenceGraphic = Symbol("_differenceGraphic");
2929
const _graphicsLayer = Symbol("_graphicsLayer");
3030
const _sketchViewModel = Symbol("_sketchViewModel");
3131

32+
let _graphicsLayerWatcher;
3233
export default class PrintingPreviewDrawer {
3334

3435
activate() {
36+
const properties = this._printingEnhancedProperties;
3537
const mapWidgetModel = this._mapWidgetModel;
38+
const graphicsLayer = this[_graphicsLayer] = new GraphicsLayer({
39+
id: properties.graphicsLayerId,
40+
title: properties.graphicsLayerTitle,
41+
listMode: "hide",
42+
internal: true
43+
});
3644
if (mapWidgetModel.map) {
37-
this._addGraphicsLayerToMap(mapWidgetModel.map);
45+
this._createGraphicsLayerWatcher(mapWidgetModel.map, graphicsLayer);
46+
this._addGraphicsLayerToMap(mapWidgetModel.map, graphicsLayer);
3847
} else {
3948
mapWidgetModel.watch("map", ({ value: map }) => {
40-
this._addGraphicsLayerToMap(map);
49+
this._createGraphicsLayerWatcher(map, graphicsLayer);
50+
this._addGraphicsLayerToMap(map, graphicsLayer);
4151
});
4252
}
4353
this[_geometry] = null;
@@ -47,6 +57,7 @@ export default class PrintingPreviewDrawer {
4757
const mapWidgetModel = this._mapWidgetModel;
4858
const map = mapWidgetModel.map;
4959
this._removeGraphicsLayerFromMap(map);
60+
this._graphicsLayerWatcher.remove();
5061
}
5162

5263
async drawTemplateDimensions(printInfos, templateOptions, defaultPageUnit) {
@@ -173,16 +184,12 @@ export default class PrintingPreviewDrawer {
173184
return await geometryEngine.difference(mapWidgetModel.extent, geometry);
174185
}
175186

176-
_addGraphicsLayerToMap(map) {
187+
_addGraphicsLayerToMap(map, graphicsLayer) {
177188
const properties = this._printingEnhancedProperties;
178189
const mapWidgetModel = this._mapWidgetModel;
179-
const graphicsLayer = this[_graphicsLayer] = new GraphicsLayer({
180-
id: properties.graphicsLayerId,
181-
title: properties.graphicsLayerTitle,
182-
listMode: "hide",
183-
internal: true
184-
});
190+
185191
map.add(graphicsLayer);
192+
186193
if (!properties.enablePrintPreviewMovement) {
187194
return;
188195
}
@@ -283,4 +290,10 @@ export default class PrintingPreviewDrawer {
283290
this[_graphicsLayer].visible = value;
284291
this._completeSketching();
285292
}
293+
294+
_createGraphicsLayerWatcher(map, graphicsLayer) {
295+
this._graphicsLayerWatcher = map.layers.on("after-add", () => {
296+
map.reorder(graphicsLayer, map.layers.length - 1);
297+
});
298+
}
286299
}

0 commit comments

Comments
 (0)