Chore lint update (#1600)

* chore: update lint config

* fix: 移除空行

* fix: util export

* chore: 优化lint 配置
This commit is contained in:
@thinkinggis 2023-02-14 18:01:02 +08:00 committed by GitHub
parent 13b9e3249d
commit 4db42a1814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
160 changed files with 2118 additions and 2235 deletions

View File

@ -172,10 +172,10 @@
"build": " yarn worker && lerna run build", "build": " yarn worker && lerna run build",
"postbuild": "yarn build:declarations", "postbuild": "yarn build:declarations",
"build:declarations": "lerna run tsc --stream --no-bail", "build:declarations": "lerna run tsc --stream --no-bail",
"tslint": "tslint packages/**/src/**/*.ts -c tslint.prod.json", "lint:tslint": "tslint -p tsconfig.json -c tslint.prod.json",
"lint:tslint-fix": "tslint packages/**/src/**/*.ts -c tslint.prod.json --fix", "lint-tslint-fix": "tslint -p tsconfig.json -c tslint.prod.json --fix",
"lint:fix": "prettier --write packages/**/src/**/*.ts packages/site/docs/api/**/*.md packages/site/docs/api/*.md dev-demos/**/**/*.tsx *.md", "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/ dev-demos/ --ext .ts,.tsx", "lint:src": "eslint dev-demos/ --ext .ts,.tsx",
"lint:examples": "eslint packages/site/examples --fix --ext .js", "lint:examples": "eslint packages/site/examples --fix --ext .js",
"lint:css": "stylelint 'packages/**/src/**/*.js{,x}'", "lint:css": "stylelint 'packages/**/src/**/*.js{,x}'",
"lint": "run-p -c lint:*", "lint": "run-p -c lint:*",

View File

@ -7,7 +7,9 @@ class TestControl extends Control {
public onAdd(): HTMLElement { public onAdd(): HTMLElement {
return DOM.create('div'); return DOM.create('div');
} }
public onRemove(): void {} public onRemove(): void {
return;
}
} }
describe('control', () => { describe('control', () => {

View File

@ -27,11 +27,11 @@ describe('mapTheme', () => {
'mapbox://styles/mapbox/streets-v11', 'mapbox://styles/mapbox/streets-v11',
); );
const optionList = ((control const optionList = (
.getPopper() control.getPopper().getContent() as HTMLDivElement
.getContent() as HTMLDivElement).querySelectorAll( ).querySelectorAll(
'.l7-select-control-item', '.l7-select-control-item',
) as unknown) as HTMLDivElement[]; ) as unknown as HTMLDivElement[];
optionList[1].click(); optionList[1].click();
// expect(control.getSelectValue()).toEqual( // expect(control.getSelectValue()).toEqual(

View File

@ -8,7 +8,7 @@ describe('popup', () => {
it('life cycle', () => { it('life cycle', () => {
const popup = new Popup({ const popup = new Popup({
html: '123456', html: '123456',
className: className, className,
lngLat: { lngLat: {
lng: 120, lng: 120,
lat: 30, lat: 30,

View File

@ -27,6 +27,7 @@ class SingleControl extends SelectControl {
} }
} }
// tslint:disable-next-line: max-classes-per-file
class MultiControl extends SelectControl { class MultiControl extends SelectControl {
public getDefault(option: any): any { public getDefault(option: any): any {
return { return {

View File

@ -36,7 +36,8 @@
"supercluster": "^7.0.0" "supercluster": "^7.0.0"
}, },
"devDependencies": { "devDependencies": {
"@antv/l7-test-utils": "2.13.6", "@antv/l7-layers": "^2.13.6",
"@antv/l7-test-utils": "^2.13.6",
"gcoord": "^0.3.2", "gcoord": "^0.3.2",
"less": "^4.1.3" "less": "^4.1.3"
}, },

View File

@ -11,7 +11,7 @@ export interface IButtonControlOption extends IControlOption {
} }
export default class ButtonControl< export default class ButtonControl<
O extends IButtonControlOption = IButtonControlOption O extends IButtonControlOption = IButtonControlOption,
> extends Control<O> { > extends Control<O> {
/** /**
* *

View File

@ -16,7 +16,6 @@ import { Container } from 'inversify';
import { ControlEvent } from '../../interface'; import { ControlEvent } from '../../interface';
export { PositionType } from '@antv/l7-core'; export { PositionType } from '@antv/l7-core';
export { Control }; export { Control };
export interface IControlOption { export interface IControlOption {

View File

@ -1,4 +1,4 @@
export * from './control';
export * from './buttonControl'; export * from './buttonControl';
export * from './control';
export * from './popperControl'; export * from './popperControl';
export * from './selectControl'; export * from './selectControl';

View File

@ -26,7 +26,7 @@ const PopperPlacementMap: Record<PositionName, PopperPlacement> = {
}; };
export default class PopperControl< export default class PopperControl<
O extends IPopperControlOption = IPopperControlOption O extends IPopperControlOption = IPopperControlOption,
> extends ButtonControl<O> { > extends ButtonControl<O> {
/** /**
* *
@ -70,11 +70,8 @@ export default class PopperControl<
} }
public initPopper() { public initPopper() {
const { const { popperClassName, popperPlacement, popperTrigger } =
popperClassName, this.controlOption;
popperPlacement,
popperTrigger,
} = this.controlOption;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const popperContainer = this.mapsService.getMapContainer()!; const popperContainer = this.mapsService.getMapContainer()!;

View File

@ -31,7 +31,7 @@ enum SelectControlConstant {
} }
export default class SelectControl< export default class SelectControl<
O extends ISelectControlOption = ISelectControlOption O extends ISelectControlOption = ISelectControlOption,
> extends PopperControl<O> { > extends PopperControl<O> {
/** /**
* *

View File

@ -6,18 +6,16 @@ import './assets/iconfont/iconfont.js';
import './css/index.css'; import './css/index.css';
export * from './control/baseControl'; export * from './control/baseControl';
export * from './control/logo';
export * from './control/fullscreen';
export * from './control/exportImage'; export * from './control/exportImage';
export * from './control/fullscreen';
export * from './control/geoLocate'; export * from './control/geoLocate';
export * from './control/mapTheme';
export * from './control/layerSwitch'; export * from './control/layerSwitch';
export * from './control/logo';
export * from './control/mapTheme';
export * from './control/mouseLocation'; export * from './control/mouseLocation';
export * from './control/zoom';
export * from './control/scale'; export * from './control/scale';
export * from './popup/popup'; export * from './control/zoom';
export * from './popup/layerPopup';
export { Marker, MarkerLayer };
export * from './interface'; export * from './interface';
export * from './popup/layerPopup';
export * from './popup/popup';
export { Marker, MarkerLayer };

View File

@ -83,7 +83,9 @@ export default class MarkerLayer extends EventEmitter {
// 设置容器大小 // 设置容器大小
private setContainerSize() { private setContainerSize() {
if (!this.mapsService) return; if (!this.mapsService) {
return;
}
const container = this.mapsService.getContainer(); const container = this.mapsService.getContainer();
this.containerSize = { this.containerSize = {
containerWidth: container?.scrollWidth || 0, containerWidth: container?.scrollWidth || 0,
@ -117,7 +119,6 @@ export default class MarkerLayer extends EventEmitter {
// if(this.inited) { // if(this.inited) {
// marker.addTo(this.scene); // marker.addTo(this.scene);
// } // }
} }
public removeMarker(marker: IMarker) { public removeMarker(marker: IMarker) {
@ -274,9 +275,8 @@ export default class MarkerLayer extends EventEmitter {
private clusterMarker(feature: any) { private clusterMarker(feature: any) {
const clusterOption = this.markerLayerOption.clusterOption; const clusterOption = this.markerLayerOption.clusterOption;
const { const { element = this.generateElement.bind(this) } =
element = this.generateElement.bind(this), clusterOption as IMarkerStyleOption;
} = clusterOption as IMarkerStyleOption;
const marker = new Marker({ const marker = new Marker({
element: element(feature), element: element(feature),
}).setLnglat({ }).setLnglat({
@ -292,9 +292,13 @@ export default class MarkerLayer extends EventEmitter {
} }
private update() { private update() {
if (!this.mapsService) return; if (!this.mapsService) {
return;
}
// 当图层中无marker时无需更新 // 当图层中无marker时无需更新
if (this.markers.length === 0) return; if (this.markers.length === 0) {
return;
}
const zoom = this.mapsService.getZoom(); const zoom = this.mapsService.getZoom();
const bbox = this.mapsService.getBounds(); const bbox = this.mapsService.getBounds();

View File

@ -27,6 +27,7 @@ export default class Marker extends EventEmitter {
private lngLat: ILngLat; private lngLat: ILngLat;
private scene: Container; private scene: Container;
private added: boolean = false; private added: boolean = false;
// tslint:disable-next-line: no-empty
public getMarkerLayerContainerSize(): IMarkerContainerAndBounds | void {} public getMarkerLayerContainerSize(): IMarkerContainerAndBounds | void {}
constructor(option?: Partial<IMarkerOption>) { constructor(option?: Partial<IMarkerOption>) {
@ -244,7 +245,9 @@ export default class Marker extends EventEmitter {
const { containerHeight, containerWidth, bounds } = const { containerHeight, containerWidth, bounds } =
this.getMarkerLayerContainerSize() || this.getCurrentContainerSize(); this.getMarkerLayerContainerSize() || this.getCurrentContainerSize();
if (!bounds) return; if (!bounds) {
return;
}
// 当前可视区域包含跨日界线 // 当前可视区域包含跨日界线
if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) { if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
if (pos.x > containerWidth) { if (pos.x > containerWidth) {
@ -349,7 +352,7 @@ export default class Marker extends EventEmitter {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
private addDragHandler(e: MouseEvent) { private addDragHandler(e: MouseEvent) {
return null return null;
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars

View File

@ -8,10 +8,38 @@ import BasePostProcessingPass from './services/renderer/passes/BasePostProcessin
import { TYPES } from './types'; import { TYPES } from './types';
import { packCircleVertex } from './utils/vertex-compression'; import { packCircleVertex } from './utils/vertex-compression';
export * from './services/asset/IFontService';
export * from './services/asset/IIconService';
export * from './services/asset/ITextureService';
export * from './services/camera/ICameraService';
export * from './services/component/IControlService';
export * from './services/component/IMarkerService';
export * from './services/component/IPopupService';
export * from './services/config/IConfigService';
export * from './services/coordinate/ICoordinateSystemService';
export * from './services/debug/IDebugService';
export * from './services/interaction/IInteractionService';
export * from './services/interaction/IPickingService';
/** 暴露服务接口供其他 packages 实现 */
export * from './services/layer/ILayerService';
export * from './services/layer/IStyleAttributeService';
export * from './services/map/IMapService';
export * from './services/renderer/gl';
/** 全部渲染服务接口 */
export * from './services/renderer/IAttribute';
export * from './services/renderer/IBuffer';
export * from './services/renderer/IElements';
export * from './services/renderer/IFramebuffer';
export * from './services/renderer/IModel';
export * from './services/renderer/IMultiPassRenderer';
export * from './services/renderer/IRenderbuffer';
export * from './services/renderer/IRendererService';
export * from './services/renderer/ITexture2D';
export * from './services/renderer/IUniform';
export * from './services/scene/ISceneService';
export * from './services/shader/IShaderModuleService';
export * from './services/source/ISourceService';
export { export {
/**
* IoC
*/
container, container,
createSceneContainer, createSceneContainer,
createLayerContainer, createLayerContainer,
@ -27,36 +55,3 @@ export {
packCircleVertex, packCircleVertex,
BasePostProcessingPass, BasePostProcessingPass,
}; };
/** 暴露服务接口供其他 packages 实现 */
export * from './services/layer/ILayerService';
export * from './services/debug/IDebugService';
export * from './services/layer/IStyleAttributeService';
export * from './services/source/ISourceService';
export * from './services/map/IMapService';
export * from './services/coordinate/ICoordinateSystemService';
export * from './services/renderer/IRendererService';
export * from './services/camera/ICameraService';
export * from './services/config/IConfigService';
export * from './services/scene/ISceneService';
export * from './services/shader/IShaderModuleService';
export * from './services/asset/IIconService';
export * from './services/asset/IFontService';
export * from './services/asset/ITextureService';
export * from './services/component/IControlService';
export * from './services/component/IMarkerService';
export * from './services/component/IPopupService';
export * from './services/interaction/IInteractionService';
export * from './services/interaction/IPickingService';
/** 全部渲染服务接口 */
export * from './services/renderer/IAttribute';
export * from './services/renderer/IBuffer';
export * from './services/renderer/IElements';
export * from './services/renderer/IFramebuffer';
export * from './services/renderer/IModel';
export * from './services/renderer/IMultiPassRenderer';
export * from './services/renderer/IRenderbuffer';
export * from './services/renderer/ITexture2D';
export * from './services/renderer/IUniform';
export * from './services/renderer/gl';

View File

@ -16,10 +16,10 @@ import { ICameraService } from './services/camera/ICameraService';
import { IControlService } from './services/component/IControlService'; import { IControlService } from './services/component/IControlService';
import { IGlobalConfigService } from './services/config/IConfigService'; import { IGlobalConfigService } from './services/config/IConfigService';
import { ICoordinateSystemService } from './services/coordinate/ICoordinateSystemService'; import { ICoordinateSystemService } from './services/coordinate/ICoordinateSystemService';
import { IDebugService } from './services/debug/IDebugService';
import { IInteractionService } from './services/interaction/IInteractionService'; import { IInteractionService } from './services/interaction/IInteractionService';
import { IPickingService } from './services/interaction/IPickingService'; import { IPickingService } from './services/interaction/IPickingService';
import { ILayerService } from './services/layer/ILayerService'; import { ILayerService } from './services/layer/ILayerService';
import { IDebugService } from './services/debug/IDebugService';
import { IStyleAttributeService } from './services/layer/IStyleAttributeService'; import { IStyleAttributeService } from './services/layer/IStyleAttributeService';
import { ISceneService } from './services/scene/ISceneService'; import { ISceneService } from './services/scene/ISceneService';
import { IShaderModuleService } from './services/shader/IShaderModuleService'; import { IShaderModuleService } from './services/shader/IShaderModuleService';
@ -33,10 +33,10 @@ import MarkerService from './services/component/MarkerService';
import PopupService from './services/component/PopupService'; import PopupService from './services/component/PopupService';
import GlobalConfigService from './services/config/ConfigService'; import GlobalConfigService from './services/config/ConfigService';
import CoordinateSystemService from './services/coordinate/CoordinateSystemService'; import CoordinateSystemService from './services/coordinate/CoordinateSystemService';
import DebugService from './services/debug/DebugService';
import InteractionService from './services/interaction/InteractionService'; import InteractionService from './services/interaction/InteractionService';
import PickingService from './services/interaction/PickingService'; import PickingService from './services/interaction/PickingService';
import LayerService from './services/layer/LayerService'; import LayerService from './services/layer/LayerService';
import DebugService from './services/debug/DebugService';
import StyleAttributeService from './services/layer/StyleAttributeService'; import StyleAttributeService from './services/layer/StyleAttributeService';
import SceneService from './services/scene/SceneService'; import SceneService from './services/scene/SceneService';
import ShaderModuleService from './services/shader/ShaderModuleService'; import ShaderModuleService from './services/shader/ShaderModuleService';
@ -95,7 +95,7 @@ export const lazyInject = (
const original = DECORATORS.lazyInject(serviceIdentifier); const original = DECORATORS.lazyInject(serviceIdentifier);
// the 'descriptor' parameter is actually always defined for class fields for Babel, but is considered undefined for TSC // the 'descriptor' parameter is actually always defined for class fields for Babel, but is considered undefined for TSC
// so we just hack it with ?/! combination to avoid "TS1240: Unable to resolve signature of property decorator when called as an expression" // so we just hack it with ?/! combination to avoid "TS1240: Unable to resolve signature of property decorator when called as an expression"
return function( return function (
this: any, this: any,
proto: any, proto: any,
key: string, key: string,
@ -117,7 +117,7 @@ export const lazyMultiInject = (
const original = DECORATORS.lazyMultiInject(serviceIdentifier); const original = DECORATORS.lazyMultiInject(serviceIdentifier);
// the 'descriptor' parameter is actually always defined for class fields for Babel, but is considered undefined for TSC // the 'descriptor' parameter is actually always defined for class fields for Babel, but is considered undefined for TSC
// so we just hack it with ?/! combination to avoid "TS1240: Unable to resolve signature of property decorator when called as an expression" // so we just hack it with ?/! combination to avoid "TS1240: Unable to resolve signature of property decorator when called as an expression"
return function( return function (
this: any, this: any,
proto: any, proto: any,
key: string, key: string,
@ -220,8 +220,9 @@ export function createSceneContainer() {
.whenTargetNamed('taa'); .whenTargetNamed('taa');
sceneContainer sceneContainer
.bind<interfaces.Factory<IPass<unknown>>>(TYPES.IFactoryNormalPass) .bind<interfaces.Factory<IPass<unknown>>>(TYPES.IFactoryNormalPass)
.toFactory<IPass<unknown>>((context) => (named: string) => .toFactory<IPass<unknown>>(
context.container.getNamed<IPass<unknown>>(TYPES.INormalPass, named), (context) => (named: string) =>
context.container.getNamed<IPass<unknown>>(TYPES.INormalPass, named),
); );
// 绑定 post processing passes // 绑定 post processing passes

View File

@ -1,6 +1,6 @@
import { $window, LRUCache } from '@antv/l7-utils'; import { $window, LRUCache } from '@antv/l7-utils';
import { injectable } from 'inversify';
import { EventEmitter } from 'eventemitter3'; import { EventEmitter } from 'eventemitter3';
import { injectable } from 'inversify';
import TinySDF from 'l7-tiny-sdf'; import TinySDF from 'l7-tiny-sdf';
import 'reflect-metadata'; import 'reflect-metadata';
import { buildMapping } from '../../utils/font_util'; import { buildMapping } from '../../utils/font_util';
@ -73,7 +73,7 @@ export default class FontService extends EventEmitter implements IFontService {
public get mapping(): IFontMapping { public get mapping(): IFontMapping {
const data = this.cache.get(this.key); const data = this.cache.get(this.key);
return data && data.mapping || {}; return (data && data.mapping) || {};
} }
public fontAtlas: IFontAtlas; public fontAtlas: IFontAtlas;
@ -162,7 +162,7 @@ export default class FontService extends EventEmitter implements IFontService {
* @param fontFamily * @param fontFamily
* @param fontPath * @param fontPath
*/ */
public addFontFace(fontFamily: string, fontPath: string): void { public addFontFace(fontFamily: string, fontPath: string): void {
const style = document.createElement('style'); const style = document.createElement('style');
style.type = 'text/css'; style.type = 'text/css';
style.innerText = ` style.innerText = `
@ -172,28 +172,24 @@ export default class FontService extends EventEmitter implements IFontService {
url('${fontPath}') format('woff'), url('${fontPath}') format('woff'),
url('${fontPath}') format('truetype'); url('${fontPath}') format('truetype');
}`; }`;
style.onload=()=>{ style.onload = () => {
if ( document.fonts) { if (document.fonts) {
try { try {
// @ts-ignore // @ts-ignore
document.fonts.load(`24px ${fontFamily}`, 'L7text'); document.fonts.load(`24px ${fontFamily}`, 'L7text');
document.fonts.ready.then(()=>{ document.fonts.ready.then(() => {
this.emit('fontloaded',{ this.emit('fontloaded', {
fontFamily fontFamily,
}) });
}) });
} catch (e) {
} catch (e) { console.warn('当前环境不支持 document.fonts !');
console.warn('当前环境不支持 document.fonts !'); console.warn('当前环境不支持 iconfont !');
console.warn('当前环境不支持 iconfont !'); console.warn(e);
console.warn(e);
}
}
} }
}
};
document.getElementsByTagName('head')[0].appendChild(style); document.getElementsByTagName('head')[0].appendChild(style);
} }
public destroy(): void { public destroy(): void {
this.cache.clear(); this.cache.clear();
@ -220,7 +216,9 @@ export default class FontService extends EventEmitter implements IFontService {
canvas = $window.document.createElement('canvas'); canvas = $window.document.createElement('canvas');
canvas.width = MAX_CANVAS_WIDTH; canvas.width = MAX_CANVAS_WIDTH;
} }
const ctx = canvas.getContext('2d', { willReadFrequently: true }) as CanvasRenderingContext2D; const ctx = canvas.getContext('2d', {
willReadFrequently: true,
}) as CanvasRenderingContext2D;
setTextStyle(ctx, fontFamily, fontSize, fontWeight); setTextStyle(ctx, fontFamily, fontSize, fontWeight);
// 1. build mapping // 1. build mapping

View File

@ -1,8 +1,11 @@
import { IColorRamp } from '@antv/l7-utils'; import { IColorRamp } from '@antv/l7-utils';
import { ITexture2D } from '../renderer/ITexture2D'; import { ITexture2D } from '../renderer/ITexture2D';
export interface ITextureService { export interface ITextureService {
setColorTexture(texture: ITexture2D,colorRamp: IColorRamp,domain?:[number,number]):void; setColorTexture(
getColorTexture(colorRamp: IColorRamp, domain?:[number,number]): ITexture2D texture: ITexture2D,
destroy():void; colorRamp: IColorRamp,
domain?: [number, number],
): void;
getColorTexture(colorRamp: IColorRamp, domain?: [number, number]): ITexture2D;
destroy(): void;
} }

View File

@ -125,17 +125,17 @@ export default class CameraService implements ICameraService {
public jitterProjectionMatrix(x: number, y: number) { public jitterProjectionMatrix(x: number, y: number) {
const translation = mat4.fromTranslation(mat4.create(), [x, y, 0]); const translation = mat4.fromTranslation(mat4.create(), [x, y, 0]);
this.jitteredProjectionMatrix = (mat4.multiply( this.jitteredProjectionMatrix = mat4.multiply(
mat4.create(), mat4.create(),
translation, translation,
(this.viewport.getProjectionMatrix() as unknown) as mat4, this.viewport.getProjectionMatrix() as unknown as mat4,
) as unknown) as number[]; ) as unknown as number[];
this.jitteredViewProjectionMatrix = (mat4.multiply( this.jitteredViewProjectionMatrix = mat4.multiply(
mat4.create(), mat4.create(),
(this.jitteredProjectionMatrix as unknown) as mat4, this.jitteredProjectionMatrix as unknown as mat4,
(this.viewport.getViewMatrix() as unknown) as mat4, this.viewport.getViewMatrix() as unknown as mat4,
) as unknown) as number[]; ) as unknown as number[];
} }
public clearJitterProjectionMatrix() { public clearJitterProjectionMatrix() {

View File

@ -2,9 +2,9 @@
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import { merge } from 'lodash'; import { merge } from 'lodash';
import 'reflect-metadata'; import 'reflect-metadata';
import { ILayerConfig,ILayerAttributesOption} from '../layer/ILayerService'; import { ILayerAttributesOption, ILayerConfig } from '../layer/ILayerService';
import { IRenderConfig } from '../renderer/IRendererService'; import { IRenderConfig } from '../renderer/IRendererService';
import { IGlobalConfigService, ISceneConfig, } from './IConfigService'; import { IGlobalConfigService, ISceneConfig } from './IConfigService';
import WarnInfo from './warnInfo'; import WarnInfo from './warnInfo';
/** /**
@ -119,13 +119,12 @@ export default class GlobalConfigService implements IGlobalConfigService {
[layerId: string]: Partial<ILayerConfig & ISceneConfig>; [layerId: string]: Partial<ILayerConfig & ISceneConfig>;
} = {}; } = {};
/** /**
* *
*/ */
private layerAttributeConfigCache: { private layerAttributeConfigCache: {
[layerId: string]: Partial<ILayerAttributesOption> [layerId: string]: Partial<ILayerAttributesOption>;
} = {}; } = {};
/** /**
@ -176,18 +175,20 @@ export default class GlobalConfigService implements IGlobalConfigService {
}; };
} }
public getAttributeConfig(layerId: string,): Partial<ILayerAttributesOption> { public getAttributeConfig(layerId: string): Partial<ILayerAttributesOption> {
return this.layerAttributeConfigCache[layerId] return this.layerAttributeConfigCache[layerId];
}
} public setAttributeConfig(
layerId: string,
public setAttributeConfig(layerId: string, attr: Partial<ILayerAttributesOption>) { attr: Partial<ILayerAttributesOption>,
) {
// TODO // TODO
this.layerAttributeConfigCache[layerId] = { this.layerAttributeConfigCache[layerId] = {
...this.layerAttributeConfigCache[layerId], ...this.layerAttributeConfigCache[layerId],
...attr ...attr,
} };
} }
public clean() { public clean() {
this.sceneConfigCache = {}; this.sceneConfigCache = {};

View File

@ -1,6 +1,6 @@
// import Ajv from 'ajv'; // import Ajv from 'ajv';
import { PositionName } from '../component/IControlService'; import { PositionName } from '../component/IControlService';
import { ILayerConfig,ILayerAttributesOption } from '../layer/ILayerService'; import { ILayerAttributesOption, ILayerConfig } from '../layer/ILayerService';
import { IMapWrapper } from '../map/IMapService'; import { IMapWrapper } from '../map/IMapService';
import { IRenderConfig } from '../renderer/IRendererService'; import { IRenderConfig } from '../renderer/IRendererService';
export interface ISceneConfig extends IRenderConfig { export interface ISceneConfig extends IRenderConfig {
@ -64,17 +64,20 @@ export interface IGlobalConfigService {
layerId: string, layerId: string,
config: Partial<ILayerConfig>, config: Partial<ILayerConfig>,
): void; ): void;
/** /**
* *
*/ */
getAttributeConfig(layerId: string,): Partial<ILayerAttributesOption> getAttributeConfig(layerId: string): Partial<ILayerAttributesOption>;
/** /**
* *
* @param layerId sh * @param layerId sh
* @param attr * @param attr
*/ */
setAttributeConfig(layerId: string, attr: Partial<ILayerAttributesOption>):void setAttributeConfig(
layerId: string,
attr: Partial<ILayerAttributesOption>,
): void;
/** /**
* Cache * Cache

View File

@ -14,7 +14,8 @@ const VECTOR_TO_POINT_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0];
@injectable() @injectable()
export default class CoordinateSystemService export default class CoordinateSystemService
implements ICoordinateSystemService { implements ICoordinateSystemService
{
public needRefresh: boolean = true; public needRefresh: boolean = true;
@inject(TYPES.ICameraService) @inject(TYPES.ICameraService)
private readonly cameraService: ICameraService; private readonly cameraService: ICameraService;
@ -152,9 +153,9 @@ export default class CoordinateSystemService
let viewMatrix = this.cameraService.getViewMatrix(); let viewMatrix = this.cameraService.getViewMatrix();
const projectionMatrix = this.cameraService.getProjectionMatrix(); const projectionMatrix = this.cameraService.getProjectionMatrix();
let viewProjectionMatrix = mat4.multiply( let viewProjectionMatrix = mat4.multiply(
([] as unknown) as mat4, [] as unknown as mat4,
(projectionMatrix as unknown) as mat4, projectionMatrix as unknown as mat4,
(viewMatrix as unknown) as mat4, viewMatrix as unknown as mat4,
); );
// 经纬度投影到 Web 墨卡托坐标系 // 经纬度投影到 Web 墨卡托坐标系
@ -164,30 +165,30 @@ export default class CoordinateSystemService
); );
// Web 墨卡托坐标系通过 VP 矩阵变换到世界坐标系 // Web 墨卡托坐标系通过 VP 矩阵变换到世界坐标系
this.viewportCenterProjection = (vec4.transformMat4( this.viewportCenterProjection = vec4.transformMat4(
([] as unknown) as vec4, [] as unknown as vec4,
[positionPixels[0], positionPixels[1], 0.0, 1.0], [positionPixels[0], positionPixels[1], 0.0, 1.0],
(viewProjectionMatrix as unknown) as mat4, viewProjectionMatrix as unknown as mat4,
) as unknown) as [number, number, number, number]; ) as unknown as [number, number, number, number];
// Always apply uncentered projection matrix if available (shader adds center) // Always apply uncentered projection matrix if available (shader adds center)
viewMatrix = this.cameraService.getViewMatrixUncentered() || viewMatrix; viewMatrix = this.cameraService.getViewMatrixUncentered() || viewMatrix;
// Zero out 4th coordinate ("after" model matrix) - avoids further translations // Zero out 4th coordinate ("after" model matrix) - avoids further translations
viewProjectionMatrix = mat4.multiply( viewProjectionMatrix = mat4.multiply(
([] as unknown) as mat4, [] as unknown as mat4,
(projectionMatrix as unknown) as mat4, projectionMatrix as unknown as mat4,
(viewMatrix as unknown) as mat4, viewMatrix as unknown as mat4,
); );
viewProjectionMatrix = mat4.multiply( viewProjectionMatrix = mat4.multiply(
([] as unknown) as mat4, [] as unknown as mat4,
viewProjectionMatrix, viewProjectionMatrix,
(VECTOR_TO_POINT_MATRIX as unknown) as mat4, VECTOR_TO_POINT_MATRIX as unknown as mat4,
); );
// 重新计算相机 VP 矩阵 // 重新计算相机 VP 矩阵
this.cameraService.setViewProjectionMatrix( this.cameraService.setViewProjectionMatrix(
(viewProjectionMatrix as unknown) as number[], viewProjectionMatrix as unknown as number[],
); );
this.pixelsPerMeter = ppm; this.pixelsPerMeter = ppm;

View File

@ -79,23 +79,23 @@ export default class DebugService
this.renderEnable = enable; this.renderEnable = enable;
} }
public renderStart(guid: string) { public renderStart(id: string) {
if (!this.renderEnable || !this.enable) { if (!this.renderEnable || !this.enable) {
return; return;
} }
const cacheRenderInfo = this.renderMap.get(guid) || {}; const cacheRenderInfo = this.renderMap.get(id) || {};
this.renderMap.set(guid, { this.renderMap.set(id, {
...cacheRenderInfo, ...cacheRenderInfo,
renderUid: guid, renderUid: id,
renderStart: Date.now(), renderStart: Date.now(),
}); });
} }
public renderEnd(guid: string) { public renderEnd(id: string) {
if (!this.renderEnable || !this.enable) { if (!this.renderEnable || !this.enable) {
return; return;
} }
const cacheRenderInfo = this.renderMap.get(guid); const cacheRenderInfo = this.renderMap.get(id);
if (cacheRenderInfo) { if (cacheRenderInfo) {
const renderStart = cacheRenderInfo.renderStart as number; const renderStart = cacheRenderInfo.renderStart as number;
const renderEnd = Date.now(); const renderEnd = Date.now();
@ -104,7 +104,7 @@ export default class DebugService
renderEnd, renderEnd,
renderDuration: renderEnd - renderStart, renderDuration: renderEnd - renderStart,
}); });
this.renderMap.delete(guid); this.renderMap.delete(id);
} }
} }

View File

@ -7,7 +7,8 @@ export interface IPickingService {
init(id: string): void; init(id: string): void;
pickFromPickingFBO(layer: ILayer, target: IInteractionTarget): boolean; pickFromPickingFBO(layer: ILayer, target: IInteractionTarget): boolean;
pickBox(layer: ILayer, box: [number, number, number, number]): any[]; pickBox(layer: ILayer, box: [number, number, number, number]): any[];
triggerHoverOnLayer(layer: ILayer, triggerHoverOnLayer(
layer: ILayer,
target: { target: {
x: number; x: number;
y: number; y: number;
@ -15,7 +16,8 @@ export interface IPickingService {
lngLat: ILngLat; lngLat: ILngLat;
feature?: unknown; feature?: unknown;
featureId?: number | null; featureId?: number | null;
}): void; },
): void;
boxPickLayer( boxPickLayer(
layer: ILayer, layer: ILayer,
@ -26,7 +28,11 @@ export interface IPickingService {
} }
export interface ILayerPickService { export interface ILayerPickService {
pickRasterLayer(layer: ILayer, target: IInteractionTarget, parent?: ILayer): boolean; pickRasterLayer(
layer: ILayer,
target: IInteractionTarget,
parent?: ILayer,
): boolean;
pick(layer: ILayer, target: IInteractionTarget): boolean; pick(layer: ILayer, target: IInteractionTarget): boolean;
/** /**
* *
@ -37,19 +43,17 @@ export interface ILayerPickService {
* *
* @param pickedColors * @param pickedColors
*/ */
selectFeature(pickedColors: Uint8Array | undefined):void selectFeature(pickedColors: Uint8Array | undefined): void;
/** /**
* active对象 * active对象
* @param pickedColors * @param pickedColors
*/ */
highlightPickedFeature(pickedColors: Uint8Array | undefined):void highlightPickedFeature(pickedColors: Uint8Array | undefined): void;
/** /**
* *
* @param id q * @param id q
*/ */
getFeatureById(id: number, lngLat?: ILngLat):any getFeatureById(id: number, lngLat?: ILngLat): any;
} }

View File

@ -18,8 +18,10 @@ const DragEventMap: { [key: string]: string } = {
* L7 canvas * L7 canvas
*/ */
@injectable() @injectable()
export default class InteractionService extends EventEmitter export default class InteractionService
implements IInteractionService { extends EventEmitter
implements IInteractionService
{
public indragging: boolean = false; public indragging: boolean = false;
@inject(TYPES.IMapService) @inject(TYPES.IMapService)
private readonly mapService: IMapService; private readonly mapService: IMapService;

View File

@ -303,8 +303,9 @@ export default class PickingService implements IPickingService {
} }
private async pickingAllLayer(target: IInteractionTarget) { private async pickingAllLayer(target: IInteractionTarget) {
// 判断是否进行拾取操作 // 判断是否进行拾取操作
if (!this.layerService.needPick(target.type) || !this.isPickingAllLayer()) if (!this.layerService.needPick(target.type) || !this.isPickingAllLayer()) {
return; return;
}
this.alreadyInPicking = true; this.alreadyInPicking = true;
await this.pickingLayers(target); await this.pickingLayers(target);
this.layerService.renderLayers(); this.layerService.renderLayers();
@ -313,13 +314,21 @@ export default class PickingService implements IPickingService {
private isPickingAllLayer() { private isPickingAllLayer() {
// this.alreadyInPicking 避免多次重复拾取 // this.alreadyInPicking 避免多次重复拾取
if (this.alreadyInPicking) { return false; } if (this.alreadyInPicking) {
return false;
}
// this.layerService.alreadyInRendering 一个渲染序列中只进行一次拾取操作 // this.layerService.alreadyInRendering 一个渲染序列中只进行一次拾取操作
if (this.layerService.alreadyInRendering) { return false; } if (this.layerService.alreadyInRendering) {
return false;
}
// this.interactionService.dragging amap2 在点击操作的时候同时会触发 dragging 的情况(避免舍去) // this.interactionService.dragging amap2 在点击操作的时候同时会触发 dragging 的情况(避免舍去)
if (this.interactionService.indragging) { return false; } if (this.interactionService.indragging) {
return false;
}
// 判断当前进行 shader pick 拾取判断 // 判断当前进行 shader pick 拾取判断
if (!this.layerService.getShaderPickStat()) { return false; } if (!this.layerService.getShaderPickStat()) {
return false;
}
// 进行拾取 // 进行拾取
return true; return true;

View File

@ -1,12 +1,20 @@
// @ts-ignore // @ts-ignore
import { SyncBailHook, SyncHook, AsyncSeriesBailHook, AsyncWaterfallHook} from '@antv/async-hook'; import {
AsyncSeriesBailHook,
AsyncWaterfallHook,
SyncBailHook,
SyncHook,
} from '@antv/async-hook';
import { IColorRamp, SourceTile, TilesetManager } from '@antv/l7-utils'; import { IColorRamp, SourceTile, TilesetManager } from '@antv/l7-utils';
import { Container } from 'inversify'; import { Container } from 'inversify';
import Clock from '../../utils/clock'; import Clock from '../../utils/clock';
import { ITextureService } from '../asset/ITextureService'; import { ITextureService } from '../asset/ITextureService';
import { ISceneConfig } from '../config/IConfigService'; import { ISceneConfig } from '../config/IConfigService';
import { IInteractionTarget } from '../interaction/IInteractionService'; import { IInteractionTarget } from '../interaction/IInteractionService';
import { ILayerPickService, IPickingService } from '../interaction/IPickingService'; import {
ILayerPickService,
IPickingService,
} from '../interaction/IPickingService';
import { IMapService } from '../map/IMapService'; import { IMapService } from '../map/IMapService';
import { IAttribute } from '../renderer/IAttribute'; import { IAttribute } from '../renderer/IAttribute';
import { import {
@ -22,7 +30,12 @@ import {
import { IRendererService } from '../renderer/IRendererService'; import { IRendererService } from '../renderer/IRendererService';
import { ITexture2D } from '../renderer/ITexture2D'; import { ITexture2D } from '../renderer/ITexture2D';
import { IUniform } from '../renderer/IUniform'; import { IUniform } from '../renderer/IUniform';
import { ISource, ISourceCFG, ITransform, IParseDataItem } from '../source/ISourceService'; import {
IParseDataItem,
ISource,
ISourceCFG,
ITransform,
} from '../source/ISourceService';
import { import {
IAnimateOption, IAnimateOption,
IEncodeFeature, IEncodeFeature,
@ -80,7 +93,7 @@ export interface ILayerModel {
getAnimateUniforms(): IModelUniform; getAnimateUniforms(): IModelUniform;
buildModels(): Promise<IModel[]>; buildModels(): Promise<IModel[]>;
initModels(): Promise<IModel[]>; initModels(): Promise<IModel[]>;
needUpdate():Promise<boolean> needUpdate(): Promise<boolean>;
clearModels(refresh?: boolean): void; clearModels(refresh?: boolean): void;
// canvasLayer // canvasLayer
@ -92,13 +105,13 @@ export interface ILayerModel {
} }
export interface ILayerAttributesOption { export interface ILayerAttributesOption {
shape: IAttrbuteOptions, shape: IAttrbuteOptions;
color: IAttrbuteOptions, color: IAttrbuteOptions;
texture:IAttrbuteOptions, texture: IAttrbuteOptions;
rotate:IAttrbuteOptions, rotate: IAttrbuteOptions;
size:IAttrbuteOptions, size: IAttrbuteOptions;
filter:IAttrbuteOptions, filter: IAttrbuteOptions;
label:IAttrbuteOptions, label: IAttrbuteOptions;
} }
export interface IModelUniform { export interface IModelUniform {
@ -119,15 +132,15 @@ export interface IActiveOption {
type ILngLat = [number, number]; type ILngLat = [number, number];
export interface ILegend { export interface ILegend {
type: ScaleTypeName | undefined type: ScaleTypeName | undefined;
field: StyleAttributeField | undefined; field: StyleAttributeField | undefined;
items:LegendItems items: LegendItems;
} }
// 分段图例 // 分段图例
export interface ILegendSegmentItem { export interface ILegendSegmentItem {
field:string;// 图例字段 field: string; // 图例字段
value: [number, number]; value: [number, number];
[key: string]: any; [key: string]: any;
} }
@ -149,18 +162,18 @@ export interface ISubLayerStyles {
} }
export interface IAttrbuteOptions { export interface IAttrbuteOptions {
field: StyleAttrField, field: StyleAttrField;
values:StyleAttributeOption values: StyleAttributeOption;
} }
/** /**
* For tile subLayer * For tile subLayer
*/ */
export interface ISubLayerInitOptions { export interface ISubLayerInitOptions {
usage?: string|undefined; usage?: string | undefined;
layerType: string; layerType: string;
transforms?: ITransform[]; transforms?: ITransform[];
visible: boolean, visible: boolean;
shape?: string | string[] | IScaleValue; shape?: string | string[] | IScaleValue;
// options // options
zIndex: number; zIndex: number;
@ -203,7 +216,7 @@ export interface IBaseTileLayerManager {
parent: ILayer; parent: ILayer;
children: ILayer[]; children: ILayer[];
addTile(tile: SourceTile):Promise<{ layers: ILayer[]; }>; addTile(tile: SourceTile): Promise<{ layers: ILayer[] }>;
addChild(layer: ILayer): void; addChild(layer: ILayer): void;
addChildren(layers: ILayer[]): void; addChildren(layers: ILayer[]): void;
@ -232,10 +245,7 @@ export interface ITile {
getFeatureById(id: number): any; getFeatureById(id: number): any;
styleUpdate(...args: any): void; styleUpdate(...args: any): void;
initTileLayer(): Promise<void>; initTileLayer(): Promise<void>;
lnglatInBounds(lnglat: { lnglatInBounds(lnglat: { lng: number; lat: number }): boolean;
lng: number;
lat: number;
}): boolean;
updateVisible(value: boolean): void; updateVisible(value: boolean): void;
updateOptions(key: string, value: any): void; updateOptions(key: string, value: any): void;
destroy(): void; destroy(): void;
@ -253,14 +263,14 @@ export interface IBaseTileLayer {
tileLayerService: ITileLayerService; tileLayerService: ITileLayerService;
getLayers(): ILayer[]; getLayers(): ILayer[];
getTiles(): ITile[]; getTiles(): ITile[];
pickRender(target: IInteractionTarget):void; pickRender(target: IInteractionTarget): void;
selectFeature(pickedColors: Uint8Array | undefined):void; selectFeature(pickedColors: Uint8Array | undefined): void;
highlightPickedFeature(pickedColors: Uint8Array | undefined):void; highlightPickedFeature(pickedColors: Uint8Array | undefined): void;
render(isPicking?: boolean): void; render(isPicking?: boolean): void;
destroy(): void; destroy(): void;
} }
export interface ITileLayer extends IBaseTileLayer{ export interface ITileLayer extends IBaseTileLayer {
pickRender(target: IInteractionTarget):void; pickRender(target: IInteractionTarget): void;
pickLayers(target: IInteractionTarget): boolean; pickLayers(target: IInteractionTarget): boolean;
clearPick(type: string): void; clearPick(type: string): void;
clearPickState(): void; clearPickState(): void;
@ -304,7 +314,7 @@ export type LayerEventType =
| any; | any;
export interface ILayer { export interface ILayer {
styleAttributeService: IStyleAttributeService, styleAttributeService: IStyleAttributeService;
layerPickService: ILayerPickService; layerPickService: ILayerPickService;
textureService: ITextureService; textureService: ITextureService;
sourceLayer?: string; sourceLayer?: string;
@ -314,7 +324,7 @@ export interface ILayer {
coordCenter: number[]; coordCenter: number[];
name: string; // name: string; //
inited: boolean; // 是否初始化完成 inited: boolean; // 是否初始化完成
startInit: boolean // 是否开始初始化; startInit: boolean; // 是否开始初始化;
zIndex: number; zIndex: number;
clusterZoom: number; clusterZoom: number;
plugins: ILayerPlugin[]; plugins: ILayerPlugin[];
@ -327,15 +337,15 @@ export interface ILayer {
sceneContainer: Container | undefined; sceneContainer: Container | undefined;
dataState: IDataState; // 数据流状态 dataState: IDataState; // 数据流状态
defaultSourceConfig: { defaultSourceConfig: {
data: any[], data: any[];
options: ISourceCFG | undefined, options: ISourceCFG | undefined;
}, };
encodeDataLength: number; encodeDataLength: number;
pickedFeatureID: number | null; pickedFeatureID: number | null;
hooks: { hooks: {
init:AsyncSeriesBailHook; init: AsyncSeriesBailHook;
afterInit: SyncBailHook; afterInit: SyncBailHook;
beforeRenderData: AsyncWaterfallHook ; beforeRenderData: AsyncWaterfallHook;
beforeRender: SyncBailHook; beforeRender: SyncBailHook;
afterRender: SyncHook; afterRender: SyncHook;
beforePickingEncode: SyncHook; beforePickingEncode: SyncHook;
@ -367,9 +377,7 @@ export interface ILayer {
*/ */
threeRenderService?: any; threeRenderService?: any;
postProcessingPassFactory: ( postProcessingPassFactory: (name: string) => IPostProcessingPass<unknown>;
name: string,
) => IPostProcessingPass<unknown>;
normalPassFactory: (name: string) => IPass<unknown>; normalPassFactory: (name: string) => IPass<unknown>;
getShaderPickStat: () => boolean; getShaderPickStat: () => boolean;
updateModelData(data: IAttributeAndElements): void; updateModelData(data: IAttributeAndElements): void;
@ -379,7 +387,7 @@ export interface ILayer {
needPick(type: string): boolean; needPick(type: string): boolean;
getAttribute(name: string): IStyleAttribute | undefined; getAttribute(name: string): IStyleAttribute | undefined;
getLayerConfig<T>(): Partial<ILayerConfig & ISceneConfig & T>; getLayerConfig<T>(): Partial<ILayerConfig & ISceneConfig & T>;
getLayerAttributeConfig():Partial<ILayerAttributesOption> getLayerAttributeConfig(): Partial<ILayerAttributesOption>;
getContainer(): Container; getContainer(): Container;
setContainer(container: Container, sceneContainer: Container): void; setContainer(container: Container, sceneContainer: Container): void;
setCurrentPickId(id: number | null): void; setCurrentPickId(id: number | null): void;
@ -390,7 +398,7 @@ export interface ILayer {
renderModels(isPicking?: boolean): void; renderModels(isPicking?: boolean): void;
buildModels(): void; buildModels(): void;
rebuildModels(): void; rebuildModels(): void;
getModelType():string; getModelType(): string;
buildLayerModel( buildLayerModel(
options: ILayerModelInitializationOptions & options: ILayerModelInitializationOptions &
Partial<IModelInitializationOptions>, Partial<IModelInitializationOptions>,
@ -407,7 +415,7 @@ export interface ILayer {
values?: StyleAttributeOption, values?: StyleAttributeOption,
updateOptions?: Partial<IStyleAttributeUpdateOptions>, updateOptions?: Partial<IStyleAttributeUpdateOptions>,
): boolean; ): boolean;
setLayerPickService(layerPickService:ILayerPickService):void; setLayerPickService(layerPickService: ILayerPickService): void;
init(): Promise<void>; init(): Promise<void>;
scale(field: string | number | IScaleOptions, cfg?: IScale): ILayer; scale(field: string | number | IScaleOptions, cfg?: IScale): ILayer;
getScale(name: string): any; getScale(name: string): any;
@ -434,8 +442,8 @@ export interface ILayer {
style(options: unknown): ILayer; style(options: unknown): ILayer;
hide(): ILayer; hide(): ILayer;
show(): ILayer; show(): ILayer;
getLegendItems(name: string,index?: number): LegendItems; getLegendItems(name: string, index?: number): LegendItems;
getLegend(name: string):ILegend; getLegend(name: string): ILegend;
setIndex(index: number): ILayer; setIndex(index: number): ILayer;
isVisible(): boolean; isVisible(): boolean;
setMaxZoom(min: number): ILayer; setMaxZoom(min: number): ILayer;
@ -564,7 +572,7 @@ export interface ILayerConfig {
maskfence: any; maskfence: any;
maskColor: string; maskColor: string;
maskOpacity: number; maskOpacity: number;
sourceLayer:string; sourceLayer: string;
colors: string[]; colors: string[];
size: number; size: number;
@ -636,7 +644,7 @@ export interface ILayerConfig {
/** /**
* *
*/ */
globalOptions: any; globalOptions: any;
/** /**
* layer point text iconfont * layer point text iconfont
*/ */
@ -678,14 +686,14 @@ export interface ILayerService {
getRenderList(): ILayer[]; getRenderList(): ILayer[];
getLayer(id: string): ILayer | undefined; getLayer(id: string): ILayer | undefined;
getLayerByName(name: string): ILayer | undefined; getLayerByName(name: string): ILayer | undefined;
remove(layer: ILayer, parentLayer?: ILayer):Promise<void>; remove(layer: ILayer, parentLayer?: ILayer): Promise<void>;
removeAllLayers():Promise<void>; removeAllLayers(): Promise<void>;
updateLayerRenderList(): void; updateLayerRenderList(): void;
reRender(): void; reRender(): void;
beforeRenderData(layer: ILayer): Promise<void>; beforeRenderData(layer: ILayer): Promise<void>;
renderMask(masks:ILayer[]): void; renderMask(masks: ILayer[]): void;
renderLayer(layer: ILayer): Promise<void> renderLayer(layer: ILayer): Promise<void>;
needPick(type:string):boolean; needPick(type: string): boolean;
throttleRenderLayers(): void; throttleRenderLayers(): void;
renderLayers(): void; renderLayers(): void;
setEnableRender(flag: boolean): void; setEnableRender(flag: boolean): void;

View File

@ -194,7 +194,7 @@ export interface IStyleAttributeService {
registerStyleAttribute( registerStyleAttribute(
options: Partial<IStyleAttributeInitializationOptions>, options: Partial<IStyleAttributeInitializationOptions>,
): IStyleAttribute; ): IStyleAttribute;
updateScaleAttribute(scale: IScaleOptions):void; updateScaleAttribute(scale: IScaleOptions): void;
updateStyleAttribute( updateStyleAttribute(
attributeName: string, attributeName: string,
attributeOptions: Partial<IStyleAttributeInitializationOptions>, attributeOptions: Partial<IStyleAttributeInitializationOptions>,
@ -227,7 +227,7 @@ export interface IStyleAttributeService {
features: IEncodeFeature[], features: IEncodeFeature[],
startFeatureIdx?: number, startFeatureIdx?: number,
endFeatureIdx?: number, endFeatureIdx?: number,
layer?: ILayer layer?: ILayer,
): void; ): void;
/** /**
* *

View File

@ -9,8 +9,8 @@ import { IRendererService } from '../renderer/IRendererService';
import { ILayer, IWorkerOption } from './ILayerService'; import { ILayer, IWorkerOption } from './ILayerService';
import { import {
IAttributeScale, IAttributeScale,
IScaleOptions,
IEncodeFeature, IEncodeFeature,
IScaleOptions,
IStyleAttribute, IStyleAttribute,
IStyleAttributeInitializationOptions, IStyleAttributeInitializationOptions,
IStyleAttributeService, IStyleAttributeService,
@ -72,16 +72,16 @@ export default class StyleAttributeService implements IStyleAttributeService {
} }
public updateScaleAttribute(scaleOption: IScaleOptions) { public updateScaleAttribute(scaleOption: IScaleOptions) {
this.attributes.forEach((attr:IStyleAttribute)=>{ this.attributes.forEach((attr: IStyleAttribute) => {
const name = attr.name; const name = attr.name;
const field = attr.scale?.field as string; const field = attr.scale?.field as string;
if(scaleOption[name] || (field && scaleOption[field])) { // 字段类型和映射类型 if (scaleOption[name] || (field && scaleOption[field])) {
// 字段类型和映射类型
attr.needRescale = true; attr.needRescale = true;
attr.needRemapping = true; attr.needRemapping = true;
attr.needRegenerateVertices = true; attr.needRegenerateVertices = true;
} }
}) });
} }
public updateStyleAttribute( public updateStyleAttribute(
@ -136,7 +136,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
features: IEncodeFeature[], features: IEncodeFeature[],
startFeatureIdx: number = 0, startFeatureIdx: number = 0,
endFeatureIdx?: number, endFeatureIdx?: number,
layer?:ILayer layer?: ILayer,
) { ) {
const attributeToUpdate = this.attributes.find( const attributeToUpdate = this.attributes.find(
(attribute) => attribute.name === attributeName, (attribute) => attribute.name === attributeName,
@ -167,8 +167,8 @@ export default class StyleAttributeService implements IStyleAttributeService {
vertexIdx++ vertexIdx++
) { ) {
const normal = normals const normal = normals
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
? normals!.slice(vertexIdx * 3, vertexIdx * 3 + 3) normals!.slice(vertexIdx * 3, vertexIdx * 3 + 3)
: []; : [];
featureData.push( featureData.push(
...update( ...update(
@ -196,10 +196,10 @@ export default class StyleAttributeService implements IStyleAttributeService {
offset: bufferOffsetInBytes, offset: bufferOffsetInBytes,
}); });
// size color 触发更新事件 // size color 触发更新事件
layer?.emit(`legend:${attributeName}`,{ layer?.emit(`legend:${attributeName}`, {
type:attributeName, type: attributeName,
attr:attributeToUpdate attr: attributeToUpdate,
}) });
} }
} }
} }
@ -223,11 +223,8 @@ export default class StyleAttributeService implements IStyleAttributeService {
.filter((d) => d); .filter((d) => d);
const { modelType, ...restOptions } = workerOptions; const { modelType, ...restOptions } = workerOptions;
const { const { createAttribute, createBuffer, createElements } =
createAttribute, this.rendererService;
createBuffer,
createElements,
} = this.rendererService;
const attributes: { const attributes: {
[attributeName: string]: IAttribute; [attributeName: string]: IAttribute;
} = {}; } = {};
@ -361,7 +358,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
if (indexes && indexes[vertexIdx] !== undefined) { if (indexes && indexes[vertexIdx] !== undefined) {
vertexIndex = indexes[vertexIdx]; vertexIndex = indexes[vertexIdx];
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
descriptors.forEach((descriptor, attributeIdx) => { descriptors.forEach((descriptor, attributeIdx) => {
if (descriptor && descriptor.update) { if (descriptor && descriptor.update) {
(descriptor.buffer.data as number[]).push( (descriptor.buffer.data as number[]).push(
@ -379,11 +376,8 @@ export default class StyleAttributeService implements IStyleAttributeService {
}); // end for each }); // end for each
} // end for } // end for
}); // end features for Each }); // end features for Each
const { const { createAttribute, createBuffer, createElements } =
createAttribute, this.rendererService;
createBuffer,
createElements,
} = this.rendererService;
const attributes: { const attributes: {
[attributeName: string]: IAttribute; [attributeName: string]: IAttribute;
@ -487,7 +481,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
if (indexes && indexes[vertexIdx] !== undefined) { if (indexes && indexes[vertexIdx] !== undefined) {
vertexIndex = indexes[vertexIdx]; vertexIndex = indexes[vertexIdx];
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
descriptors.forEach((descriptor, attributeIdx) => { descriptors.forEach((descriptor, attributeIdx) => {
if (descriptor && descriptor.update) { if (descriptor && descriptor.update) {
(descriptor.buffer.data as number[]).push( (descriptor.buffer.data as number[]).push(

View File

@ -48,7 +48,7 @@ export interface IExtensions {
export interface IRendererService { export interface IRendererService {
extensionObject: IExtensions; extensionObject: IExtensions;
init(canvas: HTMLCanvasElement, cfg: IRenderConfig,gl: any): Promise<void>; init(canvas: HTMLCanvasElement, cfg: IRenderConfig, gl: any): Promise<void>;
testExtension(name: string): boolean; testExtension(name: string): boolean;
clear(options: IClearOptions): void; clear(options: IClearOptions): void;
createModel(options: IModelInitializationOptions): IModel; createModel(options: IModelInitializationOptions): IModel;

View File

@ -94,7 +94,7 @@ export interface ITexture2DInitializationOptions {
export interface ITexture2D { export interface ITexture2D {
get(): unknown; get(): unknown;
getSize():[number,number]; getSize(): [number, number];
update(options: any): void; update(options: any): void;
bind(): void; bind(): void;
resize(options: { width: number; height: number }): void; resize(options: { width: number; height: number }): void;

View File

@ -14,7 +14,8 @@ import { IRendererService } from '../IRendererService';
*/ */
@injectable() @injectable()
export default class BaseNormalPass<InitializationOptions = {}> export default class BaseNormalPass<InitializationOptions = {}>
implements IPass<InitializationOptions> { implements IPass<InitializationOptions>
{
// @inject(TYPES.IShaderModuleService) // @inject(TYPES.IShaderModuleService)
protected shaderModuleService: IShaderModuleService; protected shaderModuleService: IShaderModuleService;

View File

@ -20,7 +20,8 @@ import { IUniform } from '../IUniform';
*/ */
@injectable() @injectable()
export default class BasePostProcessingPass<InitializationOptions = {}> export default class BasePostProcessingPass<InitializationOptions = {}>
implements IPostProcessingPass<InitializationOptions> { implements IPostProcessingPass<InitializationOptions>
{
@inject(TYPES.IShaderModuleService) @inject(TYPES.IShaderModuleService)
protected shaderModuleService: IShaderModuleService; protected shaderModuleService: IShaderModuleService;
@ -166,9 +167,7 @@ export default class BasePostProcessingPass<InitializationOptions = {}>
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
protected convertOptionsToUniforms( protected convertOptionsToUniforms(options: Partial<InitializationOptions>): {
options: Partial<InitializationOptions>,
): {
[uniformName: string]: IUniform; [uniformName: string]: IUniform;
} | void { } | void {
const uniforms: { const uniforms: {

View File

@ -8,7 +8,7 @@ import BaseNormalPass from './BaseNormalPass';
*/ */
@injectable() @injectable()
export default class ClearPass< export default class ClearPass<
InitializationOptions = {} InitializationOptions = {},
> extends BaseNormalPass<InitializationOptions> { > extends BaseNormalPass<InitializationOptions> {
public getName() { public getName() {
return 'clear'; return 'clear';

View File

@ -18,7 +18,7 @@ import BaseNormalPass from './BaseNormalPass';
*/ */
@injectable() @injectable()
export default class PixelPickingPass< export default class PixelPickingPass<
InitializationOptions = {} InitializationOptions = {},
> extends BaseNormalPass<InitializationOptions> { > extends BaseNormalPass<InitializationOptions> {
/** /**
* picking framebuffer attributes * picking framebuffer attributes
@ -50,11 +50,8 @@ export default class PixelPickingPass<
public init(layer: ILayer, config?: Partial<InitializationOptions>) { public init(layer: ILayer, config?: Partial<InitializationOptions>) {
super.init(layer, config); super.init(layer, config);
this.layer = layer; this.layer = layer;
const { const { createTexture2D, createFramebuffer, getViewportSize } =
createTexture2D, this.rendererService;
createFramebuffer,
getViewportSize,
} = this.rendererService;
const { width, height } = getViewportSize(); const { width, height } = getViewportSize();
// 创建 picking framebuffer后续实时 resize // 创建 picking framebuffer后续实时 resize
this.pickingFBO = createFramebuffer({ this.pickingFBO = createFramebuffer({
@ -129,11 +126,8 @@ export default class PixelPickingPass<
if (!this.layer.isVisible() || !this.layer.needPick(type)) { if (!this.layer.isVisible() || !this.layer.needPick(type)) {
return; return;
} }
const { const { getViewportSize, readPixels, useFramebuffer } =
getViewportSize, this.rendererService;
readPixels,
useFramebuffer,
} = this.rendererService;
const { width, height } = getViewportSize(); const { width, height } = getViewportSize();
const { enableHighlight, enableSelect } = this.layer.getLayerConfig(); const { enableHighlight, enableSelect } = this.layer.getLayerConfig();

View File

@ -9,7 +9,7 @@ import BaseNormalPass from './BaseNormalPass';
*/ */
@injectable() @injectable()
export default class RenderPass< export default class RenderPass<
InitializationOptions = {} InitializationOptions = {},
> extends BaseNormalPass<InitializationOptions> { > extends BaseNormalPass<InitializationOptions> {
public getType() { public getType() {
return PassType.Normal; return PassType.Normal;

View File

@ -37,9 +37,9 @@ let accumulatingId = 1;
* @see https://yuque.antfin-inc.com/yuqi.pyq/fgetpa/ri52hv * @see https://yuque.antfin-inc.com/yuqi.pyq/fgetpa/ri52hv
*/ */
@injectable() @injectable()
export default class TAAPass<InitializationOptions = {}> extends BaseNormalPass< export default class TAAPass<
InitializationOptions InitializationOptions = {},
> { > extends BaseNormalPass<InitializationOptions> {
@inject(TYPES.IShaderModuleService) @inject(TYPES.IShaderModuleService)
protected readonly shaderModuleService: IShaderModuleService; protected readonly shaderModuleService: IShaderModuleService;
@ -305,9 +305,8 @@ export default class TAAPass<InitializationOptions = {}> extends BaseNormalPass<
fs: fragmentShader, fs: fragmentShader,
}); });
const { vs, fs, uniforms } = this.shaderModuleService.getModule( const { vs, fs, uniforms } =
shaderModuleName, this.shaderModuleService.getModule(shaderModuleName);
);
const { createAttribute, createBuffer, createModel } = this.rendererService; const { createAttribute, createBuffer, createModel } = this.rendererService;
return createModel({ return createModel({
vs, vs,

View File

@ -13,18 +13,15 @@ export interface IBloomPassConfig {
} }
@injectable() @injectable()
export default class BloomPass extends BasePostProcessingPass< export default class BloomPass extends BasePostProcessingPass<IBloomPassConfig> {
IBloomPassConfig
> {
protected setupShaders() { protected setupShaders() {
this.shaderModuleService.registerModule('blur-pass', { this.shaderModuleService.registerModule('blur-pass', {
vs: quad, vs: quad,
fs: blur, fs: blur,
}); });
const { vs, fs, uniforms } = this.shaderModuleService.getModule( const { vs, fs, uniforms } =
'blur-pass', this.shaderModuleService.getModule('blur-pass');
);
const { width, height } = this.rendererService.getViewportSize(); const { width, height } = this.rendererService.getViewportSize();
return { return {
@ -37,9 +34,7 @@ export default class BloomPass extends BasePostProcessingPass<
}; };
} }
protected convertOptionsToUniforms( protected convertOptionsToUniforms(options: Partial<IBloomPassConfig>): {
options: Partial<IBloomPassConfig>,
): {
[uniformName: string]: IUniform; [uniformName: string]: IUniform;
} | void { } | void {
const uniforms: { const uniforms: {

View File

@ -11,18 +11,15 @@ export interface IBlurHPassConfig {
} }
@injectable() @injectable()
export default class BlurHPass extends BasePostProcessingPass< export default class BlurHPass extends BasePostProcessingPass<IBlurHPassConfig> {
IBlurHPassConfig
> {
protected setupShaders() { protected setupShaders() {
this.shaderModuleService.registerModule('blur-pass', { this.shaderModuleService.registerModule('blur-pass', {
vs: quad, vs: quad,
fs: blur, fs: blur,
}); });
const { vs, fs, uniforms } = this.shaderModuleService.getModule( const { vs, fs, uniforms } =
'blur-pass', this.shaderModuleService.getModule('blur-pass');
);
const { width, height } = this.rendererService.getViewportSize(); const { width, height } = this.rendererService.getViewportSize();
return { return {
@ -35,9 +32,7 @@ export default class BlurHPass extends BasePostProcessingPass<
}; };
} }
protected convertOptionsToUniforms( protected convertOptionsToUniforms(options: Partial<IBlurHPassConfig>): {
options: Partial<IBlurHPassConfig>,
): {
[uniformName: string]: IUniform; [uniformName: string]: IUniform;
} | void { } | void {
const uniforms: { const uniforms: {

View File

@ -10,18 +10,15 @@ export interface IBlurVPassConfig {
} }
@injectable() @injectable()
export default class BlurVPass extends BasePostProcessingPass< export default class BlurVPass extends BasePostProcessingPass<IBlurVPassConfig> {
IBlurVPassConfig
> {
public setupShaders() { public setupShaders() {
this.shaderModuleService.registerModule('blur-pass', { this.shaderModuleService.registerModule('blur-pass', {
vs: quad, vs: quad,
fs: blur, fs: blur,
}); });
const { vs, fs, uniforms } = this.shaderModuleService.getModule( const { vs, fs, uniforms } =
'blur-pass', this.shaderModuleService.getModule('blur-pass');
);
const { width, height } = this.rendererService.getViewportSize(); const { width, height } = this.rendererService.getViewportSize();
return { return {
@ -34,9 +31,7 @@ export default class BlurVPass extends BasePostProcessingPass<
}; };
} }
protected convertOptionsToUniforms( protected convertOptionsToUniforms(options: Partial<IBlurVPassConfig>): {
options: Partial<IBlurVPassConfig>,
): {
[uniformName: string]: IUniform; [uniformName: string]: IUniform;
} | void { } | void {
const uniforms: { const uniforms: {

View File

@ -11,18 +11,15 @@ export interface IColorHalftonePassConfig {
} }
@injectable() @injectable()
export default class ColorHalftonePass extends BasePostProcessingPass< export default class ColorHalftonePass extends BasePostProcessingPass<IColorHalftonePassConfig> {
IColorHalftonePassConfig
> {
protected setupShaders() { protected setupShaders() {
this.shaderModuleService.registerModule('colorhalftone-pass', { this.shaderModuleService.registerModule('colorhalftone-pass', {
vs: quad, vs: quad,
fs: colorHalftone, fs: colorHalftone,
}); });
const { vs, fs, uniforms } = this.shaderModuleService.getModule( const { vs, fs, uniforms } =
'colorhalftone-pass', this.shaderModuleService.getModule('colorhalftone-pass');
);
const { width, height } = this.rendererService.getViewportSize(); const { width, height } = this.rendererService.getViewportSize();
return { return {

View File

@ -10,9 +10,7 @@ export interface IHexagonalPixelatePassConfig {
} }
@injectable() @injectable()
export default class HexagonalPixelatePass extends BasePostProcessingPass< export default class HexagonalPixelatePass extends BasePostProcessingPass<IHexagonalPixelatePassConfig> {
IHexagonalPixelatePassConfig
> {
protected setupShaders() { protected setupShaders() {
this.shaderModuleService.registerModule('hexagonalpixelate-pass', { this.shaderModuleService.registerModule('hexagonalpixelate-pass', {
vs: quad, vs: quad,

View File

@ -9,9 +9,7 @@ export interface INoisePassConfig {
} }
@injectable() @injectable()
export default class NoisePass extends BasePostProcessingPass< export default class NoisePass extends BasePostProcessingPass<INoisePassConfig> {
INoisePassConfig
> {
public setupShaders() { public setupShaders() {
this.shaderModuleService.registerModule('noise-pass', { this.shaderModuleService.registerModule('noise-pass', {
vs: quad, vs: quad,

View File

@ -9,9 +9,7 @@ export interface ISepiaPassConfig {
} }
@injectable() @injectable()
export default class SepiaPass extends BasePostProcessingPass< export default class SepiaPass extends BasePostProcessingPass<ISepiaPassConfig> {
ISepiaPassConfig
> {
public setupShaders() { public setupShaders() {
this.shaderModuleService.registerModule('sepia-pass', { this.shaderModuleService.registerModule('sepia-pass', {
vs: quad, vs: quad,

View File

@ -1,6 +1,6 @@
import EventEmitter from 'eventemitter3';
import { ISceneConfig } from '../config/IConfigService'; import { ISceneConfig } from '../config/IConfigService';
import { ILayer } from '../layer/ILayerService'; import { ILayer } from '../layer/ILayerService';
import EventEmitter from 'eventemitter3';
export interface ISceneService extends EventEmitter { export interface ISceneService extends EventEmitter {
destroyed: boolean; destroyed: boolean;
@ -18,7 +18,7 @@ export interface ISceneService extends EventEmitter {
render(): void; render(): void;
getSceneContainer(): HTMLDivElement; getSceneContainer(): HTMLDivElement;
getMarkerContainer(): HTMLElement; getMarkerContainer(): HTMLElement;
exportPng(type?: 'png' | 'jpg'): Promise<string> ; exportPng(type?: 'png' | 'jpg'): Promise<string>;
addFontFace(fontname: string, fontpath: string): void; addFontFace(fontname: string, fontpath: string): void;
destroy(): void; destroy(): void;
} }

View File

@ -15,6 +15,7 @@ import { IMarkerService } from '../component/IMarkerService';
import { IPopupService } from '../component/IPopupService'; import { IPopupService } from '../component/IPopupService';
import { IGlobalConfigService, ISceneConfig } from '../config/IConfigService'; import { IGlobalConfigService, ISceneConfig } from '../config/IConfigService';
import { ICoordinateSystemService } from '../coordinate/ICoordinateSystemService'; import { ICoordinateSystemService } from '../coordinate/ICoordinateSystemService';
import { IDebugService } from '../debug/IDebugService';
import { import {
IInteractionService, IInteractionService,
IInteractionTarget, IInteractionTarget,
@ -26,7 +27,6 @@ import { IMapService } from '../map/IMapService';
import { IRenderConfig, IRendererService } from '../renderer/IRendererService'; import { IRenderConfig, IRendererService } from '../renderer/IRendererService';
import { IShaderModuleService } from '../shader/IShaderModuleService'; import { IShaderModuleService } from '../shader/IShaderModuleService';
import { ISceneService } from './ISceneService'; import { ISceneService } from './ISceneService';
import { IDebugService } from '../debug/IDebugService';
/** /**
* will emit `loaded` `resize` `destroy` event panstart panmove panend * will emit `loaded` `resize` `destroy` event panstart panmove panend
@ -139,15 +139,14 @@ export default class Scene extends EventEmitter implements ISceneService {
*/ */
this.hooks.init.tapPromise('initMap', async () => { this.hooks.init.tapPromise('initMap', async () => {
this.debugService.log('map.mapInitStart', { this.debugService.log('map.mapInitStart', {
type: this.map.version type: this.map.version,
}) });
// 等待首次相机同步 // 等待首次相机同步
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
this.map.onCameraChanged((viewport: IViewport) => { this.map.onCameraChanged((viewport: IViewport) => {
this.cameraService.init(); this.cameraService.init();
this.cameraService.update(viewport); this.cameraService.update(viewport);
resolve(); resolve();
}); });
this.map.init(); this.map.init();
}); });
@ -218,8 +217,10 @@ export default class Scene extends EventEmitter implements ISceneService {
private registerContextLost() { private registerContextLost() {
const canvas = this.rendererService.getCanvas(); const canvas = this.rendererService.getCanvas();
if(canvas) { if (canvas) {
canvas.addEventListener('webglcontextlost', () => this.emit('webglcontextlost')); canvas.addEventListener('webglcontextlost', () =>
this.emit('webglcontextlost'),
);
} }
} }
@ -401,7 +402,6 @@ export default class Scene extends EventEmitter implements ISceneService {
?.removeListener(this.handleWindowResized); ?.removeListener(this.handleWindowResized);
} }
this.pickingService.destroy(); this.pickingService.destroy();
this.layerService.destroy(); this.layerService.destroy();
@ -413,8 +413,6 @@ export default class Scene extends EventEmitter implements ISceneService {
this.fontService.destroy(); this.fontService.destroy();
this.iconService.destroy(); this.iconService.destroy();
this.removeAllListeners(); this.removeAllListeners();
this.inited = false; this.inited = false;
@ -427,7 +425,7 @@ export default class Scene extends EventEmitter implements ISceneService {
// Tip: 把这一部分销毁放到写下一个事件循环中执行,兼容 L7React 中 scene 和 layer 同时销毁的情况 // Tip: 把这一部分销毁放到写下一个事件循环中执行,兼容 L7React 中 scene 和 layer 同时销毁的情况
this.rendererService.destroy(); this.rendererService.destroy();
}); });
// 销毁 container 容器 // 销毁 container 容器
this.$container?.parentNode?.removeChild(this.$container); this.$container?.parentNode?.removeChild(this.$container);
this.emit('destroy'); this.emit('destroy');
} }

View File

@ -30,7 +30,10 @@ export interface ITileParserCFG {
minZoom?: number; minZoom?: number;
maxZoom?: number; maxZoom?: number;
zoomOffset?: number; zoomOffset?: number;
getCustomData: (tile: { x: number, y: number, z: number },cb:(err:any,data:any)=>void)=>void, getCustomData: (
tile: { x: number; y: number; z: number },
cb: (err: any, data: any) => void,
) => void;
extent?: [number, number, number, number]; extent?: [number, number, number, number];
requestParameters: Partial<RequestParameters>; requestParameters: Partial<RequestParameters>;
updateStrategy?: 'overlap' | 'replace'; updateStrategy?: 'overlap' | 'replace';
@ -50,9 +53,12 @@ export interface ITileParserCFG {
operation?: any; operation?: any;
// 用户自定义请求url // 用户自定义请求url
getURLFromTemplate?: (template: string, properties: { x: number; y: number; z: number }) => string; getURLFromTemplate?: (
template: string,
properties: { x: number; y: number; z: number },
) => string;
// 用户自定义处理返回数据回调 // 用户自定义处理返回数据回调
transformResponse?: (response: Object) => any; transformResponse?: (response: object) => any;
} }
export interface IWMTSServiceOption { export interface IWMTSServiceOption {

View File

@ -1,11 +1,10 @@
import Source from '@antv/l7-source'; import Source from '@antv/l7-source';
export * from '@antv/l7-core';
export * from '@antv/l7-scene';
export * from '@antv/l7-maps';
export * from '@antv/l7-layers';
export * from '@antv/l7-component'; export * from '@antv/l7-component';
export * from '@antv/l7-core';
export * from '@antv/l7-layers';
export * from '@antv/l7-maps';
export * from '@antv/l7-scene';
export * from '@antv/l7-utils'; export * from '@antv/l7-utils';
export * from './version'; export * from './version';
export { Source }; export { Source };

View File

@ -59,7 +59,8 @@
"@types/d3-scale": "^2.1.1", "@types/d3-scale": "^2.1.1",
"@types/earcut": "^2.1.0", "@types/earcut": "^2.1.0",
"@types/gl-matrix": "^2.4.5", "@types/gl-matrix": "^2.4.5",
"@types/lodash": "^4.14.138" "@types/lodash": "^4.14.138",
"@antv/l7-test-utils":"^2.13.4"
}, },
"gitHead": "684ba4eb806a798713496d3fc0b4d1e17517dc31", "gitHead": "684ba4eb806a798713496d3fc0b4d1e17517dc31",
"publishConfig": { "publishConfig": {

View File

@ -17,9 +17,8 @@ export default class BillBoardModel extends BaseModel {
private radian: number = 0; // 旋转的弧度 private radian: number = 0; // 旋转的弧度
public planeGeometryTriangulation = () => { public planeGeometryTriangulation = () => {
const { const { center = [120, 30] } =
center = [120, 30], this.layer.getLayerConfig() as IGeometryLayerStyleOptions;
} = this.layer.getLayerConfig() as IGeometryLayerStyleOptions;
return { return {
size: 4, size: 4,
indices: [0, 1, 2, 2, 3, 0], indices: [0, 1, 2, 2, 3, 0],
@ -98,31 +97,28 @@ export default class BillBoardModel extends BaseModel {
this.updateTexture(drawCanvas); this.updateTexture(drawCanvas);
} }
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'geometryBillboard',
moduleName: 'geometryBillboard', vertexShader: planeVert,
vertexShader: planeVert, fragmentShader: planeFrag,
fragmentShader: planeFrag, triangulation: this.planeGeometryTriangulation,
triangulation: this.planeGeometryTriangulation, primitive: gl.TRIANGLES,
primitive: gl.TRIANGLES, depth: { enable: true },
depth: { enable: true }, blend: this.getBlend(),
blend: this.getBlend(), stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
return await this.initModels(); return this.initModels();
} }
public updateTexture(drawCanvas: (canvas: HTMLCanvasElement) => void): void { public updateTexture(drawCanvas: (canvas: HTMLCanvasElement) => void): void {
const { createTexture2D } = this.rendererService; const { createTexture2D } = this.rendererService;
const { const { canvasWidth = 1, canvasHeight = 1 } =
canvasWidth = 1, this.layer.getLayerConfig() as IGeometryLayerStyleOptions;
canvasHeight = 1,
} = this.layer.getLayerConfig() as IGeometryLayerStyleOptions;
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
canvas.width = canvasWidth; canvas.width = canvasWidth;
canvas.height = canvasHeight; canvas.height = canvasHeight;

View File

@ -151,26 +151,25 @@ export default class PlaneModel extends BaseModel {
this.updateTexture(mapTexture); this.updateTexture(mapTexture);
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'geometryPlane',
moduleName: 'geometryPlane', vertexShader: planeVert,
vertexShader: planeVert, fragmentShader: planeFrag,
fragmentShader: planeFrag, triangulation: this.planeGeometryTriangulation,
triangulation: this.planeGeometryTriangulation, primitive: gl.TRIANGLES,
primitive: gl.TRIANGLES, depth: { enable: true },
depth: { enable: true }, stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), blend: this.getBlend(),
blend: this.getBlend(), cull: {
cull: { enable: true,
enable: true, face: gl.BACK, // gl.FRONT | gl.BACK;
face: gl.BACK, // gl.FRONT | gl.BACK; },
}, });
}) return [model];
return [model]
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
return await this.initModels(); return this.initModels();
} }
public createModelData(options?: any) { public createModelData(options?: any) {
@ -181,12 +180,8 @@ export default class PlaneModel extends BaseModel {
width: oldwidth, width: oldwidth,
height: oldheight, height: oldheight,
} = this.layer.getLayerConfig() as IGeometryLayerStyleOptions; } = this.layer.getLayerConfig() as IGeometryLayerStyleOptions;
const { const { widthSegments, heightSegments, width, height } =
widthSegments, options as IGeometryLayerStyleOptions;
heightSegments,
width,
height,
} = options as IGeometryLayerStyleOptions;
this.layer.style({ this.layer.style({
widthSegments: widthSegments:
widthSegments !== undefined ? widthSegments : oldwidthSegments, widthSegments !== undefined ? widthSegments : oldwidthSegments,

View File

@ -1,9 +1,4 @@
import { import { gl, IModel, IModelUniform, ITexture2D } from '@antv/l7-core';
gl,
IModel,
IModelUniform,
ITexture2D,
} from '@antv/l7-core';
import { Version } from '@antv/l7-maps'; import { Version } from '@antv/l7-maps';
import BaseModel from '../../core/BaseModel'; import BaseModel from '../../core/BaseModel';
@ -63,9 +58,8 @@ export default class SpriteModel extends BaseModel {
} }
public planeGeometryUpdateTriangulation = () => { public planeGeometryUpdateTriangulation = () => {
const { const { spriteBottom = -100000 } =
spriteBottom = -100000, this.layer.getLayerConfig() as IGeometryLayerStyleOptions;
} = this.layer.getLayerConfig() as IGeometryLayerStyleOptions;
const updateZ = this.spriteUpdate; const updateZ = this.spriteUpdate;
const bottomZ = spriteBottom; const bottomZ = spriteBottom;
const topZ = this.spriteTop; const topZ = this.spriteTop;
@ -175,21 +169,20 @@ export default class SpriteModel extends BaseModel {
this.updateModel(); this.updateModel();
}, 100); }, 100);
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'geometrySprite',
moduleName: 'geometrySprite', vertexShader: spriteVert,
vertexShader: spriteVert, fragmentShader: spriteFrag,
fragmentShader: spriteFrag, triangulation: this.planeGeometryTriangulation,
triangulation: this.planeGeometryTriangulation, primitive: gl.POINTS,
primitive: gl.POINTS, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), });
}) return [model];
return [model]
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
return await this.initModels(); return this.initModels();
} }
public updateTexture(mapTexture: string | undefined): void { public updateTexture(mapTexture: string | undefined): void {

View File

@ -61,9 +61,8 @@ export default class CanvaModel extends BaseModel {
} }
public async initModels() { public async initModels() {
const { const { update = CanvasUpdateType.ALWAYS } =
update = CanvasUpdateType.ALWAYS, this.layer.getLayerConfig() as ICanvasLayerStyleOptions;
} = this.layer.getLayerConfig() as ICanvasLayerStyleOptions;
this.updateMode = update as CanvasUpdateType; this.updateMode = update as CanvasUpdateType;
this.initCanvas(); this.initCanvas();
@ -79,10 +78,8 @@ export default class CanvaModel extends BaseModel {
const { zIndex } = this.layer.getLayerConfig() as ICanvasLayerStyleOptions; const { zIndex } = this.layer.getLayerConfig() as ICanvasLayerStyleOptions;
const size = this.mapService.getSize(); const size = this.mapService.getSize();
const [width, height] = size; const [width, height] = size;
const { const { width: viewWidth, height: viewHeight } =
width: viewWidth, this.rendererService.getViewportSize();
height: viewHeight,
} = this.rendererService.getViewportSize();
this.prevSize = [viewWidth, viewHeight]; this.prevSize = [viewWidth, viewHeight];
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
@ -110,10 +107,8 @@ export default class CanvaModel extends BaseModel {
}; };
public renderCanvas = () => { public renderCanvas = () => {
const { const { width: viewWidth, height: viewHeight } =
width: viewWidth, this.rendererService.getViewportSize();
height: viewHeight,
} = this.rendererService.getViewportSize();
if (this.prevSize[0] !== viewWidth || this.prevSize[1] !== viewHeight) { if (this.prevSize[0] !== viewWidth || this.prevSize[1] !== viewHeight) {
this.prevSize = [viewWidth, viewHeight]; this.prevSize = [viewWidth, viewHeight];
const size = this.mapService.getSize(); const size = this.mapService.getSize();
@ -124,9 +119,8 @@ export default class CanvaModel extends BaseModel {
this.canvas.style.height = height + 'px'; this.canvas.style.height = height + 'px';
} }
const { const { drawingOnCanvas } =
drawingOnCanvas, this.layer.getLayerConfig() as ICanvasLayerStyleOptions;
} = this.layer.getLayerConfig() as ICanvasLayerStyleOptions;
if (this.ctx) { if (this.ctx) {
drawingOnCanvas({ drawingOnCanvas({

View File

@ -1,10 +1,10 @@
import { AttributeType, gl, IEncodeFeature, IModel } from '@antv/l7-core'; import { AttributeType, gl, IEncodeFeature, IModel } from '@antv/l7-core';
import { rgb2arr } from '@antv/l7-utils'; import { rgb2arr } from '@antv/l7-utils';
import BaseModel from '../../core/BaseModel'; import BaseModel from '../../core/BaseModel';
import { ICityBuildLayerStyleOptions } from '../../core/interface';
import { PolygonExtrudeTriangulation } from '../../core/triangulation'; import { PolygonExtrudeTriangulation } from '../../core/triangulation';
import buildFrag from '../shaders/build_frag.glsl'; import buildFrag from '../shaders/build_frag.glsl';
import buildVert from '../shaders/build_vert.glsl'; import buildVert from '../shaders/build_vert.glsl';
import { ICityBuildLayerStyleOptions } from '../../core/interface';
export default class CityBuildModel extends BaseModel { export default class CityBuildModel extends BaseModel {
private cityCenter: [number, number]; private cityCenter: [number, number];
private cityMinSize: number; private cityMinSize: number;
@ -67,23 +67,22 @@ export default class CityBuildModel extends BaseModel {
this.startModelAnimate(); this.startModelAnimate();
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'cityBuilding',
moduleName: 'cityBuilding', vertexShader: buildVert,
vertexShader: buildVert, fragmentShader: buildFrag,
fragmentShader: buildFrag, triangulation: PolygonExtrudeTriangulation,
triangulation: PolygonExtrudeTriangulation, depth: { enable: true },
depth: { enable: true }, cull: {
cull: { enable: true,
enable: true, face: gl.BACK,
face: gl.BACK, },
}, });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
@ -124,9 +123,7 @@ export default class CityBuildModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 10 } = feature; const { size = 10 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },

View File

@ -17,35 +17,33 @@ interface IAtmoSphereLayerStyleOptions {
export default class EarthAtomSphereModel extends BaseModel { export default class EarthAtomSphereModel extends BaseModel {
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
const { const { opacity = 1 } =
opacity = 1, this.layer.getLayerConfig() as IAtmoSphereLayerStyleOptions;
} = this.layer.getLayerConfig() as IAtmoSphereLayerStyleOptions;
return { return {
u_opacity: isNumber(opacity) ? opacity : 1.0, u_opacity: isNumber(opacity) ? opacity : 1.0,
}; };
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
return ''; return '';
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
// TODO: 调整图层的绘制顺序 地球大气层 // TODO: 调整图层的绘制顺序 地球大气层
this.layer.zIndex = -997; this.layer.zIndex = -997;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'earthAtmoSphere',
moduleName: 'earthAtmoSphere', vertexShader: atmoSphereVert,
vertexShader: atmoSphereVert, fragmentShader: atmoSphereFrag,
fragmentShader: atmoSphereFrag, triangulation: earthTriangulation,
triangulation: earthTriangulation, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
@ -61,9 +59,7 @@ export default class EarthAtomSphereModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },

View File

@ -80,27 +80,26 @@ export default class BaseEarthModel extends BaseModel {
this.layerService.reRender(); this.layerService.reRender();
}); });
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
return ''; return '';
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
// Tip: 调整图层的绘制顺序 地球大气层 // Tip: 调整图层的绘制顺序 地球大气层
this.layer.zIndex = -998; this.layer.zIndex = -998;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'earthBase',
moduleName: 'earthBase', vertexShader: baseVert,
vertexShader: baseVert, fragmentShader: baseFrag,
fragmentShader: baseFrag, triangulation: earthTriangulation,
triangulation: earthTriangulation, depth: { enable: true },
depth: { enable: true }, blend: this.getBlend(),
blend: this.getBlend(), });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
@ -115,9 +114,7 @@ export default class BaseEarthModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },

View File

@ -17,35 +17,33 @@ interface IBloomLayerStyleOptions {
export default class EarthBloomSphereModel extends BaseModel { export default class EarthBloomSphereModel extends BaseModel {
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
const { const { opacity = 1 } =
opacity = 1, this.layer.getLayerConfig() as IBloomLayerStyleOptions;
} = this.layer.getLayerConfig() as IBloomLayerStyleOptions;
return { return {
u_opacity: isNumber(opacity) ? opacity : 1.0, u_opacity: isNumber(opacity) ? opacity : 1.0,
}; };
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
return ''; return '';
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
// Tip: 调整图层的绘制顺序,让它保持在地球后面(减少锯齿现象) // Tip: 调整图层的绘制顺序,让它保持在地球后面(减少锯齿现象)
this.layer.zIndex = -999; this.layer.zIndex = -999;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'earthBloom',
moduleName: 'earthBloom', vertexShader: bloomSphereVert,
vertexShader: bloomSphereVert, fragmentShader: bloomSphereFrag,
fragmentShader: bloomSphereFrag, triangulation: earthOuterTriangulation,
triangulation: earthOuterTriangulation, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
@ -60,9 +58,7 @@ export default class EarthBloomSphereModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },

View File

@ -13,11 +13,8 @@ import heatmapGridVert from '../shaders/grid_vert.glsl';
import heatmapGridFrag from '../shaders/hexagon_frag.glsl'; import heatmapGridFrag from '../shaders/hexagon_frag.glsl';
export default class GridModel extends BaseModel { export default class GridModel extends BaseModel {
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
const { const { opacity, coverage, angle } =
opacity, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
coverage,
angle,
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
return { return {
u_opacity: opacity || 1.0, u_opacity: opacity || 1.0,
u_coverage: coverage || 0.9, u_coverage: coverage || 0.9,
@ -30,25 +27,22 @@ export default class GridModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
maskInside = true, const model = await this.layer.buildLayerModel({
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions; moduleName: 'heatmapGrid',
const model = await this.layer vertexShader: heatmapGridVert,
.buildLayerModel({ fragmentShader: heatmapGridFrag,
moduleName: 'heatmapGrid', triangulation: HeatmapGridTriangulation,
vertexShader: heatmapGridVert, primitive: gl.TRIANGLES,
fragmentShader: heatmapGridFrag, depth: { enable: false },
triangulation: HeatmapGridTriangulation, stencil: getMask(mask, maskInside),
primitive: gl.TRIANGLES, });
depth: { enable: false }, return [model];
stencil: getMask(mask, maskInside),
})
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({ this.styleAttributeService.registerStyleAttribute({
@ -63,9 +57,11 @@ export default class GridModel extends BaseModel {
}, },
size: 3, size: 3,
update: (feature: IEncodeFeature) => { update: (feature: IEncodeFeature) => {
const coordinates = (feature.version === 'GAODE2.x' const coordinates = (
? feature.originCoordinates feature.version === 'GAODE2.x'
: feature.coordinates) as number[]; ? feature.originCoordinates
: feature.coordinates
) as number[];
return [coordinates[0], coordinates[1], 0]; return [coordinates[0], coordinates[1], 0];
}, },
}, },

View File

@ -13,11 +13,8 @@ import heatmapGrid3dVert from '../shaders/hexagon_3d_vert.glsl';
import heatmapGridFrag from '../shaders/hexagon_frag.glsl'; import heatmapGridFrag from '../shaders/hexagon_frag.glsl';
export default class Grid3DModel extends BaseModel { export default class Grid3DModel extends BaseModel {
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
const { const { opacity, coverage, angle } =
opacity, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
coverage,
angle,
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
return { return {
u_opacity: opacity || 1.0, u_opacity: opacity || 1.0,
u_coverage: coverage || 1.0, u_coverage: coverage || 1.0,
@ -30,27 +27,23 @@ export default class Grid3DModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
maskInside = true, const model = await this.layer.buildLayerModel({
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions; moduleName: 'heatmapGrid3d',
const model = await this.layer vertexShader: heatmapGrid3dVert,
.buildLayerModel({ fragmentShader: heatmapGridFrag,
moduleName: 'heatmapGrid3d', triangulation: PointExtrudeTriangulation,
vertexShader: heatmapGrid3dVert, primitive: gl.TRIANGLES,
fragmentShader: heatmapGridFrag, depth: { enable: true },
triangulation: PointExtrudeTriangulation, blend: this.getBlend(),
primitive: gl.TRIANGLES, stencil: getMask(mask, maskInside),
depth: { enable: true }, });
blend: this.getBlend(), return [model];
stencil: getMask(mask, maskInside),
})
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({ this.styleAttributeService.registerStyleAttribute({
@ -64,9 +57,7 @@ export default class Grid3DModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size } = feature; const { size } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },
@ -107,9 +98,11 @@ export default class Grid3DModel extends BaseModel {
}, },
size: 3, size: 3,
update: (feature: IEncodeFeature) => { update: (feature: IEncodeFeature) => {
const coordinates = (feature.version === 'GAODE2.x' const coordinates = (
? feature.originCoordinates feature.version === 'GAODE2.x'
: feature.coordinates) as number[]; ? feature.originCoordinates
: feature.coordinates
) as number[];
return [coordinates[0], coordinates[1], 0]; return [coordinates[0], coordinates[1], 0];
}, },
}, },

View File

@ -60,15 +60,11 @@ export default class HeatMapModel extends BaseModel {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
const { const { createFramebuffer, getViewportSize, createTexture2D } =
createFramebuffer, this.rendererService;
getViewportSize, const shapeAttr =
createTexture2D, this.styleAttributeService.getLayerStyleAttribute('shape');
} = this.rendererService;
const shapeAttr = this.styleAttributeService.getLayerStyleAttribute(
'shape',
);
const shapeType = shapeAttr?.scale?.field || 'heatmap'; const shapeType = shapeAttr?.scale?.field || 'heatmap';
this.shapeType = shapeType as string; this.shapeType = shapeType as string;
// 生成热力图密度图 // 生成热力图密度图
@ -95,12 +91,11 @@ export default class HeatMapModel extends BaseModel {
}); });
this.updateColorTexture(); this.updateColorTexture();
return [this.intensityModel, this.colorModel] return [this.intensityModel, this.colorModel];
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
return await this.initModels(); return this.initModels();
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
@ -137,9 +132,7 @@ export default class HeatMapModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return [size as number]; return [size as number];
}, },
@ -174,24 +167,17 @@ export default class HeatMapModel extends BaseModel {
} }
private buildHeatmapColor(): IModel { private buildHeatmapColor(): IModel {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
this.shaderModuleService.registerModule('heatmapColor', { this.shaderModuleService.registerModule('heatmapColor', {
vs: heatmapColorVert, vs: heatmapColorVert,
fs: heatmapColorFrag, fs: heatmapColorFrag,
}); });
const { vs, fs, uniforms } = this.shaderModuleService.getModule( const { vs, fs, uniforms } =
'heatmapColor', this.shaderModuleService.getModule('heatmapColor');
); const { createAttribute, createElements, createBuffer, createModel } =
const { this.rendererService;
createAttribute,
createElements,
createBuffer,
createModel,
} = this.rendererService;
return createModel({ return createModel({
vs, vs,
fs, fs,
@ -249,9 +235,8 @@ export default class HeatMapModel extends BaseModel {
} }
private drawColorMode() { private drawColorMode() {
const { const { opacity } =
opacity, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
this.colorModel?.draw({ this.colorModel?.draw({
uniforms: { uniforms: {
u_opacity: opacity || 1.0, u_opacity: opacity || 1.0,
@ -262,9 +247,8 @@ export default class HeatMapModel extends BaseModel {
} }
private draw3DHeatMap() { private draw3DHeatMap() {
const { const { opacity } =
opacity, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
// const invert = mat4.invert( // const invert = mat4.invert(
// mat4.create(), // mat4.create(),
@ -284,16 +268,15 @@ export default class HeatMapModel extends BaseModel {
u_opacity: opacity || 1.0, u_opacity: opacity || 1.0,
u_colorTexture: this.colorTexture, u_colorTexture: this.colorTexture,
u_texture: this.heatmapFramerBuffer, u_texture: this.heatmapFramerBuffer,
u_ViewProjectionMatrixUncentered: this.cameraService.getViewProjectionMatrixUncentered(), u_ViewProjectionMatrixUncentered:
this.cameraService.getViewProjectionMatrixUncentered(),
u_InverseViewProjectionMatrix: [...invert], u_InverseViewProjectionMatrix: [...invert],
}, },
}); });
} }
private build3dHeatMap() { private build3dHeatMap() {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
const { getViewportSize } = this.rendererService; const { getViewportSize } = this.rendererService;
const { width, height } = getViewportSize(); const { width, height } = getViewportSize();
const triangulation = heatMap3DTriangulation(width / 4.0, height / 4.0); const triangulation = heatMap3DTriangulation(width / 4.0, height / 4.0);
@ -302,15 +285,10 @@ export default class HeatMapModel extends BaseModel {
fs: heatmap3DFrag, fs: heatmap3DFrag,
}); });
const { vs, fs, uniforms } = this.shaderModuleService.getModule( const { vs, fs, uniforms } =
'heatmap3dColor', this.shaderModuleService.getModule('heatmap3dColor');
); const { createAttribute, createElements, createBuffer, createModel } =
const { this.rendererService;
createAttribute,
createElements,
createBuffer,
createModel,
} = this.rendererService;
return createModel({ return createModel({
vs, vs,
fs, fs,
@ -364,9 +342,8 @@ export default class HeatMapModel extends BaseModel {
this.texture.destroy(); this.texture.destroy();
} }
const { const { rampColors } =
rampColors, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
const imageData = generateColorRamp(rampColors as IColorRamp); const imageData = generateColorRamp(rampColors as IColorRamp);
this.colorTexture = createTexture2D({ this.colorTexture = createTexture2D({
data: new Uint8Array(imageData.data), data: new Uint8Array(imageData.data),

View File

@ -14,11 +14,8 @@ import heatmapGridVert from '../shaders/hexagon_vert.glsl';
export default class HexagonModel extends BaseModel { export default class HexagonModel extends BaseModel {
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
const { const { opacity, coverage, angle } =
opacity, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
coverage,
angle,
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
return { return {
u_opacity: opacity || 1.0, u_opacity: opacity || 1.0,
u_coverage: coverage || 0.9, u_coverage: coverage || 0.9,
@ -31,26 +28,23 @@ export default class HexagonModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IHeatMapLayerStyleOptions;
maskInside = true, const model = await this.layer.buildLayerModel({
} = this.layer.getLayerConfig() as IHeatMapLayerStyleOptions; moduleName: 'heatmapHexagon',
const model = await this.layer vertexShader: heatmapGridVert,
.buildLayerModel({ fragmentShader: heatmapGridFrag,
moduleName: 'heatmapHexagon', triangulation: HeatmapGridTriangulation,
vertexShader: heatmapGridVert, depth: { enable: false },
fragmentShader: heatmapGridFrag, primitive: gl.TRIANGLES,
triangulation: HeatmapGridTriangulation, blend: this.getBlend(),
depth: { enable: false }, stencil: getMask(mask, maskInside),
primitive: gl.TRIANGLES, });
blend: this.getBlend(), return [model];
stencil: getMask(mask, maskInside),
})
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({ this.styleAttributeService.registerStyleAttribute({
@ -65,9 +59,11 @@ export default class HexagonModel extends BaseModel {
}, },
size: 3, size: 3,
update: (feature: IEncodeFeature) => { update: (feature: IEncodeFeature) => {
const coordinates = (feature.version === 'GAODE2.x' const coordinates = (
? feature.originCoordinates feature.version === 'GAODE2.x'
: feature.coordinates) as number[]; ? feature.originCoordinates
: feature.coordinates
) as number[];
return [coordinates[0], coordinates[1], 0]; return [coordinates[0], coordinates[1], 0];
}, },
}, },

View File

@ -24,10 +24,8 @@ export default class ImageModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IImageLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as IImageLayerStyleOptions;
const source = this.layer.getSource(); const source = this.layer.getSource();
const { createTexture2D } = this.rendererService; const { createTexture2D } = this.rendererService;
@ -61,24 +59,22 @@ export default class ImageModel extends BaseModel {
mag: gl.LINEAR, mag: gl.LINEAR,
min: gl.LINEAR, min: gl.LINEAR,
}); });
} }
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'rasterImage',
moduleName: 'rasterImage', vertexShader: ImageVert,
vertexShader: ImageVert, fragmentShader: ImageFrag,
fragmentShader: ImageFrag, triangulation: RasterImageTriangulation,
triangulation: RasterImageTriangulation, primitive: gl.TRIANGLES,
primitive: gl.TRIANGLES, blend: {
blend: { // Tip: 优化显示效果
// Tip: 优化显示效果 enable: true,
enable: true, },
}, depth: { enable: false },
depth: { enable: false }, stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
public clearModels(): void { public clearModels(): void {
@ -86,7 +82,7 @@ export default class ImageModel extends BaseModel {
} }
public async buildModels(): Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
return await this.initModels(); return this.initModels();
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {

View File

@ -137,6 +137,7 @@ container
.to(LayerModelPlugin) .to(LayerModelPlugin)
.inRequestScope(); .inRequestScope();
export * from './core/interface';
export { export {
BaseLayer, BaseLayer,
BaseModel, BaseModel,
@ -154,5 +155,3 @@ export {
MaskLayer, MaskLayer,
TileDebugLayer, TileDebugLayer,
}; };
export * from './core/interface';

View File

@ -133,7 +133,7 @@ export default class ArcModel extends BaseModel {
this.updateTexture(); this.updateTexture();
this.iconService.on('imageUpdate', this.updateTexture); this.iconService.on('imageUpdate', this.updateTexture);
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
@ -143,11 +143,8 @@ export default class ArcModel extends BaseModel {
} }
public getShaders(): { frag: string; vert: string; type: string } { public getShaders(): { frag: string; vert: string; type: string } {
const { const { sourceColor, targetColor, lineType } =
sourceColor, this.layer.getLayerConfig() as ILineLayerStyleOptions;
targetColor,
lineType,
} = this.layer.getLayerConfig() as ILineLayerStyleOptions;
if (lineType === 'dash') { if (lineType === 'dash') {
return { return {
frag: arc_dash_frag, frag: arc_dash_frag,
@ -172,7 +169,7 @@ export default class ArcModel extends BaseModel {
} }
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const {
segmentNumber = 30, segmentNumber = 30,
mask = false, mask = false,
@ -180,18 +177,17 @@ export default class ArcModel extends BaseModel {
} = this.layer.getLayerConfig() as ILineLayerStyleOptions; } = this.layer.getLayerConfig() as ILineLayerStyleOptions;
const { frag, vert, type } = this.getShaders(); const { frag, vert, type } = this.getShaders();
// //
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'lineArc2d' + type,
moduleName: 'lineArc2d' + type, vertexShader: vert,
vertexShader: vert, fragmentShader: frag,
fragmentShader: frag, triangulation: LineArcTriangulation,
triangulation: LineArcTriangulation, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), segmentNumber,
segmentNumber, stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
@ -207,9 +203,7 @@ export default class ArcModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },
@ -249,9 +243,7 @@ export default class ArcModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const iconMap = this.iconService.getIconMap(); const iconMap = this.iconService.getIconMap();
const { texture } = feature; const { texture } = feature;
const { x, y } = iconMap[texture as string] || { x: 0, y: 0 }; const { x, y } = iconMap[texture as string] || { x: 0, y: 0 };

View File

@ -124,11 +124,10 @@ export default class Arc3DModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
this.updateTexture(); this.updateTexture();
this.iconService.on('imageUpdate', this.updateTexture); this.iconService.on('imageUpdate', this.updateTexture);
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
@ -138,10 +137,8 @@ export default class Arc3DModel extends BaseModel {
} }
public getShaders(): { frag: string; vert: string; type: string } { public getShaders(): { frag: string; vert: string; type: string } {
const { const { sourceColor, targetColor } =
sourceColor, this.layer.getLayerConfig() as ILineLayerStyleOptions;
targetColor,
} = this.layer.getLayerConfig() as ILineLayerStyleOptions;
if (sourceColor && targetColor) { if (sourceColor && targetColor) {
// 分离 linear 功能 // 分离 linear 功能
@ -159,7 +156,7 @@ export default class Arc3DModel extends BaseModel {
} }
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const {
segmentNumber = 30, segmentNumber = 30,
mask = false, mask = false,
@ -167,17 +164,16 @@ export default class Arc3DModel extends BaseModel {
} = this.layer.getLayerConfig() as ILineLayerStyleOptions; } = this.layer.getLayerConfig() as ILineLayerStyleOptions;
const { frag, vert, type } = this.getShaders(); const { frag, vert, type } = this.getShaders();
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'lineArc3d' + type,
moduleName: 'lineArc3d' + type, vertexShader: vert,
vertexShader: vert, fragmentShader: frag,
fragmentShader: frag, triangulation: LineArcTriangulation,
triangulation: LineArcTriangulation, blend: this.getBlend(),
blend: this.getBlend(), segmentNumber,
segmentNumber, stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({ this.styleAttributeService.registerStyleAttribute({
@ -192,9 +188,7 @@ export default class Arc3DModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },
@ -233,9 +227,7 @@ export default class Arc3DModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const iconMap = this.iconService.getIconMap(); const iconMap = this.iconService.getIconMap();
const { texture } = feature; const { texture } = feature;
const { x, y } = iconMap[texture as string] || { x: 0, y: 0 }; const { x, y } = iconMap[texture as string] || { x: 0, y: 0 };

View File

@ -127,7 +127,7 @@ export default class Arc3DModel extends BaseModel {
this.updateTexture(); this.updateTexture();
this.iconService.on('imageUpdate', this.updateTexture); this.iconService.on('imageUpdate', this.updateTexture);
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
@ -137,10 +137,8 @@ export default class Arc3DModel extends BaseModel {
} }
public getShaders(): { frag: string; vert: string; type: string } { public getShaders(): { frag: string; vert: string; type: string } {
const { const { sourceColor, targetColor } =
sourceColor, this.layer.getLayerConfig() as ILineLayerStyleOptions;
targetColor,
} = this.layer.getLayerConfig() as ILineLayerStyleOptions;
if (sourceColor && targetColor) { if (sourceColor && targetColor) {
// 分离 linear 功能 // 分离 linear 功能
@ -158,25 +156,24 @@ export default class Arc3DModel extends BaseModel {
} }
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const {
segmentNumber = 30, segmentNumber = 30,
mask = false, mask = false,
maskInside = true, maskInside = true,
} = this.layer.getLayerConfig() as ILineLayerStyleOptions; } = this.layer.getLayerConfig() as ILineLayerStyleOptions;
const { frag, vert, type } = this.getShaders(); const { frag, vert, type } = this.getShaders();
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'lineEarthArc3d' + type,
moduleName: 'lineEarthArc3d' + type, vertexShader: vert,
vertexShader: vert, fragmentShader: frag,
fragmentShader: frag, triangulation: LineArcTriangulation,
triangulation: LineArcTriangulation, depth: { enable: true },
depth: { enable: true }, blend: this.getBlend(),
blend: this.getBlend(), segmentNumber,
segmentNumber, stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({ this.styleAttributeService.registerStyleAttribute({
@ -191,9 +188,7 @@ export default class Arc3DModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },
@ -232,9 +227,7 @@ export default class Arc3DModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const iconMap = this.iconService.getIconMap(); const iconMap = this.iconService.getIconMap();
const { texture } = feature; const { texture } = feature;
const { x, y } = iconMap[texture as string] || { x: 0, y: 0 }; const { x, y } = iconMap[texture as string] || { x: 0, y: 0 };

View File

@ -116,7 +116,7 @@ export default class GreatCircleModel extends BaseModel {
this.updateTexture(); this.updateTexture();
this.iconService.on('imageUpdate', this.updateTexture); this.iconService.on('imageUpdate', this.updateTexture);
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
@ -125,22 +125,19 @@ export default class GreatCircleModel extends BaseModel {
this.iconService.off('imageUpdate', this.updateTexture); this.iconService.off('imageUpdate', this.updateTexture);
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as ILineLayerStyleOptions;
maskInside = true, const model = await this.layer.buildLayerModel({
} = this.layer.getLayerConfig() as ILineLayerStyleOptions; moduleName: 'lineGreatCircle',
const model = await this.layer vertexShader: line_arc2d_vert,
.buildLayerModel({ fragmentShader: line_arc_frag,
moduleName: 'lineGreatCircle', triangulation: LineArcTriangulation,
vertexShader: line_arc2d_vert, depth: { enable: false },
fragmentShader: line_arc_frag, blend: this.getBlend(),
triangulation: LineArcTriangulation, stencil: getMask(mask, maskInside),
depth: { enable: false }, });
blend: this.getBlend(), return [model];
stencil: getMask(mask, maskInside),
})
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({ this.styleAttributeService.registerStyleAttribute({
@ -155,9 +152,7 @@ export default class GreatCircleModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },
@ -197,9 +192,7 @@ export default class GreatCircleModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const iconMap = this.iconService.getIconMap(); const iconMap = this.iconService.getIconMap();
const { texture } = feature; const { texture } = feature;
// console.log('icon feature', feature) // console.log('icon feature', feature)

View File

@ -85,14 +85,14 @@ export default class LineModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
this.dataTexture?.destroy(); this.dataTexture?.destroy();
} }
public async buildModels(): Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const {
mask = false, mask = false,
maskInside = true, maskInside = true,
@ -101,17 +101,16 @@ export default class LineModel extends BaseModel {
const { frag, vert } = this.getShaders(); const { frag, vert } = this.getShaders();
this.layer.triangulation = LineTriangulation; this.layer.triangulation = LineTriangulation;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'lineHalf',
moduleName: 'lineHalf', vertexShader: vert,
vertexShader: vert, fragmentShader: frag,
fragmentShader: frag, triangulation: LineTriangulation,
triangulation: LineTriangulation, depth: { enable: depth },
depth: { enable: depth }, blend: this.getBlend(),
blend: this.getBlend(), stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
/** /**
@ -165,9 +164,7 @@ export default class LineModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 4, size: 4,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const startPoint = (feature.coordinates[0] || [0, 0]) as number[]; const startPoint = (feature.coordinates[0] || [0, 0]) as number[];
const endPoint = (feature.coordinates[3] || [0, 0]) as number[]; const endPoint = (feature.coordinates[3] || [0, 0]) as number[];
@ -188,9 +185,7 @@ export default class LineModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0]; return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0];
}, },

View File

@ -68,8 +68,8 @@ export default class LineModel extends BaseModel {
dashArray.push(0, 0); dashArray.push(0, 0);
} }
if (this.rendererService.getDirty()) { if (this.rendererService.getDirty() && this.texture) {
this.texture && this.texture.bind(); this.texture.bind();
} }
// 转化渐变色 // 转化渐变色

View File

@ -78,7 +78,7 @@ export default class LinearLineModel extends BaseModel {
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
this.updateTexture(); this.updateTexture();
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
@ -86,7 +86,7 @@ export default class LinearLineModel extends BaseModel {
this.dataTexture?.destroy(); this.dataTexture?.destroy();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const {
mask = false, mask = false,
maskInside = true, maskInside = true,
@ -95,17 +95,16 @@ export default class LinearLineModel extends BaseModel {
this.layer.triangulation = LineTriangulation; this.layer.triangulation = LineTriangulation;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'lineRampColors',
moduleName: 'lineRampColors', vertexShader: linear_line_vert,
vertexShader: linear_line_vert, fragmentShader: linear_line_frag,
fragmentShader: linear_line_frag, triangulation: LineTriangulation,
triangulation: LineTriangulation, depth: { enable: depth },
depth: { enable: depth }, blend: this.getBlend(),
blend: this.getBlend(), stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
@ -169,9 +168,7 @@ export default class LinearLineModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0]; return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0];
}, },
@ -231,9 +228,8 @@ export default class LinearLineModel extends BaseModel {
if (this.colorTexture) { if (this.colorTexture) {
this.colorTexture.destroy(); this.colorTexture.destroy();
} }
const { const { rampColors } =
rampColors, this.layer.getLayerConfig() as ILineLayerStyleOptions;
} = this.layer.getLayerConfig() as ILineLayerStyleOptions;
const imageData = generateColorRamp(rampColors as IColorRamp); const imageData = generateColorRamp(rampColors as IColorRamp);
this.colorTexture = createTexture2D({ this.colorTexture = createTexture2D({
data: new Uint8Array(imageData.data), data: new Uint8Array(imageData.data),

View File

@ -79,7 +79,7 @@ export default class SimpleLineModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
@ -87,10 +87,8 @@ export default class SimpleLineModel extends BaseModel {
} }
public getShaders(): { frag: string; vert: string; type: string } { public getShaders(): { frag: string; vert: string; type: string } {
const { const { sourceColor, targetColor } =
sourceColor, this.layer.getLayerConfig() as ILineLayerStyleOptions;
targetColor,
} = this.layer.getLayerConfig() as ILineLayerStyleOptions;
if (sourceColor && targetColor) { if (sourceColor && targetColor) {
// 分离 linear 功能 // 分离 linear 功能
return { return {
@ -107,27 +105,24 @@ export default class SimpleLineModel extends BaseModel {
} }
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as ILineLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as ILineLayerStyleOptions;
const { frag, vert, type } = this.getShaders(); const { frag, vert, type } = this.getShaders();
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: type,
moduleName: type, vertexShader: vert,
vertexShader: vert, fragmentShader: frag,
fragmentShader: frag, triangulation: SimpleLineTriangulation,
triangulation: SimpleLineTriangulation, primitive: gl.LINES,
primitive: gl.LINES, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), pick: false,
pick: false, });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({ this.styleAttributeService.registerStyleAttribute({
@ -185,9 +180,7 @@ export default class SimpleLineModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0]; return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0];
}, },

View File

@ -74,7 +74,7 @@ export default class LineWallModel extends BaseModel {
this.updateTexture(); this.updateTexture();
this.iconService.on('imageUpdate', this.updateTexture); this.iconService.on('imageUpdate', this.updateTexture);
return await this.buildModels(); return this.buildModels();
} }
public clearModels() { public clearModels() {
@ -82,17 +82,16 @@ export default class LineWallModel extends BaseModel {
this.iconService.off('imageUpdate', this.updateTexture); this.iconService.off('imageUpdate', this.updateTexture);
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'lineWall',
moduleName: 'lineWall', vertexShader: line_vert,
vertexShader: line_vert, fragmentShader: line_frag,
fragmentShader: line_frag, triangulation: LineTriangulation,
triangulation: LineTriangulation, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), });
}) return [model];
return [model]
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({ this.styleAttributeService.registerStyleAttribute({
@ -150,9 +149,7 @@ export default class LineWallModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0]; return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0];
}, },
@ -219,9 +216,7 @@ export default class LineWallModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 2, size: 2,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const iconMap = this.iconService.getIconMap(); const iconMap = this.iconService.getIconMap();
const { texture } = feature; const { texture } = feature;
const { x, y } = iconMap[texture as string] || { x: 0, y: 0 }; const { x, y } = iconMap[texture as string] || { x: 0, y: 0 };

View File

@ -9,10 +9,8 @@ import mask_vert from '../shaders/mask_vert.glsl';
export default class MaskModel extends BaseModel { export default class MaskModel extends BaseModel {
public getUninforms() { public getUninforms() {
const { const { opacity = 0, color = '#000' } =
opacity = 0, this.layer.getLayerConfig() as IMaskLayerStyleOptions;
color = '#000'
} = this.layer.getLayerConfig() as IMaskLayerStyleOptions;
return { return {
u_opacity: isNumber(opacity) ? opacity : 0.0, u_opacity: isNumber(opacity) ? opacity : 0.0,
u_color: rgb2arr(color), u_color: rgb2arr(color),
@ -20,39 +18,40 @@ export default class MaskModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels(): Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'mask',
moduleName: 'mask', vertexShader: mask_vert,
vertexShader: mask_vert, fragmentShader: mask_frag,
fragmentShader: mask_frag, triangulation: polygonTriangulation,
triangulation: polygonTriangulation, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), stencil: {
stencil: { enable: true,
enable: true, mask: 0xff,
func: {
cmp: gl.ALWAYS,
ref: 1,
mask: 0xff, mask: 0xff,
func: {
cmp: gl.ALWAYS,
ref: 1,
mask: 0xff,
},
opFront: {
fail: gl.REPLACE,
zfail: gl.REPLACE,
zpass: gl.REPLACE,
},
}, },
pick: false opFront: {
}) fail: gl.REPLACE,
return [model] zfail: gl.REPLACE,
zpass: gl.REPLACE,
},
},
pick: false,
});
return [model];
} }
public clearModels(refresh = true) { public clearModels(refresh = true) {
refresh && this.layerService.clear(); if (refresh) {
this.layerService.clear();
}
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {

View File

@ -8,92 +8,88 @@ describe('template', () => {
const body = document.querySelector('body') as HTMLBodyElement; const body = document.querySelector('body') as HTMLBodyElement;
body.appendChild(el); body.appendChild(el);
const scene = TestScene({}); const scene = TestScene({});
const testData = [ const testData = [
{ {
x: 112, x: 112,
y: 30, y: 30,
name:'text1', name: 'text1',
v:10, v: 10,
}, },
{ {
x: 112, x: 112,
y: 32, y: 32,
name:'text2', name: 'text2',
v:20 v: 20,
}, },
]; ];
it('scene layer fill', async () => { it('scene layer fill', async () => {
const layer = new PointLayer().source( const layer = new PointLayer()
testData, .source(testData, {
{
parser: { parser: {
type: 'json', type: 'json',
x: 'x', x: 'x',
y: 'y', y: 'y',
}, },
}, })
).shape('circle') .shape('circle')
.color('red') .color('red')
.size(10) .size(10);
scene.on('loaded', () =>{ scene.on('loaded', () => {
scene.addLayer(layer) scene.addLayer(layer);
}) });
}); });
it('scene layer text', async () => { it('scene layer text', async () => {
const layer = new PointLayer({name:'text'}).source( const layer = new PointLayer({ name: 'text' })
testData, .source(testData, {
{
parser: { parser: {
type: 'json', type: 'json',
x: 'x', x: 'x',
y: 'y', y: 'y',
}, },
}, })
).shape('name','text') .shape('name', 'text')
.color('name',['red','blue']) .color('name', ['red', 'blue'])
.size('v',[10,20]) .size('v', [10, 20]);
scene.on('loaded', () =>{ scene.on('loaded', () => {
scene.addLayer(layer) scene.addLayer(layer);
expect(layer.name).toEqual('text') expect(layer.name).toEqual('text');
}) });
}); });
it('scene layer extrude', async () => { it('scene layer extrude', async () => {
const layer = new PointLayer().source( const layer = new PointLayer()
testData, .source(testData, {
{
parser: { parser: {
type: 'json', type: 'json',
x: 'x', x: 'x',
y: 'y', y: 'y',
}, },
}, })
).shape('cloumn') .shape('cloumn')
.color('red') .color('red')
.size([5,5,10]) .size([5, 5, 10]);
scene.on('loaded', () =>{ scene.on('loaded', () => {
scene.addLayer(layer) scene.addLayer(layer);
}) });
}); });
it('scene layer simplePoint', async () => { it('scene layer simplePoint', async () => {
const layer = new PointLayer().source( const layer = new PointLayer()
testData, .source(testData, {
{
parser: { parser: {
type: 'json', type: 'json',
x: 'x', x: 'x',
y: 'y', y: 'y',
}, },
}, })
).shape('simple') .shape('simple')
.color('red') .color('red')
.size(1) .size(1);
scene.on('loaded', () =>{ scene.on('loaded', () => {
scene.addLayer(layer) scene.addLayer(layer);
}) });
}); });
}); });

View File

@ -129,31 +129,30 @@ export default class ExtrudeModel extends BaseModel {
u_lightEnable: Number(lightEnable), u_lightEnable: Number(lightEnable),
}; };
} }
public async initModels():Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
// GAODE1.x GAODE2.x MAPBOX // GAODE1.x GAODE2.x MAPBOX
const { const {
animateOption: { repeat = 1 }, animateOption: { repeat = 1 },
} = this.layer.getLayerConfig() as ILayerConfig; } = this.layer.getLayerConfig() as ILayerConfig;
this.raiseRepeat = repeat; this.raiseRepeat = repeat;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'pointEarthExtrude',
moduleName: 'pointEarthExtrude', vertexShader: pointExtrudeVert,
vertexShader: pointExtrudeVert, fragmentShader: pointExtrudeFrag,
fragmentShader: pointExtrudeFrag, triangulation: PointExtrudeTriangulation,
triangulation: PointExtrudeTriangulation, depth: { enable: true },
depth: { enable: true }, cull: {
cull: { enable: true,
enable: true, face: getCullFace(this.mapService.version),
face: getCullFace(this.mapService.version), },
}, blend: this.getBlend(),
blend: this.getBlend(), });
}); return [model];
return [model]
} }
public clearModels() { public clearModels() {
this.dataTexture?.destroy(); this.dataTexture?.destroy();
@ -170,9 +169,7 @@ export default class ExtrudeModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 3, size: 3,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size } = feature; const { size } = feature;
if (size) { if (size) {
let buffersize: number[] = []; let buffersize: number[] = [];

View File

@ -90,9 +90,8 @@ export default class FillModel extends BaseModel {
}; };
} }
public getAnimateUniforms(): IModelUniform { public getAnimateUniforms(): IModelUniform {
const { const { animateOption = { enable: false } } =
animateOption = { enable: false }, this.layer.getLayerConfig() as ILayerConfig;
} = this.layer.getLayerConfig() as ILayerConfig;
return { return {
u_animate: this.animateOption2Array(animateOption), u_animate: this.animateOption2Array(animateOption),
u_time: this.layer.getLayerAnimateTime(), u_time: this.layer.getLayerAnimateTime(),
@ -100,7 +99,7 @@ export default class FillModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels(): Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {

View File

@ -127,11 +127,11 @@ export default class ExtrudeModel extends BaseModel {
u_lightEnable: Number(lightEnable), u_lightEnable: Number(lightEnable),
}; };
} }
public async initModels():Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
// GAODE1.x GAODE2.x MAPBOX // GAODE1.x GAODE2.x MAPBOX
const { const {
depth = true, depth = true,
@ -139,23 +139,21 @@ export default class ExtrudeModel extends BaseModel {
} = this.layer.getLayerConfig() as ILayerConfig; } = this.layer.getLayerConfig() as ILayerConfig;
this.raiseRepeat = repeat; this.raiseRepeat = repeat;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'pointExtrude',
moduleName: 'pointExtrude', vertexShader: pointExtrudeVert,
vertexShader: pointExtrudeVert, fragmentShader: pointExtrudeFrag,
fragmentShader: pointExtrudeFrag, triangulation: PointExtrudeTriangulation,
triangulation: PointExtrudeTriangulation, blend: this.getBlend(),
blend: this.getBlend(), cull: {
cull: { enable: true,
enable: true, face: getCullFace(this.mapService.version),
face: getCullFace(this.mapService.version), },
}, depth: {
depth: { enable: depth,
enable: depth, },
}, });
}) return [model];
return [model]
} }
public clearModels() { public clearModels() {
this.dataTexture?.destroy(); this.dataTexture?.destroy();
@ -173,9 +171,7 @@ export default class ExtrudeModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 3, size: 3,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size } = feature; const { size } = feature;
if (size) { if (size) {
let buffersize: number[] = []; let buffersize: number[] = [];

View File

@ -28,42 +28,39 @@ export default class NormalModel extends BaseModel {
}; };
} }
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
const { const { opacity = 1 } =
opacity = 1, this.layer.getLayerConfig() as IPointLayerStyleOptions;
} = this.layer.getLayerConfig() as IPointLayerStyleOptions;
return { return {
u_opacity: isNumber(opacity) ? opacity : 1.0, u_opacity: isNumber(opacity) ? opacity : 1.0,
}; };
} }
public async initModels():Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IPointLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as IPointLayerStyleOptions;
this.layer.triangulation = PointTriangulation; this.layer.triangulation = PointTriangulation;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'pointNormal',
moduleName: 'pointNormal', vertexShader: normalVert,
vertexShader: normalVert, fragmentShader: normalFrag,
fragmentShader: normalFrag, triangulation: PointTriangulation,
triangulation: PointTriangulation, depth: { enable: false },
depth: { enable: false }, primitive: gl.POINTS,
primitive: gl.POINTS, blend: this.getBlend(),
blend: this.getBlend(), stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), pick: false,
pick: false, });
}) return [model];
return [model]
} }
public clearModels() { public clearModels() {
return;
} }
protected registerBuiltinAttributes() { protected registerBuiltinAttributes() {
@ -78,9 +75,7 @@ export default class NormalModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },

View File

@ -12,12 +12,11 @@ import {
import { getMask } from '@antv/l7-utils'; import { getMask } from '@antv/l7-utils';
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
import BaseModel from '../../core/BaseModel'; import BaseModel from '../../core/BaseModel';
import { IPointLayerStyleOptions } from '../../core/interface'; import { IPointLayerStyleOptions, SizeUnitType } from '../../core/interface';
import { PointFillTriangulation } from '../../core/triangulation'; import { PointFillTriangulation } from '../../core/triangulation';
import pointFillFrag from '../shaders/radar/radar_frag.glsl'; import pointFillFrag from '../shaders/radar/radar_frag.glsl';
import pointFillVert from '../shaders/radar/radar_vert.glsl'; import pointFillVert from '../shaders/radar/radar_vert.glsl';
import { SizeUnitType } from '../../core/interface'
export default class RadarModel extends BaseModel { export default class RadarModel extends BaseModel {
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
@ -25,7 +24,7 @@ export default class RadarModel extends BaseModel {
opacity = 1, opacity = 1,
blend, blend,
speed = 1, speed = 1,
unit = 'pixel' unit = 'pixel',
} = this.layer.getLayerConfig() as IPointLayerStyleOptions; } = this.layer.getLayerConfig() as IPointLayerStyleOptions;
return { return {
@ -36,9 +35,8 @@ export default class RadarModel extends BaseModel {
}; };
} }
public getAnimateUniforms(): IModelUniform { public getAnimateUniforms(): IModelUniform {
const { const { animateOption = { enable: false } } =
animateOption = { enable: false }, this.layer.getLayerConfig() as ILayerConfig;
} = this.layer.getLayerConfig() as ILayerConfig;
return { return {
u_animate: this.animateOption2Array(animateOption), u_animate: this.animateOption2Array(animateOption),
u_time: this.layer.getLayerAnimateTime(), u_time: this.layer.getLayerAnimateTime(),
@ -57,30 +55,24 @@ export default class RadarModel extends BaseModel {
); );
} }
public async initModels():Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels(): Promise<IModel[]> {
const { mask = false, maskInside = true } =
this.layer.getLayerConfig() as IPointLayerStyleOptions;
const model = await this.layer.buildLayerModel({
public async buildModels():Promise<IModel[]> { moduleName: 'pointRadar',
const { vertexShader: pointFillVert,
mask = false, fragmentShader: pointFillFrag,
maskInside = true, triangulation: PointFillTriangulation,
} = this.layer.getLayerConfig() as IPointLayerStyleOptions; depth: { enable: false },
blend: this.getBlend(),
const model = await this.layer stencil: getMask(mask, maskInside),
.buildLayerModel({ });
moduleName: 'pointRadar', return [model];
vertexShader: pointFillVert,
fragmentShader: pointFillFrag,
triangulation: PointFillTriangulation,
depth: { enable: false },
blend: this.getBlend(),
stencil: getMask(mask, maskInside),
})
return [model]
} }
public clearModels() { public clearModels() {
@ -134,13 +126,9 @@ export default class RadarModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 5 } = feature; const { size = 5 } = feature;
return Array.isArray(size) return Array.isArray(size) ? [size[0]] : [size as number];
? [size[0]]
: [(size as number)];
}, },
}, },
}); });

View File

@ -92,29 +92,26 @@ export default class SimplePointModel extends BaseModel {
}; };
} }
public async initModels():Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IPointLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as IPointLayerStyleOptions;
this.layer.triangulation = PointTriangulation; this.layer.triangulation = PointTriangulation;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'pointSimple',
moduleName: 'pointSimple', vertexShader: simplePointVert,
vertexShader: simplePointVert, fragmentShader: simplePointFrag,
fragmentShader: simplePointFrag, triangulation: PointTriangulation,
triangulation: PointTriangulation, depth: { enable: false },
depth: { enable: false }, primitive: gl.POINTS,
primitive: gl.POINTS, blend: this.getBlend(),
blend: this.getBlend(), stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
public clearModels() { public clearModels() {
@ -133,9 +130,7 @@ export default class SimplePointModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 1 } = feature; const { size = 1 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },

View File

@ -11,8 +11,8 @@ import BaseModel from '../../core/BaseModel';
import { IPolygonLayerStyleOptions } from '../../core/interface'; import { IPolygonLayerStyleOptions } from '../../core/interface';
import { PolygonExtrudeTriangulation } from '../../core/triangulation'; import { PolygonExtrudeTriangulation } from '../../core/triangulation';
import polygonExtrudeFrag from '../shaders/extrude/polygon_extrude_frag.glsl'; import polygonExtrudeFrag from '../shaders/extrude/polygon_extrude_frag.glsl';
// extrude
import polygonExtrudeVert from '../shaders/extrude/polygon_extrude_vert.glsl'; import polygonExtrudeVert from '../shaders/extrude/polygon_extrude_vert.glsl';
// extrude
import polygonExtrudeTexFrag from '../shaders/extrude/polygon_extrudetex_frag.glsl'; import polygonExtrudeTexFrag from '../shaders/extrude/polygon_extrudetex_frag.glsl';
// texture // texture
import polygonExtrudeTexVert from '../shaders/extrude/polygon_extrudetex_vert.glsl'; import polygonExtrudeTexVert from '../shaders/extrude/polygon_extrudetex_vert.glsl';
@ -95,32 +95,27 @@ export default class ExtrudeModel extends BaseModel {
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
this.loadTexture(); this.loadTexture();
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
const { frag, vert, type } = this.getShaders(); const { frag, vert, type } = this.getShaders();
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: type,
moduleName: type, vertexShader: vert,
vertexShader: vert, fragmentShader: frag,
fragmentShader: frag, triangulation: PolygonExtrudeTriangulation,
triangulation: PolygonExtrudeTriangulation, stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
public getShaders() { public getShaders() {
const { const { pickLight, mapTexture } =
pickLight, this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
mapTexture,
} = this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
if (mapTexture) { if (mapTexture) {
return { return {
frag: polygonExtrudeTexFrag, frag: polygonExtrudeTexFrag,
@ -212,9 +207,7 @@ export default class ExtrudeModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}, },
size: 1, size: 1,
update: ( update: (feature: IEncodeFeature) => {
feature: IEncodeFeature,
) => {
const { size = 10 } = feature; const { size = 10 } = feature;
return Array.isArray(size) ? [size[0]] : [size as number]; return Array.isArray(size) ? [size[0]] : [size as number];
}, },
@ -223,9 +216,8 @@ export default class ExtrudeModel extends BaseModel {
} }
private loadTexture() { private loadTexture() {
const { const { mapTexture } =
mapTexture, this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
} = this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
const { createTexture2D } = this.rendererService; const { createTexture2D } = this.rendererService;
this.texture = createTexture2D({ this.texture = createTexture2D({

View File

@ -53,7 +53,6 @@ export default class FillModel extends BaseModel {
width: 1, width: 1,
height: 1, height: 1,
}); });
} }
return { return {
@ -70,10 +69,10 @@ export default class FillModel extends BaseModel {
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { frag, vert, triangulation, type } = this.getModelParams(); const { frag, vert, triangulation, type } = this.getModelParams();
const { const {
mask = false, mask = false,
@ -84,23 +83,22 @@ export default class FillModel extends BaseModel {
ILayerConfig & IPolygonLayerStyleOptions ILayerConfig & IPolygonLayerStyleOptions
>; >;
this.layer.triangulation = triangulation; this.layer.triangulation = triangulation;
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: type,
moduleName: type, vertexShader: vert,
vertexShader: vert, fragmentShader: frag,
fragmentShader: frag, triangulation,
triangulation, primitive: gl.TRIANGLES,
primitive: gl.TRIANGLES, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), workerEnabled,
workerEnabled, workerOptions: {
workerOptions: { modelType: type,
modelType: type, enablePicking,
enablePicking, },
}, });
}) return [model];
return [model]
} }
public clearModels() { public clearModels() {

View File

@ -19,7 +19,7 @@ export type PolygonModelType =
| 'point_extrude' | 'point_extrude'
| 'text' | 'text'
| 'water' | 'water'
| 'ocean' | 'ocean';
const PolygonModels: { [key in PolygonModelType]: any } = { const PolygonModels: { [key in PolygonModelType]: any } = {
fill: FillModel, fill: FillModel,
line: LineModel, line: LineModel,

View File

@ -43,25 +43,22 @@ export default class OceanModel extends BaseModel {
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
this.loadTexture(); this.loadTexture();
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
maskInside = true, const model = await this.layer.buildLayerModel({
} = this.layer.getLayerConfig() as IPolygonLayerStyleOptions; moduleName: 'polygonOcean',
const model = await this.layer vertexShader: ocean_vert,
.buildLayerModel({ fragmentShader: ocean_frag,
moduleName: 'polygonOcean', triangulation: polygonTriangulation,
vertexShader: ocean_vert, primitive: gl.TRIANGLES,
fragmentShader: ocean_frag, depth: { enable: false },
triangulation: polygonTriangulation, stencil: getMask(mask, maskInside),
primitive: gl.TRIANGLES, });
depth: { enable: false }, return [model];
stencil: getMask(mask, maskInside),
})
return [model]
} }
public clearModels() { public clearModels() {
@ -94,7 +91,10 @@ export default class OceanModel extends BaseModel {
vertex: number[], vertex: number[],
attributeIdx: number, attributeIdx: number,
) => { ) => {
const v = (feature.version === Version['GAODE2.x'] ? feature.originCoordinates[0][attributeIdx] : vertex) const v =
feature.version === Version['GAODE2.x']
? feature.originCoordinates[0][attributeIdx]
: vertex;
const [lng, lat] = v; const [lng, lat] = v;
return [(lng - minLng) / lngLen, (lat - minLat) / latLen]; return [(lng - minLng) / lngLen, (lat - minLat) / latLen];
}, },

View File

@ -17,10 +17,8 @@ import water_vert from '../shaders/water/polygon_water_vert.glsl';
export default class WaterModel extends BaseModel { export default class WaterModel extends BaseModel {
private texture: ITexture2D; private texture: ITexture2D;
public getUninforms() { public getUninforms() {
const { const { opacity = 1, speed = 0.5 } =
opacity = 1, this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
speed = 0.5,
} = this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
return { return {
u_texture: this.texture, u_texture: this.texture,
u_speed: speed, u_speed: speed,
@ -36,25 +34,22 @@ export default class WaterModel extends BaseModel {
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
this.loadTexture(); this.loadTexture();
return await this.buildModels(); return this.buildModels();
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
maskInside = true, const model = await this.layer.buildLayerModel({
} = this.layer.getLayerConfig() as IPolygonLayerStyleOptions; moduleName: 'polygonWater',
const model = await this.layer vertexShader: water_vert,
.buildLayerModel({ fragmentShader: water_frag,
moduleName: 'polygonWater', triangulation: polygonTriangulation,
vertexShader: water_vert, primitive: gl.TRIANGLES,
fragmentShader: water_frag, depth: { enable: false },
triangulation: polygonTriangulation, stencil: getMask(mask, maskInside),
primitive: gl.TRIANGLES, });
depth: { enable: false }, return [model];
stencil: getMask(mask, maskInside),
})
return [model]
} }
public clearModels() { public clearModels() {
@ -83,9 +78,12 @@ export default class WaterModel extends BaseModel {
feature: IEncodeFeature, feature: IEncodeFeature,
featureIdx: number, featureIdx: number,
vertex: number[], vertex: number[],
attributeIdx: number attributeIdx: number,
) => { ) => {
const v = (feature.version === Version['GAODE2.x'] ? feature.originCoordinates[0][attributeIdx] : vertex) const v =
feature.version === Version['GAODE2.x']
? feature.originCoordinates[0][attributeIdx]
: vertex;
const [lng, lat] = v; const [lng, lat] = v;
return [(lng - minLng) / lngLen, (lat - minLat) / latLen]; return [(lng - minLng) / lngLen, (lat - minLat) / latLen];
}, },
@ -94,9 +92,8 @@ export default class WaterModel extends BaseModel {
} }
private loadTexture() { private loadTexture() {
const { const { waterTexture } =
waterTexture, this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
} = this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
const { createTexture2D } = this.rendererService; const { createTexture2D } = this.rendererService;
this.texture = createTexture2D({ this.texture = createTexture2D({

View File

@ -2,7 +2,7 @@ import { IParseDataItem } from '@antv/l7-core';
// @ts-ignore // @ts-ignore
import Martini from '@mapbox/martini'; import Martini from '@mapbox/martini';
export function RasterTriangulation(parserData: IParseDataItem) { export function RasterTriangulation(parserData: IParseDataItem) {
const { data,width, height } = parserData; const { data, width, height } = parserData;
const maxlength = Math.max(width, height); const maxlength = Math.max(width, height);
const gridSize = Math.pow(2, Math.ceil(Math.log2(maxlength))) + 1; const gridSize = Math.pow(2, Math.ceil(Math.log2(maxlength))) + 1;
const terrain = new Float32Array(gridSize * gridSize); const terrain = new Float32Array(gridSize * gridSize);

View File

@ -1,13 +1,17 @@
import RasterModel from './raster'; import RasterModel from './raster';
import RasterRgbModel from './rasterRgb'; import RasterRgbModel from './rasterRgb';
import RasterTerrainRGB from './rasterTerrainRgb'; import RasterTerrainRGB from './rasterTerrainRgb';
export type RasterModelType = 'raster' | 'raster3d' | 'rasterRgb' | 'rasterTerrainRgb'; export type RasterModelType =
| 'raster'
| 'raster3d'
| 'rasterRgb'
| 'rasterTerrainRgb';
const RasterModels: { [key in RasterModelType]: any } = { const RasterModels: { [key in RasterModelType]: any } = {
raster: RasterModel, raster: RasterModel,
rasterRgb: RasterRgbModel, rasterRgb: RasterRgbModel,
raster3d: RasterModel, raster3d: RasterModel,
rasterTerrainRgb: RasterTerrainRGB rasterTerrainRgb: RasterTerrainRGB,
}; };
export default RasterModels; export default RasterModels;

View File

@ -5,7 +5,7 @@ import {
IModel, IModel,
ITexture2D, ITexture2D,
} from '@antv/l7-core'; } from '@antv/l7-core';
import { getMask,getDefaultDomain } from '@antv/l7-utils'; import { getDefaultDomain, getMask } from '@antv/l7-utils';
import BaseModel from '../../core/BaseModel'; import BaseModel from '../../core/BaseModel';
import { IRasterLayerStyleOptions } from '../../core/interface'; import { IRasterLayerStyleOptions } from '../../core/interface';
import { RasterImageTriangulation } from '../../core/triangulation'; import { RasterImageTriangulation } from '../../core/triangulation';
@ -23,8 +23,11 @@ export default class RasterModel extends BaseModel {
domain, domain,
rampColors, rampColors,
} = this.layer.getLayerConfig() as IRasterLayerStyleOptions; } = this.layer.getLayerConfig() as IRasterLayerStyleOptions;
const newdomain = domain ||getDefaultDomain(rampColors) const newdomain = domain || getDefaultDomain(rampColors);
this.colorTexture = this.layer.textureService.getColorTexture(rampColors,newdomain); this.colorTexture = this.layer.textureService.getColorTexture(
rampColors,
newdomain,
);
return { return {
u_opacity: opacity || 1, u_opacity: opacity || 1,
u_texture: this.texture, u_texture: this.texture,
@ -37,34 +40,32 @@ export default class RasterModel extends BaseModel {
} }
private async getRasterData(parserDataItem: any) { private async getRasterData(parserDataItem: any) {
if(Array.isArray(parserDataItem.data)) { if (Array.isArray(parserDataItem.data)) {
// 直接传入波段数据 // 直接传入波段数据
return { return {
data: parserDataItem.data, data: parserDataItem.data,
width: parserDataItem.width, width: parserDataItem.width,
height: parserDataItem.height, height: parserDataItem.height,
} };
} else { } else {
// 多波段形式、需要进行处理 // 多波段形式、需要进行处理
const { rasterData, width, height } = await parserDataItem.data; const { rasterData, width, height } = await parserDataItem.data;
return { return {
data: Array.from(rasterData), data: Array.from(rasterData),
width, width,
height height,
} };
} }
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IRasterLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as IRasterLayerStyleOptions;
const source = this.layer.getSource(); const source = this.layer.getSource();
const { createTexture2D } = this.rendererService; const { createTexture2D } = this.rendererService;
const parserDataItem = source.data.dataArray[0]; const parserDataItem = source.data.dataArray[0];
const {data, width, height} = await this.getRasterData(parserDataItem); const { data, width, height } = await this.getRasterData(parserDataItem);
this.texture = createTexture2D({ this.texture = createTexture2D({
data, data,
@ -75,21 +76,20 @@ export default class RasterModel extends BaseModel {
// aniso: 4, // aniso: 4,
}); });
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'rasterImageData',
moduleName: 'rasterImageData', vertexShader: rasterVert,
vertexShader: rasterVert, fragmentShader: rasterFrag,
fragmentShader: rasterFrag, triangulation: RasterImageTriangulation,
triangulation: RasterImageTriangulation, primitive: gl.TRIANGLES,
primitive: gl.TRIANGLES, depth: { enable: false },
depth: { enable: false }, stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
return await this.initModels(); return this.initModels();
} }
public clearModels(): void { public clearModels(): void {
@ -121,5 +121,4 @@ export default class RasterModel extends BaseModel {
}, },
}); });
} }
} }

View File

@ -9,18 +9,16 @@ import { getMask } from '@antv/l7-utils';
import BaseModel from '../../core/BaseModel'; import BaseModel from '../../core/BaseModel';
import { IRasterLayerStyleOptions } from '../../core/interface'; import { IRasterLayerStyleOptions } from '../../core/interface';
import { RasterImageTriangulation } from '../../core/triangulation'; import { RasterImageTriangulation } from '../../core/triangulation';
import rasterFrag from '../shaders/raster_rgb_frag.glsl';
import rasterVert from '../shaders/raster_2d_vert.glsl'; import rasterVert from '../shaders/raster_2d_vert.glsl';
import rasterFrag from '../shaders/raster_rgb_frag.glsl';
export default class RasterModel extends BaseModel { export default class RasterModel extends BaseModel {
protected texture: ITexture2D; protected texture: ITexture2D;
protected dataOption: any = {}; protected dataOption: any = {};
public getUninforms() { public getUninforms() {
const { const { opacity = 1, noDataValue = 0 } =
opacity = 1, this.layer.getLayerConfig() as IRasterLayerStyleOptions;
noDataValue = 0, const { rMinMax, gMinMax, bMinMax } = this.dataOption;
} = this.layer.getLayerConfig() as IRasterLayerStyleOptions;
const {rMinMax,gMinMax,bMinMax} = this.dataOption;
return { return {
u_opacity: opacity || 1, u_opacity: opacity || 1,
u_texture: this.texture, u_texture: this.texture,
@ -28,48 +26,44 @@ export default class RasterModel extends BaseModel {
u_rminmax: rMinMax, u_rminmax: rMinMax,
u_gminmax: gMinMax, u_gminmax: gMinMax,
u_bminmax: bMinMax, u_bminmax: bMinMax,
}; };
} }
private async getRasterData(parserDataItem: any) { private async getRasterData(parserDataItem: any) {
if (Array.isArray(parserDataItem.data)) {
if(Array.isArray(parserDataItem.data)) { const { data, ...rescfg } = parserDataItem;
const {data,...rescfg} = parserDataItem;
this.dataOption = rescfg; this.dataOption = rescfg;
return { return {
data, data,
...rescfg ...rescfg,
} };
} }
const { rasterData,...rest } = await parserDataItem.data; const { rasterData, ...rest } = await parserDataItem.data;
this.dataOption = rest; this.dataOption = rest;
if(Array.isArray(rasterData)) { if (Array.isArray(rasterData)) {
// 直接传入波段数据 // 直接传入波段数据
return { return {
data: rasterData, data: rasterData,
...rest ...rest,
} };
} else { } else {
// 多波段形式、需要进行处理 // 多波段形式、需要进行处理
// 支持彩色栅格(多通道) // 支持彩色栅格(多通道)
return { return {
data: Array.from(rasterData), data: Array.from(rasterData),
...rest ...rest,
} };
} }
} }
public async initModels(): Promise<IModel[]> { public async initModels(): Promise<IModel[]> {
const { const { mask = false, maskInside = true } =
mask = false, this.layer.getLayerConfig() as IRasterLayerStyleOptions;
maskInside = true,
} = this.layer.getLayerConfig() as IRasterLayerStyleOptions;
const source = this.layer.getSource(); const source = this.layer.getSource();
const { createTexture2D } = this.rendererService; const { createTexture2D } = this.rendererService;
const parserDataItem = source.data.dataArray[0]; const parserDataItem = source.data.dataArray[0];
const {data, width, height} = await this.getRasterData(parserDataItem); const { data, width, height } = await this.getRasterData(parserDataItem);
this.texture = createTexture2D({ this.texture = createTexture2D({
// @ts-ignore // @ts-ignore
data, data,
@ -79,21 +73,20 @@ export default class RasterModel extends BaseModel {
type: gl.FLOAT, type: gl.FLOAT,
}); });
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'rasterImageDataRGBA',
moduleName: 'rasterImageDataRGBA', vertexShader: rasterVert,
vertexShader: rasterVert, fragmentShader: rasterFrag,
fragmentShader: rasterFrag, triangulation: RasterImageTriangulation,
triangulation: RasterImageTriangulation, primitive: gl.TRIANGLES,
primitive: gl.TRIANGLES, depth: { enable: false },
depth: { enable: false }, stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
} }
public async buildModels():Promise<IModel[]> { public async buildModels(): Promise<IModel[]> {
return await this.initModels(); return this.initModels();
} }
public clearModels(): void { public clearModels(): void {

View File

@ -1,105 +1,108 @@
import { import {
AttributeType, AttributeType,
gl, gl,
IEncodeFeature, IEncodeFeature,
IModel, IModel,
IModelUniform, IModelUniform,
ITexture2D, ITexture2D,
} from '@antv/l7-core'; } from '@antv/l7-core';
import { getMask,getDefaultDomain } from '@antv/l7-utils'; import { getDefaultDomain, getMask } from '@antv/l7-utils';
import BaseModel from '../../core/BaseModel'; import BaseModel from '../../core/BaseModel';
import { IRasterLayerStyleOptions } from '../../core/interface'; import { IRasterLayerStyleOptions } from '../../core/interface';
import { RasterImageTriangulation } from '../../core/triangulation'; import { RasterImageTriangulation } from '../../core/triangulation';
import Raster_terrainFrag from '../shaders/raster_terrain_rgb_frag.glsl'; import Raster_terrainFrag from '../shaders/raster_terrain_rgb_frag.glsl';
import Raster_terrainVert from '../shaders/rater_terrain_rgb_vert.glsl'; import Raster_terrainVert from '../shaders/rater_terrain_rgb_vert.glsl';
export default class RasterTerrainRGB extends BaseModel { export default class RasterTerrainRGB extends BaseModel {
protected texture: ITexture2D; protected texture: ITexture2D;
public getUninforms(): IModelUniform { public getUninforms(): IModelUniform {
const { const {
opacity, opacity,
clampLow = true, clampLow = true,
clampHigh = true, clampHigh = true,
noDataValue = -9999999, noDataValue = -9999999,
domain, domain,
rampColors,
colorTexture,
} = this.layer.getLayerConfig() as IRasterLayerStyleOptions;
const newdomain = domain || getDefaultDomain(rampColors);
let texture: ITexture2D | undefined = colorTexture;
if (!colorTexture) {
texture = this.layer.textureService.getColorTexture(
rampColors, rampColors,
colorTexture newdomain,
} = this.layer.getLayerConfig() as IRasterLayerStyleOptions; ) as ITexture2D;
const newdomain = domain ||getDefaultDomain(rampColors) } else {
let texture:ITexture2D | undefined = colorTexture; this.layer.textureService.setColorTexture(
if(!colorTexture) { colorTexture,
texture = this.layer.textureService.getColorTexture(rampColors,newdomain) as ITexture2D; rampColors,
} else { newdomain,
this.layer.textureService.setColorTexture(colorTexture,rampColors,newdomain) );
}
return {
u_opacity: opacity || 1,
u_texture: this.texture,
u_domain: newdomain,
u_clampLow: clampLow,
u_clampHigh: typeof clampHigh !== 'undefined' ? clampHigh : clampLow,
u_noDataValue: noDataValue,
u_colorTexture: texture!,
};
} }
public async initModels(): Promise<IModel[]> { return {
const { u_opacity: opacity || 1,
mask = false, u_texture: this.texture,
maskInside = true, u_domain: newdomain,
} = this.layer.getLayerConfig() as IRasterLayerStyleOptions; u_clampLow: clampLow,
u_clampHigh: typeof clampHigh !== 'undefined' ? clampHigh : clampLow,
u_noDataValue: noDataValue,
u_colorTexture: texture!,
};
}
public async initModels(): Promise<IModel[]> {
const { mask = false, maskInside = true } =
this.layer.getLayerConfig() as IRasterLayerStyleOptions;
const source = this.layer.getSource(); const source = this.layer.getSource();
const { createTexture2D } = this.rendererService; const { createTexture2D } = this.rendererService;
const imageData = await source.data.images; const imageData = await source.data.images;
this.texture = createTexture2D({ this.texture = createTexture2D({
data: imageData[0], data: imageData[0],
width: imageData[0].width, width: imageData[0].width,
height: imageData[0].height, height: imageData[0].height,
}); });
const model = await this.layer const model = await this.layer.buildLayerModel({
.buildLayerModel({ moduleName: 'RasterTileDataImage',
moduleName: 'RasterTileDataImage', vertexShader: Raster_terrainVert,
vertexShader: Raster_terrainVert, fragmentShader: Raster_terrainFrag,
fragmentShader: Raster_terrainFrag, triangulation: RasterImageTriangulation,
triangulation: RasterImageTriangulation, primitive: gl.TRIANGLES,
primitive: gl.TRIANGLES, depth: { enable: false },
depth: { enable: false }, blend: this.getBlend(),
blend: this.getBlend(), stencil: getMask(mask, maskInside),
stencil: getMask(mask, maskInside), });
}) return [model];
return [model]
}
public clearModels(): void {
this.texture?.destroy();
}
public async buildModels(): Promise<IModel[]> {
return await this.initModels();
}
protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({
name: 'uv',
type: AttributeType.Attribute,
descriptor: {
name: 'a_Uv',
buffer: {
usage: gl.DYNAMIC_DRAW,
data: [],
type: gl.FLOAT,
},
size: 2,
update: (
feature: IEncodeFeature,
featureIdx: number,
vertex: number[],
) => {
return [vertex[3], vertex[4]];
},
},
});
}
} }
public clearModels(): void {
this.texture?.destroy();
}
public async buildModels(): Promise<IModel[]> {
return this.initModels();
}
protected registerBuiltinAttributes() {
this.styleAttributeService.registerStyleAttribute({
name: 'uv',
type: AttributeType.Attribute,
descriptor: {
name: 'a_Uv',
buffer: {
usage: gl.DYNAMIC_DRAW,
data: [],
type: gl.FLOAT,
},
size: 2,
update: (
feature: IEncodeFeature,
featureIdx: number,
vertex: number[],
) => {
return [vertex[3], vertex[4]];
},
},
});
}
}

View File

@ -1,81 +1,78 @@
import { import { IMapService, IRendererService } from '@antv/l7-core';
IMapService,
IRendererService
} from '@antv/l7-core';
import { DOM, SourceTile } from '@antv/l7-utils'; import { DOM, SourceTile } from '@antv/l7-utils';
export function readRasterValue( export function readRasterValue(
tile: SourceTile, tile: SourceTile,
mapService: IMapService, mapService: IMapService,
x: number, x: number,
y: number, y: number,
) {
const bbox = tile?.bboxPolygon?.bbox || [0, 0, 10, -10];
const [minLng = 0, minLat = 0, maxLng = 10, maxLat = -10] = bbox;
const tileXY = mapService.lngLatToContainer([minLng, minLat]);
const tileMaxXY = mapService.lngLatToContainer([maxLng, maxLat]);
const tilePixelWidth = tileMaxXY.x - tileXY.x;
const tilePixelHeight = tileXY.y - tileMaxXY.y;
const pos = [
(x - tileXY.x) / tilePixelWidth, // x
(y - tileMaxXY.y) / tilePixelHeight, // y
];
const tileWidth = tile?.data?.width || 1;
const tileHeight = tile?.data?.height || 1;
const indexX = Math.floor(pos[0] * tileWidth);
const indexY = Math.floor(pos[1] * tileHeight);
const index = Math.max(0, indexY - 1) * tileWidth + indexX;
const data = tile?.data?.data[index];
return data;
}
export function readPixel(
x: number,
y: number,
rendererService: IRendererService,
) {
const { readPixels, getContainer } = rendererService;
const xInDevicePixel = x * DOM.DPR;
const yInDevicePixel = y * DOM.DPR;
let { width, height } = getContainerSize(
getContainer() as HTMLCanvasElement | HTMLElement,
);
width *= DOM.DPR;
height *= DOM.DPR;
if (
xInDevicePixel > width - 1 * DOM.DPR ||
xInDevicePixel < 0 ||
yInDevicePixel > height - 1 * DOM.DPR ||
yInDevicePixel < 0
) { ) {
const bbox = tile?.bboxPolygon?.bbox || [0, 0, 10, -10]; return false;
const [minLng = 0, minLat = 0, maxLng = 10, maxLat = -10] = bbox;
const tileXY = mapService.lngLatToContainer([minLng, minLat]);
const tileMaxXY = mapService.lngLatToContainer([maxLng, maxLat]);
const tilePixelWidth = tileMaxXY.x - tileXY.x;
const tilePixelHeight = tileXY.y - tileMaxXY.y;
const pos = [
(x - tileXY.x) / tilePixelWidth, // x
(y - tileMaxXY.y) / tilePixelHeight, // y
];
const tileWidth = tile?.data?.width || 1;
const tileHeight = tile?.data?.height || 1;
const indexX = Math.floor(pos[0] * tileWidth);
const indexY = Math.floor(pos[1] * tileHeight);
const index = Math.max(0, indexY - 1) * tileWidth + indexX;
const data = tile?.data?.data[index];
return data;
} }
export function readPixel( const pickedColors = readPixels({
x: number, x: Math.floor(xInDevicePixel),
y: number, // 视口坐标系原点在左上,而 WebGL 在左下,需要翻转 Y 轴
rendererService: IRendererService, y: Math.floor(height - (y + 1) * DOM.DPR),
) { width: 1,
const { readPixels, getContainer } = rendererService; height: 1,
const xInDevicePixel = x * DOM.DPR; data: new Uint8Array(1 * 1 * 4),
const yInDevicePixel = y * DOM.DPR; });
let { width, height } = getContainerSize( return pickedColors;
getContainer() as HTMLCanvasElement | HTMLElement, }
);
width *= DOM.DPR;
height *= DOM.DPR;
if (
xInDevicePixel > width - 1 * DOM.DPR ||
xInDevicePixel < 0 ||
yInDevicePixel > height - 1 * DOM.DPR ||
yInDevicePixel < 0
) {
return false;
}
const pickedColors = readPixels({ function getContainerSize(container: HTMLCanvasElement | HTMLElement) {
x: Math.floor(xInDevicePixel), if ((container as HTMLCanvasElement).getContext) {
// 视口坐标系原点在左上,而 WebGL 在左下,需要翻转 Y 轴 return {
y: Math.floor(height - (y + 1) * DOM.DPR), width: (container as HTMLCanvasElement).width / DOM.DPR,
width: 1, height: (container as HTMLCanvasElement).height / DOM.DPR,
height: 1, };
data: new Uint8Array(1 * 1 * 4), } else {
}); return container.getBoundingClientRect();
return pickedColors;
}
function getContainerSize(container: HTMLCanvasElement | HTMLElement) {
if ((container as HTMLCanvasElement).getContext) {
return {
width: (container as HTMLCanvasElement).width / DOM.DPR,
height: (container as HTMLCanvasElement).height / DOM.DPR,
};
} else {
return container.getBoundingClientRect();
}
} }
}

View File

@ -1,64 +1,67 @@
import { import { ILayer } from '@antv/l7-core';
ILayer,
} from '@antv/l7-core';
import { decodePickingColor } from '@antv/l7-utils'; import { decodePickingColor } from '@antv/l7-utils';
export function clearPickState(layers: ILayer[]) { export function clearPickState(layers: ILayer[]) {
layers layers
.filter((layer) => layer.inited && layer.isVisible()) .filter((layer) => layer.inited && layer.isVisible())
.filter((layer) => layer.getCurrentSelectedId() !== null) .filter((layer) => layer.getCurrentSelectedId() !== null)
.map((layer) => { .map((layer) => {
selectFeature(layer, new Uint8Array([0, 0, 0, 0])); selectFeature(layer, new Uint8Array([0, 0, 0, 0]));
layer.setCurrentSelectedId(null); layer.setCurrentSelectedId(null);
}); });
} }
export function setSelect(layers: ILayer[], pickedColors: any, renderList: ILayer[]) { export function setSelect(
const selectedId = decodePickingColor(pickedColors); layers: ILayer[],
let pickColor pickedColors: any,
layers.map((layer) => { renderList: ILayer[],
if ( ) {
layer.getCurrentSelectedId() === null || const selectedId = decodePickingColor(pickedColors);
selectedId !== layer.getCurrentSelectedId() let pickColor;
) { layers.map((layer) => {
selectFeature(layer, pickedColors); if (
layer.setCurrentSelectedId(selectedId); layer.getCurrentSelectedId() === null ||
pickColor = pickedColors; selectedId !== layer.getCurrentSelectedId()
} else { ) {
selectFeature(layer, new Uint8Array([0, 0, 0, 0])); // toggle select selectFeature(layer, pickedColors);
layer.setCurrentSelectedId(null); layer.setCurrentSelectedId(selectedId);
pickColor = null; pickColor = pickedColors;
} } else {
selectFeature(layer, new Uint8Array([0, 0, 0, 0])); // toggle select
layer.setCurrentSelectedId(null);
pickColor = null;
}
});
// unselect normal layer
renderList
.filter(
(layer) => layer.inited && layer.isVisible() && layer.needPick('click'),
)
.filter((layer) => layer.getCurrentSelectedId() !== null)
.map((layer) => {
selectFeature(layer, new Uint8Array([0, 0, 0, 0]));
layer.setCurrentSelectedId(null);
}); });
// unselect normal layer return pickColor;
renderList
.filter(
(layer) =>
layer.inited &&
layer.isVisible() &&
layer.needPick('click'),
)
.filter((layer) => layer.getCurrentSelectedId() !== null)
.map((layer) => {
selectFeature(layer, new Uint8Array([0, 0, 0, 0]));
layer.setCurrentSelectedId(null);
});
return pickColor;
} }
export function setHighlight(layers: ILayer[], pickedColors: any) { export function setHighlight(layers: ILayer[], pickedColors: any) {
const pickId = decodePickingColor(pickedColors); const pickId = decodePickingColor(pickedColors);
layers.filter((layer) => layer.inited && layer.isVisible()) layers
.filter((layer) => layer.inited && layer.isVisible())
// @ts-ignore // @ts-ignore
.filter((layer) => layer.getPickID() !== pickId) .filter((layer) => layer.getPickID() !== pickId)
.map((layer) => { .map((layer) => {
// @ts-ignore // @ts-ignore
layer.setPickID(pickId); layer.setPickID(pickId);
layer.hooks.beforeHighlight.call(pickedColors); layer.hooks.beforeHighlight.call(pickedColors);
}); });
} }
export function setPickState(layers: ILayer[], pickColors: { select: any, active: any }) { export function setPickState(
layers: ILayer[],
pickColors: { select: any; active: any },
) {
if (pickColors.select) { if (pickColors.select) {
layers.map((layer) => { layers.map((layer) => {
selectFeature(layer, pickColors.select); selectFeature(layer, pickColors.select);
@ -74,24 +77,27 @@ export function setPickState(layers: ILayer[], pickColors: { select: any, active
} }
} }
export function selectFeature(layer: ILayer, pickedColors: Uint8Array | undefined) { export function selectFeature(
// @ts-ignore layer: ILayer,
const [r, g, b] = pickedColors; pickedColors: Uint8Array | undefined,
layer.hooks.beforeSelect.call([r, g, b]); ) {
// @ts-ignore
const [r, g, b] = pickedColors;
layer.hooks.beforeSelect.call([r, g, b]);
} }
export function setFeatureSelect(color: any, layers: ILayer[]) { export function setFeatureSelect(color: any, layers: ILayer[]) {
const id = decodePickingColor(color); const id = decodePickingColor(color);
layers.map((layer) => { layers.map((layer) => {
selectFeature(layer, color); selectFeature(layer, color);
layer.setCurrentSelectedId(id); layer.setCurrentSelectedId(id);
}); });
} }
export function setFeatureActive(color: any, layers: ILayer[]) { export function setFeatureActive(color: any, layers: ILayer[]) {
const id = decodePickingColor(color); const id = decodePickingColor(color);
layers.map((layer) => { layers.map((layer) => {
layer.hooks.beforeHighlight.call(color); layer.hooks.beforeHighlight.call(color);
layer.setCurrentPickId(id); layer.setCurrentPickId(id);
}); });
} }

View File

@ -1,10 +1,10 @@
import { import {
ILayer,
IRendererService,
IMapService,
ISubLayerInitOptions,
createLayerContainer, createLayerContainer,
ILayer,
ILayerService, ILayerService,
IMapService,
IRendererService,
ISubLayerInitOptions,
} from '@antv/l7-core'; } from '@antv/l7-core';
import { SourceTile } from '@antv/l7-utils'; import { SourceTile } from '@antv/l7-utils';
import { Container } from 'inversify'; import { Container } from 'inversify';
@ -22,16 +22,18 @@ export class Base {
private tileLayerCache: Map<string, ILayer[]> = new Map(); private tileLayerCache: Map<string, ILayer[]> = new Map();
private async initTileLayers(layers: ILayer[], tile: SourceTile) { private async initTileLayers(layers: ILayer[], tile: SourceTile) {
return Promise.all(layers.map(async (layer) => { return Promise.all(
const container = createLayerContainer( layers.map(async (layer) => {
this.parent.sceneContainer as Container, const container = createLayerContainer(
); this.parent.sceneContainer as Container,
layer.setContainer(container, this.parent.sceneContainer as Container); );
await layer.init(); layer.setContainer(container, this.parent.sceneContainer as Container);
this.addChild(layer); await layer.init();
tile.layerLoad(); this.addChild(layer);
this.render() tile.layerLoad();
})); this.render();
}),
);
} }
public render() { public render() {
@ -46,10 +48,11 @@ export class Base {
public async addTile(tile: SourceTile) { public async addTile(tile: SourceTile) {
// oldTile 存在的时候暂时直接结束 // oldTile 存在的时候暂时直接结束
// TODO合并不存在的时候 // TODO合并不存在的时候
if (this.hasTile(tile)) if (this.hasTile(tile)) {
return { return {
layers: [], layers: [],
}; };
}
// 存储当前 tile // 存储当前 tile
this.tileCache.set(tile.key, tile); this.tileCache.set(tile.key, tile);
@ -68,7 +71,6 @@ export class Base {
// updateLayersConfig(this.getLayers(t),'visible',visible) // updateLayersConfig(this.getLayers(t),'visible',visible)
// }) // })
return layerCollections; return layerCollections;
} }
@ -101,7 +103,9 @@ export class Base {
} }
public getLayers(tile: SourceTile) { public getLayers(tile: SourceTile) {
if (!tile) return []; if (!tile) {
return [];
}
return this.tileLayerCache.get(tile.key) || []; return this.tileLayerCache.get(tile.key) || [];
} }
@ -121,7 +125,6 @@ export class Base {
} }
public initTileFactory() { public initTileFactory() {
// this.tileFactory = new TileFactory({ // this.tileFactory = new TileFactory({
// parent: this.parent, // parent: this.parent,
// mapService: this.mapService, // mapService: this.mapService,
@ -144,13 +147,12 @@ export class Base {
public updateTileVisible(tile: SourceTile, layerService: ILayerService) { public updateTileVisible(tile: SourceTile, layerService: ILayerService) {
const layers = this.getLayers(tile); const layers = this.getLayers(tile);
if (layers.length === 0) return; if (layers.length === 0) {
return;
}
if (tile.isVisible) { if (tile.isVisible) {
// 如果可见直接进行渲染,父级发 // 如果可见直接进行渲染,父级发
updateLayersConfig(layers, 'visible', tile.isVisible); updateLayersConfig(layers, 'visible', tile.isVisible);
} else { } else {
// 如果不可见,放大,等到子瓦片渲染完成,缩小:父级渲染成功 // 如果不可见,放大,等到子瓦片渲染完成,缩小:父级渲染成功
// console.log('updateTileVisible',`${tile.x}_${tile.y}_${tile.z}`,tile.isVisible) // console.log('updateTileVisible',`${tile.x}_${tile.y}_${tile.z}`,tile.isVisible)
@ -184,14 +186,18 @@ export class Base {
} }
public isTileLoaded(tile: SourceTile) { public isTileLoaded(tile: SourceTile) {
if (tile.isLoad) return true; if (tile.isLoad) {
return true;
}
const isLoad = this.getLayers(tile).length === tile.loadedLayers; const isLoad = this.getLayers(tile).length === tile.loadedLayers;
tile.isLoad = isLoad; tile.isLoad = isLoad;
return isLoad; return isLoad;
} }
public isTileChildLoaded(tile: SourceTile) { public isTileChildLoaded(tile: SourceTile) {
if (tile.isChildLoad) return true; if (tile.isChildLoad) {
return true;
}
const children = tile.children; const children = tile.children;
const isLoad = const isLoad =
children.filter((child) => this.isTileLoaded(child)).length === children.filter((child) => this.isTileLoaded(child)).length ===

View File

@ -1,11 +1,17 @@
import { ILayer, ILayerService, ILngLat, IRendererService, ITile } from '@antv/l7-core'; import {
ILayer,
ILayerService,
ILngLat,
IRendererService,
ITile,
} from '@antv/l7-core';
import { SourceTile } from '@antv/l7-utils'; import { SourceTile } from '@antv/l7-utils';
import 'reflect-metadata'; import 'reflect-metadata';
interface TileLayerServiceOptions { interface ITileLayerServiceOptions {
rendererService: IRendererService; rendererService: IRendererService;
layerService: ILayerService layerService: ILayerService;
parent:ILayer; parent: ILayer;
} }
export class TileLayerService { export class TileLayerService {
/** /**
@ -16,42 +22,47 @@ export class TileLayerService {
private layerService: ILayerService; private layerService: ILayerService;
private parent: ILayer; private parent: ILayer;
private layerTiles: ITile[] = [];
private _tiles: ITile[] = []; constructor({
constructor({ rendererService,layerService, parent }: TileLayerServiceOptions) { rendererService,
layerService,
parent,
}: ITileLayerServiceOptions) {
this.rendererService = rendererService; this.rendererService = rendererService;
this.layerService =layerService; this.layerService = layerService;
this.parent = parent; this.parent = parent;
} }
get tiles(): ITile[] { get tiles(): ITile[] {
return this._tiles; return this.layerTiles;
} }
hasTile(tileKey: string): boolean { public hasTile(tileKey: string): boolean {
return this._tiles.some((tile) => tile.key === tileKey); return this.layerTiles.some((tile) => tile.key === tileKey);
} }
addTile(tile: ITile) { public addTile(tile: ITile) {
this._tiles.push(tile); this.layerTiles.push(tile);
} }
getTile(tileKey: string): ITile | undefined { public getTile(tileKey: string): ITile | undefined {
return this._tiles.find((tile) => tile.key === tileKey); return this.layerTiles.find((tile) => tile.key === tileKey);
} }
getVisibleTileBylngLat(lngLat: ILngLat): ITile | undefined { public getVisibleTileBylngLat(lngLat: ILngLat): ITile | undefined {
// 加载完成 & 可见 & 鼠标选中 // 加载完成 & 可见 & 鼠标选中
return this._tiles.find( return this.layerTiles.find(
(tile) => tile.isLoaded && tile.visible && tile.lnglatInBounds(lngLat), (tile) => tile.isLoaded && tile.visible && tile.lnglatInBounds(lngLat),
); );
} }
removeTile(tileKey: string) { public removeTile(tileKey: string) {
const index = this._tiles.findIndex((tile) => tile.key === tileKey); const index = this.layerTiles.findIndex((t) => t.key === tileKey);
const tile = this._tiles.splice(index, 1); const tile = this.layerTiles.splice(index, 1);
tile[0] && tile[0].destroy(); if (tile[0]) {
tile[0].destroy();
}
} }
updateTileVisible(sourceTile: SourceTile) { public updateTileVisible(sourceTile: SourceTile) {
const tile = this.getTile(sourceTile.key); const tile = this.getTile(sourceTile.key);
// if(sourceTile.isVisible) { // if(sourceTile.isVisible) {
// // 不可见 => 可见 兄弟节点加载完成 // // 不可见 => 可见 兄弟节点加载完成
@ -73,60 +84,60 @@ export class TileLayerService {
// } // }
tile?.updateVisible(sourceTile.isVisible); tile?.updateVisible(sourceTile.isVisible);
} }
public isParentLoaded(sourceTile: SourceTile): boolean { public isParentLoaded(sourceTile: SourceTile): boolean {
const parentTile = sourceTile.parent; const parentTile = sourceTile.parent;
if(!parentTile) { if (!parentTile) {
return true return true;
} }
const tile = this.getTile(parentTile?.key) const tile = this.getTile(parentTile?.key);
if(tile?.isLoaded) { // 递归父级 if (tile?.isLoaded) {
return true // 递归父级
return true;
} }
return false return false;
} }
public isChildrenLoaded(sourceTile: SourceTile):boolean { public isChildrenLoaded(sourceTile: SourceTile): boolean {
const childrenTile = sourceTile?.children; const childrenTile = sourceTile?.children;
if(childrenTile.length === 0) { if (childrenTile.length === 0) {
return true return true;
} }
return childrenTile.some((tile:SourceTile)=>{ return childrenTile.some((tile: SourceTile) => {
const tileLayer = this.getTile(tile?.key) const tileLayer = this.getTile(tile?.key);
return tileLayer?.isLoaded === false return tileLayer?.isLoaded === false;
}) });
} }
async render() { public async render() {
const layers = this.getRenderLayers(); const layers = this.getRenderLayers();
layers.map(async layer => { layers.map(async (layer) => {
await this.layerService.renderLayer(layer); await this.layerService.renderLayer(layer);
}) });
} }
getRenderLayers() { public getRenderLayers() {
const tileList = this._tiles.filter((t)=>t.visible && t.isLoaded); const tileList = this.layerTiles.filter(
(t: ITile) => t.visible && t.isLoaded,
);
const layers: ILayer[] = []; const layers: ILayer[] = [];
tileList.map(tile => layers.push(...tile.getLayers())) tileList.map((tile: ITile) => layers.push(...tile.getLayers()));
return layers; return layers;
} }
getLayers(){ public getLayers() {
const tileList = this._tiles.filter((t)=>t.isLoaded); const tileList = this.layerTiles.filter((t: ITile) => t.isLoaded);
const layers: ILayer[] = []; const layers: ILayer[] = [];
tileList.map(tile => layers.push(...tile.getLayers())) tileList.map((tile) => layers.push(...tile.getLayers()));
return layers; return layers;
} }
getTiles() { public getTiles() {
return this._tiles; return this.layerTiles;
} }
public destroy() {
destroy() { this.layerTiles.forEach((t: ITile) => t.destroy());
this._tiles.forEach((t) => t.destroy());
this.tileResource.clear(); this.tileResource.clear();
} }
} }

View File

@ -124,10 +124,10 @@ export class TilePickService implements ITilePickService {
// 提取当前可见瓦片 // 提取当前可见瓦片
const tiles = this.tileLayerService const tiles = this.tileLayerService
.getTiles() .getTiles()
.filter((tile) => tile.visible); .filter((tile: ITile) => tile.visible);
// 提取当前可见瓦片中匹配 ID 的 feature 列表 // 提取当前可见瓦片中匹配 ID 的 feature 列表
const features: any[] = []; const features: any[] = [];
tiles.forEach((tile) => { tiles.forEach((tile: ITile) => {
features.push(...tile.getFeatureById(pickedFeatureIdx)); features.push(...tile.getFeatureById(pickedFeatureIdx));
}); });

View File

@ -11,6 +11,7 @@ export class TileSourceService {
const properties = features[0]; const properties = features[0];
features.map((feature) => { features.map((feature) => {
const polygon = turf.polygon(feature.coordinates); const polygon = turf.polygon(feature.coordinates);
// tslint:disable-next-line: prefer-conditional-expression
if (p === null) { if (p === null) {
p = polygon; p = polygon;
} else { } else {

View File

@ -1,20 +1,19 @@
// TileLayer 需要代理的子图层的方法 // TileLayer 需要代理的子图层的方法
// 一般都是在 BaseLayer 上的方法 // 一般都是在 BaseLayer 上的方法
export const ProxyFuncs = [ export const ProxyFuncs = [
/** /**
* 1. * 1.
* 2. model * 2. model
*/ */
'shape', 'shape',
'color', 'color',
'size', 'size',
'style', 'style',
'animate', 'animate',
'filter', 'filter',
'rotate', 'rotate',
'scale', 'scale',
'setBlend', 'setBlend',
'setSelect', 'setSelect',
'setActive', 'setActive',
] ];

View File

@ -1,17 +1,16 @@
import { ILayer } from '@antv/l7-core'; import { ILayer } from '@antv/l7-core';
export function updateLayersConfig(layers: ILayer[], key: string, value: any) { export function updateLayersConfig(layers: ILayer[], key: string, value: any) {
layers.map((layer) => { layers.map((layer) => {
if (key === 'mask') { if (key === 'mask') {
// Tip: 栅格瓦片生效、设置全局的 mask、瓦片被全局的 mask 影响 // Tip: 栅格瓦片生效、设置全局的 mask、瓦片被全局的 mask 影响
layer.style({ layer.style({
mask: value, mask: value,
}); });
} else { } else {
layer.updateLayerConfig({ layer.updateLayerConfig({
[key]: value, [key]: value,
}); });
} }
}); });
} }

View File

@ -1,6 +1,6 @@
import Tile from './Tile';
import PointLayer from '../../point';
import LineLayer from '../../line'; import LineLayer from '../../line';
import PointLayer from '../../point';
import Tile from './Tile';
export default class DebugTile extends Tile { export default class DebugTile extends Tile {
public async initTileLayer(): Promise<void> { public async initTileLayer(): Promise<void> {
@ -11,24 +11,23 @@ export default class DebugTile extends Tile {
.size(1) .size(1)
.shape('line') .shape('line')
.color('red'); .color('red');
const pointLayer = new PointLayer({ const pointLayer = new PointLayer({
minZoom:this.z-1, minZoom: this.z - 1,
maxZoom: this.z+1 maxZoom: this.z + 1,
}) })
.source([pointData],{ .source([pointData], {
parser: { parser: {
type: 'json', type: 'json',
x: 'textLng', x: 'textLng',
y: 'textLat', y: 'textLat',
} },
}) })
.size(20) .size(20)
.color('red') .color('red')
.shape(this.key) .shape(this.key)
.style({ .style({
stroke: '#fff', stroke: '#fff',
strokeWidth: 2 strokeWidth: 2,
}); });
await this.addLayer(lineLayer); await this.addLayer(lineLayer);
@ -39,8 +38,7 @@ export default class DebugTile extends Tile {
protected getSourceOption() { protected getSourceOption() {
const rawSource = this.parent.getSource(); const rawSource = this.parent.getSource();
const features = this.sourceTile.data.layers['testTile'] const features = this.sourceTile.data.layers.testTile.features;
.features;
return { return {
data: { data: {
type: 'FeatureCollection', type: 'FeatureCollection',

View File

@ -1,24 +1,25 @@
import { ILayerAttributesOption } from '@antv/l7-core'; import { ILayerAttributesOption } from '@antv/l7-core';
import ImageLayer from '../../image' import ImageLayer from '../../image';
import Tile from './Tile'; import Tile from './Tile';
export default class ImageTile extends Tile { export default class ImageTile extends Tile {
public async initTileLayer(): Promise<void> { public async initTileLayer(): Promise<void> {
const attributes = this.parent.getLayerAttributeConfig(); const attributes = this.parent.getLayerAttributeConfig();
const layerOptions = this.getLayerOptions(); const layerOptions = this.getLayerOptions();
const sourceOptions = this.getSourceOption(); const sourceOptions = this.getSourceOption();
const layer = new ImageLayer({...layerOptions}).source( const layer = new ImageLayer({ ...layerOptions }).source(
sourceOptions.data, sourceOptions.data,
sourceOptions.options, sourceOptions.options,
); );
// 初始化数据映射 // 初始化数据映射
attributes && Object.keys(attributes).forEach((type) => { // tslint:disable-next-line: no-unused-expression
const attr = type as keyof ILayerAttributesOption; attributes &&
// @ts-ignore Object.keys(attributes).forEach((type) => {
layer[attr](attributes[attr]?.field, attributes[attr]?.values); const attr = type as keyof ILayerAttributesOption;
}); // @ts-ignore
layer[attr](attributes[attr]?.field, attributes[attr]?.values);
});
await this.addLayer(layer); await this.addLayer(layer);
this.isLoaded = true; this.isLoaded = true;

Some files were not shown because too many files have changed in this diff Show More