Skip to content

Commit 9a9eb3c

Browse files
authored
DrawTool support set layer zIndex (#2073)
1 parent f837590 commit 9a9eb3c

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

src/map/tool/DistanceTool.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class DistanceTool extends DrawTool {
125125
}
126126
delete this._lastMeasure;
127127
delete this._lastVertex;
128+
this._outLayers(this._measureLayers);
128129
this._measureLayers = [];
129130
return this;
130131
}
@@ -230,15 +231,21 @@ class DistanceTool extends DrawTool {
230231
const uid = UID();
231232
const layerId = 'distancetool_' + uid;
232233
const markerLayerId = 'distancetool_markers_' + uid;
234+
const zIndex = this.options.zIndex;
233235
if (!map.getLayer(layerId)) {
234-
this._measureLineLayer = new VectorLayer(layerId).addTo(map);
235-
this._measureMarkerLayer = new VectorLayer(markerLayerId).addTo(map);
236+
this._measureLineLayer = new VectorLayer(layerId, {
237+
zIndex
238+
}).addTo(map);
239+
this._measureMarkerLayer = new VectorLayer(markerLayerId, {
240+
zIndex
241+
}).addTo(map);
236242
} else {
237243
this._measureLineLayer = map.getLayer(layerId);
238244
this._measureMarkerLayer = map.getLayer(markerLayerId);
239245
}
240246
this._measureLayers.push(this._measureLineLayer);
241247
this._measureLayers.push(this._measureMarkerLayer);
248+
this._pushLayers([this._measureLineLayer, this._measureMarkerLayer]);
242249
//start marker
243250
const marker = new Marker(param['coordinate'], {
244251
'symbol': this.options['vertexSymbol']

src/map/tool/DrawTool.js

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { INTERNAL_LAYER_PREFIX } from '../../core/Constants';
2-
import { extend, isFunction, isNil } from '../../core/util';
2+
import { extend, isFunction, isNil, isNumber } from '../../core/util';
33
import { extendSymbol } from '../../core/util/style';
44
import { getExternalResources } from '../../core/util/resource';
55
import { stopPropagation } from '../../core/util/dom';
@@ -14,6 +14,7 @@ import MapTool from './MapTool';
1414
* @property {Boolean} [options.once=null] - whether disable immediately once drawn a geometry.
1515
* @property {Boolean} [options.autoPanAtEdge=false] - Whether to make edge judgement or not.
1616
* @property {Boolean} [options.blockGeometryEvents=false] - Whether Disable geometryEvents when drawing.
17+
* @property {Number} [options.zIndex=Number.MAX_VALUE] - drawlayer zIndex.The default drawn layer will be at the top
1718
* @memberOf DrawTool
1819
* @instance
1920
*/
@@ -30,7 +31,8 @@ const options = {
3031
'once': false,
3132
'autoPanAtEdge': false,
3233
'ignoreMouseleave': true,
33-
'blockGeometryEvents': false
34+
'blockGeometryEvents': false,
35+
'zIndex': Number.MAX_VALUE
3436
};
3537

3638
const registeredMode = {};
@@ -696,10 +698,12 @@ class DrawTool extends MapTool {
696698
if (!drawToolLayer) {
697699
drawToolLayer = new VectorLayer(drawLayerId, {
698700
'enableSimplify': false,
699-
'enableAltitude': this.options['enableAltitude']
701+
'enableAltitude': this.options['enableAltitude'],
702+
'zIndex': this.options.zIndex
700703
});
701704
this._map.addLayer(drawToolLayer);
702705
}
706+
this._pushLayers(drawToolLayer);
703707
return drawToolLayer;
704708
}
705709

@@ -715,6 +719,60 @@ class DrawTool extends MapTool {
715719
MapTool.prototype._fireEvent.call(this, eventName, param);
716720
}
717721

722+
_pushLayers(layers) {
723+
if (!layers) {
724+
return this;
725+
}
726+
if (!Array.isArray(layers)) {
727+
layers = [layers];
728+
}
729+
this._layers = this._layers || [];
730+
layers.forEach(layer => {
731+
if (this._layers.indexOf(layer) === -1) {
732+
this._layers.push(layer);
733+
}
734+
});
735+
return this;
736+
}
737+
738+
_outLayers(layers) {
739+
if (!layers) {
740+
return this;
741+
}
742+
if (!Array.isArray(layers)) {
743+
layers = [layers];
744+
}
745+
this._layers = this._layers || [];
746+
layers.forEach(layer => {
747+
for (let i = 0, len = this._layers.length; i < len; i++) {
748+
if (layer === this._layers[i]) {
749+
this._layers.splice(i, 1);
750+
break;
751+
}
752+
}
753+
});
754+
return this;
755+
}
756+
757+
/**
758+
* set draw inner layers zIndex
759+
* @param {Number} zIndex - draw layer zIndex
760+
* @return {this}
761+
*/
762+
setLayerZIndex(zIndex) {
763+
if (!isNumber(zIndex)) {
764+
return this;
765+
}
766+
this.options.zIndex = zIndex;
767+
this._layers = this._layers || [];
768+
this._layers.forEach(layer => {
769+
if (layer && layer.setZIndex) {
770+
layer.setZIndex(zIndex);
771+
}
772+
});
773+
return this;
774+
}
775+
718776
}
719777

720778
DrawTool.mergeOptions(options);

0 commit comments

Comments
 (0)