11import { INTERNAL_LAYER_PREFIX } from '../../core/Constants' ;
2- import { extend , isFunction , isNil } from '../../core/util' ;
2+ import { extend , isFunction , isNil , isNumber } from '../../core/util' ;
33import { extendSymbol } from '../../core/util/style' ;
44import { getExternalResources } from '../../core/util/resource' ;
55import { 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
3638const 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
720778DrawTool . mergeOptions ( options ) ;
0 commit comments