diff --git a/dev-demos/features/point/simpleline.md b/dev-demos/features/point/simpleline.md new file mode 100644 index 0000000000..f6b78bf749 --- /dev/null +++ b/dev-demos/features/point/simpleline.md @@ -0,0 +1,2 @@ +### Simple Line + \ No newline at end of file diff --git a/dev-demos/features/point/simpleline.tsx b/dev-demos/features/point/simpleline.tsx new file mode 100644 index 0000000000..c7509f2641 --- /dev/null +++ b/dev-demos/features/point/simpleline.tsx @@ -0,0 +1,209 @@ +import { + LineLayer, + Scene, + // @ts-ignore +} from '@antv/l7'; +// @ts-ignore +import { GaodeMap } from '@antv/l7-maps'; +import React, { useEffect } from 'react'; + +function getImageData(img: HTMLImageElement) { + const canvas: HTMLCanvasElement = document.createElement('canvas'); + const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; + const { width, height } = img; + canvas.width = width; + canvas.height = height; + + ctx.drawImage(img, 0, 0, width, height); + const imageData = ctx.getImageData(0, 0, width, height); + + return imageData; +} + +function getLatData(data: number[]) { + const size = Math.floor(Math.sqrt(data.length)); + + const arr = []; + const startLng = 110; + const lngStep = 5 / (size - 1); + const startLat = 30; + const latStep = -5 / (size - 1); + for (let i = 0; i < size; i++) { + const arr2 = []; + for (let j = 0; j < size; j++) { + const index = i + j * size; + const x = startLng + lngStep * i; + const y = startLat + latStep * j; + // @ts-ignore + arr2.push([x, y, data[index]]); + } + // @ts-ignore + arr.push(arr2); + } + return arr; +} + +function getLngData(data: number[]) { + const size = Math.floor(Math.sqrt(data.length)); + const arr = []; + const startLng = 110; + const lngStep = 5 / (size - 1); + const startLat = 30; + const latStep = -5 / (size - 1); + + for (let i = 0; i < size; i++) { + const arr2 = []; + for (let j = 0; j < size; j++) { + const index = i * size + j; + const x = startLng + lngStep * j; + const y = startLat + latStep * i; + // @ts-ignore + arr2.push([x, y, data[index]]); + } + // @ts-ignore + arr.push(arr2); + } + return arr; +} + +function getR(data: Uint8ClampedArray) { + const arr = []; + for (let i = 0; i < data.length; i += 4) { + // @ts-ignore + arr.push(data[i]); + } + return arr; +} + +export default () => { + useEffect(() => { + const scene = new Scene({ + id: 'map', + map: new GaodeMap({ + center: [121.268, 30.3628], + pitch: 0, + // style: 'blank', + zoom: 3, + }), + }); + + const layer = new LineLayer() + .source({ + type: 'FeatureCollection', + features: [ + { + type: 'Feature', + properties: {}, + geometry: { + type: 'MultiLineString', + coordinates: [ + [ + [80, 30, 5000], + [150, 30, 5000], + [150, 10, 5000], + ], + [ + [120, 50, 5000], + [120, 30, 5000], + ], + ], + }, + }, + { + type: 'Feature', + properties: {}, + geometry: { + type: 'MultiLineString', + coordinates: [ + [ + [100, 35, 100], + [120, 50, 100], + [120, 20, 100], + [130, 20, 100], + ], + ], + }, + }, + ], + }) + // .source([ + // { + // lng1: 120, + // lat1: 30, + // lng2: 130, + // lat2: 30 + // } + // ], { + // parser: { + // type: 'json', + // x: 'lng1', + // y: 'lat1', + // x1: 'lng2', + // y1: 'lat2' + // } + // }) + .shape('simple') + .color('#f00') + .style({ + vertexHeightScale: 2000, + sourceColor: '#f00', + targetColor: '#0f0', + }); + + scene.on('loaded', () => { + scene.addLayer(layer); + }); + + const img: HTMLImageElement = new Image(); + img.crossOrigin = 'none'; + img.src = + 'https://gw.alipayobjects.com/mdn/rms_816329/afts/img/A*UkvYRYS5jTAAAAAAAAAAAAAAARQnAQ'; + img.onload = function() { + const data = getImageData(img); + const rData = getR(data.data); + const d1 = getLngData(rData); + const d2 = getLatData(rData); + const geoData = { + type: 'FeatureCollection', + features: [ + { + type: 'Feature', + properties: {}, + geometry: { + type: 'MultiLineString', + coordinates: d1, + }, + }, + { + type: 'Feature', + properties: {}, + geometry: { + type: 'MultiLineString', + coordinates: d2, + }, + }, + ], + }; + // console.log(geoData) + const layer = new LineLayer({}) + .source(geoData) + .size(1) + .shape('simple') + .color('#f00') + .style({ + vertexHeightScale: 2000, + opacity: 0.4, + }); + scene.addLayer(layer); + }; + }, []); + return ( +
+ ); +}; diff --git a/jest.config.js b/jest.config.js index 9a70316fc5..96439ac705 100644 --- a/jest.config.js +++ b/jest.config.js @@ -49,10 +49,10 @@ module.exports = { coverageReporters: ["html"], coverageThreshold: { global: { - branches: 7, + branches: 6, functions: 7, - lines: 10, - statements: 10, + lines: 9, + statements: 9, }, }, }; diff --git a/package.json b/package.json index 812d728620..8db24d9282 100644 --- a/package.json +++ b/package.json @@ -167,7 +167,7 @@ "postbuild": "yarn build:declarations", "build:declarations": "lerna run tsc --stream --no-bail", "lint:fix": "prettier --write packages/**/src/**/*.ts packages/site/docs/api/**/*.md packages/site/docs/api/*.md dev-demos/**/**/*.tsx *.md", - "lint:src": "eslint packages/**/src/**/*.ts dev-demos/**/**/*.tsx ", + "lint:src": "eslint packages/**/src/ dev-demos/ --ext .ts,.tsx", "lint:examples": "eslint packages/site/examples --fix --ext .js", "lint:css": "stylelint 'packages/**/src/**/*.js{,x}'", "lint": "run-p -c lint:*", @@ -180,7 +180,7 @@ "release-cdn": "antv-bin upload -n @antv/l7", "test": "umi-test", "test-cover": "umi-test --coverage", - "cover-viewer": "umi-test --coverage && cd coverage && http-server -p 6001 -o", + "test-cover-viewer": "umi-test --coverage && cd coverage && http-server -p 6001 -o", "test-live": "umi-test --watch", "tsc": "tsc", "watch": "yarn clean && yarn worker && lerna run watch --parallel", diff --git a/packages/component/src/popup.ts b/packages/component/src/popup.ts index db599fc64c..341bae97a7 100644 --- a/packages/component/src/popup.ts +++ b/packages/component/src/popup.ts @@ -1,7 +1,6 @@ import { ILngLat, IMapService, - IPoint, IPopup, IPopupOption, ISceneService, diff --git a/packages/core/src/services/asset/FontService.ts b/packages/core/src/services/asset/FontService.ts index 84c6139b13..c0dbf9299b 100644 --- a/packages/core/src/services/asset/FontService.ts +++ b/packages/core/src/services/asset/FontService.ts @@ -1,12 +1,11 @@ import { $window, LRUCache } from '@antv/l7-utils'; -import { inject, injectable } from 'inversify'; +import { injectable } from 'inversify'; import TinySDF from 'l7-tiny-sdf'; import 'reflect-metadata'; import { buildMapping } from '../../utils/font_util'; import { IFontAtlas, IFontMapping, - IFontMappingItem, IFontOptions, IFontService, IIconFontGlyph, diff --git a/packages/core/src/services/asset/IconService.ts b/packages/core/src/services/asset/IconService.ts index a112305633..0fa9e034fa 100644 --- a/packages/core/src/services/asset/IconService.ts +++ b/packages/core/src/services/asset/IconService.ts @@ -1,6 +1,6 @@ import { $window } from '@antv/l7-utils'; import { EventEmitter } from 'eventemitter3'; -import { inject, injectable } from 'inversify'; +import { injectable } from 'inversify'; import 'reflect-metadata'; import { buildIconMaping } from '../../utils/font_util'; import { ITexture2D } from '../renderer/ITexture2D'; @@ -9,7 +9,6 @@ import { IIcon, IICONMap, IIconService, - IIconValue, IImage, } from './IIconService'; const BUFFER = 3; diff --git a/packages/core/src/services/camera/CameraService.ts b/packages/core/src/services/camera/CameraService.ts index fcf2dce2c1..e9f5fb6b95 100644 --- a/packages/core/src/services/camera/CameraService.ts +++ b/packages/core/src/services/camera/CameraService.ts @@ -1,5 +1,5 @@ import { mat4 } from 'gl-matrix'; -import { inject, injectable } from 'inversify'; +import { injectable } from 'inversify'; import 'reflect-metadata'; import { ICameraService, IViewport } from './ICameraService'; diff --git a/packages/core/src/services/camera/Landmark.ts b/packages/core/src/services/camera/Landmark.ts index 0279aa3a7e..c697a64548 100644 --- a/packages/core/src/services/camera/Landmark.ts +++ b/packages/core/src/services/camera/Landmark.ts @@ -1,4 +1,4 @@ -import { mat3, mat4, quat, vec3, vec4 } from 'gl-matrix'; +import { mat4, vec3 } from 'gl-matrix'; import Camera from './Camera'; /** diff --git a/packages/core/src/services/component/IMarkerService.ts b/packages/core/src/services/component/IMarkerService.ts index f31fa270e5..302ebfdfb2 100644 --- a/packages/core/src/services/component/IMarkerService.ts +++ b/packages/core/src/services/component/IMarkerService.ts @@ -1,5 +1,5 @@ import { anchorType } from '@antv/l7-utils'; -import { Container, injectable } from 'inversify'; +import { Container } from 'inversify'; import { ILngLat, IMapService, IPoint } from '../map/IMapService'; import { IPopup } from './IPopupService'; export interface IMarkerScene { diff --git a/packages/core/src/services/component/IPopupService.ts b/packages/core/src/services/component/IPopupService.ts index 642548994b..c62213983a 100644 --- a/packages/core/src/services/component/IPopupService.ts +++ b/packages/core/src/services/component/IPopupService.ts @@ -1,6 +1,6 @@ import { anchorType } from '@antv/l7-utils'; import { Container } from 'inversify'; -import { ILngLat, IMapService } from '../map/IMapService'; +import { ILngLat } from '../map/IMapService'; export interface IPopupOption { closeButton: boolean; diff --git a/packages/core/src/services/component/MarkerService.ts b/packages/core/src/services/component/MarkerService.ts index c18190c9de..4bf9850c76 100644 --- a/packages/core/src/services/component/MarkerService.ts +++ b/packages/core/src/services/component/MarkerService.ts @@ -6,7 +6,6 @@ import { IMarker, IMarkerLayer, IMarkerService, - IMarkerServiceCfg, } from './IMarkerService'; @injectable() diff --git a/packages/core/src/services/config/ConfigService.ts b/packages/core/src/services/config/ConfigService.ts index 85e5291414..d037ef219b 100644 --- a/packages/core/src/services/config/ConfigService.ts +++ b/packages/core/src/services/config/ConfigService.ts @@ -1,11 +1,11 @@ // import Ajv from 'ajv'; -import { injectable, postConstruct } from 'inversify'; +import { injectable } from 'inversify'; import { merge } from 'lodash'; import 'reflect-metadata'; import { ILayerConfig } from '../layer/ILayerService'; import { IRenderConfig } from '../renderer/IRendererService'; import { IGlobalConfigService, ISceneConfig } from './IConfigService'; -import WarnInfo, { IWarnInfo } from './warnInfo'; +import WarnInfo from './warnInfo'; /** * 场景默认配置项 diff --git a/packages/core/src/services/layer/ILayerService.ts b/packages/core/src/services/layer/ILayerService.ts index 0ec72fdeac..ba21d4b973 100644 --- a/packages/core/src/services/layer/ILayerService.ts +++ b/packages/core/src/services/layer/ILayerService.ts @@ -30,7 +30,6 @@ import { IStyleAttribute, IStyleAttributeService, IStyleAttributeUpdateOptions, - ScaleAttributeType, StyleAttrField, StyleAttributeField, StyleAttributeOption, diff --git a/packages/core/src/services/layer/IStyleAttributeService.ts b/packages/core/src/services/layer/IStyleAttributeService.ts index 8990976d51..b2f505603d 100644 --- a/packages/core/src/services/layer/IStyleAttributeService.ts +++ b/packages/core/src/services/layer/IStyleAttributeService.ts @@ -4,8 +4,6 @@ import { } from '../renderer/IAttribute'; import { IBufferInitializationOptions } from '../renderer/IBuffer'; import { IElements } from '../renderer/IElements'; -import { IParseDataItem, IParserData } from '../source/ISourceService'; -import { ILayer } from './ILayerService'; /** * 1. 提供各个 Layer 样式属性初始值的注册服务 @@ -178,6 +176,7 @@ export type Triangulation = ( size: number; normals?: number[]; indexes?: number[]; + count?: number; }; export interface IStyleAttributeUpdateOptions { @@ -215,6 +214,7 @@ export interface IStyleAttributeService { [attributeName: string]: IAttribute; }; elements: IElements; + count: number | null; }; createAttributesAndIndicesAscy( encodedFeatures: IEncodeFeature[], diff --git a/packages/core/src/services/layer/LayerService.ts b/packages/core/src/services/layer/LayerService.ts index 6d54b71307..c393860b73 100644 --- a/packages/core/src/services/layer/LayerService.ts +++ b/packages/core/src/services/layer/LayerService.ts @@ -7,7 +7,7 @@ import Clock from '../../utils/clock'; import { IGlobalConfigService } from '../config/IConfigService'; import { IMapService } from '../map/IMapService'; import { IRendererService } from '../renderer/IRendererService'; -import { ILayerModel, ILayerService } from './ILayerService'; +import { ILayerService } from './ILayerService'; @injectable() export default class LayerService implements ILayerService { diff --git a/packages/core/src/services/layer/StyleAttribute.ts b/packages/core/src/services/layer/StyleAttribute.ts index 5893a3987d..a44f15d40d 100644 --- a/packages/core/src/services/layer/StyleAttribute.ts +++ b/packages/core/src/services/layer/StyleAttribute.ts @@ -1,7 +1,6 @@ import { isNil } from 'lodash'; import { IAttributeScale, - IScaleOption, IStyleAttribute, StyleScaleType, } from '../layer/IStyleAttributeService'; @@ -11,7 +10,6 @@ import { IEncodeFeature, IFeatureRange, IStyleAttributeInitializationOptions, - IStyleScale, IVertexAttributeDescriptor, } from './IStyleAttributeService'; diff --git a/packages/core/src/services/layer/StyleAttributeService.ts b/packages/core/src/services/layer/StyleAttributeService.ts index c16573934b..8b1a36df50 100644 --- a/packages/core/src/services/layer/StyleAttributeService.ts +++ b/packages/core/src/services/layer/StyleAttributeService.ts @@ -1,13 +1,12 @@ import { executeWorkerTask } from '@antv/l7-utils'; -import { inject, injectable, optional } from 'inversify'; +import { inject, injectable } from 'inversify'; import 'reflect-metadata'; import { TYPES } from '../../types'; import { gl } from '../renderer/gl'; import { IAttribute } from '../renderer/IAttribute'; import { IElements } from '../renderer/IElements'; import { IRendererService } from '../renderer/IRendererService'; -import { IParseDataItem } from '../source/ISourceService'; -import { ILayer, IWorkerOption } from './ILayerService'; +import { IWorkerOption } from './ILayerService'; import { IAttributeScale, IEncodeFeature, @@ -40,6 +39,7 @@ export default class StyleAttributeService implements IStyleAttributeService { [attributeName: string]: IAttribute; }; elements: IElements; + count: number | null; }; @inject(TYPES.IRendererService) private readonly rendererService: IRendererService; @@ -249,6 +249,7 @@ export default class StyleAttributeService implements IStyleAttributeService { this.attributesAndIndices = { attributes, elements, + count: null, }; resolve(this.attributesAndIndices); @@ -269,6 +270,7 @@ export default class StyleAttributeService implements IStyleAttributeService { [attributeName: string]: IAttribute; }; elements: IElements; + count: number | null; } { // 每次创建的初始化化 LayerOut this.featureLayout = { @@ -283,6 +285,7 @@ export default class StyleAttributeService implements IStyleAttributeService { return attr.descriptor; }); let verticesNum = 0; + let vecticesCount = 0; // 在不使用 element 的时候记录顶点、图层所有顶点的总数 const vertices: number[] = []; const indices: number[] = []; const normals: number[] = []; @@ -295,7 +298,13 @@ export default class StyleAttributeService implements IStyleAttributeService { normals: normalsForCurrentFeature, size: vertexSize, indexes, + count, } = this.triangulation(feature, segmentNumber); + + if (typeof count === 'number') { + vecticesCount += count; + } + indicesForCurrentFeature.forEach((i) => { indices.push(i + verticesNum); }); @@ -383,6 +392,7 @@ export default class StyleAttributeService implements IStyleAttributeService { this.attributesAndIndices = { attributes, elements, + count: vecticesCount, }; return this.attributesAndIndices; } diff --git a/packages/core/src/services/renderer/IRendererService.ts b/packages/core/src/services/renderer/IRendererService.ts index 0d06fd6a83..bc3715f146 100644 --- a/packages/core/src/services/renderer/IRendererService.ts +++ b/packages/core/src/services/renderer/IRendererService.ts @@ -1,4 +1,3 @@ -import { ILayer } from '../layer/ILayerService'; import { IAttribute, IAttributeInitializationOptions } from './IAttribute'; import { IBuffer, IBufferInitializationOptions } from './IBuffer'; import { IElements, IElementsInitializationOptions } from './IElements'; @@ -7,7 +6,7 @@ import { IFramebufferInitializationOptions, } from './IFramebuffer'; import { IModel, IModelInitializationOptions } from './IModel'; -import { IMultiPassRenderer, IPass } from './IMultiPassRenderer'; +import { IPass } from './IMultiPassRenderer'; import { ITexture2D, ITexture2DInitializationOptions } from './ITexture2D'; export interface IRenderConfig { diff --git a/packages/core/src/services/renderer/passes/BaseNormalPass.ts b/packages/core/src/services/renderer/passes/BaseNormalPass.ts index 0978ac0475..f476d27d0c 100644 --- a/packages/core/src/services/renderer/passes/BaseNormalPass.ts +++ b/packages/core/src/services/renderer/passes/BaseNormalPass.ts @@ -1,4 +1,4 @@ -import { inject, injectable } from 'inversify'; +import { injectable } from 'inversify'; import 'reflect-metadata'; import { TYPES } from '../../../types'; import { ICameraService } from '../../camera/ICameraService'; diff --git a/packages/core/src/services/renderer/passes/PixelPickingPass.ts b/packages/core/src/services/renderer/passes/PixelPickingPass.ts index 51e73c29ee..a76f7c7e28 100644 --- a/packages/core/src/services/renderer/passes/PixelPickingPass.ts +++ b/packages/core/src/services/renderer/passes/PixelPickingPass.ts @@ -1,7 +1,6 @@ import { decodePickingColor, DOM, encodePickingColor } from '@antv/l7-utils'; -import { inject, injectable } from 'inversify'; +import { injectable } from 'inversify'; import 'reflect-metadata'; -import { TYPES } from '../../../types'; import { IInteractionTarget, InteractionEvent, diff --git a/packages/core/src/services/scene/SceneService.ts b/packages/core/src/services/scene/SceneService.ts index 63789f36c3..7c954c6385 100644 --- a/packages/core/src/services/scene/SceneService.ts +++ b/packages/core/src/services/scene/SceneService.ts @@ -22,7 +22,7 @@ import { } from '../interaction/IInteractionService'; import { IPickingService } from '../interaction/IPickingService'; import { ILayer, ILayerService } from '../layer/ILayerService'; -import { IMapCamera, IMapConfig, IMapService } from '../map/IMapService'; +import { IMapService } from '../map/IMapService'; import { IRenderConfig, IRendererService } from '../renderer/IRendererService'; import { IShaderModuleService } from '../shader/IShaderModuleService'; import { ISceneService } from './ISceneService'; diff --git a/packages/core/src/utils/__tests__/math.spec.ts b/packages/core/src/utils/__tests__/math.spec.ts index a6e0fe3322..4a6f48bd9b 100644 --- a/packages/core/src/utils/__tests__/math.spec.ts +++ b/packages/core/src/utils/__tests__/math.spec.ts @@ -1,4 +1,4 @@ -import { createVec3, getAngle } from '../math'; +import { getAngle } from '../math'; describe('util.math', () => { it('should clamp angle with `getAngle()`', () => { diff --git a/packages/layers/src/Geometry/models/billboard.ts b/packages/layers/src/Geometry/models/billboard.ts index 5853a9ade5..296429fc97 100644 --- a/packages/layers/src/Geometry/models/billboard.ts +++ b/packages/layers/src/Geometry/models/billboard.ts @@ -1,7 +1,6 @@ import { AttributeType, gl, - IAttrubuteAndElements, IEncodeFeature, IModel, IModelUniform, diff --git a/packages/layers/src/Geometry/models/sprite.ts b/packages/layers/src/Geometry/models/sprite.ts index 2df492ad94..94df676fd9 100644 --- a/packages/layers/src/Geometry/models/sprite.ts +++ b/packages/layers/src/Geometry/models/sprite.ts @@ -1,9 +1,5 @@ import { - AttributeType, gl, - IAnimateOption, - IEncodeFeature, - ILayerConfig, IModel, IModelUniform, ITexture2D, diff --git a/packages/layers/src/canvas/models/canvas.ts b/packages/layers/src/canvas/models/canvas.ts index a517b54f91..6d54521fab 100644 --- a/packages/layers/src/canvas/models/canvas.ts +++ b/packages/layers/src/canvas/models/canvas.ts @@ -1,9 +1,8 @@ -import { ILayerConfig, IModelUniform } from '@antv/l7-core'; +import { ILayerConfig } from '@antv/l7-core'; import BaseModel from '../../core/BaseModel'; import { CanvasUpdateType, ICanvasLayerStyleOptions, - IDrawingOnCanvas, } from '../../core/interface'; export default class CanvaModel extends BaseModel { diff --git a/packages/layers/src/core/BaseLayer.ts b/packages/layers/src/core/BaseLayer.ts index b639d3f624..89ab6a53d9 100644 --- a/packages/layers/src/core/BaseLayer.ts +++ b/packages/layers/src/core/BaseLayer.ts @@ -1186,12 +1186,13 @@ export default class BaseLayer const { attributes, elements, + count, } = this.styleAttributeService.createAttributesAndIndices( this.encodedData, triangulation, segmentNumber, ); - const m = createModel({ + const modeloptions = { attributes, uniforms, fs, @@ -1199,7 +1200,11 @@ export default class BaseLayer elements, blend: BlendTypes[BlendType.normal], ...rest, - }); + }; + if (count) { + modeloptions.count = count; + } + const m = createModel(modeloptions); resolve(m); } }); diff --git a/packages/layers/src/core/triangulation.ts b/packages/layers/src/core/triangulation.ts index 2d28ba58bf..63409da3f0 100644 --- a/packages/layers/src/core/triangulation.ts +++ b/packages/layers/src/core/triangulation.ts @@ -145,49 +145,73 @@ export function LineTriangulation(feature: IEncodeFeature) { } export function SimpleLineTriangulation(feature: IEncodeFeature) { - const { coordinates, originCoordinates, version } = feature; + const { coordinates } = feature; + const pos: any[] = []; - const line = new ExtrudePolyline({ - dash: true, - join: 'bevel', + const { results, totalDistance } = getSimpleLineVertices( + coordinates as IPosition[], + ); + results.map((point) => { + pos.push(point[0], point[1], point[2], point[3], 0, totalDistance); }); - if (version === 'GAODE2.x') { - // 处理高德2.0几何体构建 - let path1 = coordinates as number[][][] | number[][]; // 计算位置 - if (!Array.isArray(path1[0][0])) { - path1 = [coordinates] as number[][][]; - } - let path2 = originCoordinates as number[][][] | number[][]; // 计算法线 - if (!Array.isArray(path2[0][0])) { - path2 = [originCoordinates] as number[][][]; - } - for (let i = 0; i < path1.length; i++) { - // 高德2.0在计算线时,需要使用经纬度计算发现,使用 customCoords.lnglatToCoords 计算的数据来计算顶点的位置 - const item1 = path1[i]; - const item2 = path2[i]; - line.simpleExtrude_gaode2(item1 as number[][], item2 as number[][]); - } - } else { - // 处理非高德2.0的几何体构建 - let path = coordinates as number[][][] | number[][]; - if (path[0] && !Array.isArray(path[0][0])) { - path = [coordinates] as number[][][]; - } - path.forEach((item: any) => { - line.simpleExtrude(item as number[][]); - }); - } - - const linebuffer = line.complex; return { - vertices: linebuffer.positions, // [ x,y,z, distance, miter, total ] - indices: linebuffer.indices, - normals: linebuffer.normals, + vertices: pos, + indices: [], + normals: [], size: 6, + count: results.length, }; } +function lineSegmentDistance(b1: number[], a1: number[]) { + const dx = a1[0] - b1[0]; + const dy = a1[1] - b1[1]; + return Math.sqrt(dx * dx + dy * dy); +} + +function pushDis(point: number[], n: number) { + if (point.length < 3) { + point.push(0); + } + point.push(n); + return point; +} + +function getSimpleLineVertices(points: number[][]) { + let distance = 0; + if (points.length < 2) { + return { + results: points, + totalDistance: 0, + }; + } else { + const results: number[][] = []; + const point = pushDis(points[0], distance); + results.push(point); + + for (let i = 1; i < points.length - 1; i++) { + const subDistance = lineSegmentDistance(points[i - 1], points[i]); + distance += subDistance; + + const mulPoint = pushDis(points[i], distance); + results.push(mulPoint); + results.push(mulPoint); + } + const pointDistance = lineSegmentDistance( + points[points.length - 2], + points[points.length - 1], + ); + distance += pointDistance; + + results.push(pushDis(points[points.length - 1], distance)); + return { + results, + totalDistance: distance, + }; + } +} + export function polygonTriangulation(feature: IEncodeFeature) { const { coordinates } = feature; const flattengeo = earcut.flatten(coordinates as number[][][]); diff --git a/packages/layers/src/earth/models/base.ts b/packages/layers/src/earth/models/base.ts index 04c24429df..f84b78be5c 100644 --- a/packages/layers/src/earth/models/base.ts +++ b/packages/layers/src/earth/models/base.ts @@ -1,15 +1,13 @@ import { AttributeType, - BlendType, gl, IEncodeFeature, - ILayerConfig, IModel, IModelUniform, ITexture2D, } from '@antv/l7-core'; -import BaseModel, { styleOffset, styleSingle } from '../../core/BaseModel'; +import BaseModel from '../../core/BaseModel'; import { earthTriangulation } from '../../core/triangulation'; import baseFrag from '../shaders/base_frag.glsl'; diff --git a/packages/layers/src/heatmap/models/heatmap.ts b/packages/layers/src/heatmap/models/heatmap.ts index 39d3e3b4ee..540dc51d72 100644 --- a/packages/layers/src/heatmap/models/heatmap.ts +++ b/packages/layers/src/heatmap/models/heatmap.ts @@ -14,7 +14,7 @@ import { IColorRamp, } from '@antv/l7-utils'; import { mat4 } from 'gl-matrix'; -import { inject, injectable } from 'inversify'; +import { injectable } from 'inversify'; import 'reflect-metadata'; import BaseModel from '../../core/BaseModel'; import { IHeatMapLayerStyleOptions } from '../../core/interface'; diff --git a/packages/layers/src/line/models/great_circle.ts b/packages/layers/src/line/models/great_circle.ts index bd1de86f4b..12cc51f8e9 100644 --- a/packages/layers/src/line/models/great_circle.ts +++ b/packages/layers/src/line/models/great_circle.ts @@ -11,7 +11,7 @@ import { import { getMask, rgb2arr } from '@antv/l7-utils'; import { isNumber } from 'lodash'; import BaseModel from '../../core/BaseModel'; -import { ILineLayerStyleOptions, lineStyleType } from '../../core/interface'; +import { ILineLayerStyleOptions } from '../../core/interface'; import { LineArcTriangulation } from '../../core/triangulation'; import line_arc_frag from '../shaders/line_arc_great_circle_frag.glsl'; import line_arc2d_vert from '../shaders/line_arc_great_circle_vert.glsl'; diff --git a/packages/layers/src/line/models/line.ts b/packages/layers/src/line/models/line.ts index d7bf50402b..9db3291346 100644 --- a/packages/layers/src/line/models/line.ts +++ b/packages/layers/src/line/models/line.ts @@ -3,7 +3,6 @@ import { gl, IAnimateOption, IEncodeFeature, - IImage, ILayerConfig, IModel, IModelUniform, diff --git a/packages/layers/src/line/models/tile.ts b/packages/layers/src/line/models/tile.ts index ab87517505..73c5834045 100644 --- a/packages/layers/src/line/models/tile.ts +++ b/packages/layers/src/line/models/tile.ts @@ -2,7 +2,6 @@ import { AttributeType, gl, IEncodeFeature, - ILayerConfig, IModel, IModelUniform, ITexture2D, diff --git a/packages/layers/src/line/shaders/simple/simpleline_vert.glsl b/packages/layers/src/line/shaders/simple/simpleline_vert.glsl index 19d47167b3..d891c6cc81 100644 --- a/packages/layers/src/line/shaders/simple/simpleline_vert.glsl +++ b/packages/layers/src/line/shaders/simple/simpleline_vert.glsl @@ -74,5 +74,6 @@ void main() { } gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy, lineHeight + h, 1.0)); + gl_PointSize = 10.0; } } diff --git a/packages/layers/src/point/__tests__/layer.spec.ts b/packages/layers/src/point/__tests__/layer.spec.ts index 1e722620ad..b8a6140f61 100644 --- a/packages/layers/src/point/__tests__/layer.spec.ts +++ b/packages/layers/src/point/__tests__/layer.spec.ts @@ -1,6 +1,4 @@ import PointLayer from '../'; -import Map from '../../../../maps/src/map'; -import { Scene } from '../../../../scene/src'; import extrudePolygon from '../shape/extrude'; describe('pointLayer', () => { const layer = new PointLayer({ diff --git a/packages/layers/src/polygon/models/tile.ts b/packages/layers/src/polygon/models/tile.ts index fc2b6df5dd..128007333f 100644 --- a/packages/layers/src/polygon/models/tile.ts +++ b/packages/layers/src/polygon/models/tile.ts @@ -1,4 +1,4 @@ -import { gl, IModel, Triangulation } from '@antv/l7-core'; +import { gl, IModel } from '@antv/l7-core'; import { getMask } from '@antv/l7-utils'; import BaseModel from '../../core/BaseModel'; import { IPolygonLayerStyleOptions } from '../../core/interface'; diff --git a/packages/layers/src/raster/buffers/triangulation.ts b/packages/layers/src/raster/buffers/triangulation.ts index af0f028383..6d3c279be1 100644 --- a/packages/layers/src/raster/buffers/triangulation.ts +++ b/packages/layers/src/raster/buffers/triangulation.ts @@ -1,4 +1,4 @@ -import { IEncodeFeature, IParseDataItem } from '@antv/l7-core'; +import { IParseDataItem } from '@antv/l7-core'; // @ts-ignore import Martini from '@mapbox/martini'; export function RasterTriangulation(parserData: IParseDataItem) { diff --git a/packages/layers/src/raster/models/raster.ts b/packages/layers/src/raster/models/raster.ts index 4c7766ad26..f840bead13 100644 --- a/packages/layers/src/raster/models/raster.ts +++ b/packages/layers/src/raster/models/raster.ts @@ -4,8 +4,6 @@ import { IEncodeFeature, IModel, ITexture2D, - lazyInject, - TYPES, } from '@antv/l7-core'; import { generateColorRamp, getMask, IColorRamp } from '@antv/l7-utils'; import { isEqual } from 'lodash'; diff --git a/packages/layers/src/tile/tileFactory/base.ts b/packages/layers/src/tile/tileFactory/base.ts index 06fc03c65d..8e22d9afbd 100644 --- a/packages/layers/src/tile/tileFactory/base.ts +++ b/packages/layers/src/tile/tileFactory/base.ts @@ -12,7 +12,6 @@ import { osmLonLat2TileXY, Tile, TilesetManager } from '@antv/l7-utils'; import MaskLayer from '../../mask'; import { getLayerShape, - readPixel, readRasterValue, registerLayers, } from '../utils'; diff --git a/packages/layers/src/tile/tileFactory/line.ts b/packages/layers/src/tile/tileFactory/line.ts index 8a835312b7..64070c5420 100644 --- a/packages/layers/src/tile/tileFactory/line.ts +++ b/packages/layers/src/tile/tileFactory/line.ts @@ -1,7 +1,7 @@ import { ILayer, ISubLayerInitOptions } from '@antv/l7-core'; import Source from '@antv/l7-source'; import { Tile } from '@antv/l7-utils'; -import { ITileFactoryOptions, ITileStyles } from '../interface'; +import { ITileFactoryOptions } from '../interface'; import TileFactory from './base'; export default class VectorPolygonTile extends TileFactory { public parentLayer: ILayer; diff --git a/packages/layers/src/tile/tileFactory/point.ts b/packages/layers/src/tile/tileFactory/point.ts index 2c1b1dc2a7..63d71e187c 100644 --- a/packages/layers/src/tile/tileFactory/point.ts +++ b/packages/layers/src/tile/tileFactory/point.ts @@ -1,7 +1,7 @@ import { ILayer, ISubLayerInitOptions } from '@antv/l7-core'; import Source from '@antv/l7-source'; import { Tile } from '@antv/l7-utils'; -import { ITileFactoryOptions, ITileStyles } from '../interface'; +import { ITileFactoryOptions } from '../interface'; import TileFactory from './base'; export default class VectorPolygonTile extends TileFactory { diff --git a/packages/layers/src/tile/tileFactory/polygon.ts b/packages/layers/src/tile/tileFactory/polygon.ts index 8a835312b7..64070c5420 100644 --- a/packages/layers/src/tile/tileFactory/polygon.ts +++ b/packages/layers/src/tile/tileFactory/polygon.ts @@ -1,7 +1,7 @@ import { ILayer, ISubLayerInitOptions } from '@antv/l7-core'; import Source from '@antv/l7-source'; import { Tile } from '@antv/l7-utils'; -import { ITileFactoryOptions, ITileStyles } from '../interface'; +import { ITileFactoryOptions } from '../interface'; import TileFactory from './base'; export default class VectorPolygonTile extends TileFactory { public parentLayer: ILayer; diff --git a/packages/layers/src/tile/tileFactory/raster.ts b/packages/layers/src/tile/tileFactory/raster.ts index c388326256..72b3e22098 100644 --- a/packages/layers/src/tile/tileFactory/raster.ts +++ b/packages/layers/src/tile/tileFactory/raster.ts @@ -1,6 +1,6 @@ import { ILayer, ISubLayerInitOptions } from '@antv/l7-core'; import Source from '@antv/l7-source'; -import { Tile, TilesetManager } from '@antv/l7-utils'; +import { Tile } from '@antv/l7-utils'; import ImageLayer from '../../image'; import { ITileFactoryOptions } from '../interface'; import TileFactory from './base'; diff --git a/packages/layers/src/tile/tileLayer/baseTileLayer.ts b/packages/layers/src/tile/tileLayer/baseTileLayer.ts index 5b60beeb38..afe356e3b4 100644 --- a/packages/layers/src/tile/tileLayer/baseTileLayer.ts +++ b/packages/layers/src/tile/tileLayer/baseTileLayer.ts @@ -3,8 +3,6 @@ import { ILayer, ILayerService, IMapService, - IScale, - IScaleOptions, ISource, ITileLayer, ITileLayerManager, diff --git a/packages/layers/src/wind/models/wind.ts b/packages/layers/src/wind/models/wind.ts index ff2707ccd4..5e829f69d7 100644 --- a/packages/layers/src/wind/models/wind.ts +++ b/packages/layers/src/wind/models/wind.ts @@ -7,7 +7,7 @@ import { ITexture2D, Point, } from '@antv/l7-core'; -import { FrequencyController, getMask } from '@antv/l7-utils'; +import { FrequencyController } from '@antv/l7-utils'; import BaseModel from '../../core/BaseModel'; import { IWindLayerStyleOptions } from '../../core/interface'; import { RasterImageTriangulation } from '../../core/triangulation'; diff --git a/packages/map/src/camera.ts b/packages/map/src/camera.ts index cf171282fb..b5cae5578d 100644 --- a/packages/map/src/camera.ts +++ b/packages/map/src/camera.ts @@ -10,14 +10,12 @@ import { Event } from './handler/events/event'; import { IMapOptions } from './interface'; type CallBack = (_: number) => void; import { - cancel, clamp, ease as defaultEasing, interpolate, now, pick, prefersReducedMotion, - raf, wrap, } from './util'; diff --git a/packages/map/src/handler/events/index.ts b/packages/map/src/handler/events/index.ts index deb1a0925c..25fac6f13f 100644 --- a/packages/map/src/handler/events/index.ts +++ b/packages/map/src/handler/events/index.ts @@ -1,5 +1,5 @@ import MapMouseEvent from './map_mouse_event'; import MapTouchEvent from './map_touch_event'; -import MapWheelEvent, { IMapBoxZoomEvent } from './map_wheel_event'; +import MapWheelEvent from './map_wheel_event'; export { MapMouseEvent, MapTouchEvent, MapWheelEvent }; diff --git a/packages/map/src/handler/mouse/mousepan_handler.ts b/packages/map/src/handler/mouse/mousepan_handler.ts index e7058219a5..3b6b352190 100644 --- a/packages/map/src/handler/mouse/mousepan_handler.ts +++ b/packages/map/src/handler/mouse/mousepan_handler.ts @@ -1,8 +1,7 @@ // @ts-ignore import Point from '../../geo/point'; -import DOM from '../../utils/dom'; import MouseHandler from './mouse_handler'; -import { buttonStillPressed, LEFT_BUTTON } from './util'; +import { LEFT_BUTTON } from './util'; export default class MousePanHandler extends MouseHandler { public mousedown(e: MouseEvent, point: Point) { super.mousedown(e, point); diff --git a/packages/map/src/handler/touch/touch_rotate.ts b/packages/map/src/handler/touch/touch_rotate.ts index 14ad6d05be..82ae2da21d 100644 --- a/packages/map/src/handler/touch/touch_rotate.ts +++ b/packages/map/src/handler/touch/touch_rotate.ts @@ -1,6 +1,5 @@ // @ts-ignore import Point from '../../geo/point'; -import DOM from '../../utils/dom'; import TwoTouchHandler from './two_touch'; const ROTATION_THRESHOLD = 25; // pixels along circumference of touch circle diff --git a/packages/map/src/handler/touch/touch_zoom.ts b/packages/map/src/handler/touch/touch_zoom.ts index f504e16b68..94d913d565 100644 --- a/packages/map/src/handler/touch/touch_zoom.ts +++ b/packages/map/src/handler/touch/touch_zoom.ts @@ -1,6 +1,5 @@ // @ts-ignore import Point from '../../geo/point'; -import DOM from '../../utils/dom'; import TwoTouchHandler from './two_touch'; const ZOOM_THRESHOLD = 0.1; diff --git a/packages/renderer/src/regl/ReglModel.ts b/packages/renderer/src/regl/ReglModel.ts index 3a2540acaa..7632a08885 100644 --- a/packages/renderer/src/regl/ReglModel.ts +++ b/packages/renderer/src/regl/ReglModel.ts @@ -81,12 +81,12 @@ export default class ReglModel implements IModel { drawParams.instances = instances; } + // Tip: // elements 中可能包含 count,此时不应传入 + // count 和 elements 相比、count 优先 if (count) { drawParams.count = count; - } - - if (elements) { + } else if (elements) { drawParams.elements = (elements as ReglElements).get(); } diff --git a/packages/scene/__tests__/l7_map.spec.ts b/packages/scene/__tests__/l7_map.spec.ts new file mode 100644 index 0000000000..003374840c --- /dev/null +++ b/packages/scene/__tests__/l7_map.spec.ts @@ -0,0 +1,9 @@ +// @ts-ignore +import { PolygonLayer } from '@antv/l7-layers'; +import { Map } from '@antv/l7-maps'; +import { Scene } from '../src/'; +describe('template', () => { + it('scene l7 map method', () => { + expect(2).toEqual(2); + }); +}); diff --git a/packages/site/examples/gallery/animate/demo/grid.js b/packages/site/examples/gallery/animate/demo/grid.js index abc5d3efa1..f39c9dd78d 100644 --- a/packages/site/examples/gallery/animate/demo/grid.js +++ b/packages/site/examples/gallery/animate/demo/grid.js @@ -321,7 +321,7 @@ img.onload = function() { type: 'Feature', properties: {}, geometry: { - type: 'LineString', + type: 'MultiLineString', coordinates: d1 } }, @@ -329,7 +329,7 @@ img.onload = function() { type: 'Feature', properties: {}, geometry: { - type: 'LineString', + type: 'MultiLineString', coordinates: d2 } } diff --git a/packages/utils/src/dom.ts b/packages/utils/src/dom.ts index aebb046108..ea55074ef4 100644 --- a/packages/utils/src/dom.ts +++ b/packages/utils/src/dom.ts @@ -1,5 +1,4 @@ -import { pull } from 'lodash'; -import { $window, isMini } from './mini-adapter'; +import { $window } from './mini-adapter'; type ELType = HTMLElement | SVGElement; export function getContainer(domId: string | HTMLDivElement) { @@ -171,46 +170,3 @@ export function getViewPortScale() { } export const DPR = getViewPortScale() < 1 ? 1 : $window.devicePixelRatio; - -export function addStyle(el: ELType, style: string) { - el.setAttribute('style', `${el.style.cssText}${style}`); -} - -export function getStyleList(style: string): string[] { - return style - .split(';') - .map((item) => item.trim()) - .filter((item) => item); -} - -export function removeStyle(el: ELType, style: string) { - const oldStyleList = getStyleList(el.getAttribute('style') ?? ''); - const targetStyleList = getStyleList(style); - const newStyleList = pull(oldStyleList, ...targetStyleList); - el.setAttribute('style', newStyleList.join(';')); -} - -export function css2Style(obj: any) { - return Object.entries(obj) - .map(([key, value]) => `${key}: ${value}`) - .join(';'); -} - -export function getDiffRect(dom1Rect: any, dom2Rect: any) { - return { - left: dom1Rect.left - dom2Rect.left, - top: dom1Rect.top - dom2Rect.top, - right: dom2Rect.left + dom2Rect.width - dom1Rect.left - dom1Rect.width, - bottom: dom2Rect.top + dom2Rect.height - dom1Rect.top - dom1Rect.height, - }; -} - -export function setChecked(el: ELType, value: boolean) { - // @ts-ignore - el.checked = value; - if (value) { - el.setAttribute('checked', 'true'); - } else { - el.removeAttribute('checked'); - } -} diff --git a/stories/Map/components/gridTile.tsx b/stories/Map/components/gridTile.tsx index 4d57af478b..4047c2bc8f 100644 --- a/stories/Map/components/gridTile.tsx +++ b/stories/Map/components/gridTile.tsx @@ -106,7 +106,7 @@ export default class GridTile extends React.Component { type: 'Feature', properties: {}, geometry: { - type: 'LineString', + type: 'MultiLineString', coordinates: d1, }, }, @@ -114,7 +114,7 @@ export default class GridTile extends React.Component { type: 'Feature', properties: {}, geometry: { - type: 'LineString', + type: 'MultiLineString', coordinates: d2, }, },