Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .changeset/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions .changeset/odd-pianos-hope.md

This file was deleted.

11 changes: 0 additions & 11 deletions .changeset/true-lamps-repair.md

This file was deleted.

132 changes: 132 additions & 0 deletions examples/demos/polygon/fill_china.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { LayerPopup, PolygonLayer } from '@antv/l7';
import type { TestCase } from '../../types';
import { CaseScene } from '../../utils';

export const fillChina: TestCase = async (options) => {
const scene = await CaseScene({
...options,
mapConfig: {
center: [-96, 37.8],
zoom: 3,
},
});

const url1 =
'https://mdn.alipayobjects.com/antforest/afts/file/A*vaL-R4SU18IAAAAAgCAAAAgAerd2AQ/original_2025-11-14.json';
// const url2 = 'https://geojson.cn/api/china/1.6.2/china.json'
const result = await fetch(url1);
const data = await result.json();
const fillData = data.features.filter((feature: any) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The feature parameter is typed as any. To improve type safety and code clarity, it would be beneficial to define a specific interface for the GeoJSON feature.

For example:

interface ChinaFeature {
  properties: {
    name: string;
    gb: string;
    // ... other properties
  };
  // ... other feature properties
}

// ...
const fillData = data.features.filter((feature: ChinaFeature) => { /* ... */ });

// 过滤掉线数据
if (feature.properties.name === '境界线') {
return false;
}
return true;
});
// 未定国界线数据
const UndelimitedBoundary = data.features.filter((feature: any) => {
// 过滤掉线数据
if (feature.properties.gb === '003') {
return true;
}
return false;
});

const boundary = data.features.filter((feature: any) => {
// 过滤掉线数据
if (feature.properties.gb !== '003') {
return true;
}
return false;
});

const color = [

Check warning on line 43 in examples/demos/polygon/fill_china.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

'color' is assigned a value but never used
'#a50026',
'#d73027',
'#f46d43',
'#fdae61',
'#fee090',
'#ffffbf',
'#e0f3f8',
'#abd9e9',
'#74add1',
'#4575b4',
'#313695',
];
// 行政区划填充色
const fillLayer = new PolygonLayer({
autoFit: true,
})
.source({
type: 'FeatureCollection',
features: fillData,
})
.color('#d6dff6')
.shape('fill')
.active({
color: '#5483ef',
})
.style({
opacity: 0.5,
});
const boundaryLayer = new PolygonLayer({
autoFit: true,
})
.source({
type: 'FeatureCollection',
features: boundary,
})
.color('#5483ef')
.shape('line')
.size(0.5)
.style({
opacity: 1,
});

// 未定国际虚线表示
const layer = new PolygonLayer({
autoFit: true,
})
.source({
type: 'FeatureCollection',
features: UndelimitedBoundary,
})
.color('red')
.shape('line')
.size(1)
.style({
opacity: 1,
lineType: 'dash',
dashArray: [5, 5],
});
Comment on lines +19 to +101

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are a few opportunities to improve the code style and clarity in this file:

  • Verbose filters: The filter calls on lines 19, 27, and 35 can be simplified to a single return statement.
  • Unused variable: The color variable (lines 43-55) is defined but never used and can be removed.
  • Naming:
    • The variable UndelimitedBoundary (line 27) should be renamed to undelimitedBoundary to follow the camelCase convention.
    • The variable layer (line 87) is too generic. Renaming it to undelimitedBoundaryLayer would make its purpose clearer. Remember to update its usage on line 127.


const layerPopup = new LayerPopup({
trigger: 'click',
items: [
{
layer: fillLayer,
fields: [
{
field: 'name',
formatField: () => '名称',
},
{
field: 'gb',
formatField: () => '编号',
formatValue: (val) => val,
},
],
},
],
});

scene.addLayer(fillLayer);

scene.addLayer(boundaryLayer);

scene.addLayer(layer);

scene.addPopup(layerPopup);

return scene;
};
1 change: 1 addition & 0 deletions examples/demos/polygon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { extrudeCity } from './extrude-city';
export { extrusion } from './extrusion';
export { fill } from './fill';
export { fillLinear } from './fill-linear';
export { fillChina } from './fill_china';
export { fill_indoor } from './fill_indoor';
export { ocean } from './ocean';
export { texture } from './texture';
Expand Down
13 changes: 13 additions & 0 deletions packages/component/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log

## 2.23.1

### Patch Changes

- [`7932838`](https://github.com/antvis/L7/commit/79328384d8b1deb547ff2422aaa4366201dfe9b2) Thanks [@lzxue](https://github.com/lzxue)! - 更新demo

- [`4f690b8`](https://github.com/antvis/L7/commit/4f690b837a322bc9923baf2b387ea43d37ba1e5d) Thanks [@lzxue](https://github.com/lzxue)! - 移动端事件

- Updated dependencies [[`7932838`](https://github.com/antvis/L7/commit/79328384d8b1deb547ff2422aaa4366201dfe9b2), [`4f690b8`](https://github.com/antvis/L7/commit/4f690b837a322bc9923baf2b387ea43d37ba1e5d)]:
- @antv/l7-layers@2.23.1
- @antv/l7-utils@2.23.1
- @antv/l7-core@2.23.1

## 2.22.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/component/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/l7-component",
"version": "2.23.0",
"version": "2.23.1",
"description": "Component for L7",
"license": "MIT",
"author": "https://github.com/orgs/antvis/people",
Expand Down
34 changes: 25 additions & 9 deletions packages/component/src/popup/layerPopup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ILayer, IPopupOption, L7Container } from '@antv/l7-core';
import { DOM, lodashUtil } from '@antv/l7-utils';
import { DOM, isPC, lodashUtil } from '@antv/l7-utils';
import Popup from './popup';

type ElementType = DOM.ElementType;
Expand All @@ -21,7 +21,7 @@ export type LayerPopupConfigItem = {
export interface ILayerPopupOption extends IPopupOption {
config?: LayerPopupConfigItem[];
items?: LayerPopupConfigItem[];
trigger: 'hover' | 'click';
trigger: 'hover' | 'click' | 'touchend' | 'touchstart';
}

type LayerMapInfo = {
Expand Down Expand Up @@ -58,6 +58,19 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
return config ?? items ?? [];
}

/**
* 根据环境获取实际的触发事件
* 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
* @protected
*/
protected getActualTriggerEvent() {
const { trigger } = this.popupOption;
if (trigger === 'click') {
return isPC() ? 'click' : 'touchend';
}
return trigger;
}

public addTo(scene: L7Container) {
super.addTo(scene);
this.bindLayerEvent();
Expand Down Expand Up @@ -88,7 +101,7 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
}

protected getDefault(option: Partial<ILayerPopupOption>): ILayerPopupOption {
const isHoverTrigger = option.trigger !== 'click';
const isHoverTrigger = option.trigger === 'hover';
return {
...super.getDefault(option),
trigger: 'hover',
Expand All @@ -111,6 +124,8 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
*/
protected bindLayerEvent() {
const { trigger, closeOnClick } = this.popupOption;
const actualTrigger = this.getActualTriggerEvent();

this.layerConfigItems.forEach((configItem) => {
const layer = this.getLayerByConfig(configItem);
if (!layer) {
Expand All @@ -131,11 +146,11 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
} else {
const onLayerClick = this.onLayerClick.bind(this, layer);
layerInfo.onClick = onLayerClick;
layer?.on('click', onLayerClick);
layer?.on(actualTrigger, onLayerClick);

const mapContainer = this.mapsService?.getMapContainer();
if (mapContainer && closeOnClick) {
mapContainer.addEventListener('click', this.onSceneClick);
mapContainer.addEventListener(actualTrigger, this.onSceneClick);
}
}
const source = layer?.getSource?.();
Expand All @@ -152,6 +167,8 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
* @protected
*/
protected unbindLayerEvent() {
const actualTrigger = this.getActualTriggerEvent();

this.layerConfigItems.forEach((configItem) => {
const layer = this.getLayerByConfig(configItem);
const layerInfo = layer && this.layerConfigMap.get(layer);
Expand All @@ -166,14 +183,14 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
layer.off('mouseout', onMouseOut);
}
if (onClick) {
layer.off('click', onClick);
layer.off(actualTrigger, onClick);
}
if (onSourceUpdate) {
layer?.getSource()?.off('update', onSourceUpdate);
}
const mapContainer = this.mapsService?.getMapContainer();
if (mapContainer) {
mapContainer.removeEventListener('click', this.onSceneClick);
mapContainer.removeEventListener(actualTrigger, this.onSceneClick);
}
});
}
Expand All @@ -191,8 +208,7 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected onLayerMouseOut(layer: ILayer, e: any) {
protected onLayerMouseOut(layer: ILayer) {
this.setDisplayFeatureInfo(undefined);
if (this.isShow) {
this.hide();
Expand Down
11 changes: 11 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## 2.23.1

### Patch Changes

- [`7932838`](https://github.com/antvis/L7/commit/79328384d8b1deb547ff2422aaa4366201dfe9b2) Thanks [@lzxue](https://github.com/lzxue)! - 更新demo

- [`4f690b8`](https://github.com/antvis/L7/commit/4f690b837a322bc9923baf2b387ea43d37ba1e5d) Thanks [@lzxue](https://github.com/lzxue)! - 移动端事件

- Updated dependencies [[`7932838`](https://github.com/antvis/L7/commit/79328384d8b1deb547ff2422aaa4366201dfe9b2), [`4f690b8`](https://github.com/antvis/L7/commit/4f690b837a322bc9923baf2b387ea43d37ba1e5d)]:
- @antv/l7-utils@2.23.1

## 2.22.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/l7-core",
"version": "2.23.0",
"version": "2.23.1",
"description": "",
"license": "MIT",
"author": "https://github.com/orgs/antvis/people",
Expand Down
17 changes: 17 additions & 0 deletions packages/l7/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Change Log

## 2.23.1

### Patch Changes

- [`7932838`](https://github.com/antvis/L7/commit/79328384d8b1deb547ff2422aaa4366201dfe9b2) Thanks [@lzxue](https://github.com/lzxue)! - 更新demo

- [`4f690b8`](https://github.com/antvis/L7/commit/4f690b837a322bc9923baf2b387ea43d37ba1e5d) Thanks [@lzxue](https://github.com/lzxue)! - 移动端事件

- Updated dependencies [[`7932838`](https://github.com/antvis/L7/commit/79328384d8b1deb547ff2422aaa4366201dfe9b2), [`4f690b8`](https://github.com/antvis/L7/commit/4f690b837a322bc9923baf2b387ea43d37ba1e5d)]:
- @antv/l7-component@2.23.1
- @antv/l7-layers@2.23.1
- @antv/l7-source@2.23.1
- @antv/l7-scene@2.23.1
- @antv/l7-utils@2.23.1
- @antv/l7-core@2.23.1
- @antv/l7-maps@2.23.1

## 2.22.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/l7/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/l7",
"version": "2.23.0",
"version": "2.23.1",
"description": "A Large-scale WebGL-powered Geospatial Data Visualization",
"repository": "git@github.com:antvis/L7.git",
"license": "MIT",
Expand Down
14 changes: 14 additions & 0 deletions packages/layers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Change Log

## 2.23.1

### Patch Changes

- [`7932838`](https://github.com/antvis/L7/commit/79328384d8b1deb547ff2422aaa4366201dfe9b2) Thanks [@lzxue](https://github.com/lzxue)! - 更新demo

- [`4f690b8`](https://github.com/antvis/L7/commit/4f690b837a322bc9923baf2b387ea43d37ba1e5d) Thanks [@lzxue](https://github.com/lzxue)! - 移动端事件

- Updated dependencies [[`7932838`](https://github.com/antvis/L7/commit/79328384d8b1deb547ff2422aaa4366201dfe9b2), [`4f690b8`](https://github.com/antvis/L7/commit/4f690b837a322bc9923baf2b387ea43d37ba1e5d)]:
- @antv/l7-source@2.23.1
- @antv/l7-utils@2.23.1
- @antv/l7-core@2.23.1
- @antv/l7-maps@2.23.1

## 2.22.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/layers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/l7-layers",
"version": "2.23.0",
"version": "2.23.1",
"description": "L7's collection of built-in layers",
"license": "MIT",
"author": "https://github.com/orgs/antvis/people",
Expand Down
Loading
Loading