raintee-maputils 1.0.36 → 1.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +45 -304
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5777,7 +5777,8 @@ const treeDataAdapter = (data) => {
|
|
|
5777
5777
|
label: layerName,
|
|
5778
5778
|
fullLayerName: groups.length === 0 ? layerName : groups.join('-') + '-' + layerName,
|
|
5779
5779
|
layerId: item.id,
|
|
5780
|
-
opacity: '1.0
|
|
5780
|
+
opacity: item.type === 'fill' ? item['paint']['fill-opacity'] : item.type === 'fill' ? item['paint']['fill-opacity'] : item.type === 'line' ? item['paint']['line-opacity'] : item.type === 'circle' ? item['paint']['circle-opacity'] : "1.0",
|
|
5781
|
+
|
|
5781
5782
|
});
|
|
5782
5783
|
if (item.layout && item.layout.visibility == 'visible') {
|
|
5783
5784
|
checkedKeys.push(currentNodeKey);
|
|
@@ -7195,325 +7196,78 @@ class CustomOptionsControl {
|
|
|
7195
7196
|
}
|
|
7196
7197
|
}
|
|
7197
7198
|
|
|
7198
|
-
// 自定义控件类:ToggleControl
|
|
7199
|
+
// 自定义控件类:ToggleControl
|
|
7199
7200
|
class CustomToggleControl {
|
|
7200
7201
|
/**
|
|
7201
7202
|
* 构造函数
|
|
7202
7203
|
* @param {Object} options
|
|
7203
|
-
* @param {string} options.name -
|
|
7204
|
-
* @param {string} options.field -
|
|
7205
|
-
* @param {boolean} options.defaultValue -
|
|
7206
|
-
* @param {string} options.svgIcon - SVG
|
|
7207
|
-
* @param {Function} [options.onToggle] -
|
|
7208
|
-
* @param {Array} [options.options] - 可选项目数组 [{id, name, icon?}]
|
|
7209
|
-
* @param {Function} [options.onOptionSelect] - 选项选择回调
|
|
7210
|
-
* @param {boolean} [options.showSearch] - 是否显示搜索框,默认 true
|
|
7204
|
+
* @param {string} options.name - 控件名称(用于识别,可选展示)
|
|
7205
|
+
* @param {string} options.field - 控制的字段名,对应 map.SourceMap[field]
|
|
7206
|
+
* @param {boolean} options.defaultValue - 默认值(当 field 未定义时使用)
|
|
7207
|
+
* @param {string} options.svgIcon - SVG 图标字符串,例如 '<svg>...</svg>'
|
|
7208
|
+
* @param {Function} [options.onToggle] - 可选的回调函数,状态切换后调用,参数为最新的布尔值
|
|
7211
7209
|
*/
|
|
7212
|
-
constructor({
|
|
7213
|
-
name,
|
|
7214
|
-
field,
|
|
7215
|
-
defaultValue = false,
|
|
7216
|
-
svgIcon,
|
|
7217
|
-
onToggle,
|
|
7218
|
-
options = [],
|
|
7219
|
-
onOptionSelect,
|
|
7220
|
-
showSearch = true
|
|
7221
|
-
}) {
|
|
7210
|
+
constructor({ name, field, defaultValue = false, svgIcon, onToggle }) {
|
|
7222
7211
|
this.name = name;
|
|
7223
7212
|
this.field = field;
|
|
7224
7213
|
this.defaultValue = defaultValue;
|
|
7225
7214
|
this.svgIcon = svgIcon;
|
|
7226
|
-
this.onToggle = onToggle;
|
|
7227
|
-
this.options = options; // 可选项目
|
|
7228
|
-
this.onOptionSelect = onOptionSelect; // 选项选择回调
|
|
7229
|
-
this.showSearch = showSearch; // 是否显示搜索框
|
|
7215
|
+
this.onToggle = onToggle; // ✅ 新增:回调函数
|
|
7230
7216
|
|
|
7231
|
-
//
|
|
7217
|
+
// 控件容器
|
|
7232
7218
|
this._container = null;
|
|
7233
7219
|
this._button = null;
|
|
7234
|
-
this.
|
|
7235
|
-
this._searchInput = null;
|
|
7236
|
-
this._optionsList = null;
|
|
7237
|
-
this.isActive = false;
|
|
7238
|
-
this.isDropdownOpen = false;
|
|
7239
|
-
this.filteredOptions = [...options]; // 过滤后的选项
|
|
7240
|
-
|
|
7241
|
-
// 绑定事件处理函数
|
|
7242
|
-
this._boundHandleClickOutside = this._handleClickOutside.bind(this);
|
|
7220
|
+
this.isActive = false; // 当前是否为激活状态(高亮/true)
|
|
7243
7221
|
}
|
|
7244
7222
|
|
|
7245
7223
|
// Mapbox 要求的 onAdd 方法
|
|
7246
7224
|
onAdd(map) {
|
|
7247
7225
|
this.map = map;
|
|
7248
7226
|
|
|
7249
|
-
// 创建外层容器
|
|
7227
|
+
// 创建外层容器 div
|
|
7250
7228
|
this._container = document.createElement('div');
|
|
7251
|
-
this._container.className = 'mapboxgl-ctrl mapboxgl-ctrl-group
|
|
7229
|
+
this._container.className = 'mapboxgl-ctrl mapboxgl-ctrl-group';
|
|
7252
7230
|
|
|
7253
|
-
//
|
|
7231
|
+
// 创建 button 元素
|
|
7254
7232
|
this._button = document.createElement('button');
|
|
7255
7233
|
this._button.type = 'button';
|
|
7256
7234
|
this._button.innerHTML = this.svgIcon;
|
|
7257
|
-
this._button.title = this.name;
|
|
7258
7235
|
|
|
7259
7236
|
// 设置按钮样式
|
|
7260
|
-
this.
|
|
7237
|
+
this._button.style.cursor = 'pointer';
|
|
7238
|
+
this._button.style.border = 'none';
|
|
7239
|
+
this._button.style.background = 'none';
|
|
7240
|
+
this._button.style.padding = '0';
|
|
7241
|
+
this._button.style.display = 'flex';
|
|
7242
|
+
this._button.style.alignItems = 'center';
|
|
7243
|
+
this._button.style.justifyContent = 'center';
|
|
7261
7244
|
|
|
7262
7245
|
// 初始化状态
|
|
7263
7246
|
this.updateStatus();
|
|
7264
7247
|
|
|
7265
|
-
//
|
|
7266
|
-
this._button.addEventListener('click', (
|
|
7267
|
-
e.stopPropagation();
|
|
7248
|
+
// 绑定点击事件
|
|
7249
|
+
this._button.addEventListener('click', () => {
|
|
7268
7250
|
this.toggle();
|
|
7269
7251
|
});
|
|
7270
7252
|
|
|
7271
7253
|
this._container.appendChild(this._button);
|
|
7272
7254
|
|
|
7273
|
-
// 创建下拉菜单(如果有选项)
|
|
7274
|
-
if (this.options.length > 0) {
|
|
7275
|
-
this._createDropdown();
|
|
7276
|
-
}
|
|
7277
|
-
|
|
7278
7255
|
return this._container;
|
|
7279
7256
|
}
|
|
7280
7257
|
|
|
7281
|
-
//
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
border: 'none',
|
|
7286
|
-
background: 'none',
|
|
7287
|
-
padding: '8px',
|
|
7288
|
-
display: 'flex',
|
|
7289
|
-
alignItems: 'center',
|
|
7290
|
-
justifyContent: 'center',
|
|
7291
|
-
borderRadius: '4px',
|
|
7292
|
-
transition: 'all 0.2s ease'
|
|
7293
|
-
});
|
|
7294
|
-
}
|
|
7295
|
-
|
|
7296
|
-
// 创建下拉菜单
|
|
7297
|
-
_createDropdown() {
|
|
7298
|
-
// 创建下拉容器
|
|
7299
|
-
this._dropdown = document.createElement('div');
|
|
7300
|
-
this._dropdown.className = 'custom-toggle-dropdown';
|
|
7301
|
-
Object.assign(this._dropdown.style, {
|
|
7302
|
-
position: 'absolute',
|
|
7303
|
-
top: '100%',
|
|
7304
|
-
right: '0',
|
|
7305
|
-
backgroundColor: 'white',
|
|
7306
|
-
border: '1px solid #ccc',
|
|
7307
|
-
borderRadius: '4px',
|
|
7308
|
-
boxShadow: '0 2px 10px rgba(0,0,0,0.1)',
|
|
7309
|
-
zIndex: '1000',
|
|
7310
|
-
minWidth: '200px',
|
|
7311
|
-
maxWidth: '300px',
|
|
7312
|
-
display: 'none',
|
|
7313
|
-
marginTop: '4px'
|
|
7314
|
-
});
|
|
7315
|
-
|
|
7316
|
-
// 创建搜索框(如果需要)
|
|
7317
|
-
if (this.showSearch && this.options.length > 5) {
|
|
7318
|
-
this._createSearchBox();
|
|
7319
|
-
}
|
|
7320
|
-
|
|
7321
|
-
// 创建选项列表
|
|
7322
|
-
this._createOptionsList();
|
|
7323
|
-
|
|
7324
|
-
this._container.appendChild(this._dropdown);
|
|
7325
|
-
}
|
|
7326
|
-
|
|
7327
|
-
// 创建搜索框
|
|
7328
|
-
_createSearchBox() {
|
|
7329
|
-
const searchContainer = document.createElement('div');
|
|
7330
|
-
Object.assign(searchContainer.style, {
|
|
7331
|
-
padding: '8px',
|
|
7332
|
-
borderBottom: '1px solid #eee'
|
|
7333
|
-
});
|
|
7334
|
-
|
|
7335
|
-
this._searchInput = document.createElement('input');
|
|
7336
|
-
this._searchInput.type = 'text';
|
|
7337
|
-
this._searchInput.placeholder = '搜索...';
|
|
7338
|
-
this._searchInput.style.cssText = `
|
|
7339
|
-
width: 100%;
|
|
7340
|
-
padding: 6px 8px;
|
|
7341
|
-
border: 1px solid #ddd;
|
|
7342
|
-
border-radius: 4px;
|
|
7343
|
-
fontSize: 12px;
|
|
7344
|
-
outline: none;
|
|
7345
|
-
box-sizing: border-box;
|
|
7346
|
-
`;
|
|
7347
|
-
|
|
7348
|
-
// 绑定搜索事件
|
|
7349
|
-
this._searchInput.addEventListener('input', (e) => {
|
|
7350
|
-
this._filterOptions(e.target.value);
|
|
7351
|
-
});
|
|
7352
|
-
|
|
7353
|
-
// 阻止下拉菜单关闭
|
|
7354
|
-
this._searchInput.addEventListener('click', (e) => {
|
|
7355
|
-
e.stopPropagation();
|
|
7356
|
-
});
|
|
7357
|
-
|
|
7358
|
-
searchContainer.appendChild(this._searchInput);
|
|
7359
|
-
this._dropdown.appendChild(searchContainer);
|
|
7360
|
-
}
|
|
7361
|
-
|
|
7362
|
-
// 创建选项列表
|
|
7363
|
-
_createOptionsList() {
|
|
7364
|
-
this._optionsList = document.createElement('div');
|
|
7365
|
-
Object.assign(this._optionsList.style, {
|
|
7366
|
-
maxHeight: '200px',
|
|
7367
|
-
overflowY: 'auto',
|
|
7368
|
-
padding: '4px 0'
|
|
7369
|
-
});
|
|
7370
|
-
|
|
7371
|
-
this._renderOptionsList();
|
|
7372
|
-
this._dropdown.appendChild(this._optionsList);
|
|
7373
|
-
}
|
|
7374
|
-
|
|
7375
|
-
// 渲染选项列表
|
|
7376
|
-
_renderOptionsList() {
|
|
7377
|
-
if (!this._optionsList) return;
|
|
7378
|
-
|
|
7379
|
-
this._optionsList.innerHTML = '';
|
|
7380
|
-
|
|
7381
|
-
this.filteredOptions.forEach(option => {
|
|
7382
|
-
const optionItem = document.createElement('div');
|
|
7383
|
-
optionItem.className = 'custom-toggle-option';
|
|
7384
|
-
optionItem.dataset.id = option.id;
|
|
7385
|
-
|
|
7386
|
-
Object.assign(optionItem.style, {
|
|
7387
|
-
padding: '8px 12px',
|
|
7388
|
-
cursor: 'pointer',
|
|
7389
|
-
display: 'flex',
|
|
7390
|
-
alignItems: 'center',
|
|
7391
|
-
gap: '8px',
|
|
7392
|
-
fontSize: '13px',
|
|
7393
|
-
transition: 'background-color 0.2s'
|
|
7394
|
-
});
|
|
7395
|
-
|
|
7396
|
-
// 添加图标(如果有)
|
|
7397
|
-
if (option.icon) {
|
|
7398
|
-
const icon = document.createElement('span');
|
|
7399
|
-
icon.innerHTML = option.icon;
|
|
7400
|
-
icon.style.fontSize = '14px';
|
|
7401
|
-
optionItem.appendChild(icon);
|
|
7402
|
-
}
|
|
7403
|
-
|
|
7404
|
-
// 添加文本
|
|
7405
|
-
const text = document.createElement('span');
|
|
7406
|
-
text.textContent = option.name;
|
|
7407
|
-
optionItem.appendChild(text);
|
|
7408
|
-
|
|
7409
|
-
// 绑定点击事件
|
|
7410
|
-
optionItem.addEventListener('click', (e) => {
|
|
7411
|
-
e.stopPropagation();
|
|
7412
|
-
this._selectOption(option);
|
|
7413
|
-
});
|
|
7414
|
-
|
|
7415
|
-
// 鼠标悬停效果
|
|
7416
|
-
optionItem.addEventListener('mouseenter', () => {
|
|
7417
|
-
optionItem.style.backgroundColor = '#f5f5f5';
|
|
7418
|
-
});
|
|
7419
|
-
|
|
7420
|
-
optionItem.addEventListener('mouseleave', () => {
|
|
7421
|
-
optionItem.style.backgroundColor = 'transparent';
|
|
7422
|
-
});
|
|
7423
|
-
|
|
7424
|
-
this._optionsList.appendChild(optionItem);
|
|
7425
|
-
});
|
|
7426
|
-
|
|
7427
|
-
// 如果没有匹配的选项
|
|
7428
|
-
if (this.filteredOptions.length === 0) {
|
|
7429
|
-
const noResults = document.createElement('div');
|
|
7430
|
-
noResults.textContent = '无匹配项';
|
|
7431
|
-
Object.assign(noResults.style, {
|
|
7432
|
-
padding: '12px',
|
|
7433
|
-
textAlign: 'center',
|
|
7434
|
-
color: '#999',
|
|
7435
|
-
fontSize: '12px'
|
|
7436
|
-
});
|
|
7437
|
-
this._optionsList.appendChild(noResults);
|
|
7438
|
-
}
|
|
7439
|
-
}
|
|
7440
|
-
|
|
7441
|
-
// 过滤选项
|
|
7442
|
-
_filterOptions(searchTerm) {
|
|
7443
|
-
const term = searchTerm.toLowerCase().trim();
|
|
7444
|
-
|
|
7445
|
-
if (!term) {
|
|
7446
|
-
this.filteredOptions = [...this.options];
|
|
7447
|
-
} else {
|
|
7448
|
-
this.filteredOptions = this.options.filter(option =>
|
|
7449
|
-
option.name.toLowerCase().includes(term) ||
|
|
7450
|
-
(option.id && option.id.toString().toLowerCase().includes(term))
|
|
7451
|
-
);
|
|
7452
|
-
}
|
|
7453
|
-
|
|
7454
|
-
this._renderOptionsList();
|
|
7455
|
-
}
|
|
7456
|
-
|
|
7457
|
-
// 选择选项
|
|
7458
|
-
_selectOption(option) {
|
|
7459
|
-
// 调用选项选择回调
|
|
7460
|
-
if (this.onOptionSelect) {
|
|
7461
|
-
this.onOptionSelect(option);
|
|
7462
|
-
}
|
|
7463
|
-
|
|
7464
|
-
// 关闭下拉菜单
|
|
7465
|
-
this.closeDropdown();
|
|
7466
|
-
}
|
|
7467
|
-
|
|
7468
|
-
// 切换下拉菜单显示状态
|
|
7469
|
-
toggle() {
|
|
7470
|
-
if (this.isDropdownOpen) {
|
|
7471
|
-
this.closeDropdown();
|
|
7472
|
-
} else {
|
|
7473
|
-
this.openDropdown();
|
|
7474
|
-
}
|
|
7475
|
-
}
|
|
7476
|
-
|
|
7477
|
-
// 打开下拉菜单
|
|
7478
|
-
openDropdown() {
|
|
7479
|
-
if (!this._dropdown || this.options.length === 0) return;
|
|
7480
|
-
|
|
7481
|
-
this.isDropdownOpen = true;
|
|
7482
|
-
this._dropdown.style.display = 'block';
|
|
7483
|
-
|
|
7484
|
-
// 添加全局点击监听
|
|
7485
|
-
document.addEventListener('click', this._boundHandleClickOutside);
|
|
7486
|
-
|
|
7487
|
-
// 聚焦搜索框
|
|
7488
|
-
if (this._searchInput) {
|
|
7489
|
-
setTimeout(() => {
|
|
7490
|
-
this._searchInput.focus();
|
|
7491
|
-
this._searchInput.value = '';
|
|
7492
|
-
this._filterOptions('');
|
|
7493
|
-
}, 100);
|
|
7494
|
-
}
|
|
7495
|
-
}
|
|
7496
|
-
|
|
7497
|
-
// 关闭下拉菜单
|
|
7498
|
-
closeDropdown() {
|
|
7499
|
-
if (!this._dropdown) return;
|
|
7500
|
-
|
|
7501
|
-
this.isDropdownOpen = false;
|
|
7502
|
-
this._dropdown.style.display = 'none';
|
|
7503
|
-
|
|
7504
|
-
// 移除全局点击监听
|
|
7505
|
-
document.removeEventListener('click', this._boundHandleClickOutside);
|
|
7506
|
-
}
|
|
7507
|
-
|
|
7508
|
-
// 处理外部点击
|
|
7509
|
-
_handleClickOutside(event) {
|
|
7510
|
-
if (!this._container.contains(event.target)) {
|
|
7511
|
-
this.closeDropdown();
|
|
7258
|
+
// Mapbox 要求的 onRemove 方法
|
|
7259
|
+
onRemove() {
|
|
7260
|
+
if (this._container && this._container.parentNode) {
|
|
7261
|
+
this._container.parentNode.removeChild(this._container);
|
|
7512
7262
|
}
|
|
7263
|
+
this.map = null;
|
|
7264
|
+
this._container = null;
|
|
7265
|
+
this._button = null;
|
|
7513
7266
|
}
|
|
7514
7267
|
|
|
7515
|
-
//
|
|
7268
|
+
// 更新控件状态(根据当前 field 值)
|
|
7516
7269
|
updateStatus() {
|
|
7270
|
+
// 从 map.SourceMap 中获取当前 field 的值,如果不存在则使用 defaultValue
|
|
7517
7271
|
let currentValue = this.defaultValue;
|
|
7518
7272
|
|
|
7519
7273
|
if (
|
|
@@ -7524,22 +7278,21 @@ class CustomToggleControl {
|
|
|
7524
7278
|
currentValue = this.map.SourceMap[this.field];
|
|
7525
7279
|
}
|
|
7526
7280
|
|
|
7527
|
-
this.isActive = currentValue;
|
|
7281
|
+
this.isActive = currentValue; // true 表示激活,false 表示未激活
|
|
7528
7282
|
|
|
7529
7283
|
// 更新按钮样式
|
|
7530
7284
|
if (this.isActive) {
|
|
7531
7285
|
this._button.style.opacity = '1';
|
|
7532
7286
|
this._button.style.filter = 'none';
|
|
7533
|
-
this._button.style.backgroundColor = '#e6f3ff';
|
|
7534
7287
|
} else {
|
|
7535
|
-
this._button.style.opacity = '0.
|
|
7288
|
+
this._button.style.opacity = '0.4';
|
|
7536
7289
|
this._button.style.filter = 'grayscale(100%)';
|
|
7537
|
-
this._button.style.backgroundColor = 'transparent';
|
|
7538
7290
|
}
|
|
7539
7291
|
}
|
|
7540
7292
|
|
|
7541
|
-
//
|
|
7542
|
-
|
|
7293
|
+
// 切换状态
|
|
7294
|
+
toggle() {
|
|
7295
|
+
// 获取当前值
|
|
7543
7296
|
let currentValue = this.defaultValue;
|
|
7544
7297
|
|
|
7545
7298
|
if (
|
|
@@ -7550,34 +7303,22 @@ class CustomToggleControl {
|
|
|
7550
7303
|
currentValue = this.map.SourceMap[this.field];
|
|
7551
7304
|
}
|
|
7552
7305
|
|
|
7306
|
+
// 切换值
|
|
7553
7307
|
const newValue = !currentValue;
|
|
7554
7308
|
|
|
7309
|
+
// 更新到 map.SourceMap 中
|
|
7555
7310
|
if (this.map && this.map.SourceMap) {
|
|
7556
7311
|
this.map.SourceMap[this.field] = newValue;
|
|
7557
7312
|
}
|
|
7558
7313
|
|
|
7314
|
+
// 更新内部状态
|
|
7559
7315
|
this.isActive = newValue;
|
|
7560
|
-
this.updateStatus();
|
|
7561
7316
|
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
}
|
|
7565
|
-
}
|
|
7566
|
-
|
|
7567
|
-
// Mapbox 要求的 onRemove 方法
|
|
7568
|
-
onRemove() {
|
|
7569
|
-
this.closeDropdown();
|
|
7570
|
-
|
|
7571
|
-
if (this._container && this._container.parentNode) {
|
|
7572
|
-
this._container.parentNode.removeChild(this._container);
|
|
7573
|
-
}
|
|
7317
|
+
// 更新 UI 样式
|
|
7318
|
+
this.updateStatus();
|
|
7574
7319
|
|
|
7575
|
-
|
|
7576
|
-
this.
|
|
7577
|
-
this._button = null;
|
|
7578
|
-
this._dropdown = null;
|
|
7579
|
-
this._searchInput = null;
|
|
7580
|
-
this._optionsList = null;
|
|
7320
|
+
// ✅ 调用回调函数(如果传入了 onToggle),并传入最新的值
|
|
7321
|
+
this.onToggle?.(newValue); // 安全调用,仅当函数存在时才执行
|
|
7581
7322
|
}
|
|
7582
7323
|
}
|
|
7583
7324
|
|