Skip to content

Commit

Permalink
Chore maplibre (#2013)
Browse files Browse the repository at this point in the history
* chore: map version

* docs: 添加 maplibre demo
  • Loading branch information
lzxue authored Nov 9, 2023
1 parent f80d7f4 commit 282f3a9
Show file tree
Hide file tree
Showing 27 changed files with 157 additions and 322 deletions.
1 change: 0 additions & 1 deletion packages/core/src/services/layer/ILayerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export interface ILayerModel {

// earth mode
setEarthTime?(time: number): void;
createModelData?(options?: any): any;
}

export interface ILayerAttributesOption {
Expand Down
36 changes: 0 additions & 36 deletions packages/layers/src/core/BaseLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import { encodePickingColor, lodashUtil } from '@antv/l7-utils';
import { EventEmitter } from 'eventemitter3';
import { Container } from 'inversify';
import { BlendTypes } from '../utils/blend';
import { calculateData } from '../utils/layerData';
import {
createMultiPassRenderer,
normalizePasses,
Expand Down Expand Up @@ -497,45 +496,10 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
}
}

public createModelData(data: any, option?: ISourceCFG) {
if (this.layerModel?.createModelData) {
// 在某些特殊图层中单独构建 attribute & elements
return this.layerModel.createModelData(option);
}
const calEncodeData = this.calculateEncodeData(data, option);
const triangulation = this.triangulation;

if (calEncodeData && triangulation) {
return this.styleAttributeService.createAttributesAndIndices(
calEncodeData,
triangulation,
);
} else {
return {
attributes: undefined,
elements: undefined,
};
}
}
public setLayerPickService(layerPickService: ILayerPickService): void {
this.layerPickService = layerPickService;
}

public calculateEncodeData(data: any, option?: ISourceCFG) {
if (this.inited) {
return calculateData(
this,
this.fontService,
this.mapService,
this.styleAttributeService,
data,
option,
);
} else {
console.warn('layer not inited!');
return null;
}
}
/**
* Model初始化前需要更新Model样式
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/layers/src/geometry/models/plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
IModelUniform,
ITexture2D,
} from '@antv/l7-core';
import { Version } from '@antv/l7-maps';
// import { mat4, vec3 } from 'gl-matrix';
import BaseModel from '../../core/BaseModel';
import { IGeometryLayerStyleOptions } from '../../core/interface';
Expand Down Expand Up @@ -49,7 +48,7 @@ export default class PlaneModel extends BaseModel {

for (let ix = 0; ix < gridX1; ix++) {
const x = ix * segmentWidth - widthHalf;
if (this.mapService.version === Version['GAODE2.x']) {
if (this.mapService.version === 'GAODE2.x') {
// @ts-ignore
const [a, b] = this.mapService.lngLatToCoord([x + lng, -y + lat]) as [
number,
Expand Down
3 changes: 1 addition & 2 deletions packages/layers/src/geometry/models/sprite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { gl, IModel, IModelUniform, ITexture2D } from '@antv/l7-core';
import { Version } from '@antv/l7-maps';

import BaseModel from '../../core/BaseModel';
import { IGeometryLayerStyleOptions } from '../../core/interface';
Expand Down Expand Up @@ -42,7 +41,7 @@ export default class SpriteModel extends BaseModel {
const randomY = radius * Math.random();
const x = -radius / 2 + randomX;
const y = -radius / 2 + randomY;
if (mapService.version === Version['GAODE2.x']) {
if (mapService.version === 'GAODE2.x') {
// @ts-ignore
const [a, b] = mapService.lngLatToCoord([x + lng, -y + lat]) as [
number,
Expand Down
7 changes: 3 additions & 4 deletions packages/layers/src/plugins/DataMappingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
Position,
TYPES,
} from '@antv/l7-core';
import { Version } from '@antv/l7-maps';
import { lodashUtil, normalize, rgb2arr } from '@antv/l7-utils';
import { inject, injectable } from 'inversify';
import 'reflect-metadata';
Expand Down Expand Up @@ -205,7 +204,7 @@ export default class DataMappingPlugin implements ILayerPlugin {
// 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移
if (
mappedData.length > 0 &&
this.mapService.version === Version['GAODE2.x']
this.mapService.version === 'GAODE2.x'
) {
const layerCenter = layer.coordCenter || layer.getSource().center;
// 单个的点数据
Expand All @@ -214,7 +213,7 @@ export default class DataMappingPlugin implements ILayerPlugin {
// TODO: 避免经纬度被重复计算导致坐标位置偏移
.filter((d) => !d.originCoordinates)
.map((d) => {
d.version = Version['GAODE2.x'];
d.version = 'GAODE2.x';
// @ts-ignore
d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)
// @ts-ignore
Expand All @@ -228,7 +227,7 @@ export default class DataMappingPlugin implements ILayerPlugin {
}

private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {
if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {
if (mappedData.length > 0 && this.mapService.version === 'SIMPLE') {
mappedData.map((d) => {
if (!d.simpleCoordinate) {
d.coordinates = this.unProjectCoordinates(d.coordinates);
Expand Down
3 changes: 1 addition & 2 deletions packages/layers/src/polygon/models/ocean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IModelUniform,
ITexture2D,
} from '@antv/l7-core';
import { Version } from '@antv/l7-maps';
import { lodashUtil, rgb2arr } from '@antv/l7-utils';
import BaseModel from '../../core/BaseModel';
import { IPolygonLayerStyleOptions } from '../../core/interface';
Expand Down Expand Up @@ -89,7 +88,7 @@ export default class OceanModel extends BaseModel {
attributeIdx: number,
) => {
const v =
feature.version === Version['GAODE2.x']
feature.version === 'GAODE2.x'
? feature.originCoordinates[0][attributeIdx]
: vertex;
const [lng, lat] = v;
Expand Down
3 changes: 1 addition & 2 deletions packages/layers/src/polygon/models/water.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IModelUniform,
ITexture2D,
} from '@antv/l7-core';
import { Version } from '@antv/l7-maps';
import { lodashUtil } from '@antv/l7-utils';
import BaseModel from '../../core/BaseModel';
import { IPolygonLayerStyleOptions } from '../../core/interface';
Expand Down Expand Up @@ -78,7 +77,7 @@ export default class WaterModel extends BaseModel {
attributeIdx: number,
) => {
const v =
feature.version === Version['GAODE2.x']
feature.version === 'GAODE2.x'
? feature.originCoordinates[0][attributeIdx]
: vertex;
const [lng, lat] = v;
Expand Down
224 changes: 0 additions & 224 deletions packages/layers/src/utils/layerData.ts

This file was deleted.

Loading

0 comments on commit 282f3a9

Please sign in to comment.