|
1 | 1 | import React, { useEffect, useState } from 'react';
|
2 | 2 | import View from './View';
|
3 | 3 | import './style';
|
4 |
| -import { uniqueId } from 'lodash'; |
| 4 | +import { isArray, uniqueId } from 'lodash'; |
5 | 5 | import { getMapboxKey, isPaintKey } from '../utils/StyleSettingUtil';
|
6 | 6 | // import '../../../../src/mapboxgl/core/MapExtend';
|
7 | 7 |
|
@@ -219,16 +219,26 @@ const App = () => {
|
219 | 219 | setLayersInfo(newLayersInfo.reverse());
|
220 | 220 | };
|
221 | 221 |
|
| 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 | + }; |
222 | 229 | // 点击切换
|
223 | 230 | const onIconClick = async (symbolId, layerId) => {
|
224 | 231 | if (!map) return;
|
225 | 232 | const type = getLayerType(layerId);
|
226 | 233 | const id = uniqueId();
|
227 | 234 | await map.loadSymbol(symbolId, (_err, symbol) => {
|
228 |
| - if(type === 'point') { |
| 235 | + if (type === 'point') { |
229 | 236 | symbol.layout['icon-allow-overlap'] = true;
|
230 | 237 | symbol.layout['icon-size'] = 0.16;
|
231 | 238 | }
|
| 239 | + // TODO 暂时这样处理,待symbol是否设置visibility明确后优化 |
| 240 | + // 图层隐藏状态下切换符号,隐藏新符号 |
| 241 | + getLayerPropertyStyle(layerId, 'visibility') === 'none' && hideSymbol(symbol); |
232 | 242 | map.addSymbol(id, symbol);
|
233 | 243 | });
|
234 | 244 | map.setSymbol(layerId, id);
|
|
0 commit comments