forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeFeature.js
More file actions
75 lines (70 loc) · 2.77 KB
/
ThemeFeature.js
File metadata and controls
75 lines (70 loc) · 2.77 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
/* Copyright© 2000 - 2020 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 L from "leaflet";
import "../../core/Base";
import {
GeoJSON,
GeoText,
GeometryPoint,
GeometryVector as Vector
} from '@supermap/iclient-common';
/**
* @class L.supermap.themeFeature
* @classdesc 客户端专题图要素类。
* 支持的 geometry 参数类型为 {@link L.Point},{@link L.LatLng},{@link L.Polyline},{@link L.Polygon}。
* @category Visualization Theme
* @extends {L.Class}
* @param {(L.Path|L.Point|L.LatLng)} geometry - 要素图形。
* @param {Object} attributes - 要素属性。
*/
export var ThemeFeature = L.Class.extend({
initialize: function (geometry, attributes) {
this.geometry = geometry;
this.attributes = attributes;
},
/**
* @function L.supermap.themeFeature.prototype.toFeature
* @description 转为内部矢量要素。
* @returns {SuperMap.Feature.Vector} 内部矢量要素。
*/
toFeature: function () {
let geometry = this.geometry;
if (geometry.toGeoJSON) {
const geojsonObject = geometry.toGeoJSON();
geojsonObject.properties = this.attributes;
return new GeoJSON().read(geojsonObject)[0];
}
if (geometry.length === 3) {
geometry = new GeoText(geometry[1], geometry[0], geometry[2]);
} else if (geometry.length === 2) {
geometry = new GeometryPoint(geometry[0], geometry[1]);
} else if (geometry instanceof L.LatLng) {
geometry = new GeometryPoint(geometry.lng, geometry.lat);
} else if (geometry instanceof L.Point) {
geometry = new GeometryPoint(geometry.x, geometry.y);
} else if (geometry instanceof L.CircleMarker) {
var latLng = geometry.getLatLng();
geometry = new GeometryPoint(latLng.lng, latLng.lat);
}
return new Vector(geometry, this.attributes);
},
/**
* @function L.supermap.themeFeature.prototype.reverseLatLngs
* @description 坐标反转。
* @param {L.Latlng} latlngs - 坐标值。
*/
reverseLatLngs: function (latlngs) {
if (!L.Util.isArray(latlngs)) {
latlngs = [latlngs];
}
for (var i = 0; i < latlngs.length; i++) {
latlngs[i] = [latlngs[i].lng, latlngs[i].lat];
}
return latlngs;
}
});
export var themeFeature = function (geometry, attributes) {
return new ThemeFeature(geometry, attributes);
};
L.supermap.themeFeature = themeFeature;