Skip to content

Commit 28bfff4

Browse files
[bug]解决图层隐藏状态下切换符号,符号显示出来的问题
(review by ytt)
1 parent 3632152 commit 28bfff4

File tree

1 file changed

+12
-2
lines changed
  • examples/mapboxgl-v2/src/application

1 file changed

+12
-2
lines changed

examples/mapboxgl-v2/src/application/App.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState } from 'react';
22
import View from './View';
33
import './style';
4-
import { uniqueId } from 'lodash';
4+
import { isArray, uniqueId } from 'lodash';
55
import { getMapboxKey, isPaintKey } from '../utils/StyleSettingUtil';
66
// import '../../../../src/mapboxgl/core/MapExtend';
77

@@ -219,16 +219,26 @@ const App = () => {
219219
setLayersInfo(newLayersInfo.reverse());
220220
};
221221

222+
const hideSymbol = (symbol) => {
223+
isArray(symbol) ?
224+
symbol.forEach(s => {
225+
s.layout = Object.assign(s.layout ?? {}, { visibility: 'none' });
226+
}) :
227+
symbol.layout = Object.assign(symbol.layout ?? {}, { visibility: 'none' });
228+
};
222229
// 点击切换
223230
const onIconClick = async (symbolId, layerId) => {
224231
if (!map) return;
225232
const type = getLayerType(layerId);
226233
const id = uniqueId();
227234
await map.loadSymbol(symbolId, (_err, symbol) => {
228-
if(type === 'point') {
235+
if (type === 'point') {
229236
symbol.layout['icon-allow-overlap'] = true;
230237
symbol.layout['icon-size'] = 0.16;
231238
}
239+
// TODO 暂时这样处理,待symbol是否设置visibility明确后优化
240+
// 图层隐藏状态下切换符号,隐藏新符号
241+
getLayerPropertyStyle(layerId, 'visibility') === 'none' && hideSymbol(symbol);
232242
map.addSymbol(id, symbol);
233243
});
234244
map.setSymbol(layerId, id);

0 commit comments

Comments
 (0)