Skip to content
Closed
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: 16 additions & 0 deletions .changeset/itchy-spoons-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@antv/l7-test-utils': minor
'@antv/l7-component': minor
'@antv/l7-renderer': minor
'@antv/l7-layers': minor
'@antv/l7-source': minor
'@antv/l7-scene': minor
'@antv/l7-three': minor
'@antv/l7-utils': minor
'@antv/l7-core': minor
'@antv/l7-maps': minor
'@antv/l7-map': minor
'@antv/l7': minor
---

移动端事件
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) => {
// 过滤掉线数据
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;
Comment on lines +19 to +40

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

这段过滤逻辑在 fillDataUndelimitedBoundaryboundary 的创建中重复出现。建议将此通用过滤逻辑提取到一个辅助函数中,以提高代码的可重用性和可维护性。

Suggested change
const fillData = data.features.filter((feature: any) => {
// 过滤掉线数据
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 filterFeatures = (features: any[], predicate: (feature: any) => boolean) => {
return features.filter(predicate);
};
const fillData = filterFeatures(data.features, (feature: any) => {
return feature.properties.name !== '境界线';
});
const UndelimitedBoundary = filterFeatures(data.features, (feature: any) => {
return feature.properties.gb === '003';
});
const boundary = filterFeatures(data.features, (feature: any) => {
return feature.properties.gb !== '003';
});

});

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',
Comment on lines +43 to +54

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

color 数组被定义但未在代码中使用。请移除此未使用的变量,以保持代码整洁。

];
// 行政区划填充色
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],
});

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
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) {

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

移除未使用的 e: any 参数是一个很好的清理,因为它没有在函数体中使用。这提高了代码的清晰度。

this.setDisplayFeatureInfo(undefined);
if (this.isShow) {
this.hide();
Expand Down
3 changes: 1 addition & 2 deletions site/.dumi/pages/Examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ExampleTopicMenu } from '@antv/dumi-theme-antv/dist/pages/Examples/comp
import { Footer } from '@antv/dumi-theme-antv/dist/slots/Footer';
import { Header } from '@antv/dumi-theme-antv/dist/slots/Header';
import NavigatorBanner from '@antv/dumi-theme-antv/dist/slots/Header/Products/NavigatorBanner';
import { SEO } from '@antv/dumi-theme-antv/dist/slots/SEO';
// import { SEO } from '@antv/dumi-theme-antv/dist/slots/SEO';

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

此行注释掉了 SEO 组件的导入。如果这是有意为之,请在 PR 描述中说明原因,以确保对示例页面的 SEO 影响是可接受的。如果不是,建议恢复此导入以保持页面可发现性。

import { usePrevAndNext } from '@antv/dumi-theme-antv/dist/slots/hooks';
import type { ExampleTopic } from '@antv/dumi-theme-antv/dist/types';
import { Layout as AntLayout, BackTop } from 'antd';
Expand Down Expand Up @@ -84,7 +84,6 @@ const Example = () => {
}, []);
return (
<>
<SEO title={title[locale.id]} />
<Header isHomePage={false} />

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

此行移除了 SEO 组件的使用。与导入一样,请确认这是否是预期行为,并评估其对页面 SEO 的潜在影响。

<AntLayout hasSider className={styles.layout}>
<ExampleTopicMenu exampleTopics={exampleTopics} />
Expand Down
3 changes: 1 addition & 2 deletions site/.dumi/theme/slots/ManualContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import readingTime from 'reading-time';
import URI from 'uri-parse';

import { ContentTable } from '@antv/dumi-theme-antv/dist/slots/ContentTable';
import { SEO } from '@antv/dumi-theme-antv/dist/slots/SEO';
// import { SEO } from '@antv/dumi-theme-antv/dist/slots/SEO';

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

此行注释掉了 SEO 组件的导入。如果这是有意为之,请在 PR 描述中说明原因,以确保对文档页面的 SEO 影响是可接受的。如果不是,建议恢复此导入以保持页面可发现性。

import GithubButtonBar from '../GithubButtonBar';

import { NavigatorBanner } from '@antv/dumi-theme-antv/dist/slots/ManualContent/NavigatorBanner';
Expand Down Expand Up @@ -265,7 +265,6 @@ export const ManualContent: React.FC<ManualContent> = ({ children }) => {

return (
<>
<SEO title={linkoTitle[window.location.pathname]} lang={locale.id} />
<Layout style={{ background: '#fff' }} hasSider className={styles.layout}>

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

此行移除了 SEO 组件的使用。与导入一样,请确认这是否是预期行为,并评估其对页面 SEO 的潜在影响。

<Affix
offsetTop={0}
Expand Down
Loading
Loading