fix(tsconfig): 修改ts提示
This commit is contained in:
parent
bfc2dd7930
commit
91ba49d94c
@ -14,7 +14,7 @@ import drawRectMode from 'mapbox-gl-draw-rectangle-mode'
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import drawStaticMode from '@mapbox/mapbox-gl-draw-static-mode'
|
import drawStaticMode from '@mapbox/mapbox-gl-draw-static-mode'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import drawCircleMode from './mode/drawCircleMode.draw.js'
|
import drawCircleMode from './mode/drawCircleMode.draw'
|
||||||
import { useControl } from 'react-map-gl';
|
import { useControl } from 'react-map-gl';
|
||||||
import type { ControlPosition } from 'react-map-gl';
|
import type { ControlPosition } from 'react-map-gl';
|
||||||
|
|
||||||
@ -65,27 +65,27 @@ const DrawControl = forwardRef<DrawControlRefProps, DrawControlProps>((props, re
|
|||||||
},
|
},
|
||||||
(context: any) => {
|
(context: any) => {
|
||||||
const { map } = context
|
const { map } = context
|
||||||
map.on('draw.create', e => props.onCreate?.(e));
|
map.on('draw.create', (e: { features: object[]; }) => props.onCreate?.(e));
|
||||||
map.on('draw.update', e => props.onUpdate?.(e));
|
map.on('draw.update', (e: { features: object[]; action: string; }) => props.onUpdate?.(e));
|
||||||
map.on('draw.delete', e => props.onDelete?.(e));
|
map.on('draw.delete', (e: { features: object[]; }) => props.onDelete?.(e));
|
||||||
map.on('draw.render', e => props.onRender?.(e));
|
map.on('draw.render', (e: { features: object[]; }) => props.onRender?.(e));
|
||||||
map.on('draw.combine', e => props.onCombine?.(e));
|
map.on('draw.combine', (e: { features: object[]; }) => props.onCombine?.(e));
|
||||||
map.on('draw.uncombine', e => props.onUncombine?.(e));
|
map.on('draw.uncombine', (e: { features: object[]; }) => props.onUncombine?.(e));
|
||||||
map.on('draw.modechange', e => props.onModeChange?.(e));
|
map.on('draw.modechange', (e: { features: object[]; }) => props.onModeChange?.(e));
|
||||||
map.on('draw.actionable', e => props.onActionable?.(e));
|
map.on('draw.actionable', (e: { features: object[]; }) => props.onActionable?.(e));
|
||||||
map.on('draw.selectionchange', e => props.onSelectionChange?.(e));
|
map.on('draw.selectionchange', (e: { features: object[]; }) => props.onSelectionChange?.(e));
|
||||||
},
|
},
|
||||||
(context: MapContextValue) => {
|
(context: any) => {
|
||||||
const { map } = context
|
const { map } = context
|
||||||
map.off('draw.create', props.onCreate);
|
map.off('draw.create', props.onCreate);
|
||||||
map.off('draw.update', props.onUpdate);
|
map.off('draw.update', props.onUpdate);
|
||||||
map.off('draw.delete', props.onDelete);
|
map.off('draw.delete', props.onDelete);
|
||||||
map.off('draw.render', e => props.onRender?.(e));
|
map.off('draw.render', (e: { features: object[]; }) => props.onRender?.(e));
|
||||||
map.off('draw.combine', e => props.onCombine?.(e));
|
map.off('draw.combine', (e: { features: object[]; }) => props.onCombine?.(e));
|
||||||
map.off('draw.uncombine', e => props.onUncombine?.(e));
|
map.off('draw.uncombine', (e: { features: object[]; }) => props.onUncombine?.(e));
|
||||||
map.off('draw.modechange', e => props.onModeChange?.(e));
|
map.off('draw.modechange', (e: { features: object[]; }) => props.onModeChange?.(e));
|
||||||
map.off('draw.actionable', e => props.onActionable?.(e));
|
map.off('draw.actionable', (e: { features: object[]; }) => props.onActionable?.(e));
|
||||||
map.off('draw.selectionchange', e => props.onSelectionChange?.(e));
|
map.off('draw.selectionchange', (e: { features: object[]; }) => props.onSelectionChange?.(e));
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
position: props.position
|
position: props.position
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import { DrawCustomModeThis, DrawCustomMode } from "@mapbox/mapbox-gl-draw";
|
||||||
|
|
||||||
const doubleClickZoom = {
|
const doubleClickZoom = {
|
||||||
enable(ctx) {
|
enable(ctx: { map: { doubleClickZoom: { enable: () => void; }; }; _ctx: { store: { getInitialConfigValue: (arg0: string) => any; }; }; }) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (
|
if (
|
||||||
!ctx.map ||
|
!ctx.map ||
|
||||||
@ -13,7 +15,7 @@ const doubleClickZoom = {
|
|||||||
ctx.map.doubleClickZoom.enable();
|
ctx.map.doubleClickZoom.enable();
|
||||||
}, 0);
|
}, 0);
|
||||||
},
|
},
|
||||||
disable(ctx) {
|
disable(ctx: DrawCustomModeThis & DrawCustomMode<any, any>) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!ctx.map || !ctx.map.doubleClickZoom) return;
|
if (!ctx.map || !ctx.map.doubleClickZoom) return;
|
||||||
ctx.map.doubleClickZoom.disable();
|
ctx.map.doubleClickZoom.disable();
|
@ -1,8 +1,10 @@
|
|||||||
import MapboxDraw from '@mapbox/mapbox-gl-draw';
|
import MapboxDraw from '@mapbox/mapbox-gl-draw';
|
||||||
import doubleClickZoom from './doubleClickZoom';
|
import doubleClickZoom from './doubleClickZoom';
|
||||||
import * as turf from '@turf/turf';
|
import * as turf from '@turf/turf';
|
||||||
|
|
||||||
const { circle, distance, helpers: turfHelpers } = turf;
|
const { circle, distance, helpers: turfHelpers } = turf;
|
||||||
const drawCircleMode = { ...MapboxDraw.modes.draw_polygon };
|
const drawCircleMode: any = { ...MapboxDraw.modes.draw_polygon };
|
||||||
|
|
||||||
drawCircleMode.onSetup = function () {
|
drawCircleMode.onSetup = function () {
|
||||||
const polygon = this.newFeature({
|
const polygon = this.newFeature({
|
||||||
type: 'Feature',
|
type: 'Feature',
|
||||||
@ -23,6 +25,7 @@ drawCircleMode.onSetup = function () {
|
|||||||
// dragPan.disable(this);
|
// dragPan.disable(this);
|
||||||
this.updateUIClasses({ mouse: 'add' });
|
this.updateUIClasses({ mouse: 'add' });
|
||||||
this.activateUIButton('Polygon');
|
this.activateUIButton('Polygon');
|
||||||
|
// @ts-ignore
|
||||||
this.setActionableState({
|
this.setActionableState({
|
||||||
trash: true,
|
trash: true,
|
||||||
});
|
});
|
||||||
@ -32,6 +35,7 @@ drawCircleMode.onSetup = function () {
|
|||||||
currentVertexPosition: 0,
|
currentVertexPosition: 0,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
// @ts-ignore
|
||||||
drawCircleMode.onClick = drawCircleMode.onTap = function (state, e) {
|
drawCircleMode.onClick = drawCircleMode.onTap = function (state, e) {
|
||||||
const currentCenter = state.polygon.properties.center;
|
const currentCenter = state.polygon.properties.center;
|
||||||
if (currentCenter.length === 0) {
|
if (currentCenter.length === 0) {
|
||||||
@ -42,7 +46,7 @@ drawCircleMode.onClick = drawCircleMode.onTap = function (state, e) {
|
|||||||
return this.changeMode('simple_select', { featureIds: [state.polygon.id] });
|
return this.changeMode('simple_select', { featureIds: [state.polygon.id] });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
drawCircleMode.onDrag = drawCircleMode.onMouseMove = function (state, e) {
|
drawCircleMode.onDrag = drawCircleMode.onMouseMove = function (state: { polygon: { properties: { center: any; radiusInKm: number; lastClickCoord: any[]; }; incomingCoords: (arg0: turf.helpers.Position[][]) => void; }; }, e: { lngLat: { lng: number; lat: number; }; }) {
|
||||||
const center = state.polygon.properties.center;
|
const center = state.polygon.properties.center;
|
||||||
if (center.length > 0) {
|
if (center.length > 0) {
|
||||||
const distanceInKm = distance(
|
const distanceInKm = distance(
|
||||||
@ -61,7 +65,7 @@ drawCircleMode.onDrag = drawCircleMode.onMouseMove = function (state, e) {
|
|||||||
//它决定当前 Drew 数据存储中的哪些特性将在地图上呈现。
|
//它决定当前 Drew 数据存储中的哪些特性将在地图上呈现。
|
||||||
//所有传递给“显示”的特性都将被渲染,因此可以为每个内部特性传递多个显示特性。
|
//所有传递给“显示”的特性都将被渲染,因此可以为每个内部特性传递多个显示特性。
|
||||||
//有关如何制作显示特性的建议,请参阅‘ styling-pull’in‘ API.md’
|
//有关如何制作显示特性的建议,请参阅‘ styling-pull’in‘ API.md’
|
||||||
drawCircleMode.toDisplayFeatures = function (state, geojson, display) {
|
drawCircleMode.toDisplayFeatures = function (state: { polygon: { id: any; }; }, geojson: { properties: { id: any; active: string; }; }, display: (arg0: any) => void) {
|
||||||
const isActivePolygon = geojson.properties.id === state.polygon.id;
|
const isActivePolygon = geojson.properties.id === state.polygon.id;
|
||||||
geojson.properties.active = isActivePolygon ? 'true' : 'false';
|
geojson.properties.active = isActivePolygon ? 'true' : 'false';
|
||||||
display(geojson);
|
display(geojson);
|
Loading…
Reference in New Issue
Block a user