Skip to content

Commit

Permalink
DrawTool support set layer zIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
deyihu committed Aug 31, 2023
1 parent 9db0e54 commit 15cb954
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/map/tool/DistanceTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class DistanceTool extends DrawTool {
}
delete this._lastMeasure;
delete this._lastVertex;
this._outLayers(this._measureLayers);
this._measureLayers = [];
return this;
}
Expand Down Expand Up @@ -230,15 +231,21 @@ class DistanceTool extends DrawTool {
const uid = UID();
const layerId = 'distancetool_' + uid;
const markerLayerId = 'distancetool_markers_' + uid;
const zIndex = this.options.zIndex;
if (!map.getLayer(layerId)) {
this._measureLineLayer = new VectorLayer(layerId).addTo(map);
this._measureMarkerLayer = new VectorLayer(markerLayerId).addTo(map);
this._measureLineLayer = new VectorLayer(layerId, {
zIndex
}).addTo(map);
this._measureMarkerLayer = new VectorLayer(markerLayerId, {
zIndex
}).addTo(map);
} else {
this._measureLineLayer = map.getLayer(layerId);
this._measureMarkerLayer = map.getLayer(markerLayerId);
}
this._measureLayers.push(this._measureLineLayer);
this._measureLayers.push(this._measureMarkerLayer);
this._pushLayers([this._measureLineLayer, this._measureMarkerLayer]);
//start marker
const marker = new Marker(param['coordinate'], {
'symbol': this.options['vertexSymbol']
Expand Down
64 changes: 61 additions & 3 deletions src/map/tool/DrawTool.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { INTERNAL_LAYER_PREFIX } from '../../core/Constants';
import { extend, isFunction, isNil } from '../../core/util';
import { extend, isFunction, isNil, isNumber } from '../../core/util';
import { extendSymbol } from '../../core/util/style';
import { getExternalResources } from '../../core/util/resource';
import { stopPropagation } from '../../core/util/dom';
Expand All @@ -14,6 +14,7 @@ import MapTool from './MapTool';
* @property {Boolean} [options.once=null] - whether disable immediately once drawn a geometry.
* @property {Boolean} [options.autoPanAtEdge=false] - Whether to make edge judgement or not.
* @property {Boolean} [options.blockGeometryEvents=false] - Whether Disable geometryEvents when drawing.
* @property {Number} [options.zIndex=Number.MAX_VALUE] - drawlayer zIndex.The default drawn layer will be at the top
* @memberOf DrawTool
* @instance
*/
Expand All @@ -30,7 +31,8 @@ const options = {
'once': false,
'autoPanAtEdge': false,
'ignoreMouseleave': true,
'blockGeometryEvents': false
'blockGeometryEvents': false,
'zIndex': Number.MAX_VALUE
};

const registeredMode = {};
Expand Down Expand Up @@ -683,10 +685,12 @@ class DrawTool extends MapTool {
if (!drawToolLayer) {
drawToolLayer = new VectorLayer(drawLayerId, {
'enableSimplify': false,
'enableAltitude': this.options['enableAltitude']
'enableAltitude': this.options['enableAltitude'],
'zIndex': this.options.zIndex
});
this._map.addLayer(drawToolLayer);
}
this._pushLayers(drawToolLayer);
return drawToolLayer;
}

Expand All @@ -702,6 +706,60 @@ class DrawTool extends MapTool {
MapTool.prototype._fireEvent.call(this, eventName, param);
}

_pushLayers(layers) {
if (!layers) {
return this;
}
if (!Array.isArray(layers)) {
layers = [layers];
}
this._layers = this._layers || [];
layers.forEach(layer => {
if (this._layers.indexOf(layer) === -1) {
this._layers.push(layer);
}
});
return this;
}

_outLayers(layers) {
if (!layers) {
return this;
}
if (!Array.isArray(layers)) {
layers = [layers];
}
this._layers = this._layers || [];
layers.forEach(layer => {
for (let i = 0, len = this._layers.length; i < len; i++) {
if (layer === this._layers[i]) {
this._layers.splice(i, 1);
break;
}
}
});
return this;
}

/**
* set draw inner layers zIndex
* @param {Number} zIndex - draw layer zIndex
* @return {this}
*/
setLayerZIndex(zIndex) {
if (!isNumber(zIndex)) {
return this;
}
this.options.zIndex = zIndex;
this._layers = this._layers || [];
this._layers.forEach(layer => {
if (layer && layer.setZIndex) {
layer.setZIndex(zIndex);
}
});
return this;
}

}

DrawTool.mergeOptions(options);
Expand Down

0 comments on commit 15cb954

Please sign in to comment.