首页 / 浏览问题 / 其他 / 问题详情
mapboxGL用ztree复选框实现mvt矢量瓦片的图层叠加
2EXP 2021年08月10日
$.ajax({
						type: 'GET',
						url: "js/data/test.json",
						success: function (rs) {
							let setting = {
								data: {
									simpleData: {
										enable: true,
										idKey: "id",
										pIdKey: "parentId",
										rootPId: 0
									},
									key: {
										checked: "checked",
										name: 'name'
									}
								},
								view: {
									showLine: true, // 是否显示节点之间的连线
								},
								check: {
									enable: true,
									chkStyle: "checkbox",
									chkboxType: {
										"Y": "ps",
										"N": "ps"
									}
								},
								callback: {
									onClick: function (event, treeId, treeNode) {
										treeObj.checkNode(treeNode, !treeNode.checked, true);
										that.overlay3D(treeNode);
									},
									onCheck: function (event, treeId, treeNode) {
										that.overlay3D(treeNode);
									}
								}
							};
							let treeObj = $.fn.zTree.init($("#overlay2D-layerTree"), setting, rs);
							let nodes = treeObj.getNodes();
							treeObj.checkAllNodes(false);
							if (nodes.length > 0) {
								for (let i = 0; i < nodes.length; i++) {
									treeObj.expandNode(nodes[i], true, false, false); //默认展开第一级节点
								}
							}
						}
					});
overlay2D: function () {
					let treeObj = $.fn.zTree.getZTreeObj("overlay2D-layerTree");
					let name = treeNode.name;
					let resultData = [];
					let mapboxStyle = mvtMap.mapboxStyle;
					for (var i = 0; i < mapboxStyle.layers.length; i++) {
						resultData.push(mapboxStyle.layers[i].id);
					}
					if (treeNode.layerName == undefined) {
						let nodes = treeObj.getNodes();
						let childNodes = [];
						for (let item in nodes) {
							for (let index in nodes[item].children) {
								childNodes.push(nodes[item].children[index]);
							}
						}
						for (var j = 0; j < childNodes.length; j++) {
							let nameChecked;
							if (childNodes[j].layerName) {
								nameChecked = childNodes[j].name;
							} else {
								nameChecked = childNodes[j].name;
							}
							for (var k = 0; k < resultData.length; k++) {
								if (nameChecked == resultData[k]) {
									if (childNodes[j].getCheckStatus().checked == true) {
										map.addLayer(mvtMap.name);
									} else {
										map.removeVectorTilesMap(mvtMap.name);
									}
								}
							}
						}
					} else {
						for (let i = 0, len = resultData.length; i < len; i++) {
							if (name == resultData[i]) {
								if (treeNode.getCheckStatus().checked == true) {
									map.addLayer(mvtMap.name);
								} else {
									map.removeVectorTilesMap(mvtMap.name);
								}
							}
						}
					}
				},

...