Skip to content

Commit ce340eb

Browse files
committed
修改DeckglLayer单元测试 打开Graphic相关的单元测试 review by songym
Graphic 开发代码修改 by songym
1 parent 100dbd0 commit ce340eb

File tree

7 files changed

+54
-29
lines changed

7 files changed

+54
-29
lines changed

src/openlayers/overlay/Graphic.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import {
1616
CommonUtil
1717
} from '@supermap/iclient-common';
1818
import {
19-
GraphicCanvasRenderer,
2019
GraphicWebGLRenderer
21-
} from './graphic/';
22-
20+
} from './graphic/WebGLRenderer';
21+
import {
22+
GraphicCanvasRenderer,
23+
} from './graphic/CanvasRenderer';
2324
const defaultProps = {
2425
color: [0, 0, 0, 255],
2526
opacity: 0.8,
@@ -169,7 +170,7 @@ export class Graphic extends ol.source.ImageCanvas {
169170
let contain = false;
170171
//icl-1047 当只有一个叶片的时候,判断是否选中的逻辑处理的更准确一点
171172
if (image instanceof CloverShape && image.getCount() === 1) {
172-
const ratation = image.getRotation()* 180 / Math.PI;
173+
const ratation = image.getRotation() * 180 / Math.PI;
173174
const angle = Number.parseFloat(image.getAngle());
174175
const r = image.getRadius() * resolution;
175176
//if(image.getAngle() )
@@ -181,9 +182,9 @@ export class Graphic extends ol.source.ImageCanvas {
181182
coors.push(center);
182183
const perAngle = angle / 8;
183184
for (let index = 0; index < 8; index++) {
184-
const radian=(ratation + index * perAngle)/180 * Math.PI;
185+
const radian = (ratation + index * perAngle) / 180 * Math.PI;
185186
coors.push([center[0] + r * Math.cos(radian),
186-
center[1] - r * Math.sin(radian)
187+
center[1] - r * Math.sin(radian)
187188
]);
188189
}
189190
coors.push(center);
@@ -293,7 +294,7 @@ export class Graphic extends ol.source.ImageCanvas {
293294

294295
}
295296
toRGBA(colorArray) {
296-
return `rgba(${colorArray[0]},${colorArray[1]},${colorArray[2]},${(colorArray[3]||255)/255})`;
297+
return `rgba(${colorArray[0]},${colorArray[1]},${colorArray[2]},${(colorArray[3] || 255) / 255})`;
297298
}
298299
/**
299300
* @function ol.source.Graphic.prototype.setStyle

test/leaflet/overlay/GraphicLayerSpec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../../libs/deck.gl/5.1.3/deck.gl';
12
import {graphicLayer} from '../../../src/leaflet/overlay/GraphicLayer';
23
import {tiledMapLayer} from '../../../src/leaflet/mapping/TiledMapLayer';
34
import {circleStyle} from '../../../src/leaflet/overlay/graphic/CircleStyle';

test/leaflet/overlay/graphic/CloverStyleSpec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../../../libs/deck.gl/5.1.3/deck.gl';
12
import {graphicLayer} from '../../../../src/leaflet/overlay/GraphicLayer';
23
import {tiledMapLayer} from '../../../../src/leaflet/mapping/TiledMapLayer';
34
import {graphic} from '../../../../src/leaflet/overlay/graphic/Graphic';

test/mapboxgl/overlay/DeckglLayerSpec.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,35 @@ describe('mapboxgl_DeckglLayer', () => {
136136
});
137137

138138
it('onAdd_scatter-plot', (done) => {
139+
var p1 = new Point(20.05408801141, 38.837029131724);
140+
var p2 = new Point(18.80757663534, 38.606951847395);
141+
var p3 = new Point(17.43207212138, 38.530259419285);
139142
deckglLayer = new DeckglLayer("scatter-plot", {
140-
data: null,
143+
data: {p1,p2,p3},
141144
props: {
142-
strokeWidth: 12 //线宽
145+
radiusScale: 300,
146+
radiusMaxPixels: 500,
147+
opacity: 0.3,
148+
autoHighlight: true,
149+
highlightColor: [255, 255, 0, 255],
143150
},
144151
callback: {
145-
getSourcePosition: d => d.from.coordinates,
146-
getTargetPosition: d => d.to.coordinates,
147-
getSourceColor: d => [Math.sqrt(d.inbound), 140, 0],
148-
getTargetColor: d => [Math.sqrt(d.outbound), 140, 0],
152+
getPosition: function (feature) {
153+
if (!feature || !feature.Longitude || !feature.Latitude) {
154+
return [0, 0, 0];
155+
}
156+
return [Number(feature.Longitude), Number(feature.Latitude), 0];
157+
},
158+
getColor: function (feature) {
159+
if (feature.Magnitude >= 2.5 && feature.Magnitude <= 3.31) {
160+
return [118, 42, 131];
161+
}
162+
return [0, 0, 0, 0]
163+
},
164+
getRadius: function (feature) {
165+
166+
return Math.pow(Number(feature.Magnitude), 2.5);
167+
}
149168
}
150169
});
151170
deckglLayer.onAdd(map);

test/openlayers/overlay/GraphicSpec.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ol from 'openlayers';
2+
import '../../libs/deck.gl/5.1.3/deck.gl';
23
import {CloverShape} from '../../../src/openlayers/overlay/graphic/CloverShape';
34
import {HitCloverShape} from '../../../src/openlayers/overlay/graphic/HitCloverShape';
45
import {Graphic} from '../../../src/openlayers/overlay/Graphic';
@@ -33,7 +34,7 @@ describe('openlayers_GraphicLayer', () => {
3334
afterEach(() => {
3435
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
3536
window.document.body.removeChild(testDiv);
36-
});
37+
});
3738

3839
it('constructor_canvas', (done) => {
3940
spyOn(FetchRequest, 'commit').and.callFake(() => {
@@ -92,7 +93,7 @@ describe('openlayers_GraphicLayer', () => {
9293
map.addLayer(graphicLayer);
9394
});
9495
setTimeout(() => {
95-
expect(1).not.toBeNull();
96+
// expect(1).not.toBeNull();
9697
var a = new Graphic({
9798
graphics: graphics,
9899
map: map
@@ -159,7 +160,7 @@ describe('openlayers_GraphicLayer', () => {
159160
map.addLayer(graphicLayer);
160161
});
161162
setTimeout(() => {
162-
expect(1).not.toBeNull();
163+
// expect(1).not.toBeNull();
163164
map.removeLayer(graphicLayer);
164165
done();
165166
}, 1000)
@@ -221,7 +222,7 @@ describe('openlayers_GraphicLayer', () => {
221222
graphics: graphics,
222223
map: map,
223224
onclick: (result) => {
224-
console.log(result);
225+
console.log(result);
225226
},
226227
highLightStyle: hitCloverShape
227228
})
@@ -230,15 +231,16 @@ describe('openlayers_GraphicLayer', () => {
230231
});
231232

232233
setTimeout(() => {
233-
expect(1).not.toBeNull();
234-
graphicLayer.getSource()._forEachFeatureAtCoordinate(coors[2], 1, (result) => {
234+
var resolution=1;
235+
graphicLayer.getSource()._forEachFeatureAtCoordinate(coors[2],resolution, (result) => {
235236
console.log(result);
237+
expect(result).not.toBeNull();
236238
});
237-
graphicLayer.getSource()._forEachFeatureAtCoordinate(coors[1], 1, (result) => {
238-
console.log(result);
239+
graphicLayer.getSource()._forEachFeatureAtCoordinate(coors[1], resolution, (result) => {
240+
expect(result).not.toBeNull();
239241
});
240-
graphicLayer.getSource()._forEachFeatureAtCoordinate([-126.16, 39.05], 1, (result) => {
241-
console.log(result);
242+
graphicLayer.getSource()._forEachFeatureAtCoordinate([-126.16, 39.05], resolution, (result) => {
243+
expect(result).not.toBeNull();
242244
});
243245

244246
let pixel = map.getPixelFromCoordinate([-36.16, 39.05]);
@@ -249,6 +251,6 @@ describe('openlayers_GraphicLayer', () => {
249251
});
250252
map.removeLayer(graphicLayer);
251253
done();
252-
}, 1000)
253-
});
254+
}, 4000)
255+
});
254256
});

test/test-main-leaflet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import './leaflet/mapping/WebMapSpec.js';
1515
import './leaflet/overlay/DataFlowlayerSpec.js';
1616
import './leaflet/overlay/EchartsLayerSpec.js';
1717
/*deck相关测试未通过,待解决后打开注释*/
18-
//import './leaflet/overlay/GraphicLayerSpec.js';
19-
//import './leaflet/overlay/graphic/CloverStyleSpec';
18+
import './leaflet/overlay/GraphicLayerSpec.js';
19+
import './leaflet/overlay/graphic/CloverStyleSpec';
2020
import './leaflet/overlay/GraphThemeLayerSpec.js';
2121
import './leaflet/overlay/HeatMapLayerSpec.js';
2222
import './leaflet/overlay/LabelThemeLayerSpec.js';

test/test-main-openlayers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import './openlayers/mapping/ImageSuperMapRestSpec.js';
1010
import './openlayers/mapping/WebMapSpec.js';
1111

1212
/*openlayers -- overlay*/
13-
/*deck相关测试未通过,待解决后打开注释*/
14-
// import './openlayers/overlay/GraphicSpec.js';
13+
14+
import './openlayers/overlay/GraphicSpec.js';
15+
1516
import './openlayers/overlay/GraphSpec.js';
1617
import './openlayers/overlay/HeatMapSpec.js';
1718
import './openlayers/overlay/LabelSpec';

0 commit comments

Comments
 (0)