1
- import { PointSymbolizer } from '../../../../src/leaflet/overlay/vectortile/PointSymbolizer' ;
2
- import { SVGRenderer } from '../../../../src/leaflet/overlay/vectortile/SVGRenderer' ;
1
+ import { PointSymbolizer } from '../../../../src/leaflet/overlay/vectortile/PointSymbolizer' ;
2
+ import { SVGRenderer } from '../../../../src/leaflet/overlay/vectortile/SVGRenderer' ;
3
3
import '../../../resources/img/baiduTileTest.png' ;
4
4
5
5
describe ( 'leaflet_PointSymbolizer' , ( ) => {
6
6
var testDiv , map ;
7
7
beforeAll ( ( ) => {
8
- testDiv = window . document . createElement ( " div" ) ;
9
- testDiv . setAttribute ( "id" , " map" ) ;
10
- testDiv . style . styleFloat = " left" ;
11
- testDiv . style . marginLeft = " 8px" ;
12
- testDiv . style . marginTop = " 50px" ;
13
- testDiv . style . width = " 400px" ;
14
- testDiv . style . height = " 400px" ;
8
+ testDiv = window . document . createElement ( ' div' ) ;
9
+ testDiv . setAttribute ( 'id' , ' map' ) ;
10
+ testDiv . style . styleFloat = ' left' ;
11
+ testDiv . style . marginLeft = ' 8px' ;
12
+ testDiv . style . marginTop = ' 50px' ;
13
+ testDiv . style . width = ' 400px' ;
14
+ testDiv . style . height = ' 400px' ;
15
15
window . document . body . appendChild ( testDiv ) ;
16
16
map = L . map ( 'map' , {
17
17
center : [ 39 , 89 , 116.34 ] ,
@@ -24,80 +24,79 @@ describe('leaflet_PointSymbolizer', () => {
24
24
25
25
it ( 'initialize' , ( ) => {
26
26
var feature1 = {
27
- geometry : [ { x : 10 , y : 10 , type : " Point" } ] ,
28
- id : "1" ,
29
- type : " Feature" ,
27
+ geometry : [ { x : 10 , y : 10 , type : ' Point' } ] ,
28
+ id : '1' ,
29
+ type : ' Feature' ,
30
30
properties : {
31
- CAP_POP : " 2207718.0" ,
32
- SMLIBTILEID : "1" ,
33
- COUNTRY_CH : "巴西" ,
34
- CAPITAL_EN : " Brasilia" ,
35
- POP : " 2207718.0" ,
36
- CAPITAL_CH : " 巴西利亚" ,
37
- SMID : "1" ,
38
- COUNTRY : "巴西" ,
39
- CAPITAL_LO : " Brasília" ,
40
- COUNTRY_EN : " Brazil" ,
41
- USERID : "0" ,
42
- SMGEOMETRYSIZE : "16" ,
43
- SMY : " -15.792110943058866" ,
44
- CAPITAL : " 巴西利亚" ,
45
- SMX : " -47.8977476573595" ,
46
- SMUSERID : "0"
31
+ CAP_POP : ' 2207718.0' ,
32
+ SMLIBTILEID : '1' ,
33
+ COUNTRY_CH : '巴西' ,
34
+ CAPITAL_EN : ' Brasilia' ,
35
+ POP : ' 2207718.0' ,
36
+ CAPITAL_CH : ' 巴西利亚' ,
37
+ SMID : '1' ,
38
+ COUNTRY : '巴西' ,
39
+ CAPITAL_LO : ' Brasília' ,
40
+ COUNTRY_EN : ' Brazil' ,
41
+ USERID : '0' ,
42
+ SMGEOMETRYSIZE : '16' ,
43
+ SMY : ' -15.792110943058866' ,
44
+ CAPITAL : ' 巴西利亚' ,
45
+ SMX : ' -47.8977476573595' ,
46
+ SMUSERID : '0'
47
47
}
48
48
} ;
49
49
var feature2 = {
50
- geometry : [
51
- [ { x : - 10 , y : - 15 , type : "Point" } ] ,
52
- [ { x : - 100 , y : 50 , type : "Point" } ] ] ,
53
- id : "1" ,
54
- type : "Feature" ,
50
+ geometry : [ [ { x : - 10 , y : - 15 , type : 'Point' } ] , [ { x : - 100 , y : 50 , type : 'Point' } ] ] ,
51
+ id : '1' ,
52
+ type : 'Feature' ,
55
53
properties : {
56
- CAP_POP : " 2207718.0" ,
57
- SMLIBTILEID : "1" ,
58
- COUNTRY_CH : " 巴西test" ,
59
- CAPITAL_EN : " Brasilia" ,
60
- POP : " 2207718.0" ,
61
- CAPITAL_CH : " 巴西利亚test" ,
62
- SMID : "1" ,
63
- COUNTRY : "巴西" ,
64
- CAPITAL_LO : " Brasília" ,
65
- COUNTRY_EN : " Brazil" ,
66
- USERID : "0" ,
67
- SMGEOMETRYSIZE : "16" ,
68
- SMY : " -15.792110943058866" ,
69
- CAPITAL : " 巴西利亚" ,
70
- SMX : " -47.8977476573595" ,
71
- SMUSERID : "0"
54
+ CAP_POP : ' 2207718.0' ,
55
+ SMLIBTILEID : '1' ,
56
+ COUNTRY_CH : ' 巴西test' ,
57
+ CAPITAL_EN : ' Brasilia' ,
58
+ POP : ' 2207718.0' ,
59
+ CAPITAL_CH : ' 巴西利亚test' ,
60
+ SMID : '1' ,
61
+ COUNTRY : '巴西' ,
62
+ CAPITAL_LO : ' Brasília' ,
63
+ COUNTRY_EN : ' Brazil' ,
64
+ USERID : '0' ,
65
+ SMGEOMETRYSIZE : '16' ,
66
+ SMY : ' -15.792110943058866' ,
67
+ CAPITAL : ' 巴西利亚' ,
68
+ SMX : ' -47.8977476573595' ,
69
+ SMUSERID : '0'
72
70
}
73
71
} ;
74
72
var pointSymbolizer1 = new PointSymbolizer ( feature1 ) ;
75
73
var pointSymbolizer2 = new PointSymbolizer ( feature2 ) ;
76
74
expect ( pointSymbolizer1 ) . not . toBeNull ( ) ;
77
75
expect ( pointSymbolizer1 . properties ) . not . toBeNull ( ) ;
78
- expect ( pointSymbolizer1 . type ) . toEqual ( " Feature" ) ;
76
+ expect ( pointSymbolizer1 . type ) . toEqual ( ' Feature' ) ;
79
77
expect ( pointSymbolizer1 . _empty ) . not . toBeNull ( ) ;
80
78
expect ( pointSymbolizer1 . _point . x ) . toEqual ( 10 ) ;
81
79
expect ( pointSymbolizer1 . _point . y ) . toEqual ( 10 ) ;
82
80
expect ( pointSymbolizer2 ) . not . toBeNull ( ) ;
83
81
expect ( pointSymbolizer2 . properties ) . not . toBeNull ( ) ;
84
- expect ( pointSymbolizer2 . type ) . toEqual ( " Feature" ) ;
82
+ expect ( pointSymbolizer2 . type ) . toEqual ( ' Feature' ) ;
85
83
expect ( pointSymbolizer2 . _empty ) . not . toBeNull ( ) ;
86
84
expect ( pointSymbolizer2 . _point . x ) . toEqual ( - 10 ) ;
87
85
expect ( pointSymbolizer2 . _point . y ) . toEqual ( - 15 ) ;
86
+ expect ( pointSymbolizer2 . getLatLng ) . toEqual ( undefined ) ;
88
87
} ) ;
89
88
90
89
it ( 'updateStyle_svgRenderer' , ( ) => {
91
- var svgRenderer = new SVGRenderer ( { x : 1686 , y : 755 , Z : 10 } , { x : 256 , y : 256 } ) ;
90
+ var svgRenderer = new SVGRenderer ( { x : 1686 , y : 755 , Z : 10 } , { x : 256 , y : 256 } ) ;
92
91
var feature = {
93
- geometry : [ { x : 10 , y : 10 , type : " Point" } ] ,
94
- type : " Feature" ,
92
+ geometry : [ { x : 10 , y : 10 , type : ' Point' } ] ,
93
+ type : ' Feature' ,
95
94
properties : {
96
- texts : [ " test" ]
95
+ texts : [ ' test' ]
97
96
}
98
97
} ;
99
98
var style = {
100
- interactive : true ,
99
+ interactive : true
101
100
} ;
102
101
var pointSymbolizer1 = new PointSymbolizer ( feature ) ;
103
102
spyOn ( pointSymbolizer1 , '_updateBounds' ) . and . callThrough ( ) ;
@@ -107,16 +106,16 @@ describe('leaflet_PointSymbolizer', () => {
107
106
} ) ;
108
107
109
108
it ( '_getImage_Null' , ( ) => {
110
- var svgRenderer = new SVGRenderer ( { x : 1686 , y : 755 , Z : 10 } , { x : 256 , y : 256 } ) ;
109
+ var svgRenderer = new SVGRenderer ( { x : 1686 , y : 755 , Z : 10 } , { x : 256 , y : 256 } ) ;
111
110
var feature = {
112
- geometry : [ { x : 10 , y : 10 , type : " Point" } ] ,
113
- type : " Feature" ,
111
+ geometry : [ { x : 10 , y : 10 , type : ' Point' } ] ,
112
+ type : ' Feature' ,
114
113
properties : {
115
- texts : [ " test" ]
114
+ texts : [ ' test' ]
116
115
}
117
116
} ;
118
117
var style1 = {
119
- interactive : true ,
118
+ interactive : true
120
119
} ;
121
120
var pointSymbolizer = new PointSymbolizer ( feature ) ;
122
121
pointSymbolizer . render ( svgRenderer , style1 ) ;
@@ -126,12 +125,12 @@ describe('leaflet_PointSymbolizer', () => {
126
125
} ) ;
127
126
128
127
it ( '_getImage' , ( ) => {
129
- var svgRenderer = new SVGRenderer ( { x : 1686 , y : 755 , Z : 10 } , { x : 256 , y : 256 } ) ;
128
+ var svgRenderer = new SVGRenderer ( { x : 1686 , y : 755 , Z : 10 } , { x : 256 , y : 256 } ) ;
130
129
var feature = {
131
- geometry : [ { x : 10 , y : 10 , type : " Point" } ] ,
132
- type : " Feature" ,
130
+ geometry : [ { x : 10 , y : 10 , type : ' Point' } ] ,
131
+ type : ' Feature' ,
133
132
properties : {
134
- texts : [ " test" ]
133
+ texts : [ ' test' ]
135
134
}
136
135
} ;
137
136
var style2 = {
@@ -143,6 +142,42 @@ describe('leaflet_PointSymbolizer', () => {
143
142
pointSymbolizer . updateStyle ( svgRenderer , style2 ) ;
144
143
var image = pointSymbolizer . _getImage ( ) ;
145
144
expect ( image ) . not . toBeNull ( ) ;
146
- expect ( image . currentSrc ) . toContain ( "data:image/png" ) ;
145
+ expect ( image . currentSrc ) . toContain ( 'data:image/png' ) ;
146
+ } ) ;
147
+ it ( 'onclick' , ( done ) => {
148
+ var feature1 = {
149
+ geometry : [ { x : 10 , y : 10 , type : 'Point' } ] ,
150
+ id : '1' ,
151
+ type : 'Feature' ,
152
+ properties : {
153
+ CAP_POP : '2207718.0' ,
154
+ SMLIBTILEID : '1' ,
155
+ COUNTRY_CH : '巴西' ,
156
+ CAPITAL_EN : 'Brasilia' ,
157
+ POP : '2207718.0' ,
158
+ CAPITAL_CH : '巴西利亚' ,
159
+ SMID : '1' ,
160
+ COUNTRY : '巴西' ,
161
+ CAPITAL_LO : 'Brasília' ,
162
+ COUNTRY_EN : 'Brazil' ,
163
+ USERID : '0' ,
164
+ SMGEOMETRYSIZE : '16' ,
165
+ SMY : '-15.792110943058866' ,
166
+ CAPITAL : '巴西利亚' ,
167
+ SMX : '-47.8977476573595' ,
168
+ SMUSERID : '0'
169
+ }
170
+ } ;
171
+
172
+ const pointSymbolizer1 = new PointSymbolizer ( feature1 ) ;
173
+ pointSymbolizer1 . on ( 'click' , function ( e ) {
174
+ expect ( e ) . not . toBeNull ( ) ;
175
+ expect ( e . latlng ) . not . toBeNull ( ) ;
176
+ expect ( e . latlng . lat ) . toEqual ( 39.25565142103588 ) ;
177
+ expect ( e . latlng . lng ) . toEqual ( 88.71734619140626 ) ;
178
+ done ( ) ;
179
+ } ) ;
180
+ map . _fireDOMEvent ( { type : 'click' , clientX :10 , clientY :10 } , 'click' , [ pointSymbolizer1 ] ) ;
181
+
147
182
} ) ;
148
183
} ) ;
0 commit comments