mirror of https://gitee.com/antv-l7/antv-l7
refactor: ts error
This commit is contained in:
parent
58d0898a81
commit
ca0174e293
|
@ -51,13 +51,13 @@ describe('moveFeature', () => {
|
|||
const res = moveFeature([pointFeature], delta) as Array<
|
||||
Feature<Geometry, Properties>
|
||||
>;
|
||||
expect(res[0].geometry.coordinates).toEqual([131, 48]);
|
||||
expect(res[0]?.geometry?.coordinates).toEqual([131, 48]);
|
||||
});
|
||||
it('move BBox', () => {
|
||||
const res = moveFeature([polyon], delta) as Array<
|
||||
Feature<Geometry, Properties>
|
||||
>;
|
||||
expect(res[0].geometry.coordinates).toEqual([
|
||||
expect(res[0]?.geometry?.coordinates).toEqual([
|
||||
[
|
||||
[50.5703125, 46.583289756006316],
|
||||
[72.3671875, 46.583289756006316],
|
||||
|
@ -71,7 +71,7 @@ describe('moveFeature', () => {
|
|||
const res = moveFeature([line], delta) as Array<
|
||||
Feature<Geometry, Properties>
|
||||
>;
|
||||
expect(res[0].geometry.coordinates).toEqual([
|
||||
expect(res[0]?.geometry?.coordinates).toEqual([
|
||||
[55.31640625, 63.91523303947614],
|
||||
[72.015625, 63.59334083012024],
|
||||
[71.48828125, 59.07787626787517],
|
||||
|
|
|
@ -80,7 +80,7 @@ export default abstract class DrawMode extends EventEmitter {
|
|||
throw new Error('子类未实现该方法');
|
||||
}
|
||||
|
||||
public getCurrentVertex(feature: Feature) {
|
||||
public getCurrentVertex() {
|
||||
return this.currentVertex;
|
||||
}
|
||||
public getCurrentFeature() {
|
||||
|
|
|
@ -59,12 +59,12 @@ export default class DrawPolygon extends DrawFeature {
|
|||
public addVertex(vertex: Feature<Geometries, Properties>) {
|
||||
// @ts-ignore
|
||||
const id = vertex.properties.id;
|
||||
const coord = vertex.geometry.coordinates as Position;
|
||||
const coord = vertex?.geometry?.coordinates as Position;
|
||||
const feature = this.currentFeature as Feature<Geometries, Properties>;
|
||||
const type = feature.geometry.type;
|
||||
const type = feature?.geometry?.type;
|
||||
const points = [];
|
||||
if (type === 'Polygon') {
|
||||
const coords = feature.geometry.coordinates as Position[][];
|
||||
const coords = feature?.geometry?.coordinates as Position[][];
|
||||
coords[0].splice(id + 1, 0, coord);
|
||||
for (let i = 0; i < coords[0].length - 1; i++) {
|
||||
points.push({
|
||||
|
@ -73,7 +73,7 @@ export default class DrawPolygon extends DrawFeature {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
const coords = feature.geometry.coordinates as Position[];
|
||||
const coords = feature?.geometry?.coordinates as Position[];
|
||||
coords.splice(id + 1, 0, coord);
|
||||
for (const coor of coords) {
|
||||
points.push({
|
||||
|
@ -169,6 +169,7 @@ export default class DrawPolygon extends DrawFeature {
|
|||
} else {
|
||||
// @ts-ignore
|
||||
const id = selectVertexed.properties.id * 1;
|
||||
// @ts-ignore
|
||||
selectVertexed.geometry.coordinates = [vertex.lng, vertex.lat];
|
||||
// @ts-ignore
|
||||
this.pointFeatures[id].geometry.coordinates = [vertex.lng, vertex.lat];
|
||||
|
@ -226,15 +227,15 @@ export default class DrawPolygon extends DrawFeature {
|
|||
|
||||
private editPolygonVertex(id: number, vertex: ILngLat) {
|
||||
const feature = this.currentFeature as Feature<Geometries, Properties>;
|
||||
const type = feature.geometry.type;
|
||||
const type = feature?.geometry?.type;
|
||||
if (type === 'Polygon') {
|
||||
const coords = feature.geometry.coordinates as Position[][];
|
||||
const coords = feature?.geometry?.coordinates as Position[][];
|
||||
coords[0][id] = [vertex.lng, vertex.lat];
|
||||
if (-id === 0) {
|
||||
coords[0][coords[0].length - 1] = [vertex.lng, vertex.lat];
|
||||
}
|
||||
} else {
|
||||
const coords = feature.geometry.coordinates as Position[];
|
||||
const coords = feature?.geometry?.coordinates as Position[];
|
||||
coords[id] = [vertex.lng, vertex.lat];
|
||||
}
|
||||
this.setCurrentFeature(feature);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ILayer, LineLayer, PointLayer, PolygonLayer } from '@antv/l7';
|
||||
import { FeatureCollection } from '@turf/helpers';
|
||||
export function renderFeature(fe: FeatureCollection, style: any): ILayer[] {
|
||||
const type = fe.features[0].geometry.type;
|
||||
const type = fe.features[0]?.geometry?.type;
|
||||
let layers;
|
||||
switch (type) {
|
||||
case 'Point':
|
||||
|
|
|
@ -91,8 +91,9 @@ export default class MapboxService
|
|||
public getContainer(): HTMLElement | null {
|
||||
return this.map.getContainer();
|
||||
}
|
||||
|
||||
public getMapCanvasContainer(): HTMLElement {
|
||||
return this.map.getCanvasContainer();
|
||||
return this.map.getCanvasContainer() as HTMLElement;
|
||||
}
|
||||
|
||||
public getSize(): [number, number] {
|
||||
|
|
|
@ -59,6 +59,7 @@ export default interface IMapController {
|
|||
// get map params
|
||||
getType(): string;
|
||||
getMapContainer(): HTMLElement | null;
|
||||
getMapCanvasContainer(): HTMLElement;
|
||||
|
||||
// control with raw map
|
||||
setRotation(rotation: number): void;
|
||||
|
|
|
@ -4179,7 +4179,7 @@
|
|||
dependencies:
|
||||
"@turf/helpers" "^5.1.5"
|
||||
|
||||
"@turf/midpoint@5.1.x":
|
||||
"@turf/midpoint@5.1.x", "@turf/midpoint@^5.1.5":
|
||||
version "5.1.5"
|
||||
resolved "https://registry.npmjs.org/@turf/midpoint/-/midpoint-5.1.5.tgz#e261f6b2b0ea8124cceff552a262dd465c9d05f0"
|
||||
integrity sha1-4mH2srDqgSTM7/VSomLdRlydBfA=
|
||||
|
|
Loading…
Reference in New Issue