test: updaye move feature test

This commit is contained in:
thinkinggis 2020-03-24 22:42:45 +08:00
parent cd05dc8e47
commit eacb859f72
3 changed files with 46 additions and 5 deletions

View File

@ -48,11 +48,15 @@ describe('moveFeature', () => {
},
};
it('move Point', () => {
const res = moveFeature([pointFeature], delta);
const res = moveFeature([pointFeature], delta) as Array<
Feature<Geometry, Properties>
>;
expect(res[0].geometry.coordinates).toEqual([131, 48]);
});
it('move BBox', () => {
const res = moveFeature([polyon], delta);
const res = moveFeature([polyon], delta) as Array<
Feature<Geometry, Properties>
>;
expect(res[0].geometry.coordinates).toEqual([
[
[50.5703125, 46.583289756006316],
@ -64,7 +68,9 @@ describe('moveFeature', () => {
]);
});
it('move line', () => {
const res = moveFeature([line], delta);
const res = moveFeature([line], delta) as Array<
Feature<Geometry, Properties>
>;
expect(res[0].geometry.coordinates).toEqual([
[55.31640625, 63.91523303947614],
[72.015625, 63.59334083012024],

View File

@ -20,6 +20,7 @@ export default class EditRenderLayer {
private polygonLayer: ILayer;
private lineLayer: ILayer;
private centerLayer: ILayer;
private endPointLayer: ILayer;
private draw: Draw;
private currentFeature: Feature;
constructor(draw: Draw) {
@ -57,10 +58,28 @@ export default class EditRenderLayer {
.color(centerStyle.color)
.size(centerStyle.size)
.style(centerStyle.style);
this.endPointLayer = new PointLayer({
zIndex: 4,
blend: 'normal',
})
.source([], {
parser: {
type: 'json',
x: 'lng',
y: 'lat',
},
})
.shape('circle')
.color(centerStyle.color)
.size(centerStyle.size)
.style(centerStyle.style);
this.draw.scene.addLayer(this.polygonLayer);
this.draw.scene.addLayer(this.lineLayer);
// this.draw.scene.addLayer(this.centerLayer);
this.draw.scene.addLayer(this.centerLayer);
}
public updateData(data: any) {
if (this.currentFeature === undefined) {
this.addLayerEvent();
@ -68,7 +87,23 @@ export default class EditRenderLayer {
this.currentFeature = data.features[0];
this.lineLayer.setData(data);
this.polygonLayer.setData(data);
// this.centerLayer.setData([data.features[0].properties.center]);
const properties = data.features[0].properties;
if (properties.startPoint) {
this.centerLayer.setData([
{
lng: properties.startPoint[0],
lat: properties.startPoint[1],
},
]);
}
if (properties.endPoint) {
this.endPointLayer.setData([
{
lng: properties.endPoint[0],
lat: properties.endPoint[1],
},
]);
}
}
public destroy() {