mirror of https://gitee.com/antv-l7/antv-l7
commit
be52b1b738
|
@ -7,7 +7,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antv/g2": "^3.5.9",
|
"@antv/g2": "^3.5.9",
|
||||||
"@antv/gatsby-theme-antv": "^0.11.5",
|
"@antv/gatsby-theme-antv": "0.10.59",
|
||||||
"@babel/cli": "^7.6.4",
|
"@babel/cli": "^7.6.4",
|
||||||
"@babel/core": "^7.6.4",
|
"@babel/core": "^7.6.4",
|
||||||
"@babel/plugin-proposal-decorators": "^7.6.0",
|
"@babel/plugin-proposal-decorators": "^7.6.0",
|
||||||
|
|
|
@ -36,6 +36,7 @@ export default class BaseLayer extends EventEmitter {
|
||||||
protected options: IDistrictLayerOption;
|
protected options: IDistrictLayerOption;
|
||||||
protected layers: ILayer[] = [];
|
protected layers: ILayer[] = [];
|
||||||
protected fillData: any;
|
protected fillData: any;
|
||||||
|
protected bubbleData: any;
|
||||||
private popup: IPopup;
|
private popup: IPopup;
|
||||||
|
|
||||||
constructor(scene: Scene, option: Partial<IDistrictLayerOption> = {}) {
|
constructor(scene: Scene, option: Partial<IDistrictLayerOption> = {}) {
|
||||||
|
@ -87,6 +88,23 @@ export default class BaseLayer extends EventEmitter {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 气泡图也需要更新
|
||||||
|
if (this.bubbleLayer) {
|
||||||
|
this.bubbleLayer.setData(this.bubbleData, {
|
||||||
|
transforms:
|
||||||
|
data.length === 0
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
type: 'join',
|
||||||
|
sourceField: joinBy[1], // data1 对应字段名
|
||||||
|
targetField: joinBy[0], // data 对应字段名 绑定到的地理数据
|
||||||
|
data,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
protected async fetchData(data: { url: any; type: string }) {
|
protected async fetchData(data: { url: any; type: string }) {
|
||||||
if (data.type === 'pbf') {
|
if (data.type === 'pbf') {
|
||||||
|
@ -215,6 +233,8 @@ export default class BaseLayer extends EventEmitter {
|
||||||
center: [feature.properties.x, feature.properties.y],
|
center: [feature.properties.x, feature.properties.y],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.bubbleData = labeldata;
|
||||||
this.addBubbleLayer(labeldata);
|
this.addBubbleLayer(labeldata);
|
||||||
}
|
}
|
||||||
if (popup.enable) {
|
if (popup.enable) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
IMarkerOption,
|
IMarkerOption,
|
||||||
IPoint,
|
IPoint,
|
||||||
IPopup,
|
IPopup,
|
||||||
|
ISceneService,
|
||||||
TYPES,
|
TYPES,
|
||||||
} from '@antv/l7-core';
|
} from '@antv/l7-core';
|
||||||
import {
|
import {
|
||||||
|
@ -22,6 +23,7 @@ export default class Marker extends EventEmitter {
|
||||||
private defaultMarker: boolean;
|
private defaultMarker: boolean;
|
||||||
private popup: IPopup;
|
private popup: IPopup;
|
||||||
private mapsService: IMapService<unknown>;
|
private mapsService: IMapService<unknown>;
|
||||||
|
private sceneSerive: ISceneService;
|
||||||
private lngLat: ILngLat;
|
private lngLat: ILngLat;
|
||||||
private scene: Container;
|
private scene: Container;
|
||||||
private added: boolean = false;
|
private added: boolean = false;
|
||||||
|
@ -49,7 +51,9 @@ export default class Marker extends EventEmitter {
|
||||||
// this.remove();
|
// this.remove();
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.mapsService = scene.get<IMapService>(TYPES.IMapService);
|
this.mapsService = scene.get<IMapService>(TYPES.IMapService);
|
||||||
|
this.sceneSerive = scene.get<ISceneService>(TYPES.ISceneService);
|
||||||
const { element, draggable } = this.markerOption;
|
const { element, draggable } = this.markerOption;
|
||||||
|
// this.sceneSerive.getSceneContainer().appendChild(element as HTMLElement);
|
||||||
this.mapsService.getMarkerContainer().appendChild(element as HTMLElement);
|
this.mapsService.getMarkerContainer().appendChild(element as HTMLElement);
|
||||||
this.registerMarkerEvent(element as HTMLElement);
|
this.registerMarkerEvent(element as HTMLElement);
|
||||||
this.mapsService.on('camerachange', this.update);
|
this.mapsService.on('camerachange', this.update);
|
||||||
|
|
|
@ -197,7 +197,7 @@ export default class Popup extends EventEmitter implements IPopup {
|
||||||
if (!this.mapsService || !hasPosition || !this.content) {
|
if (!this.mapsService || !hasPosition || !this.content) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const popupContainer = this.sceneSerive.getSceneContainer();
|
const popupContainer = this.mapsService.getMarkerContainer();
|
||||||
if (!this.container && popupContainer) {
|
if (!this.container && popupContainer) {
|
||||||
this.container = this.creatDom(
|
this.container = this.creatDom(
|
||||||
'div',
|
'div',
|
||||||
|
@ -213,11 +213,14 @@ export default class Popup extends EventEmitter implements IPopup {
|
||||||
.forEach((name) => this.container.classList.add(name));
|
.forEach((name) => this.container.classList.add(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ['mousemove', 'mousedown', 'mouseup', 'click'].forEach((type) => {
|
// 高德地图需要阻止事件冒泡 // 测试mapbox 地图不需要添加
|
||||||
// this.container.addEventListener(type, (e) => {
|
['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(
|
||||||
// e.stopPropagation();
|
(type) => {
|
||||||
// });
|
this.container.addEventListener(type, (e) => {
|
||||||
// });
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (maxWidth && this.container.style.maxWidth !== maxWidth) {
|
if (maxWidth && this.container.style.maxWidth !== maxWidth) {
|
||||||
this.container.style.maxWidth = maxWidth;
|
this.container.style.maxWidth = maxWidth;
|
||||||
|
|
|
@ -14,6 +14,7 @@ export interface ISceneService {
|
||||||
getSceneConfig(): Partial<ISceneConfig>;
|
getSceneConfig(): Partial<ISceneConfig>;
|
||||||
render(): void;
|
render(): void;
|
||||||
getSceneContainer(): HTMLDivElement;
|
getSceneContainer(): HTMLDivElement;
|
||||||
|
getMarkerContainer(): HTMLElement;
|
||||||
exportPng(type?: 'png' | 'jpg'): string;
|
exportPng(type?: 'png' | 'jpg'): string;
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,8 @@ export default class Scene extends EventEmitter implements ISceneService {
|
||||||
|
|
||||||
private canvas: HTMLCanvasElement;
|
private canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
|
private markerContainer: HTMLElement;
|
||||||
|
|
||||||
private hooks: {
|
private hooks: {
|
||||||
init: AsyncParallelHook;
|
init: AsyncParallelHook;
|
||||||
};
|
};
|
||||||
|
@ -171,8 +173,12 @@ export default class Scene extends EventEmitter implements ISceneService {
|
||||||
const $container = createRendererContainer(
|
const $container = createRendererContainer(
|
||||||
this.configService.getSceneConfig(this.id).id || '',
|
this.configService.getSceneConfig(this.id).id || '',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 添加marker container;
|
||||||
this.$container = $container;
|
this.$container = $container;
|
||||||
|
|
||||||
|
// this.addMarkerContainer();
|
||||||
|
|
||||||
if ($container) {
|
if ($container) {
|
||||||
this.canvas = DOM.create('canvas', '', $container) as HTMLCanvasElement;
|
this.canvas = DOM.create('canvas', '', $container) as HTMLCanvasElement;
|
||||||
this.setCanvas();
|
this.setCanvas();
|
||||||
|
@ -261,6 +267,19 @@ export default class Scene extends EventEmitter implements ISceneService {
|
||||||
return this.configService.getSceneConfig(this.id as string);
|
return this.configService.getSceneConfig(this.id as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public addMarkerContainer(): void {
|
||||||
|
// @ts-ignore
|
||||||
|
const mapContainer = this.$container.parentElement as HTMLElement;
|
||||||
|
if (mapContainer !== null) {
|
||||||
|
this.markerContainer = DOM.create('div', 'l7-marker-container', mapContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMarkerContainer() {
|
||||||
|
return this.markerContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public destroy() {
|
public destroy() {
|
||||||
if (!this.inited) {
|
if (!this.inited) {
|
||||||
this.destroyed = true;
|
this.destroyed = true;
|
||||||
|
@ -333,4 +352,5 @@ export default class Scene extends EventEmitter implements ISceneService {
|
||||||
private addSceneEvent(target: IInteractionTarget) {
|
private addSceneEvent(target: IInteractionTarget) {
|
||||||
this.emit(target.type, target);
|
this.emit(target.type, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,6 +195,24 @@ export default class Country extends React.Component {
|
||||||
value: null,
|
value: null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const ProvinceData2 = [
|
||||||
|
{
|
||||||
|
name: '云南省',
|
||||||
|
code: 530000,
|
||||||
|
value: 178810.12,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '黑龙江省',
|
||||||
|
code: 230000,
|
||||||
|
value: 163610.62,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '贵州省',
|
||||||
|
code: 520000,
|
||||||
|
value: 148060.45,
|
||||||
|
},
|
||||||
|
];
|
||||||
scene.on('loaded', () => {
|
scene.on('loaded', () => {
|
||||||
const Layer = new CountryLayer(scene, {
|
const Layer = new CountryLayer(scene, {
|
||||||
data: ProvinceData,
|
data: ProvinceData,
|
||||||
|
@ -204,7 +222,7 @@ export default class Country extends React.Component {
|
||||||
enable: true,
|
enable: true,
|
||||||
size: {
|
size: {
|
||||||
field: 'value',
|
field: 'value',
|
||||||
values: [3, 20],
|
values: [8, 20],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
popup: {
|
popup: {
|
||||||
|
@ -214,6 +232,10 @@ export default class Country extends React.Component {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
Layer.updateData(ProvinceData2);
|
||||||
|
}, 2000);
|
||||||
});
|
});
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue