refactor: tslint error

This commit is contained in:
thinkinggis 2020-02-22 17:13:28 +08:00
parent 4666fc782c
commit a9054342f5
17 changed files with 85 additions and 80 deletions

View File

@ -82,3 +82,18 @@ yarn add -W -D typescript jest
```bash
yarn commit
```
## 发布
### 设置版本号
```bash
yarn run version:prerelease
```
设置完成后需要commit一下代码
### 发布
yarn run release

View File

@ -55,7 +55,7 @@ export interface IMapService<RawMap = {}> {
setCenter(center: [number, number]): void;
setPitch(pitch: number): void;
setZoom(zoom: number): void;
setMapStyle(style: string): void;
setMapStyle(style: any): void;
// coordinates methods
pixelToLngLat(pixel: Point): ILngLat;

View File

@ -87,6 +87,7 @@ export default class BasePostProcessingPass<InitializationOptions = {}>
},
// @ts-ignore
uniforms: {
// @ts-ignore
u_Texture: null,
...uniforms,
...(this.config && this.convertOptionsToUniforms(this.config)),

View File

@ -10,9 +10,14 @@ export function getAngle(angle: number | undefined) {
}
export function createVec3(x: number | vec3 | vec4, y?: number, z?: number) {
return x instanceof vec3
? vec3.clone(x)
: x instanceof vec4
? vec3.fromValues(x[0], x[1], x[2])
: vec3.fromValues(x, y as number, z as number);
// @ts-ignore
if (x instanceof vec3) {
return vec3.clone(x as vec3);
// @ts-ignore
} else if (x instanceof vec4) {
x = x as vec4;
return vec3.fromValues(x[0], x[1], x[2]);
} else {
return vec3.fromValues(x as number, y as number, z as number);
}
}

View File

@ -17,8 +17,8 @@ export function computeNormal(out: vec2, dir: vec2) {
return vec2.set(out, -dir[1], dir[0]);
}
export function direction(out: vec2, a: vec2, b: vec2) {
const a1 = aProjectFlat([a[0], a[1]]);
const b1 = aProjectFlat([b[0], b[1]]);
const a1 = aProjectFlat([a[0], a[1]]) as [number, number];
const b1 = aProjectFlat([b[0], b[1]]) as [number, number];
vec2.sub(out, a1, b1);
vec2.normalize(out, out);
return out;

View File

@ -174,7 +174,7 @@ export default class MapboxService
});
}
public setMapStyle(style: string): void {
public setMapStyle(style: any): void {
this.map.setStyle(this.getMapStyle(style));
}
// TODO: 计算像素坐标

View File

@ -13,7 +13,7 @@ interface IMapSceneConig {
const AMapScene = React.memo((props: IMapSceneConig) => {
const { style, className, map } = props;
const container = createRef();
const [scene, setScene] = useState();
const [scene, setScene] = useState<Scene>();
useEffect(() => {
const sceneInstance = new Scene({
id: container.current as HTMLDivElement,
@ -33,7 +33,7 @@ const AMapScene = React.memo((props: IMapSceneConig) => {
scene.setMapStyle(map.style);
}, [map.style]);
return (
return scene !== undefined ? (
<SceneContext.Provider value={scene}>
{createElement(
'div',
@ -45,7 +45,7 @@ const AMapScene = React.memo((props: IMapSceneConig) => {
scene && props.children,
)}
</SceneContext.Provider>
);
) : null;
});
export default AMapScene;

View File

@ -29,7 +29,7 @@ export default function BaseLayer(type: string, props: ILayerProps) {
options,
} = props;
const mapScene = (useSceneValue() as unknown) as Scene;
const [layer, setLayer] = useState();
const [layer, setLayer] = useState<ILayer>();
if (!layer) {
let l: ILayer;
switch (type) {
@ -49,10 +49,12 @@ export default function BaseLayer(type: string, props: ILayerProps) {
}
useEffect(() => {
mapScene.addLayer(layer);
return () => {
mapScene.removeLayer(layer);
};
if (layer !== undefined) {
mapScene.addLayer(layer as ILayer);
return () => {
mapScene.removeLayer(layer as ILayer);
};
}
}, []);
useEffect(() => {
// 重绘layer
@ -66,10 +68,10 @@ export default function BaseLayer(type: string, props: ILayerProps) {
});
useEffect(() => {
if (layer && layer.inited) {
if (layer && layer.inited && options) {
layer.updateLayerConfig(options);
}
}, [options?.maxZoom, options?.maxZoom, options?.visible]);
}, [options?.minZoom, options?.maxZoom, options?.visible]);
useEffect(() => {
if (layer && layer.inited && options && options.zIndex) {
@ -83,7 +85,7 @@ export default function BaseLayer(type: string, props: ILayerProps) {
}
}, [options?.blend]);
return (
return layer !== null && layer !== undefined ? (
<LayerContext.Provider value={layer}>
<Source layer={layer} source={source} />
{scale && <Scale layer={layer} scale={scale} />}
@ -96,5 +98,5 @@ export default function BaseLayer(type: string, props: ILayerProps) {
{/* LayerContext主要传入LayerEvent组件 */}
{props.children}
</LayerContext.Provider>
);
) : null;
}

View File

@ -1,7 +1,7 @@
import { Layers } from '@antv/l7';
import { ILayer } from '@antv/l7';
import { createContext, useContext } from 'react';
export const LayerContext = createContext(null);
export function useLayerValue(): Layers {
return (useContext(LayerContext) as unknown) as Layers;
export const LayerContext = createContext({});
export function useLayerValue(): ILayer {
return (useContext(LayerContext) as unknown) as ILayer;
}

View File

@ -13,7 +13,7 @@ interface IMapSceneConig {
const MapboxScene = React.memo((props: IMapSceneConig) => {
const { style, className, map } = props;
const container = createRef();
const [scene, setScene] = useState();
const [scene, setScene] = useState<Scene>();
// 地图初始
useEffect(() => {
@ -31,39 +31,34 @@ const MapboxScene = React.memo((props: IMapSceneConig) => {
// 更新地图样式
useEffect(() => {
if (!scene) {
return;
if (scene && map.style) {
scene.setMapStyle(map.style);
}
scene.setMapStyle(map.style);
}, [map.style]);
useEffect(() => {
if (!scene) {
return;
if (scene && map.zoom) {
scene.setZoom(map.zoom);
}
scene.setZoom(map.zoom);
}, [map.zoom, map.center, map.pitch, map.rotation]);
}, [map.zoom]);
useEffect(() => {
if (!scene) {
return;
if (scene && map.center) {
scene.setCenter(map.center);
}
scene.setCenter(map.center);
}, [map.center]);
useEffect(() => {
if (!scene) {
return;
if (scene && map.pitch) {
scene.setPitch(map.pitch);
}
scene.setPitch(map.pitch);
}, [map.pitch]);
useEffect(() => {
if (!scene) {
return;
if (scene && map.rotation) {
scene.setRotation(map.rotation);
}
scene.setRotation(map.rotation);
}, [map.rotation]);
return (
return scene !== undefined ? (
<SceneContext.Provider value={scene}>
{createElement(
'div',
@ -75,7 +70,7 @@ const MapboxScene = React.memo((props: IMapSceneConig) => {
scene && props.children,
)}
</SceneContext.Provider>
);
) : null;
});
export default MapboxScene;

View File

@ -22,7 +22,7 @@ interface IPopupProps {
export default React.memo(function LoadImage(props: IPopupProps) {
const mapScene = (useSceneValue() as unknown) as Scene;
const { lnglat, html, text, children } = props;
const [popup, setPopup] = React.useState();
const [popup, setPopup] = React.useState<Popup>();
const el = document.createElement('div');
useEffect(() => {
const p = new Popup(props.option);

View File

@ -11,7 +11,7 @@ interface IMapSceneConig {
export default React.memo((props: IMapSceneConig) => {
const { style, className, map } = props;
const container = createRef();
const [scene, setScene] = useState();
const [scene, setScene] = useState<Scene>();
useEffect(() => {
const sceneInstance = new Scene({
id: container.current as HTMLDivElement,
@ -25,7 +25,7 @@ export default React.memo((props: IMapSceneConig) => {
};
}, []);
return (
return scene !== null && scene !== undefined ? (
<SceneContext.Provider value={scene}>
{createElement(
'div',
@ -37,5 +37,5 @@ export default React.memo((props: IMapSceneConig) => {
scene && props.children,
)}
</SceneContext.Provider>
);
) : null;
});

View File

@ -1,7 +1,7 @@
import { Scene } from '@antv/l7';
import { createContext, useContext } from 'react';
export const SceneContext = createContext(null);
export const SceneContext = createContext({});
export function useSceneValue(): Scene {
return (useContext(SceneContext) as unknown) as Scene;
}

View File

@ -49,6 +49,7 @@ describe('ReglModel', () => {
attributes: {},
// @ts-ignore
uniforms: {
// @ts-ignore
u_Struct: [
{
a: 1,

View File

@ -57,6 +57,7 @@ describe('uniforms in ReglModel', () => {
attributes: {},
// @ts-ignore
uniforms: {
// @ts-ignore
u_Struct: [
{
a: 1,
@ -86,6 +87,7 @@ describe('uniforms in ReglModel', () => {
attributes: {},
// @ts-ignore
uniforms: {
// @ts-ignore
u_Struct: {
a: 1,
b: [1, 2],
@ -155,6 +157,7 @@ describe('uniforms in ReglModel', () => {
a: 1,
b: 2,
},
// @ts-ignore
u_5: [
{
c: 1,

View File

@ -210,10 +210,18 @@ class Scene
return this.mapService.getCenter();
}
public setCenter(center: [number, number]) {
return this.mapService.setCenter(center);
}
public getPitch(): number {
return this.mapService.getPitch();
}
public setPitch(pitch: number) {
return this.mapService.setPitch(pitch);
}
public getRotation(): number {
return this.mapService.getRotation();
}
@ -252,7 +260,7 @@ class Scene
this.mapService.setZoomAndCenter(zoom, center);
}
public setMapStyle(style: string): void {
public setMapStyle(style: any): void {
this.mapService.setMapStyle(style);
}

View File

@ -8336,7 +8336,7 @@ detect-indent@^5.0.0:
resolved "https://registry.npmjs.org/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d"
integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50=
detect-libc@^1.0.2, detect-libc@^1.0.3:
detect-libc@^1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=
@ -12570,7 +12570,7 @@ i18next@^19.0.0:
dependencies:
"@babel/runtime" "^7.3.1"
iconv-lite@0.4, iconv-lite@0.4.24, iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13:
iconv-lite@0.4, iconv-lite@0.4.24, iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@~0.4.13:
version "0.4.24"
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
@ -16153,15 +16153,6 @@ nearley@^2.7.10:
randexp "0.4.6"
semver "^5.4.1"
needle@^2.2.1:
version "2.3.2"
resolved "https://registry.npmjs.org/needle/-/needle-2.3.2.tgz#3342dea100b7160960a450dc8c22160ac712a528"
integrity sha512-DUzITvPVDUy6vczKKYTnWc/pBZ0EnjMJnQ3y+Jo5zfKFimJs7S3HFCxCRZYB9FUZcrzUQr3WsmvZgddMEIZv6w==
dependencies:
debug "^3.2.6"
iconv-lite "^0.4.4"
sax "^1.2.4"
negotiator@0.6.2:
version "0.6.2"
resolved "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
@ -16377,22 +16368,6 @@ node-object-hash@^2.0.0:
resolved "https://registry.npmjs.org/node-object-hash/-/node-object-hash-2.0.0.tgz#9971fcdb7d254f05016bd9ccf508352bee11116b"
integrity sha512-VZR0zroAusy1ETZMZiGeLkdu50LGjG5U1KHZqTruqtTyQ2wfWhHG2Ow4nsUbfTFGlaREgNHcCWoM/OzEm6p+NQ==
node-pre-gyp@*:
version "0.14.0"
resolved "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.14.0.tgz#9a0596533b877289bcad4e143982ca3d904ddc83"
integrity sha512-+CvDC7ZttU/sSt9rFjix/P05iS43qHCOOGzcr3Ry99bXG7VX953+vFyEuph/tfqoYu8dttBkE86JSKBO2OzcxA==
dependencies:
detect-libc "^1.0.2"
mkdirp "^0.5.1"
needle "^2.2.1"
nopt "^4.0.1"
npm-packlist "^1.1.6"
npmlog "^4.0.2"
rc "^1.2.7"
rimraf "^2.6.1"
semver "^5.3.0"
tar "^4.4.2"
node-releases@^1.1.29, node-releases@^1.1.49:
version "1.1.49"
resolved "https://registry.npmjs.org/node-releases/-/node-releases-1.1.49.tgz#67ba5a3fac2319262675ef864ed56798bb33b93e"
@ -16578,7 +16553,7 @@ npm-package-arg@^5.1.2:
semver "^5.1.0"
validate-npm-package-name "^3.0.0"
npm-packlist@^1.1.6, npm-packlist@^1.4.4:
npm-packlist@^1.4.4:
version "1.4.8"
resolved "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.8.tgz#56ee6cc135b9f98ad3d51c1c95da22bbb9b2ef3e"
integrity sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==
@ -16640,7 +16615,7 @@ npm-run-path@^4.0.0:
dependencies:
path-key "^3.0.0"
"npmlog@0 || 1 || 2 || 3 || 4", npmlog@^4.0.0, npmlog@^4.0.1, npmlog@^4.0.2, npmlog@^4.1.2:
"npmlog@0 || 1 || 2 || 3 || 4", npmlog@^4.0.0, npmlog@^4.0.1, npmlog@^4.1.2:
version "4.1.2"
resolved "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b"
integrity sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==
@ -22543,7 +22518,7 @@ tar@^2.0.0:
fstream "^1.0.12"
inherits "2"
tar@^4.4.10, tar@^4.4.12, tar@^4.4.2, tar@^4.4.8:
tar@^4.4.10, tar@^4.4.12, tar@^4.4.8:
version "4.4.13"
resolved "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525"
integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==