@@ -208,6 +208,23 @@ describe('MapExtendSymbol', () => {
208208 expect ( layer ) . not . toBeNull ( ) ;
209209 } ) ;
210210
211+ it ( 'map.addLayer exists layerID' , ( ) => {
212+ spyOn ( map . symbolHandler , 'getLayerIds' ) . and . returnValue ( [ "point-1" , "point-2" ] ) ;
213+ spyOn ( map . symbolHandler , 'addLayer' ) ;
214+ spyOn ( map , 'addLayerBySymbolBak' ) ;
215+ const mylayer = {
216+ "id" : "PopDensity_P@Population" ,
217+ "source" : "全国人口密度空间分布图" ,
218+ "source-layer" : "PopDensity_R@Population" ,
219+ "type" : "symbol" ,
220+ "symbol" : "start"
221+ } ;
222+ map . addLayer ( mylayer ) ;
223+ expect ( map . symbolHandler . getLayerIds ) . toHaveBeenCalled ( ) ;
224+ expect ( map . symbolHandler . addLayer ) . not . toHaveBeenCalled ( ) ;
225+ expect ( map . addLayerBySymbolBak ) . not . toHaveBeenCalled ( ) ;
226+ } ) ;
227+
211228 it ( 'setFilter' , ( ) => {
212229 spyOn ( map . style , 'setFilter' ) ;
213230 spyOn ( map . style , 'getFilter' )
@@ -281,4 +298,65 @@ describe('MapExtendSymbol', () => {
281298 expect ( map . symbolHandler . getSymbol ) . toHaveBeenCalled ( ) ;
282299 expect ( value . paint [ "icon-color" ] ) . toBe ( "red" ) ;
283300 } ) ;
301+ it ( 'map.on' , ( ) => {
302+ spyOn ( map , 'onBak' ) ;
303+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( {
304+ id : "point"
305+ } ) ;
306+ spyOn ( map . symbolHandler , 'getLayerIds' ) . and . returnValue ( [ ] ) ;
307+ const listnener = ( ) => { } ;
308+ map . on ( "click" , "point" , listnener ) ;
309+ expect ( map . onBak ) . toHaveBeenCalled ( ) ;
310+ expect ( map . style . getLayer ) . toHaveBeenCalled ( ) ;
311+ expect ( map . symbolHandler . getLayerIds ) . not . toHaveBeenCalled ( ) ;
312+ } ) ;
313+ it ( 'map.on getLayerIds' , ( ) => {
314+ spyOn ( map , 'onBak' ) ;
315+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( undefined ) ;
316+ spyOn ( map . symbolHandler , 'getLayerIds' ) . and . returnValue ( [ "point-1" , "point-2" ] ) ;
317+ map . on ( "click" , "point" , ( ) => { } ) ;
318+ expect ( map . onBak ) . toHaveBeenCalled ( ) ;
319+ expect ( map . style . getLayer ) . toHaveBeenCalled ( ) ;
320+ expect ( map . symbolHandler . getLayerIds ) . toHaveBeenCalled ( ) ;
321+ } ) ;
322+ it ( 'map.once' , ( ) => {
323+ spyOn ( map , 'onceBak' ) ;
324+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( {
325+ id : "point"
326+ } ) ;
327+ spyOn ( map . symbolHandler , 'getLayerIds' ) . and . returnValue ( [ ] ) ;
328+ map . once ( "click" , "point" , ( ) => { } ) ;
329+ expect ( map . onceBak ) . toHaveBeenCalled ( ) ;
330+ expect ( map . style . getLayer ) . toHaveBeenCalled ( ) ;
331+ expect ( map . symbolHandler . getLayerIds ) . not . toHaveBeenCalled ( ) ;
332+ } ) ;
333+ it ( 'map.once getLayerIds' , ( ) => {
334+ spyOn ( map , 'onceBak' ) ;
335+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( undefined ) ;
336+ spyOn ( map . symbolHandler , 'getLayerIds' ) . and . returnValue ( [ "point-1" , "point-2" ] ) ;
337+ map . once ( "click" , "point" , ( ) => { } ) ;
338+ expect ( map . onceBak ) . toHaveBeenCalled ( ) ;
339+ expect ( map . style . getLayer ) . toHaveBeenCalled ( ) ;
340+ expect ( map . symbolHandler . getLayerIds ) . toHaveBeenCalled ( ) ;
341+ } ) ;
342+ it ( 'map.off' , ( ) => {
343+ spyOn ( map , 'offBak' ) ;
344+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( {
345+ id : "point"
346+ } ) ;
347+ spyOn ( map . symbolHandler , 'getLayerIds' ) . and . returnValue ( [ ] ) ;
348+ map . off ( "click" , "point" , ( ) => { } ) ;
349+ expect ( map . offBak ) . toHaveBeenCalled ( ) ;
350+ expect ( map . style . getLayer ) . toHaveBeenCalled ( ) ;
351+ expect ( map . symbolHandler . getLayerIds ) . not . toHaveBeenCalled ( ) ;
352+ } ) ;
353+ it ( 'map.off getLayerIds' , ( ) => {
354+ spyOn ( map , 'offBak' ) ;
355+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( undefined ) ;
356+ spyOn ( map . symbolHandler , 'getLayerIds' ) . and . returnValue ( [ "point-1" , "point-2" ] ) ;
357+ map . off ( "click" , "point" , ( ) => { } ) ;
358+ expect ( map . offBak ) . toHaveBeenCalled ( ) ;
359+ expect ( map . style . getLayer ) . toHaveBeenCalled ( ) ;
360+ expect ( map . symbolHandler . getLayerIds ) . toHaveBeenCalled ( ) ;
361+ } ) ;
284362} ) ;
0 commit comments