11import mapboxgl from 'mapbox-gl' ;
22import '../../libs/deck.gl/5.1.3/deck.gl' ;
3- import { Point } from '../../../src/common/commontypes/geometry/Point' ;
4- import { LineString } from '../../../src/common/commontypes/geometry/LineString' ;
5- import { DeckglLayer } from '../../../src/mapboxgl/overlay/DeckglLayer' ;
3+ import { Point } from '../../../src/common/commontypes/geometry/Point' ;
4+ import { LineString } from '../../../src/common/commontypes/geometry/LineString' ;
5+ import { DeckglLayer } from '../../../src/mapboxgl/overlay/DeckglLayer' ;
66
77mapboxgl . accessToken = 'pk.eyJ1IjoibW9ua2VyIiwiYSI6ImNpd2Z6aTE5YTAwdHEyb2tpOWs2ZzRydmoifQ.LwQMRArUP8Q9P7QApuOIHg' ;
88describe ( 'mapboxgl_DeckglLayer' , ( ) => {
@@ -140,7 +140,7 @@ describe('mapboxgl_DeckglLayer', () => {
140140 var p2 = new Point ( 18.80757663534 , 38.606951847395 ) ;
141141 var p3 = new Point ( 17.43207212138 , 38.530259419285 ) ;
142142 deckglLayer = new DeckglLayer ( "scatter-plot" , {
143- data : { p1, p2, p3} ,
143+ data : { p1, p2, p3} ,
144144 props : {
145145 radiusScale : 300 ,
146146 radiusMaxPixels : 500 ,
@@ -158,11 +158,11 @@ describe('mapboxgl_DeckglLayer', () => {
158158 getColor : function ( feature ) {
159159 if ( feature . Magnitude >= 2.5 && feature . Magnitude <= 3.31 ) {
160160 return [ 118 , 42 , 131 ] ;
161- }
161+ }
162162 return [ 0 , 0 , 0 , 0 ]
163163 } ,
164164 getRadius : function ( feature ) {
165-
165+
166166 return Math . pow ( Number ( feature . Magnitude ) , 2.5 ) ;
167167 }
168168 }
@@ -182,8 +182,8 @@ describe('mapboxgl_DeckglLayer', () => {
182182
183183 it ( 'setData,removeFromMap' , ( done ) => {
184184 var data = [
185- { "ADDRESS" : "939 ELLIS ST" , "RACKS" : 2 , "SPACES" : 4 , "COORDINATES" : [ - 122.42177834 , 37.78346622 ] } ,
186- { "ADDRESS" : "1380 HOWARD ST" , "RACKS" : 1 , "SPACES" : 2 , "COORDINATES" : [ - 122.414411 , 37.774458 ] }
185+ { "ADDRESS" : "939 ELLIS ST" , "RACKS" : 2 , "SPACES" : 4 , "COORDINATES" : [ - 122.42177834 , 37.78346622 ] } ,
186+ { "ADDRESS" : "1380 HOWARD ST" , "RACKS" : 1 , "SPACES" : 2 , "COORDINATES" : [ - 122.414411 , 37.774458 ] }
187187 ] ;
188188 deckglLayer = new DeckglLayer ( "hexagon-layer" , {
189189 data : features ,
@@ -211,15 +211,15 @@ describe('mapboxgl_DeckglLayer', () => {
211211 expect ( deckglLayer . data . length ) . toEqual ( 0 ) ;
212212 done ( ) ;
213213 } , 3000 )
214-
214+
215215
216216 } ) ;
217217
218218 it ( 'addData,removeData' , ( done ) => {
219219 var data = [
220- { "ADDRESS" : "939 ELLIS ST" , "RACKS" : 2 , "SPACES" : 4 , "COORDINATES" : [ - 122.42177834 , 37.78346622 ] } ,
221- { "ADDRESS" : "1380 HOWARD ST" , "RACKS" : 1 , "SPACES" : 2 , "COORDINATES" : [ - 122.414411 , 37.774458 ] } ,
222- { "ADDRESS" : "685 CHENERY ST" , "RACKS" : 1 , "SPACES" : 2 , "COORDINATES" : [ - 122.433618 , 37.73435 ] }
220+ { "ADDRESS" : "939 ELLIS ST" , "RACKS" : 2 , "SPACES" : 4 , "COORDINATES" : [ - 122.42177834 , 37.78346622 ] } ,
221+ { "ADDRESS" : "1380 HOWARD ST" , "RACKS" : 1 , "SPACES" : 2 , "COORDINATES" : [ - 122.414411 , 37.774458 ] } ,
222+ { "ADDRESS" : "685 CHENERY ST" , "RACKS" : 1 , "SPACES" : 2 , "COORDINATES" : [ - 122.433618 , 37.73435 ] }
223223 ] ;
224224 deckglLayer = new DeckglLayer ( "arc-layer" , {
225225 data : features ,
@@ -248,118 +248,4 @@ describe('mapboxgl_DeckglLayer', () => {
248248 done ( ) ;
249249 } , 3000 )
250250 } ) ;
251-
252- it ( "getGraphicBy add getGraphicById" , ( done ) => {
253- let graphics = [ ] ;
254- map = new ol . Map ( {
255- target : 'map' ,
256- view : new ol . View ( {
257- center : [ 0 , 0 ] ,
258- zoom : 2 ,
259- projection : 'EPSG:4326'
260- } ) ,
261- renderer : [ 'canvas' ]
262- } ) ;
263- for ( let j = 0 ; j < coors . length ; ++ j ) {
264- graphics [ j ] = new ol . Graphic ( new ol . geom . Point ( coors [ j ] ) ) ;
265- graphics [ j ] . setId ( j ) ;
266- graphics [ j ] . setAttributes ( { name : "graphic_" + j } ) ;
267- }
268- const graphicLayer = new ol . layer . Image ( {
269- source : new Graphic ( {
270- graphics : graphics ,
271- map : map
272- } )
273- } ) ;
274- map . addLayer ( graphicLayer ) ;
275-
276- setTimeout ( ( ) => {
277- const graphic = graphicLayer . getSource ( ) . getGraphicBy ( "id" , 1 ) ;
278- expect ( graphic ) . not . toBeNull ( ) ;
279- expect ( graphic . getId ( ) ) . toEqual ( 1 ) ;
280-
281- const graphic1 = graphicLayer . getSource ( ) . getGraphicById ( 1 ) ;
282- expect ( graphic1 . getId ( ) ) . toEqual ( 1 ) ;
283-
284- map . removeLayer ( graphicLayer ) ;
285- done ( ) ;
286- } , 4000 )
287-
288-
289- } ) ;
290- it ( "getGraphicsByAttribute" , ( done ) => {
291- let graphics = [ ] ;
292- map = new ol . Map ( {
293- target : 'map' ,
294- view : new ol . View ( {
295- center : [ 0 , 0 ] ,
296- zoom : 2 ,
297- projection : 'EPSG:4326'
298- } ) ,
299- renderer : [ 'canvas' ]
300- } ) ;
301- for ( let j = 0 ; j < coors . length ; ++ j ) {
302- graphics [ j ] = new ol . Graphic ( new ol . geom . Point ( coors [ j ] ) ) ;
303- graphics [ j ] . setId ( j ) ;
304- graphics [ j ] . setAttributes ( { name : "graphic_" + j } ) ;
305- }
306- const graphicLayer = new ol . layer . Image ( {
307- source : new Graphic ( {
308- graphics : graphics ,
309- map : map
310- } )
311- } ) ;
312- map . addLayer ( graphicLayer ) ;
313-
314- setTimeout ( ( ) => {
315- const graphic = graphicLayer . getSource ( ) . getGraphicsByAttribute ( "name" , "graphic_1" ) ;
316- expect ( graphic ) . not . toBeNull ( ) ;
317- expect ( graphic [ 0 ] . getAttributes ( ) . name ) . toBe ( "graphic_1" ) ;
318- map . removeLayer ( graphicLayer ) ;
319- done ( ) ;
320- } , 4000 ) ;
321- } ) ;
322- it ( "removeGraphics" , ( ) => {
323- let graphics = [ ] ;
324- map = new ol . Map ( {
325- target : 'map' ,
326- view : new ol . View ( {
327- center : [ 0 , 0 ] ,
328- zoom : 2 ,
329- projection : 'EPSG:4326'
330- } ) ,
331- renderer : [ 'canvas' ]
332- } ) ;
333- for ( let j = 0 ; j < coors . length ; ++ j ) {
334- graphics [ j ] = new ol . Graphic ( new ol . geom . Point ( coors [ j ] ) ) ;
335- graphics [ j ] . setId ( j ) ;
336- graphics [ j ] . setAttributes ( { name : "graphic_" + j } ) ;
337- }
338- const graphicLayer = new ol . layer . Image ( {
339- source : new Graphic ( {
340- graphics : graphics ,
341- map : map
342- } )
343- } ) ;
344- map . addLayer ( graphicLayer ) ;
345-
346- setTimeout ( ( ) => {
347- const graphicSource = graphicLayer . getSource ( ) ;
348- //删除单个
349- let deleteGraphic = graphic [ 0 ] ;
350- expect ( graphicSource . graphics . length ) . toEqual ( 5 ) ;
351- graphicSource . removeGraphics ( deleteGraphic ) ;
352- expect ( graphicSource . graphics . length ) . toEqual ( 4 ) ;
353-
354- //多个
355- deleteGraphic = [ graphic [ 1 ] , graphic [ 2 ] ] ;
356- graphicSource . removeGraphics ( deleteGraphic ) ;
357- expect ( graphicSource . graphics . length ) . toEqual ( 2 ) ;
358-
359- //默认
360- graphicSource . removeGraphics ( ) ;
361- expect ( graphicSource . graphics . length ) . toEqual ( 0 ) ;
362- } , 4000 ) ;
363-
364- } ) ;
365251} ) ;
0 commit comments