mirror of https://gitee.com/antv-l7/antv-l7
chore: 代码警告清理 & 部分代码优化 (#1392)
* chore: 完善属性注册的写法 * feat: clean code & fix raster pick failed * chore: code clean * style: lint style Co-authored-by: shihui <yiqianyao.yqy@alibaba-inc.com>
This commit is contained in:
parent
3b2bdc3999
commit
849c095ea8
|
@ -35,7 +35,7 @@ export default () => {
|
|||
zoomOffset: 0,
|
||||
extent: [-180, -85.051129, 179, 85.051129],
|
||||
minZoom: 0,
|
||||
format: async (data: any, bands) => {
|
||||
format: async (data: any) => {
|
||||
// console.log(bands)
|
||||
const blob: Blob = new Blob([new Uint8Array(data)], {
|
||||
type: 'image/png',
|
||||
|
|
|
@ -105,11 +105,18 @@ export default () => {
|
|||
rampColors: {
|
||||
colors: colorList,
|
||||
positions
|
||||
// colors: ['#f00', '#f00'],
|
||||
// positions: [0, 1]
|
||||
}
|
||||
});
|
||||
|
||||
scene.addLayer(layer);
|
||||
|
||||
layer.on('click', (e) => {
|
||||
console.log('layer click')
|
||||
console.log(e)
|
||||
})
|
||||
|
||||
// setTimeout(() => {
|
||||
// layer.style({
|
||||
// rampColors: {
|
||||
|
|
|
@ -22,7 +22,7 @@ const MAX_CANVAS_WIDTH = 1024;
|
|||
const BASELINE_SCALE = 1.0;
|
||||
const HEIGHT_SCALE = 1.0;
|
||||
const CACHE_LIMIT = 3;
|
||||
const VALID_PROPS = [
|
||||
export const VALID_PROPS = [
|
||||
'fontFamily',
|
||||
'fontWeight',
|
||||
'characterSet',
|
||||
|
|
|
@ -79,7 +79,7 @@ export default class PickingService implements IPickingService {
|
|||
box: [number, number, number, number],
|
||||
cb: (...args: any[]) => void,
|
||||
): Promise<any> {
|
||||
const { useFramebuffer, clear, getContainer } = this.rendererService;
|
||||
const { useFramebuffer, clear } = this.rendererService;
|
||||
this.resizePickingFBO();
|
||||
useFramebuffer(this.pickingFBO, () => {
|
||||
clear({
|
||||
|
|
|
@ -78,6 +78,7 @@ export default class StyleAttribute implements IStyleAttribute {
|
|||
return this.scale?.defaultValues || [];
|
||||
}
|
||||
return params.map((param, idx) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const scaleFunc = this.scale?.scalers![idx].func;
|
||||
// @ts-ignore // TODO 支持双变量映射
|
||||
const value = scaleFunc(param);
|
||||
|
|
|
@ -151,6 +151,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
|
|||
vertexIdx++
|
||||
) {
|
||||
const normal = normals
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
? normals!.slice(vertexIdx * 3, vertexIdx * 3 + 3)
|
||||
: [];
|
||||
featureData.push(
|
||||
|
@ -222,6 +223,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
|
|||
(descriptor: IVertexAttributeDescriptor, attributeIdx: number) => {
|
||||
if (descriptor) {
|
||||
// IAttribute 参数透传
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { buffer, update, name, ...rest } = descriptor;
|
||||
|
||||
const vertexAttribute = createAttribute({
|
||||
|
@ -282,8 +284,10 @@ export default class StyleAttributeService implements IStyleAttributeService {
|
|||
});
|
||||
let verticesNum = 0;
|
||||
let vecticesCount = 0; // 在不使用 element 的时候记录顶点、图层所有顶点的总数
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const vertices: number[] = [];
|
||||
const indices: number[] = [];
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const normals: number[] = [];
|
||||
let size = 3;
|
||||
features.forEach((feature, featureIdx) => {
|
||||
|
@ -336,7 +340,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
|
|||
if (indexes && indexes[vertexIdx] !== undefined) {
|
||||
vertexIndex = indexes[vertexIdx];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
descriptors.forEach((descriptor, attributeIdx) => {
|
||||
if (descriptor && descriptor.update) {
|
||||
(descriptor.buffer.data as number[]).push(
|
||||
|
@ -366,6 +370,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
|
|||
descriptors.forEach((descriptor, attributeIdx) => {
|
||||
if (descriptor) {
|
||||
// IAttribute 参数透传
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { buffer, update, name, ...rest } = descriptor;
|
||||
|
||||
const vertexAttribute = createAttribute({
|
||||
|
@ -460,7 +465,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
|
|||
if (indexes && indexes[vertexIdx] !== undefined) {
|
||||
vertexIndex = indexes[vertexIdx];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
descriptors.forEach((descriptor, attributeIdx) => {
|
||||
if (descriptor && descriptor.update) {
|
||||
(descriptor.buffer.data as number[]).push(
|
||||
|
@ -486,6 +491,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
|
|||
descriptors.forEach((descriptor, attributeIdx) => {
|
||||
if (descriptor) {
|
||||
// IAttribute 参数透传
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { buffer, update, name, ...rest } = descriptor;
|
||||
|
||||
const vertexAttribute = createAttribute({
|
||||
|
|
|
@ -35,7 +35,7 @@ type stencilOp =
|
|||
| gl.DECR
|
||||
| gl.INCR_WRAP
|
||||
| gl.DECR_WRAP;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
type BlendingFunctionCombined = Partial<{
|
||||
src:
|
||||
| gl.ZERO
|
||||
|
|
|
@ -54,6 +54,7 @@ export default class BaseNormalPass<InitializationOptions = {}>
|
|||
.get<IShaderModuleService>(TYPES.IShaderModuleService);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public render(layer: ILayer) {
|
||||
//
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ export default class PostProcessor implements IPostProcessor {
|
|||
*/
|
||||
public getReadFBOTex() {
|
||||
const { useFramebuffer } = this.rendererService;
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve) => {
|
||||
useFramebuffer(this.readFBO, async () => {
|
||||
resolve(this.getCurrentFBOTex());
|
||||
});
|
||||
|
|
|
@ -56,6 +56,7 @@ export interface ICellProperty {
|
|||
count: number;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export default class BaseModel<ChildLayerStyleOptions = {}>
|
||||
implements ILayerModel {
|
||||
public triangulation: Triangulation;
|
||||
|
|
|
@ -428,7 +428,6 @@ export function HeatmapTriangulation(feature: IEncodeFeature) {
|
|||
if (coordinates.length === 2) {
|
||||
coordinates.push(0);
|
||||
}
|
||||
const size = feature.size as number;
|
||||
const dir = addDir(-1, 1);
|
||||
const dir1 = addDir(1, 1);
|
||||
const dir2 = addDir(-1, -1);
|
||||
|
@ -468,7 +467,7 @@ function getGeometry(shape: ShapeType3D, needFlat = false): IExtrudeGeomety {
|
|||
return geometry;
|
||||
}
|
||||
|
||||
function computeVertexNormals(
|
||||
export function computeVertexNormals(
|
||||
positions: number[],
|
||||
indexArray: number[],
|
||||
dim: number = 3,
|
||||
|
@ -525,7 +524,7 @@ function normalizeNormals(normals: Float32Array) {
|
|||
}
|
||||
}
|
||||
|
||||
function checkIsClosed(points: number[][][]) {
|
||||
export function checkIsClosed(points: number[][][]) {
|
||||
const p1 = points[0][0];
|
||||
const p2 = points[0][points[0].length - 1];
|
||||
return p1[0] === p2[0] && p1[1] === p2[1];
|
||||
|
|
|
@ -169,7 +169,6 @@ export default class HeatMapModel extends BaseModel {
|
|||
dstAlpha: 1,
|
||||
},
|
||||
},
|
||||
pick: false
|
||||
});
|
||||
return model;
|
||||
}
|
||||
|
@ -194,7 +193,6 @@ export default class HeatMapModel extends BaseModel {
|
|||
createModel,
|
||||
} = this.rendererService;
|
||||
return createModel({
|
||||
pick: false,
|
||||
vs,
|
||||
fs,
|
||||
attributes: {
|
||||
|
|
|
@ -101,7 +101,6 @@ export default class ImageDataModel extends BaseModel {
|
|||
depth: { enable: false },
|
||||
blend: this.getBlend(),
|
||||
stencil: getMask(mask, maskInside),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
callbackModel([model]);
|
||||
|
|
|
@ -79,7 +79,6 @@ export default class ImageModel extends BaseModel {
|
|||
},
|
||||
depth: { enable: false },
|
||||
stencil: getMask(mask, maskInside),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
callbackModel([model]);
|
||||
|
|
|
@ -87,7 +87,6 @@ export default class ImageDataModel extends BaseModel {
|
|||
depth: { enable: false },
|
||||
blend: this.getBlend(),
|
||||
stencil: getMask(mask, maskInside),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
callbackModel([model]);
|
||||
|
|
|
@ -163,9 +163,6 @@ export default class GreatCircleModel extends BaseModel {
|
|||
size: 1,
|
||||
update: (
|
||||
feature: IEncodeFeature,
|
||||
featureIdx: number,
|
||||
vertex: number[],
|
||||
attributeIdx: number,
|
||||
) => {
|
||||
const { size = 1 } = feature;
|
||||
return Array.isArray(size) ? [size[0]] : [size as number];
|
||||
|
@ -188,7 +185,6 @@ export default class GreatCircleModel extends BaseModel {
|
|||
feature: IEncodeFeature,
|
||||
featureIdx: number,
|
||||
vertex: number[],
|
||||
attributeIdx: number,
|
||||
) => {
|
||||
return [vertex[3], vertex[4], vertex[5], vertex[6]];
|
||||
},
|
||||
|
@ -209,9 +205,6 @@ export default class GreatCircleModel extends BaseModel {
|
|||
size: 2,
|
||||
update: (
|
||||
feature: IEncodeFeature,
|
||||
featureIdx: number,
|
||||
vertex: number[],
|
||||
attributeIdx: number,
|
||||
) => {
|
||||
const iconMap = this.iconService.getIconMap();
|
||||
const { texture } = feature;
|
||||
|
|
|
@ -121,6 +121,7 @@ export default class FeatureScalePlugin implements ILayerPlugin {
|
|||
if (attribute.scale) {
|
||||
// 创建Scale
|
||||
const attributeScale = attribute.scale;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
attributeScale.names = this.parseFields(attribute!.scale!.field || []);
|
||||
const scales: IStyleScale[] = [];
|
||||
// 为每个字段创建 Scale
|
||||
|
@ -245,6 +246,7 @@ export default class FeatureScalePlugin implements ILayerPlugin {
|
|||
}
|
||||
return styleScale;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const firstValue = data!.find((d) => !isNil(d[field]))?.[field];
|
||||
// 常量 Scale
|
||||
if (this.isNumber(field) || (isNil(firstValue) && !scaleOption)) {
|
||||
|
|
|
@ -82,7 +82,7 @@ export function generateLightingUniforms(
|
|||
if (!lights || !lights.length) {
|
||||
lights = [DEFAULT_LIGHT];
|
||||
}
|
||||
lights.forEach(({ type = 'directional', ...rest }, i) => {
|
||||
lights.forEach(({ type = 'directional', ...rest }) => {
|
||||
const lightsUniformName = lightTypeUniformMap[type].lights;
|
||||
const lightsNumUniformName = lightTypeUniformMap[type].num;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from '@antv/l7-core';
|
||||
import { injectable } from 'inversify';
|
||||
import 'reflect-metadata';
|
||||
import { isTileGroup } from '../tile/utils';
|
||||
|
||||
/**
|
||||
* 在初始化阶段完成属性的注册,以及首次根据 Layer 指定的三角化方法完成 indices 和 attribute 的创建
|
||||
|
@ -21,6 +22,9 @@ export default class RegisterStyleAttributePlugin implements ILayerPlugin {
|
|||
}: { styleAttributeService: IStyleAttributeService },
|
||||
) {
|
||||
layer.hooks.init.tap('RegisterStyleAttributePlugin', () => {
|
||||
// 过滤 tileGroup layer (瓦片图层不需要注册)
|
||||
if (isTileGroup(layer)) return;
|
||||
|
||||
this.registerBuiltinAttributes(styleAttributeService, layer);
|
||||
});
|
||||
}
|
||||
|
@ -29,23 +33,15 @@ export default class RegisterStyleAttributePlugin implements ILayerPlugin {
|
|||
styleAttributeService: IStyleAttributeService,
|
||||
layer: ILayer,
|
||||
) {
|
||||
// 过滤 tileGroup layer (瓦片图层)
|
||||
const source = layer.getSource();
|
||||
switch (source.parser.type) {
|
||||
case 'mvt':
|
||||
case 'testTile':
|
||||
case 'rasterTile':
|
||||
// layer 仅作为 group 使用
|
||||
return;
|
||||
}
|
||||
|
||||
// MaskLayer 只需要注册 a_Position
|
||||
if (layer.type === 'MaskLayer') {
|
||||
this.registerPositionAttribute(styleAttributeService);
|
||||
return;
|
||||
}
|
||||
|
||||
// 用途为 basemap 的 Layer 也只需要注册 a_Position
|
||||
const { usage } = layer.getLayerConfig();
|
||||
if (usage === 'basemap ') {
|
||||
if (usage === 'basemap') {
|
||||
this.registerPositionAttribute(styleAttributeService);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -157,9 +157,6 @@ export default class ImageModel extends BaseModel {
|
|||
size: 2,
|
||||
update: (
|
||||
feature: IEncodeFeature,
|
||||
featureIdx: number,
|
||||
vertex: number[],
|
||||
attributeIdx: number,
|
||||
) => {
|
||||
const iconMap = this.iconService.getIconMap();
|
||||
const { shape } = feature;
|
||||
|
|
|
@ -60,7 +60,6 @@ export default class OceanModel extends BaseModel {
|
|||
primitive: gl.TRIANGLES,
|
||||
depth: { enable: false },
|
||||
stencil: getMask(mask, maskInside),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
callbackModel([model]);
|
||||
|
|
|
@ -53,7 +53,6 @@ export default class WaterModel extends BaseModel {
|
|||
primitive: gl.TRIANGLES,
|
||||
depth: { enable: false },
|
||||
stencil: getMask(mask, maskInside),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
callbackModel([model]);
|
||||
|
|
|
@ -100,7 +100,6 @@ export default class RasterModel extends BaseModel {
|
|||
primitive: gl.TRIANGLES,
|
||||
depth: { enable: false },
|
||||
stencil: getMask(mask, maskInside),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
callbackModel([model]);
|
||||
|
|
|
@ -84,7 +84,6 @@ export default class RasterModel extends BaseModel {
|
|||
primitive: gl.TRIANGLES,
|
||||
depth: { enable: false },
|
||||
stencil: getMask(mask, maskInside),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
callbackModel([model]);
|
||||
|
|
|
@ -64,7 +64,6 @@ export default class RasterModel extends BaseModel {
|
|||
triangulation: RasterImageTriangulation,
|
||||
depth: { enable: false },
|
||||
stencil: getMask(mask, maskInside),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
callbackModel([model]);
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
ISubLayerInitOptions,
|
||||
} from '@antv/l7-core';
|
||||
import Source from '@antv/l7-source';
|
||||
import { osmLonLat2TileXY, Tile, TilesetManager } from '@antv/l7-utils';
|
||||
import { Tile, TilesetManager } from '@antv/l7-utils';
|
||||
import { setStyleAttributeField, setScale } from '../style/utils';
|
||||
import { registerLayers } from '../utils';
|
||||
import { readRasterValue } from '../interaction/getRasterData';
|
||||
|
@ -25,6 +25,8 @@ import {
|
|||
Timeout,
|
||||
} from '../interface';
|
||||
|
||||
type IEvent = { lngLat: {lng: number, lat: number}, x: number, y: number, value: any};
|
||||
|
||||
const EMPTY_FEATURE_DATA = {
|
||||
features: [],
|
||||
featureId: null,
|
||||
|
@ -197,100 +199,103 @@ export default class TileFactory implements ITileFactory {
|
|||
|
||||
protected getTile(lng: number, lat: number) {
|
||||
const zoom = this.mapService.getZoom();
|
||||
const z = Math.ceil(zoom) + this.zoomOffset;
|
||||
const xy = osmLonLat2TileXY(lng, lat, z);
|
||||
|
||||
const tiles = this.tilesetManager.tiles.filter(
|
||||
(t) => t.key === `${xy[0]},${xy[1]},${z}`,
|
||||
);
|
||||
return tiles[0];
|
||||
return this.tilesetManager.getTileByLngLat(lng, lat, zoom);
|
||||
}
|
||||
|
||||
protected emitEvent(layers: ILayer[], isVector?: boolean) {
|
||||
private bindVectorEvent(layer: ILayer) {
|
||||
layer.on('click', (e) => {
|
||||
this.eventCache.click = 1;
|
||||
this.getFeatureAndEmitEvent('subLayerClick', e);
|
||||
});
|
||||
layer.on('mousemove', (e) => {
|
||||
this.eventCache.mousemove = 1;
|
||||
this.getFeatureAndEmitEvent('subLayerMouseMove', e);
|
||||
});
|
||||
layer.on('mouseenter', (e) => {
|
||||
this.getFeatureAndEmitEvent('subLayerMouseEnter', e);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private readRasterTile(e: IEvent, name: string) {
|
||||
const { lng, lat } = e.lngLat;
|
||||
const tile = this.getTile(lng, lat);
|
||||
if(!tile) return;
|
||||
const data = readRasterValue(tile, this.mapService, e.x, e.y);
|
||||
e.value = data;
|
||||
this.parentLayer.emit(name, e);
|
||||
}
|
||||
|
||||
private bindRasterEvent(layer: ILayer) {
|
||||
layer.on('click', (e) => {
|
||||
this.eventCache.click = 1;
|
||||
this.readRasterTile(e, 'subLayerClick');
|
||||
});
|
||||
layer.on('mousemove', (e) => {
|
||||
this.eventCache.mousemove = 1;
|
||||
this.readRasterTile(e, 'subLayerMouseMove');
|
||||
});
|
||||
layer.on('mouseenter', (e) => {
|
||||
this.readRasterTile(e, 'subLayerMouseMove');
|
||||
});
|
||||
}
|
||||
|
||||
private bindCommonEvent(layer: ILayer) {
|
||||
layer.on('mouseup', (e) => {
|
||||
this.eventCache.mouseup = 1;
|
||||
this.getFeatureAndEmitEvent('subLayerMouseUp', e);
|
||||
});
|
||||
|
||||
layer.on('mouseout', (e) => {
|
||||
this.getFeatureAndEmitEvent('subLayerMouseOut', e);
|
||||
});
|
||||
layer.on('mousedown', (e) => {
|
||||
this.eventCache.mousedown = 1;
|
||||
this.getFeatureAndEmitEvent('subLayerMouseDown', e);
|
||||
});
|
||||
layer.on('contextmenu', (e) => {
|
||||
this.eventCache.contextmenu = 1;
|
||||
this.getFeatureAndEmitEvent('subLayerContextmenu', e);
|
||||
});
|
||||
|
||||
// out side
|
||||
layer.on('unclick', (e) =>
|
||||
this.handleOutsideEvent('click', 'subLayerUnClick', layer, e),
|
||||
);
|
||||
layer.on('unmouseup', (e) =>
|
||||
this.handleOutsideEvent('mouseup', 'subLayerUnMouseUp', layer, e),
|
||||
);
|
||||
layer.on('unmousedown', (e) =>
|
||||
this.handleOutsideEvent('mousedown', 'subLayerUnMouseDown', layer, e),
|
||||
);
|
||||
layer.on('uncontextmenu', (e) =>
|
||||
this.handleOutsideEvent(
|
||||
'contextmenu',
|
||||
'subLayerUnContextmenu',
|
||||
layer,
|
||||
e,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected emitEvent(layers: ILayer[]) {
|
||||
layers.map((layer) => {
|
||||
layer.once('modelLoaded', () => {
|
||||
layer.on('click', (e) => {
|
||||
this.eventCache.click = 1;
|
||||
if (this.parentLayer.type === 'RasterLayer') {
|
||||
const { lng, lat } = e.lngLat;
|
||||
const tile = this.getTile(lng, lat);
|
||||
tile && this.getFeatureAndEmitEvent(
|
||||
layer,
|
||||
'subLayerClick',
|
||||
e,
|
||||
isVector,
|
||||
tile,
|
||||
);
|
||||
} else {
|
||||
this.getFeatureAndEmitEvent(layer, 'subLayerClick', e);
|
||||
}
|
||||
});
|
||||
this.bindVectorEvent(layer);
|
||||
|
||||
layer.on('mousemove', (e) => {
|
||||
this.eventCache.mousemove = 1;
|
||||
if (this.parentLayer.type === 'RasterLayer') {
|
||||
const { lng, lat } = e.lngLat;
|
||||
const tile = this.getTile(lng, lat);
|
||||
tile && this.getFeatureAndEmitEvent(
|
||||
layer,
|
||||
'subLayerMouseMove',
|
||||
e,
|
||||
isVector,
|
||||
tile,
|
||||
);
|
||||
} else {
|
||||
this.getFeatureAndEmitEvent(layer, 'subLayerMouseMove', e);
|
||||
}
|
||||
});
|
||||
layer.on('mouseup', (e) => {
|
||||
this.eventCache.mouseup = 1;
|
||||
this.getFeatureAndEmitEvent(layer, 'subLayerMouseUp', e);
|
||||
});
|
||||
layer.on('mouseenter', (e) => {
|
||||
if (this.parentLayer.type === 'RasterLayer') {
|
||||
const { lng, lat } = e.lngLat;
|
||||
const tile = this.getTile(lng, lat);
|
||||
tile && this.getFeatureAndEmitEvent(
|
||||
layer,
|
||||
'subLayerMouseMove',
|
||||
e,
|
||||
isVector,
|
||||
tile,
|
||||
);
|
||||
} else {
|
||||
this.getFeatureAndEmitEvent(layer, 'subLayerMouseEnter', e);
|
||||
}
|
||||
});
|
||||
layer.on('mouseout', (e) => {
|
||||
this.getFeatureAndEmitEvent(layer, 'subLayerMouseOut', e);
|
||||
});
|
||||
layer.on('mousedown', (e) => {
|
||||
this.eventCache.mousedown = 1;
|
||||
this.getFeatureAndEmitEvent(layer, 'subLayerMouseDown', e);
|
||||
});
|
||||
layer.on('contextmenu', (e) => {
|
||||
this.eventCache.contextmenu = 1;
|
||||
this.getFeatureAndEmitEvent(layer, 'subLayerContextmenu', e);
|
||||
});
|
||||
this.bindCommonEvent(layer);
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// out side
|
||||
layer.on('unclick', (e) =>
|
||||
this.handleOutsideEvent('click', 'subLayerUnClick', layer, e),
|
||||
);
|
||||
layer.on('unmouseup', (e) =>
|
||||
this.handleOutsideEvent('mouseup', 'subLayerUnMouseUp', layer, e),
|
||||
);
|
||||
layer.on('unmousedown', (e) =>
|
||||
this.handleOutsideEvent('mousedown', 'subLayerUnMouseDown', layer, e),
|
||||
);
|
||||
layer.on('uncontextmenu', (e) =>
|
||||
this.handleOutsideEvent(
|
||||
'contextmenu',
|
||||
'subLayerUnContextmenu',
|
||||
layer,
|
||||
e,
|
||||
),
|
||||
);
|
||||
protected emitRasterEvent(layers: ILayer[]) {
|
||||
layers.map((layer) => {
|
||||
layer.once('modelLoaded', () => {
|
||||
|
||||
this.bindRasterEvent(layer);
|
||||
|
||||
this.bindCommonEvent(layer);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -314,28 +319,18 @@ export default class TileFactory implements ITileFactory {
|
|||
}
|
||||
|
||||
protected getFeatureAndEmitEvent(
|
||||
layer: ILayer,
|
||||
eventName: string,
|
||||
e: any,
|
||||
isVector?: boolean,
|
||||
tile?: any,
|
||||
) {
|
||||
if (isVector === false) {
|
||||
// raster tile get rgb
|
||||
// e.pickedColors = readPixel(e.x, e.y, this.rendererService);
|
||||
// raster tile origin value
|
||||
e.value = readRasterValue(tile, this.mapService, e.x, e.y);
|
||||
} else {
|
||||
// VectorLayer
|
||||
const featureId = e.featureId;
|
||||
const features = this.getAllFeatures(featureId);
|
||||
try {
|
||||
e.feature = this.getCombineFeature(features);
|
||||
} catch (err) {
|
||||
console.warn('Combine Featuer Err! Return First Feature!');
|
||||
e.feature = features[0];
|
||||
}
|
||||
const featureId = e.featureId;
|
||||
const features = this.getAllFeatures(featureId);
|
||||
try {
|
||||
e.feature = this.getCombineFeature(features);
|
||||
} catch (err) {
|
||||
console.warn('Combine Featuer Err! Return First Feature!');
|
||||
e.feature = features[0];
|
||||
}
|
||||
|
||||
this.parentLayer.emit(eventName, e);
|
||||
}
|
||||
|
||||
|
@ -378,7 +373,7 @@ export default class TileFactory implements ITileFactory {
|
|||
if (this.eventCache[type] > 0) {
|
||||
this.eventCache[type] = 0;
|
||||
} else {
|
||||
this.getFeatureAndEmitEvent(layer, emitType, e);
|
||||
this.getFeatureAndEmitEvent(emitType, e);
|
||||
}
|
||||
}, 64);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ export default class VectorLayer extends BaseLayer<
|
|||
> {
|
||||
public needListen: boolean = true;
|
||||
public isVector: boolean = true;
|
||||
public isTileLayer: boolean = true;
|
||||
public type: string = this.layerType as string || 'vectorLayer';
|
||||
// Tip: 单独被 tile 瓦片的渲染链路使用(用于优化性能)
|
||||
private pickedID: number | null = null;
|
||||
|
|
|
@ -51,8 +51,7 @@ export default class RasterTiffTile extends TileFactory {
|
|||
clampHigh,
|
||||
clampLow,
|
||||
});
|
||||
this.emitEvent([layer], false);
|
||||
|
||||
this.emitRasterEvent([layer]);
|
||||
return {
|
||||
layers: [layer],
|
||||
layerIDList: [layer.id],
|
||||
|
|
|
@ -64,10 +64,6 @@ export default class TestTile extends TileFactory {
|
|||
color: '#000'
|
||||
});
|
||||
|
||||
// Tip: sign tile layer
|
||||
text.isTileLayer = true;
|
||||
line.isTileLayer = true;
|
||||
|
||||
return {
|
||||
layers: [line, text],
|
||||
layerIDList: [line.id, text.id],
|
||||
|
|
|
@ -5,6 +5,16 @@ import { updateLayersConfig } from './style/utils';
|
|||
|
||||
export const tileVectorParser = ['mvt', 'geojsonvt', 'testTile'];
|
||||
|
||||
/**
|
||||
* 判断当前图层是否是瓦片图层
|
||||
* @param layer
|
||||
* @returns
|
||||
*/
|
||||
export function isTileGroup(layer: ILayer) {
|
||||
const source = layer.getSource();
|
||||
return tileVectorParser.includes(source.parser.type);
|
||||
}
|
||||
|
||||
export function isVectorTile(parserType: string) {
|
||||
return tileVectorParser.indexOf(parserType) >= 0;
|
||||
}
|
||||
|
|
|
@ -19,9 +19,6 @@ interface IConfigToUpdate {
|
|||
textOffset?: any;
|
||||
}
|
||||
|
||||
// 画布默认的宽度
|
||||
const WIDTH = 1024;
|
||||
|
||||
/**
|
||||
* 当 style 中使用的 opacity 不是常数的时候根据数据进行映射
|
||||
* @param field
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { aProjectFlat } from '@antv/l7-utils';
|
||||
import { vec2, vec3 } from 'gl-matrix';
|
||||
const tmp = vec2.create();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const capEnd = vec2.create();
|
||||
const lineA = vec2.create();
|
||||
const lineB = vec2.create();
|
||||
|
@ -33,7 +34,7 @@ function isPointEqual(a: vec2, b: vec2) {
|
|||
return a[0] === b[0] && a[1] === b[1];
|
||||
}
|
||||
|
||||
function getArrayUnique(matrix: number[][]) {
|
||||
export function getArrayUnique(matrix: number[][]) {
|
||||
const map = new Map();
|
||||
for (let i = 0; i < matrix.length; i++) {
|
||||
const key = matrix[0].toString() + '-' + matrix[1].toString();
|
||||
|
@ -375,6 +376,7 @@ export default class ExtrudePolyline {
|
|||
next: vec3,
|
||||
originLast: vec3,
|
||||
originCur: vec3,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
originNext: vec3,
|
||||
) {
|
||||
let count = 0;
|
||||
|
|
|
@ -25,7 +25,7 @@ export function createMultiPassRenderer(
|
|||
normalPassFactory: (name: string) => IPass<unknown>,
|
||||
) {
|
||||
const multiPassRenderer = layer.multiPassRenderer;
|
||||
const { enablePicking, enableTAA } = layer.getLayerConfig();
|
||||
const { enableTAA } = layer.getLayerConfig();
|
||||
|
||||
// picking pass if enabled
|
||||
// if (enablePicking) {
|
||||
|
|
|
@ -123,7 +123,6 @@ export default class WindModel extends BaseModel {
|
|||
depth: { enable: false },
|
||||
stencil: getMask(mask, maskInside),
|
||||
blend: this.getBlend(),
|
||||
pick: false,
|
||||
})
|
||||
.then((model) => {
|
||||
this.colorModel = model;
|
||||
|
|
|
@ -79,9 +79,11 @@ export default class Camera extends EventEmitter {
|
|||
renderWorldCopies,
|
||||
);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public requestRenderFrame(cb: CallBack): number {
|
||||
return 0;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public cancelRenderFrame(_: number): void {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -141,6 +141,7 @@ export class EarthMap extends Camera {
|
|||
this.transform.setMaxBounds(LngLatBounds.convert(bounds));
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public setStyle(style: any) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ const earthCircumfrence = 2 * Math.PI * earthRadius; // meters
|
|||
/*
|
||||
* The circumference at a line of latitude in meters.
|
||||
*/
|
||||
function circumferenceAtLatitude(latitude: number) {
|
||||
export function circumferenceAtLatitude(latitude: number) {
|
||||
return earthCircumfrence * Math.cos((latitude * Math.PI) / 180);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ export function mercatorYfromLat(lat: number) {
|
|||
return lat;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function mercatorZfromAltitude(altitude: number, lat: number) {
|
||||
return altitude;
|
||||
}
|
||||
|
@ -32,6 +33,7 @@ export function latFromMercatorY(y: number) {
|
|||
return y;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function altitudeFromMercatorZ(z: number, y: number) {
|
||||
return z;
|
||||
}
|
||||
|
@ -46,6 +48,7 @@ export function altitudeFromMercatorZ(z: number, y: number) {
|
|||
* @returns {number} scale factor
|
||||
* @private
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function mercatorScale(lat: number) {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -97,11 +97,13 @@ export default class MouseHandler {
|
|||
return this.active;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected correctButton(e: MouseEvent, button: number) {
|
||||
// eslint-disable-line
|
||||
return false; // implemented by child
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected move(lastPoint: Point, point: Point) {
|
||||
// eslint-disable-line
|
||||
return; // implemented by child
|
||||
|
|
|
@ -19,12 +19,16 @@ export default class TwoTouchHandler {
|
|||
//@ts-ignore
|
||||
delete this.firstTwoTouches;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public start(points: [Point, Point]) {
|
||||
return;
|
||||
} // eslint-disable-line
|
||||
public move(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
points: [Point, Point],
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
pinchAround: Point | null,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
e: TouchEvent,
|
||||
) {
|
||||
return;
|
||||
|
|
|
@ -173,6 +173,7 @@ export class Map extends Camera {
|
|||
this.transform.setMaxBounds(LngLatBounds.convert(bounds));
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public setStyle(style: any) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -127,10 +127,7 @@ export default class Viewport implements IViewport {
|
|||
/**
|
||||
* P20 坐标系,固定 scale
|
||||
*/
|
||||
public projectFlat(
|
||||
lngLat: [number, number],
|
||||
scale?: number | undefined,
|
||||
): [number, number] {
|
||||
public projectFlat(lngLat: [number, number]): [number, number] {
|
||||
const maxs = 85.0511287798;
|
||||
const lat = Math.max(Math.min(maxs, lngLat[1]), -maxs);
|
||||
// tslint:disable-next-line:no-bitwise
|
||||
|
|
|
@ -148,7 +148,6 @@ export default class AMapBaseService
|
|||
public getCenter(options?: ICameraOptions): ILngLat {
|
||||
if (options?.padding) {
|
||||
const originCenter = this.getCenter();
|
||||
const [w, h] = this.getSize();
|
||||
const padding = toPaddingOptions(options.padding);
|
||||
const px = this.lngLatToPixel([originCenter.lng, originCenter.lat]);
|
||||
const offsetPx = [
|
||||
|
@ -295,7 +294,9 @@ export default class AMapBaseService
|
|||
}
|
||||
|
||||
public lngLatToMercator(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
lnglat: [number, number],
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
altitude: number,
|
||||
): IMercator {
|
||||
return {
|
||||
|
@ -398,7 +399,7 @@ export default class AMapBaseService
|
|||
version: AMAP_VERSION, // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
||||
plugins: plugin, // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
||||
})
|
||||
.then((AMap) => {
|
||||
.then(() => {
|
||||
resolveMap();
|
||||
|
||||
if (pendingResolveQueue.length) {
|
||||
|
@ -437,6 +438,7 @@ export default class AMapBaseService
|
|||
return coordDis / meterDis;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public updateView(viewOption: Partial<IMapCamera>): void {}
|
||||
public getOverlayContainer(): HTMLElement | undefined {
|
||||
return undefined;
|
||||
|
|
|
@ -15,7 +15,7 @@ export default class ReglFramebuffer implements IFramebuffer {
|
|||
private framebuffer: regl.Framebuffer;
|
||||
|
||||
constructor(reGl: regl.Regl, options: IFramebufferInitializationOptions) {
|
||||
const { width, height, color, colors, depth, stencil } = options;
|
||||
const { width, height, color, colors } = options;
|
||||
|
||||
const framebufferOptions: regl.FramebufferOptions = {
|
||||
width,
|
||||
|
|
|
@ -57,9 +57,6 @@ describe('ReglAttribute', () => {
|
|||
});
|
||||
|
||||
it('should update buffer correctly', () => {
|
||||
const buffer = new ReglBuffer(reGL, {
|
||||
data: [-4, -4, 4, -4, 0, 4],
|
||||
});
|
||||
|
||||
const attribute = new ReglAttribute(reGL, {
|
||||
buffer: new ReglBuffer(reGL, {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { IParserData } from '@antv/l7-core';
|
||||
type CallBack = (...args: any[]) => any;
|
||||
export function map(data: IParserData, options: { [key: string]: any }) {
|
||||
const { callback } = options;
|
||||
if (callback) {
|
||||
|
|
|
@ -211,7 +211,6 @@ export default class ThreeJSLayer
|
|||
}
|
||||
|
||||
public renderAMapModels() {
|
||||
const gl = this.rendererService.getGLContext();
|
||||
// gl.frontFace(gl.CCW);
|
||||
// gl.enable(gl.CULL_FACE);
|
||||
// gl.cullFace(gl.BACK);
|
||||
|
@ -236,6 +235,7 @@ export default class ThreeJSLayer
|
|||
this.animateMixer.push(mixer);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public setBottomColor(color: string): void {
|
||||
console.warn('empty function');
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ export class AJAXError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function makeFetchRequest(
|
||||
requestParameters: RequestParameters,
|
||||
callback: ResponseCallback<any>,
|
||||
|
@ -233,7 +234,7 @@ export const postData = (
|
|||
return makeRequest({ ...requestParameters, method: 'POST' }, callback);
|
||||
};
|
||||
|
||||
function sameOrigin(url: string) {
|
||||
export function sameOrigin(url: string) {
|
||||
const a = $window.document.createElement('a');
|
||||
a.href = url;
|
||||
return (
|
||||
|
|
|
@ -162,7 +162,7 @@ export function getViewPortScale() {
|
|||
}
|
||||
const contentItems = (meta as any).content?.split(',');
|
||||
const scale = contentItems.find((item: string) => {
|
||||
const [key, value] = item.split('=');
|
||||
const [key] = item.split('=');
|
||||
return key === 'initial-scale';
|
||||
});
|
||||
return scale ? scale.split('=')[1] * 1 : 1;
|
||||
|
|
|
@ -215,6 +215,7 @@ export function lnglatDistance(
|
|||
|
||||
return radiansToLength(
|
||||
2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
(units = 'meters'),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ export function greatCircleLineAtOffset(
|
|||
offset: number,
|
||||
thetaOffset: number | undefined,
|
||||
mapVersion: Version | undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
segmentNumber: number = 30,
|
||||
autoFit: boolean,
|
||||
) {
|
||||
|
|
|
@ -19,7 +19,7 @@ export function lineAtOffset(source: Source, option: ILineAtOffset) {
|
|||
}
|
||||
|
||||
export function lineAtOffsetAsyc(source: Source, option: ILineAtOffset) {
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve) => {
|
||||
if (source.inited) {
|
||||
resolve(lineAtOffset(source, option));
|
||||
} else {
|
||||
|
|
|
@ -80,6 +80,7 @@ export class LRUCache {
|
|||
private appendOrder(key: string) {
|
||||
this.order.push(key);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
private defaultDestroy(value: any, key: string) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
getLatLonBoundsBuffer,
|
||||
isLatLonBoundsContains,
|
||||
} from './utils/bound-buffer';
|
||||
import { getTileIndices } from './utils/lonlat-tile';
|
||||
import { getTileIndices, osmLonLat2TileXY } from './utils/lonlat-tile';
|
||||
import { throttle } from 'lodash';
|
||||
|
||||
/**
|
||||
|
@ -165,11 +165,20 @@ export class TilesetManager extends EventEmitter {
|
|||
}
|
||||
|
||||
while (abortCandidates.length > 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const tile = abortCandidates.shift()!;
|
||||
tile.abortLoad();
|
||||
}
|
||||
}
|
||||
|
||||
public getTileByLngLat(lng: number, lat: number, zoom: number) {
|
||||
const { zoomOffset } = this.options;
|
||||
const z = Math.ceil(zoom) + zoomOffset;
|
||||
const xy = osmLonLat2TileXY(lng, lat, z);
|
||||
const tiles = this.tiles.filter((t) => t.key === `${xy[0]},${xy[1]},${z}`);
|
||||
return tiles[0];
|
||||
}
|
||||
|
||||
// 摧毁
|
||||
public destroy() {
|
||||
for (const tile of this.cacheTiles.values()) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { IEncodeFeature } from './interface';
|
||||
|
||||
export function a_Color(feature: IEncodeFeature, featureIdx: number) {
|
||||
export function a_Color(feature: IEncodeFeature) {
|
||||
const { color } = feature;
|
||||
return !color || !color.length ? [1, 1, 1, 1] : color;
|
||||
}
|
||||
|
@ -15,16 +15,11 @@ export function a_Position(
|
|||
: [vertex[0], vertex[1], vertex[2]];
|
||||
}
|
||||
|
||||
export function a_filter(feature: IEncodeFeature, featureIdx: number) {
|
||||
export function a_filter(feature: IEncodeFeature) {
|
||||
const { filter } = feature;
|
||||
return filter ? [1] : [0];
|
||||
}
|
||||
|
||||
export function a_vertexId(
|
||||
feature: IEncodeFeature,
|
||||
featureIdx: number,
|
||||
vertex: number[],
|
||||
attributeIdx: number,
|
||||
) {
|
||||
export function a_vertexId(feature: IEncodeFeature, featureIdx: number) {
|
||||
return [featureIdx];
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { aProjectFlat } from '../geo';
|
||||
const tmp = vec2.create();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const capEnd = vec2.create();
|
||||
const lineA = vec2.create();
|
||||
const lineB = vec2.create();
|
||||
|
@ -33,7 +34,7 @@ function isPointEqual(a: vec2, b: vec2) {
|
|||
return a[0] === b[0] && a[1] === b[1];
|
||||
}
|
||||
|
||||
function getArrayUnique(matrix: number[][]) {
|
||||
export function getArrayUnique(matrix: number[][]) {
|
||||
const map = new Map();
|
||||
for (let i = 0; i < matrix.length; i++) {
|
||||
const key = matrix[0].toString() + '-' + matrix[1].toString();
|
||||
|
@ -267,6 +268,7 @@ export default class ExtrudePolyline {
|
|||
next: vec3,
|
||||
originLast: vec3,
|
||||
originCur: vec3,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
originNext: vec3,
|
||||
) {
|
||||
let count = 0;
|
||||
|
|
|
@ -42,7 +42,6 @@ export const lineModel = async ({
|
|||
feature: IEncodeFeature,
|
||||
featureIdx: number,
|
||||
vertex: number[],
|
||||
attributeIdx: number,
|
||||
) => {
|
||||
return [vertex[5]];
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue