forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueThemeLayer.js
More file actions
107 lines (98 loc) · 4.64 KB
/
UniqueThemeLayer.js
File metadata and controls
107 lines (98 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import mapboxgl from 'mapbox-gl';
import '../core/Base';
import {ShapeFactory, ThemeVector as Vector, CommonUtil} from '@supermap/iclient-common';
import {GeoFeature} from './theme/GeoFeatureThemeLayer';
/**
* @class mapboxgl.supermap.UniqueThemeLayer
* @category Visualization Theme
* @classdesc 单值专题图层。
* @param {string} name - 图层名。
* @param {Object} opt_options - 参数。
* @param {string} opt_options.themeField - 指定创建专题图字段。
* @param {Object} opt_options.style - 专题图样式。
* @param {Object} opt_options.styleGroups - 各专题类型样式组。
* @param {mapboxgl.Map} opt_options.map - 当前 mapboxgl map 对象。
* @param {string} [opt_options.id] - 专题图层 ID。默认使用 CommonUtil.createUniqueID("themeLayer_") 创建专题图层 ID。
* @param {boolean} [opt_options.loadWhileAnimating=true] - 是否实时重绘。
* @param {number} [opt_options.opacity=1] - 图层透明度。
* @param {boolean} [opt_options.isHoverAble=false] - 是否开启 hover 事件。
* @param {Object} [opt_options.highlightStyle] - 开启 hover 事件后,触发的样式风格。
* @extends {mapboxgl.supermap.GeoFeatureThemeLayer}
*/
export class Unique extends GeoFeature {
constructor(name, opt_options) {
super(name, opt_options);
this.themeField = opt_options.themeField;
this.style = opt_options.style;
this.styleGroups = opt_options.styleGroups;
this.isHoverAble = opt_options.isHoverAble;
this.highlightStyle = opt_options.highlightStyle;
}
/**
* @private
* @function mapboxgl.supermap.UniqueThemeLayer.prototype.createThematicFeature
* @description 创建专题图要素。
* @param {Object} feature - 要创建的专题图形要素。
*/
createThematicFeature(feature) {
//赋 style
var style = this.getStyleByData(feature);
//创建专题要素时的可选参数
var options = {};
options.nodesClipPixel = this.nodesClipPixel;
options.isHoverAble = this.isHoverAble;
options.isMultiHover = this.isMultiHover;
options.isClickAble = this.isClickAble;
options.highlightStyle = ShapeFactory.transformStyle(this.highlightStyle);
//将数据转为专题要素(Vector)
var thematicFeature = new Vector(feature, this, ShapeFactory.transformStyle(style), options);
//直接添加图形到渲染器
for (var m = 0; m < thematicFeature.shapes.length; m++) {
this.renderer.addShape(thematicFeature.shapes[m]);
}
return thematicFeature;
}
/**
* @private
* @function mapboxgl.supermap.UniqueThemeLayer.prototype.getStyleByData
* @description 通过数据获取 style。
* @param {Object} fea - 要素数据。
*/
getStyleByData(fea) {
var style = {};
var feature = fea;
style = CommonUtil.copyAttributesWithClip(style, this.style);
if (this.themeField && this.styleGroups && this.styleGroups.length > 0 && feature.attributes) {
var tf = this.themeField;
var Attrs = feature.attributes;
var Gro = this.styleGroups;
var isSfInAttrs = false; //指定的 themeField 是否是 feature 的属性字段之一
var attr = null; //属性值
for (var property in Attrs) {
if (tf === property) {
isSfInAttrs = true;
attr = Attrs[property];
break;
}
}
//判断属性值是否属于styleGroups的某一个范围,以便对获取分组 style
if (isSfInAttrs) {
for (var i = 0, len = Gro.length; i < len; i++) {
if ((attr).toString() === ( Gro[i].value).toString()) {
//feature.style = CommonUtil.copyAttributes(feature.style, this.defaultStyle);
var sty1 = Gro[i].style;
style = CommonUtil.copyAttributesWithClip(style, sty1);
}
}
}
}
if (feature.style && this.isAllowFeatureStyle === true) {
style = CommonUtil.copyAttributesWithClip(feature.style);
}
return style;
}
}
mapboxgl.supermap.UniqueThemeLayer = Unique;