egovamap 0.23.0 → 0.24.1

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.
@@ -0,0 +1,96 @@
1
+ import RingsConvert from "./RingsConvert";
2
+ function checkGeometryType(geometryType) {
3
+ let types = [
4
+ "Point",
5
+ "MultiPoint",
6
+ "LineString",
7
+ "MultiLineString",
8
+ "Polygon",
9
+ "MultiPolygon",
10
+ ];
11
+ return types.includes(geometryType);
12
+ }
13
+ let GeometryTrans = {
14
+ agsToWKT: function (geometry) {
15
+ var wktStr = "";
16
+ if (geometry["rings"] && geometry["rings"].length) {
17
+ geometry = RingsConvert(geometry["rings"]);
18
+ wktStr = JSON.stringify(geometry.coordinates);
19
+ wktStr = wktStr
20
+ .replace(/\[(-?\d+\.?\d*E?\d*),(-?\d+\.?\d*E?\d*)\]/g, "$1 $2")
21
+ .replace(/\[/g, "(")
22
+ .replace(/\]/g, ")");
23
+ if (geometry.type == "Polygon") {
24
+ wktStr = "POLYGON" + wktStr;
25
+ } else {
26
+ wktStr = "MULTIPOLYGON" + wktStr;
27
+ }
28
+ } else if (geometry["paths"] && geometry["paths"].length) {
29
+ wktStr = JSON.stringify(geometry["paths"]);
30
+ wktStr = wktStr.replace(
31
+ /\[(-?\d+\.?\d*E?\d*),(-?\d+\.?\d*E?\d*)\]/g,
32
+ "$1 $2"
33
+ );
34
+ wktStr = wktStr.replace(/\[/g, "(").replace(/\]/g, ")");
35
+ wktStr = "MULTILINESTRING" + wktStr;
36
+ } else if (geometry["x"] !== undefined && geometry["y"] !== undefined) {
37
+ wktStr = "POINT(" + geometry["x"] + " " + geometry["y"] + ")";
38
+ } else if (geometry["xmin"] != undefined) {
39
+ xmin = geometry["xmin"];
40
+ ymin = geometry["ymin"] || 0;
41
+ xmax = geometry["xmax"] || 0;
42
+ ymax = geometry["ymax"] || 0;
43
+ wktStr =
44
+ "POLYGON((" +
45
+ xmin +
46
+ " " +
47
+ ymin +
48
+ "," +
49
+ xmax +
50
+ " " +
51
+ ymin +
52
+ "," +
53
+ xmax +
54
+ " " +
55
+ ymax +
56
+ "," +
57
+ xmin +
58
+ " " +
59
+ ymax +
60
+ "," +
61
+ xmin +
62
+ " " +
63
+ ymin +
64
+ "))";
65
+ }
66
+ return wktStr;
67
+ },
68
+ geoJsonToWKT: function (geometry) {
69
+ let geometryType = geometry.type;
70
+ if (!geometryType || !checkGeometryType(geometryType)) {
71
+ return `${geometryType}是不支持的几何类型`;
72
+ }
73
+ let coordinates = geometry["coordinates"];
74
+ var wktStr = "";
75
+ wktStr = JSON.stringify(coordinates);
76
+ wktStr = wktStr.replace(
77
+ /\[(-?\d+\.?\d*E?\d*),(-?\d+\.?\d*E?\d*)\]/g,
78
+ "$1 $2"
79
+ );
80
+ wktStr = wktStr.replace(/\[/g, "(").replace(/\]/g, ")");
81
+ if (geometryType === 'Point') {
82
+ wktStr = geometryType.toUpperCase() + "(" + wktStr + ")";
83
+ } else {
84
+ wktStr = geometryType.toUpperCase() + wktStr;
85
+ }
86
+ return wktStr;
87
+ },
88
+ geometryToWKT: function (geometry) {
89
+ if (geometry["coordinates"]) {
90
+ return this.geoJsonToWKT(geometry)
91
+ } else {
92
+ return this.agsToWKT(geometry)
93
+ }
94
+ }
95
+ };
96
+ export default GeometryTrans;
@@ -0,0 +1,172 @@
1
+ function isNumber(n) {
2
+ return !isNaN(parseFloat(n)) && isFinite(n);
3
+ }
4
+
5
+ function ringIsClockwise(ringToTest) {
6
+ var total = 0,
7
+ i = 0;
8
+ var rLength = ringToTest.length;
9
+ var pt1 = ringToTest[i];
10
+ var pt2;
11
+ for (i; i < rLength - 1; i++) {
12
+ pt2 = ringToTest[i + 1];
13
+ total += (pt2[0] - pt1[0]) * (pt2[1] + pt1[1]);
14
+ pt1 = pt2;
15
+ }
16
+ return (total >= 0);
17
+ }
18
+
19
+ function closeRing(coordinates) {
20
+ if (!pointsEqual(coordinates[0], coordinates[coordinates.length - 1])) {
21
+ coordinates.push(coordinates[0]);
22
+ }
23
+ return coordinates;
24
+ }
25
+
26
+ // checks if 2 x,y points are equal
27
+ function pointsEqual(a, b) {
28
+ for (var i = 0; i < a.length; i++) {
29
+ if (a[i] !== b[i]) {
30
+ return false;
31
+ }
32
+ }
33
+ return true;
34
+ }
35
+
36
+ function coordinatesContainPoint(coordinates, point) {
37
+ var contains = false;
38
+ for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) {
39
+ if (((coordinates[i][1] <= point[1] && point[1] < coordinates[j][1]) ||
40
+ (coordinates[j][1] <= point[1] && point[1] < coordinates[i][1])) &&
41
+ (point[0] < (coordinates[j][0] - coordinates[i][0]) * (point[1] - coordinates[i][1]) / (coordinates[j][1] - coordinates[i][1]) + coordinates[i][0])) {
42
+ contains = !contains;
43
+ }
44
+ }
45
+ return contains;
46
+ }
47
+
48
+ function edgeIntersectsEdge(a1, a2, b1, b2) {
49
+ var ua_t = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]);
50
+ var ub_t = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]);
51
+ var u_b = (b2[1] - b1[1]) * (a2[0] - a1[0]) - (b2[0] - b1[0]) * (a2[1] - a1[1]);
52
+
53
+ if (u_b !== 0) {
54
+ var ua = ua_t / u_b;
55
+ var ub = ub_t / u_b;
56
+
57
+ if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) {
58
+ return true;
59
+ }
60
+ }
61
+
62
+ return false;
63
+ }
64
+
65
+ function arraysIntersectArrays(a, b) {
66
+ if (isNumber(a[0][0])) {
67
+ if (isNumber(b[0][0])) {
68
+ for (var i = 0; i < a.length - 1; i++) {
69
+ for (var j = 0; j < b.length - 1; j++) {
70
+ if (edgeIntersectsEdge(a[i], a[i + 1], b[j], b[j + 1])) {
71
+ return true;
72
+ }
73
+ }
74
+ }
75
+ } else {
76
+ for (var k = 0; k < b.length; k++) {
77
+ if (arraysIntersectArrays(a, b[k])) {
78
+ return true;
79
+ }
80
+ }
81
+ }
82
+ } else {
83
+ for (var l = 0; l < a.length; l++) {
84
+ if (arraysIntersectArrays(a[l], b)) {
85
+ return true;
86
+ }
87
+ }
88
+ }
89
+ return false;
90
+ }
91
+
92
+ function coordinatesContainCoordinates(outer, inner) {
93
+ var intersects = arraysIntersectArrays(outer, inner);
94
+ var contains = coordinatesContainPoint(outer, inner[0]);
95
+ if (!intersects && contains) {
96
+ return true;
97
+ }
98
+ return false;
99
+ }
100
+
101
+ function convertRingsToGeoJSON(rings) {
102
+ var outerRings = [];
103
+ var holes = [];
104
+ var x;
105
+ var outerRing;
106
+ var hole;
107
+
108
+
109
+ for (var r = 0; r < rings.length; r++) {
110
+ var ring = closeRing(rings[r].slice(0));
111
+ if (ring.length < 4) {
112
+ continue;
113
+ }
114
+
115
+ if (ringIsClockwise(ring)) {
116
+ var polygon = [ring.slice().reverse()];
117
+ outerRings.push(polygon);
118
+ } else {
119
+ holes.push(ring.slice().reverse());
120
+ }
121
+ }
122
+
123
+ var uncontainedHoles = [];
124
+
125
+ while (holes.length) {
126
+ hole = holes.pop();
127
+ var contained = false;
128
+ for (x = outerRings.length - 1; x >= 0; x--) {
129
+ outerRing = outerRings[x][0];
130
+ if (coordinatesContainCoordinates(outerRing, hole)) {
131
+ outerRings[x].push(hole);
132
+ contained = true;
133
+ break;
134
+ }
135
+ }
136
+
137
+ if (!contained) {
138
+ uncontainedHoles.push(hole);
139
+ }
140
+ }
141
+
142
+ while (uncontainedHoles.length) {
143
+ hole = uncontainedHoles.pop();
144
+
145
+ var intersects = false;
146
+ for (x = outerRings.length - 1; x >= 0; x--) {
147
+ outerRing = outerRings[x][0];
148
+ if (arraysIntersectArrays(outerRing, hole)) {
149
+ outerRings[x].push(hole);
150
+ intersects = true;
151
+ break;
152
+ }
153
+ }
154
+
155
+ if (!intersects) {
156
+ outerRings.push([hole.reverse()]);
157
+ }
158
+ }
159
+
160
+ if (outerRings.length === 1) {
161
+ return {
162
+ type: 'Polygon',
163
+ coordinates: outerRings[0]
164
+ };
165
+ } else {
166
+ return {
167
+ type: 'MultiPolygon',
168
+ coordinates: outerRings
169
+ };
170
+ }
171
+ }
172
+ export default convertRingsToGeoJSON;
@@ -1019,7 +1019,8 @@ var egovaBI = function(globeMap, gisMap, mapType){
1019
1019
  maxZoom: options.visiblitySetting.endLevel,
1020
1020
  layerId: options.layerName,
1021
1021
  comCallbak: callback,
1022
- order: options.order
1022
+ order: options.order,
1023
+ inverse: options.inverse
1023
1024
  // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
1024
1025
  };
1025
1026
  if (options.labelSetting.labelZoomEnabled == 'show') {
@@ -8,7 +8,7 @@ import MapSwich from './mapswich';
8
8
  import EGovaScene from './EGovaScene';
9
9
  import MapUtils from './mapUtils';
10
10
  import './egovamap.css';
11
-
11
+ import GeometryTrans from './GeometryTrans';
12
12
  var defaultMapID = null;
13
13
  var mapList = {};
14
14
  var mapArray = [];
@@ -4369,6 +4369,11 @@ var EGovaMap = function (containerID, callback, mapConfig, mapType, mapParam, co
4369
4369
  gisMap.agsToWKT(geometry, callback);
4370
4370
  }
4371
4371
  }
4372
+
4373
+ //geometyr转WKT
4374
+ that.geometryToWKT = function(geometry){
4375
+ return GeometryTrans.geometryToWKT(geometry)
4376
+ }
4372
4377
  that.initMap(containerID, callback, mapType, mapConfig);
4373
4378
 
4374
4379
  // EGovaBI(globeMap).bind(this)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egovamap",
3
- "version": "0.23.0",
3
+ "version": "0.24.1",
4
4
  "description": "eUrbanGIS SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {