potato-map3d-ui2 0.0.31 → 0.0.33

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.
@@ -331,13 +331,19 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
331
331
  _hoisted_1$8
332
332
  ]),
333
333
  createElementVNode("span", {
334
- class: normalizeClass(["m-control-text", __props.placement === "left" ? "m-control-textLeft" : "m-control-textRight"])
334
+ class: normalizeClass([
335
+ "m-control-text",
336
+ __props.placement === "left" ? "m-control-textLeft" : "m-control-textRight"
337
+ ])
335
338
  }, [
336
339
  renderSlot(_ctx.$slots, "default", {}, () => [
337
340
  createTextVNode("缩小")
338
341
  ]),
339
342
  createElementVNode("div", {
340
- class: normalizeClass(["m-control-triangle", __props.placement === "left" ? "m-control-triangleLeft" : "m-control-triangleRight"])
343
+ class: normalizeClass([
344
+ "m-control-triangle",
345
+ __props.placement === "left" ? "m-control-triangleLeft" : "m-control-triangleRight"
346
+ ])
341
347
  }, null, 2)
342
348
  ], 2)
343
349
  ]);
@@ -467,13 +473,19 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
467
473
  _hoisted_1$5
468
474
  ]),
469
475
  createElementVNode("span", {
470
- class: normalizeClass(["m-control-text", __props.placement === "left" ? "m-control-textLeft" : "m-control-textRight"])
476
+ class: normalizeClass([
477
+ "m-control-text",
478
+ __props.placement === "left" ? "m-control-textLeft" : "m-control-textRight"
479
+ ])
471
480
  }, [
472
481
  renderSlot(_ctx.$slots, "default", {}, () => [
473
482
  createTextVNode("全屏")
474
483
  ]),
475
484
  createElementVNode("div", {
476
- class: normalizeClass(["m-control-triangle", __props.placement === "left" ? "m-control-triangleLeft" : "m-control-triangleRight"])
485
+ class: normalizeClass([
486
+ "m-control-triangle",
487
+ __props.placement === "left" ? "m-control-triangleLeft" : "m-control-triangleRight"
488
+ ])
477
489
  }, null, 2)
478
490
  ], 2)
479
491
  ]);
@@ -518,7 +530,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
518
530
  ])
519
531
  }, [
520
532
  renderSlot(_ctx.$slots, "default", {}, () => [
521
- createTextVNode("全屏")
533
+ createTextVNode("复位")
522
534
  ]),
523
535
  createElementVNode("div", {
524
536
  class: normalizeClass([
@@ -937,6 +949,363 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
937
949
  };
938
950
  }
939
951
  });
952
+ function wktToGeometry(wkt) {
953
+ try {
954
+ const typeStr = wkt.match(/^[A-Z]+(?=\()/);
955
+ if (!typeStr) {
956
+ console.log("wkt数据格式不对,没有解析到type");
957
+ return;
958
+ }
959
+ const type = typeStr[0];
960
+ let geometry;
961
+ if (type === "POINT") {
962
+ const res = wkt.match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
963
+ if (!res) {
964
+ console.log("没有解析到POINT的坐标");
965
+ return;
966
+ }
967
+ const coords = res[0].split(" ").map(Number);
968
+ geometry = { type: "Point", coordinates: coords };
969
+ } else if (type === "LINESTRING") {
970
+ const res = wkt.match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
971
+ if (!res) {
972
+ console.log("没有解析到LINESTRING的坐标");
973
+ return;
974
+ }
975
+ const coords = [];
976
+ res.forEach((item) => {
977
+ coords.push(item.split(" ").map(Number));
978
+ });
979
+ geometry = { type: "LineString", coordinates: coords };
980
+ } else if (type === "MULTIPOINT") {
981
+ const res = wkt.match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
982
+ if (!res) {
983
+ console.log("没有解析到MULTIPOINT的坐标");
984
+ return;
985
+ }
986
+ const coords = [];
987
+ res.forEach((item) => {
988
+ coords.push(item.split(" ").map(Number));
989
+ });
990
+ geometry = { type: "MultiPoint", coordinates: coords };
991
+ } else if (type === "POLYGON") {
992
+ const resArr = wkt.split(/,(?=\()/);
993
+ const coords = [];
994
+ for (let i = 0; i < resArr.length; i++) {
995
+ const res = resArr[i].match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
996
+ if (!res) {
997
+ console.log("没有解析到POLYGON的坐标");
998
+ return;
999
+ }
1000
+ const ringCoords = [];
1001
+ res.forEach((ele) => {
1002
+ ringCoords.push(ele.split(" ").map(Number));
1003
+ });
1004
+ coords.push(ringCoords);
1005
+ }
1006
+ geometry = { type: "Polygon", coordinates: coords };
1007
+ } else if (type === "MULTILINESTRING") {
1008
+ const resArr = wkt.split(/,(?=\()/);
1009
+ const coords = [];
1010
+ for (let i = 0; i < resArr.length; i++) {
1011
+ const res = resArr[i].match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
1012
+ if (!res) {
1013
+ console.log("没有解析到MULTILINESTRING的坐标");
1014
+ return;
1015
+ }
1016
+ const ringCoords = [];
1017
+ res.forEach((ele) => {
1018
+ ringCoords.push(ele.split(" ").map(Number));
1019
+ });
1020
+ coords.push(ringCoords);
1021
+ }
1022
+ geometry = { type: "MultiLineString", coordinates: coords };
1023
+ } else if (type === "MULTIPOLYGON") {
1024
+ const resArr1 = wkt.split(/,(?=\(\()/);
1025
+ const coords = [];
1026
+ for (let i = 0; i < resArr1.length; i++) {
1027
+ const resArr2 = resArr1[i].split(/,(?=\()/);
1028
+ const polyCoords = [];
1029
+ for (let j = 0; j < resArr2.length; j++) {
1030
+ const res = resArr2[j].match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
1031
+ if (!res) {
1032
+ console.log("没有解析到MULTIPOLYGON的坐标");
1033
+ return;
1034
+ }
1035
+ const ringCoords = [];
1036
+ res.forEach((ele) => {
1037
+ ringCoords.push(ele.split(" ").map(Number));
1038
+ });
1039
+ polyCoords.push(ringCoords);
1040
+ }
1041
+ coords.push(polyCoords);
1042
+ }
1043
+ geometry = { type: "MultiPolygon", coordinates: coords };
1044
+ }
1045
+ return geometry;
1046
+ } catch (error) {
1047
+ console.log("格式解析出错", error);
1048
+ }
1049
+ }
1050
+ function wktToGeojson(wkt) {
1051
+ try {
1052
+ wkt = wkt.replaceAll("\n", "").replaceAll(" ", "").replaceAll(" ,", ",").replaceAll(", ", ",").replaceAll(" (", "(").replaceAll("( ", "(").replaceAll(" )", ")").replaceAll(") ", ")").toUpperCase();
1053
+ const typeStr = wkt.match(/^[A-Z]+(?=\()/);
1054
+ if (!typeStr) {
1055
+ console.log("wkt数据格式不对,没有解析到type");
1056
+ return;
1057
+ }
1058
+ const type = typeStr[0];
1059
+ if (type === "GEOMETRYCOLLECTION") {
1060
+ wkt = wkt.substring(19, wkt.length - 1);
1061
+ const resArr = wkt.split(/,(?=[A-Z]+)/);
1062
+ const features = [];
1063
+ for (let i = 0; i < resArr.length; i++) {
1064
+ const geometry = wktToGeometry(resArr[i]);
1065
+ if (!geometry)
1066
+ return;
1067
+ features.push({ type: "Feature", geometry });
1068
+ }
1069
+ return { type: "FeatureCollection", features };
1070
+ } else {
1071
+ const resArr = wkt.split(/,(?=[A-Z]+)/);
1072
+ if (resArr.length > 1) {
1073
+ const features = [];
1074
+ for (let i = 0; i < resArr.length; i++) {
1075
+ const geometry = wktToGeometry(resArr[i]);
1076
+ if (!geometry)
1077
+ return;
1078
+ features.push({ type: "Feature", geometry });
1079
+ }
1080
+ return { type: "FeatureCollection", features };
1081
+ } else {
1082
+ if ([
1083
+ "POINT",
1084
+ "LINESTRING",
1085
+ "POLYGON",
1086
+ "MULTIPOINT",
1087
+ "MULTILINESTRING",
1088
+ "MULTIPOLYGON"
1089
+ ].includes(type)) {
1090
+ const geometry = wktToGeometry(wkt);
1091
+ if (!geometry)
1092
+ return;
1093
+ return { type: "Feature", geometry };
1094
+ } else {
1095
+ console.log("wkt数据的type不太对-->", type);
1096
+ return;
1097
+ }
1098
+ }
1099
+ }
1100
+ } catch (error) {
1101
+ console.log("格式解析出错", error);
1102
+ }
1103
+ }
1104
+ function geometryToWkt(geometry) {
1105
+ if (!geometry) {
1106
+ console.log("没有geojson数据");
1107
+ return "";
1108
+ }
1109
+ const { type } = geometry;
1110
+ if (!type) {
1111
+ console.log("数据中没有type");
1112
+ return "";
1113
+ }
1114
+ if (typeof type !== "string") {
1115
+ console.log("数据中的type不是字符串");
1116
+ return "";
1117
+ }
1118
+ const coords = geometry.coordinates;
1119
+ if (!coords) {
1120
+ console.log("数据中没有coordinates");
1121
+ return "";
1122
+ }
1123
+ if (!(coords instanceof Array)) {
1124
+ console.log("数据的coordinates不是数组");
1125
+ return "";
1126
+ }
1127
+ if (coords.length === 0) {
1128
+ console.log("数据的coordinates是空的");
1129
+ return "";
1130
+ }
1131
+ const wktCoords = [];
1132
+ switch (type.toUpperCase()) {
1133
+ case "POINT":
1134
+ if (coords.length < 2) {
1135
+ console.log("type为Point的coordinates格式不对-->", geometry);
1136
+ return "";
1137
+ }
1138
+ for (let i = 0; i < coords.length; i++) {
1139
+ if (typeof coords[i] !== "number" || isNaN(coords[i])) {
1140
+ console.log("type为Point的coordinates格式不对-->", geometry);
1141
+ return "";
1142
+ }
1143
+ }
1144
+ wktCoords.push(coords.slice(0, 2).join(" "));
1145
+ break;
1146
+ case "LINESTRING":
1147
+ case "MULTIPOINT":
1148
+ for (let i = 0; i < coords.length; i++) {
1149
+ const coord = coords[i];
1150
+ if (!(coord instanceof Array) || coord.length < 2) {
1151
+ console.log("type为MultiPoint或LineString的coordinates格式不对-->", geometry);
1152
+ return "";
1153
+ }
1154
+ for (let j = 0; j < coord.length; j++) {
1155
+ if (typeof coord[j] !== "number" || isNaN(coord[j])) {
1156
+ console.log("type为MultiPoint或LineString的coordinates格式不对-->", geometry);
1157
+ return "";
1158
+ }
1159
+ }
1160
+ wktCoords.push(coord.slice(0, 2).join(" "));
1161
+ }
1162
+ break;
1163
+ case "POLYGON":
1164
+ case "MULTILINESTRING":
1165
+ for (let i = 0; i < coords.length; i++) {
1166
+ const item = coords[i];
1167
+ const ringCoords = [];
1168
+ if (!(item instanceof Array)) {
1169
+ console.log("type为Polygon或MultiLineString的coordinates格式不对-->", geometry);
1170
+ return "";
1171
+ }
1172
+ for (let j = 0; j < item.length; j++) {
1173
+ const ele = item[j];
1174
+ if (!(ele instanceof Array) || ele.length < 2) {
1175
+ console.log("type为Polygon或MultiLineString的coordinates格式不对-->", geometry);
1176
+ return "";
1177
+ }
1178
+ for (let k = 0; k < ele.length; k++) {
1179
+ if (typeof ele[k] !== "number" || isNaN(ele[k])) {
1180
+ console.log("type为Polygon或MultiLineString的coordinates格式不对-->", geometry);
1181
+ return "";
1182
+ }
1183
+ }
1184
+ ringCoords.push(ele.slice(0, 2).join(" "));
1185
+ }
1186
+ wktCoords.push(`(${ringCoords.join(",")})`);
1187
+ }
1188
+ break;
1189
+ case "MULTIPOLYGON":
1190
+ for (let i = 0; i < coords.length; i++) {
1191
+ const item = coords[i];
1192
+ const polyCoords = [];
1193
+ if (!(item instanceof Array)) {
1194
+ console.log("type为MultiPolygon的coordinates格式不对-->", geometry);
1195
+ return "";
1196
+ }
1197
+ for (let j = 0; j < item.length; j++) {
1198
+ const ele = item[j];
1199
+ const ringCoords = [];
1200
+ if (!(ele instanceof Array)) {
1201
+ console.log("type为MultiPolygon的coordinates格式不对-->", geometry);
1202
+ return "";
1203
+ }
1204
+ for (let k = 0; k < ele.length; k++) {
1205
+ const mem = ele[k];
1206
+ if (!(mem instanceof Array) || mem.length < 2) {
1207
+ console.log("type为MultiPolygon的coordinates格式不对-->", geometry);
1208
+ return "";
1209
+ }
1210
+ for (let n = 0; n < mem.length; n++) {
1211
+ if (typeof mem[n] !== "number" || isNaN(mem[n])) {
1212
+ console.log("type为Polygon或MultiLineString的coordinates格式不对-->", geometry);
1213
+ return "";
1214
+ }
1215
+ }
1216
+ ringCoords.push(mem.slice(0, 2).join(" "));
1217
+ }
1218
+ polyCoords.push(`(${ringCoords.join(",")})`);
1219
+ }
1220
+ wktCoords.push(`(${polyCoords.join(",")})`);
1221
+ }
1222
+ break;
1223
+ default:
1224
+ console.log(`这个geojson中的type值好像不太对--> type: ${type}`);
1225
+ return "";
1226
+ }
1227
+ return `${type.toUpperCase()}(${wktCoords.join(",")})`;
1228
+ }
1229
+ function geojsonToWkt(geojson) {
1230
+ if (!geojson) {
1231
+ console.log("没有geojson数据");
1232
+ return "";
1233
+ }
1234
+ const { type } = geojson;
1235
+ if (!type) {
1236
+ console.log("这个geojson没有type");
1237
+ return "";
1238
+ }
1239
+ if (typeof type !== "string") {
1240
+ console.log("这个geojson的type不是字符串");
1241
+ return "";
1242
+ }
1243
+ if ([
1244
+ "POINT",
1245
+ "LINESTRING",
1246
+ "POLYGON",
1247
+ "MULTIPOINT",
1248
+ "MULTILINESTRING",
1249
+ "MULTIPOLYGON"
1250
+ ].includes(type.toUpperCase())) {
1251
+ return geometryToWkt(geojson);
1252
+ } else if (type.toUpperCase() === "FEATURE") {
1253
+ const { geometry } = geojson;
1254
+ if (!geometry) {
1255
+ console.log("type为Feature的数据没有geometry-->", geojson);
1256
+ return "";
1257
+ }
1258
+ return geometryToWkt(geometry);
1259
+ } else if (type.toUpperCase() === "GEOMETRYCOLLECTION") {
1260
+ const wkts = [];
1261
+ const { geometries } = geojson;
1262
+ if (!geometries) {
1263
+ console.log("type为GeometryCollection的数据没有geometries-->", geojson);
1264
+ return "";
1265
+ }
1266
+ if (!(geometries instanceof Array)) {
1267
+ console.log("type为GeometryCollection的数据中geometries不是数组-->", geojson);
1268
+ return "";
1269
+ }
1270
+ for (let i = 0; i < geometries.length; i++) {
1271
+ wkts.push(geometryToWkt(geometries[i]));
1272
+ }
1273
+ return `GEOMETRYCOLLECTION(${wkts.join(",")})`;
1274
+ } else if (type.toUpperCase() === "FEATURECOLLECTION") {
1275
+ const wkts = [];
1276
+ const { features } = geojson;
1277
+ if (!features) {
1278
+ console.log("type为FeatureCollection的数据没有features-->", geojson);
1279
+ return "";
1280
+ }
1281
+ if (!(features instanceof Array)) {
1282
+ console.log("type为FeatureCollection的数据中features不是数组-->", geojson);
1283
+ return "";
1284
+ }
1285
+ for (let i = 0; i < features.length; i++) {
1286
+ const item = features[i];
1287
+ const { type: type2 } = item;
1288
+ if (!type2) {
1289
+ console.log("这个feature没有type-->", item);
1290
+ return "";
1291
+ }
1292
+ if (typeof type2 !== "string") {
1293
+ console.log("这个feature的type不是字符串-->", item);
1294
+ return "";
1295
+ }
1296
+ const { geometry } = item;
1297
+ if (!geometry) {
1298
+ console.log("这个feature没有geometry-->", item);
1299
+ return "";
1300
+ }
1301
+ wkts.push(geometryToWkt(geometry));
1302
+ }
1303
+ return `GEOMETRYCOLLECTION(${wkts.join(",")})`;
1304
+ } else {
1305
+ console.log(`这个geojson的type值好像不太对--> type: ${type}`);
1306
+ return "";
1307
+ }
1308
+ }
940
1309
  const potatoMap3dUi2 = {
941
1310
  install: (app) => {
942
1311
  app.component("Map3dT", _sfc_main$9);
@@ -949,6 +1318,10 @@ const potatoMap3dUi2 = {
949
1318
  app.component("ControlFaceNorth", _sfc_main$3);
950
1319
  app.component("ControlSquarelyView", _sfc_main$2);
951
1320
  app.component("ControlBaseMap", _sfc_main$1);
1321
+ },
1322
+ functions: {
1323
+ geojsonToWkt,
1324
+ wktToGeojson
952
1325
  }
953
1326
  };
954
1327
  export {
@@ -334,13 +334,19 @@
334
334
  _hoisted_1$8
335
335
  ]),
336
336
  vue.createElementVNode("span", {
337
- class: vue.normalizeClass(["m-control-text", __props.placement === "left" ? "m-control-textLeft" : "m-control-textRight"])
337
+ class: vue.normalizeClass([
338
+ "m-control-text",
339
+ __props.placement === "left" ? "m-control-textLeft" : "m-control-textRight"
340
+ ])
338
341
  }, [
339
342
  vue.renderSlot(_ctx.$slots, "default", {}, () => [
340
343
  vue.createTextVNode("缩小")
341
344
  ]),
342
345
  vue.createElementVNode("div", {
343
- class: vue.normalizeClass(["m-control-triangle", __props.placement === "left" ? "m-control-triangleLeft" : "m-control-triangleRight"])
346
+ class: vue.normalizeClass([
347
+ "m-control-triangle",
348
+ __props.placement === "left" ? "m-control-triangleLeft" : "m-control-triangleRight"
349
+ ])
344
350
  }, null, 2)
345
351
  ], 2)
346
352
  ]);
@@ -470,13 +476,19 @@
470
476
  _hoisted_1$5
471
477
  ]),
472
478
  vue.createElementVNode("span", {
473
- class: vue.normalizeClass(["m-control-text", __props.placement === "left" ? "m-control-textLeft" : "m-control-textRight"])
479
+ class: vue.normalizeClass([
480
+ "m-control-text",
481
+ __props.placement === "left" ? "m-control-textLeft" : "m-control-textRight"
482
+ ])
474
483
  }, [
475
484
  vue.renderSlot(_ctx.$slots, "default", {}, () => [
476
485
  vue.createTextVNode("全屏")
477
486
  ]),
478
487
  vue.createElementVNode("div", {
479
- class: vue.normalizeClass(["m-control-triangle", __props.placement === "left" ? "m-control-triangleLeft" : "m-control-triangleRight"])
488
+ class: vue.normalizeClass([
489
+ "m-control-triangle",
490
+ __props.placement === "left" ? "m-control-triangleLeft" : "m-control-triangleRight"
491
+ ])
480
492
  }, null, 2)
481
493
  ], 2)
482
494
  ]);
@@ -521,7 +533,7 @@
521
533
  ])
522
534
  }, [
523
535
  vue.renderSlot(_ctx.$slots, "default", {}, () => [
524
- vue.createTextVNode("全屏")
536
+ vue.createTextVNode("复位")
525
537
  ]),
526
538
  vue.createElementVNode("div", {
527
539
  class: vue.normalizeClass([
@@ -940,6 +952,363 @@
940
952
  };
941
953
  }
942
954
  });
955
+ function wktToGeometry(wkt) {
956
+ try {
957
+ const typeStr = wkt.match(/^[A-Z]+(?=\()/);
958
+ if (!typeStr) {
959
+ console.log("wkt数据格式不对,没有解析到type");
960
+ return;
961
+ }
962
+ const type = typeStr[0];
963
+ let geometry;
964
+ if (type === "POINT") {
965
+ const res = wkt.match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
966
+ if (!res) {
967
+ console.log("没有解析到POINT的坐标");
968
+ return;
969
+ }
970
+ const coords = res[0].split(" ").map(Number);
971
+ geometry = { type: "Point", coordinates: coords };
972
+ } else if (type === "LINESTRING") {
973
+ const res = wkt.match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
974
+ if (!res) {
975
+ console.log("没有解析到LINESTRING的坐标");
976
+ return;
977
+ }
978
+ const coords = [];
979
+ res.forEach((item) => {
980
+ coords.push(item.split(" ").map(Number));
981
+ });
982
+ geometry = { type: "LineString", coordinates: coords };
983
+ } else if (type === "MULTIPOINT") {
984
+ const res = wkt.match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
985
+ if (!res) {
986
+ console.log("没有解析到MULTIPOINT的坐标");
987
+ return;
988
+ }
989
+ const coords = [];
990
+ res.forEach((item) => {
991
+ coords.push(item.split(" ").map(Number));
992
+ });
993
+ geometry = { type: "MultiPoint", coordinates: coords };
994
+ } else if (type === "POLYGON") {
995
+ const resArr = wkt.split(/,(?=\()/);
996
+ const coords = [];
997
+ for (let i = 0; i < resArr.length; i++) {
998
+ const res = resArr[i].match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
999
+ if (!res) {
1000
+ console.log("没有解析到POLYGON的坐标");
1001
+ return;
1002
+ }
1003
+ const ringCoords = [];
1004
+ res.forEach((ele) => {
1005
+ ringCoords.push(ele.split(" ").map(Number));
1006
+ });
1007
+ coords.push(ringCoords);
1008
+ }
1009
+ geometry = { type: "Polygon", coordinates: coords };
1010
+ } else if (type === "MULTILINESTRING") {
1011
+ const resArr = wkt.split(/,(?=\()/);
1012
+ const coords = [];
1013
+ for (let i = 0; i < resArr.length; i++) {
1014
+ const res = resArr[i].match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
1015
+ if (!res) {
1016
+ console.log("没有解析到MULTILINESTRING的坐标");
1017
+ return;
1018
+ }
1019
+ const ringCoords = [];
1020
+ res.forEach((ele) => {
1021
+ ringCoords.push(ele.split(" ").map(Number));
1022
+ });
1023
+ coords.push(ringCoords);
1024
+ }
1025
+ geometry = { type: "MultiLineString", coordinates: coords };
1026
+ } else if (type === "MULTIPOLYGON") {
1027
+ const resArr1 = wkt.split(/,(?=\(\()/);
1028
+ const coords = [];
1029
+ for (let i = 0; i < resArr1.length; i++) {
1030
+ const resArr2 = resArr1[i].split(/,(?=\()/);
1031
+ const polyCoords = [];
1032
+ for (let j = 0; j < resArr2.length; j++) {
1033
+ const res = resArr2[j].match(/(-*\d+\.*\d*\s-*\d+\.*\d*)/g);
1034
+ if (!res) {
1035
+ console.log("没有解析到MULTIPOLYGON的坐标");
1036
+ return;
1037
+ }
1038
+ const ringCoords = [];
1039
+ res.forEach((ele) => {
1040
+ ringCoords.push(ele.split(" ").map(Number));
1041
+ });
1042
+ polyCoords.push(ringCoords);
1043
+ }
1044
+ coords.push(polyCoords);
1045
+ }
1046
+ geometry = { type: "MultiPolygon", coordinates: coords };
1047
+ }
1048
+ return geometry;
1049
+ } catch (error) {
1050
+ console.log("格式解析出错", error);
1051
+ }
1052
+ }
1053
+ function wktToGeojson(wkt) {
1054
+ try {
1055
+ wkt = wkt.replaceAll("\n", "").replaceAll(" ", "").replaceAll(" ,", ",").replaceAll(", ", ",").replaceAll(" (", "(").replaceAll("( ", "(").replaceAll(" )", ")").replaceAll(") ", ")").toUpperCase();
1056
+ const typeStr = wkt.match(/^[A-Z]+(?=\()/);
1057
+ if (!typeStr) {
1058
+ console.log("wkt数据格式不对,没有解析到type");
1059
+ return;
1060
+ }
1061
+ const type = typeStr[0];
1062
+ if (type === "GEOMETRYCOLLECTION") {
1063
+ wkt = wkt.substring(19, wkt.length - 1);
1064
+ const resArr = wkt.split(/,(?=[A-Z]+)/);
1065
+ const features = [];
1066
+ for (let i = 0; i < resArr.length; i++) {
1067
+ const geometry = wktToGeometry(resArr[i]);
1068
+ if (!geometry)
1069
+ return;
1070
+ features.push({ type: "Feature", geometry });
1071
+ }
1072
+ return { type: "FeatureCollection", features };
1073
+ } else {
1074
+ const resArr = wkt.split(/,(?=[A-Z]+)/);
1075
+ if (resArr.length > 1) {
1076
+ const features = [];
1077
+ for (let i = 0; i < resArr.length; i++) {
1078
+ const geometry = wktToGeometry(resArr[i]);
1079
+ if (!geometry)
1080
+ return;
1081
+ features.push({ type: "Feature", geometry });
1082
+ }
1083
+ return { type: "FeatureCollection", features };
1084
+ } else {
1085
+ if ([
1086
+ "POINT",
1087
+ "LINESTRING",
1088
+ "POLYGON",
1089
+ "MULTIPOINT",
1090
+ "MULTILINESTRING",
1091
+ "MULTIPOLYGON"
1092
+ ].includes(type)) {
1093
+ const geometry = wktToGeometry(wkt);
1094
+ if (!geometry)
1095
+ return;
1096
+ return { type: "Feature", geometry };
1097
+ } else {
1098
+ console.log("wkt数据的type不太对-->", type);
1099
+ return;
1100
+ }
1101
+ }
1102
+ }
1103
+ } catch (error) {
1104
+ console.log("格式解析出错", error);
1105
+ }
1106
+ }
1107
+ function geometryToWkt(geometry) {
1108
+ if (!geometry) {
1109
+ console.log("没有geojson数据");
1110
+ return "";
1111
+ }
1112
+ const { type } = geometry;
1113
+ if (!type) {
1114
+ console.log("数据中没有type");
1115
+ return "";
1116
+ }
1117
+ if (typeof type !== "string") {
1118
+ console.log("数据中的type不是字符串");
1119
+ return "";
1120
+ }
1121
+ const coords = geometry.coordinates;
1122
+ if (!coords) {
1123
+ console.log("数据中没有coordinates");
1124
+ return "";
1125
+ }
1126
+ if (!(coords instanceof Array)) {
1127
+ console.log("数据的coordinates不是数组");
1128
+ return "";
1129
+ }
1130
+ if (coords.length === 0) {
1131
+ console.log("数据的coordinates是空的");
1132
+ return "";
1133
+ }
1134
+ const wktCoords = [];
1135
+ switch (type.toUpperCase()) {
1136
+ case "POINT":
1137
+ if (coords.length < 2) {
1138
+ console.log("type为Point的coordinates格式不对-->", geometry);
1139
+ return "";
1140
+ }
1141
+ for (let i = 0; i < coords.length; i++) {
1142
+ if (typeof coords[i] !== "number" || isNaN(coords[i])) {
1143
+ console.log("type为Point的coordinates格式不对-->", geometry);
1144
+ return "";
1145
+ }
1146
+ }
1147
+ wktCoords.push(coords.slice(0, 2).join(" "));
1148
+ break;
1149
+ case "LINESTRING":
1150
+ case "MULTIPOINT":
1151
+ for (let i = 0; i < coords.length; i++) {
1152
+ const coord = coords[i];
1153
+ if (!(coord instanceof Array) || coord.length < 2) {
1154
+ console.log("type为MultiPoint或LineString的coordinates格式不对-->", geometry);
1155
+ return "";
1156
+ }
1157
+ for (let j = 0; j < coord.length; j++) {
1158
+ if (typeof coord[j] !== "number" || isNaN(coord[j])) {
1159
+ console.log("type为MultiPoint或LineString的coordinates格式不对-->", geometry);
1160
+ return "";
1161
+ }
1162
+ }
1163
+ wktCoords.push(coord.slice(0, 2).join(" "));
1164
+ }
1165
+ break;
1166
+ case "POLYGON":
1167
+ case "MULTILINESTRING":
1168
+ for (let i = 0; i < coords.length; i++) {
1169
+ const item = coords[i];
1170
+ const ringCoords = [];
1171
+ if (!(item instanceof Array)) {
1172
+ console.log("type为Polygon或MultiLineString的coordinates格式不对-->", geometry);
1173
+ return "";
1174
+ }
1175
+ for (let j = 0; j < item.length; j++) {
1176
+ const ele = item[j];
1177
+ if (!(ele instanceof Array) || ele.length < 2) {
1178
+ console.log("type为Polygon或MultiLineString的coordinates格式不对-->", geometry);
1179
+ return "";
1180
+ }
1181
+ for (let k = 0; k < ele.length; k++) {
1182
+ if (typeof ele[k] !== "number" || isNaN(ele[k])) {
1183
+ console.log("type为Polygon或MultiLineString的coordinates格式不对-->", geometry);
1184
+ return "";
1185
+ }
1186
+ }
1187
+ ringCoords.push(ele.slice(0, 2).join(" "));
1188
+ }
1189
+ wktCoords.push(`(${ringCoords.join(",")})`);
1190
+ }
1191
+ break;
1192
+ case "MULTIPOLYGON":
1193
+ for (let i = 0; i < coords.length; i++) {
1194
+ const item = coords[i];
1195
+ const polyCoords = [];
1196
+ if (!(item instanceof Array)) {
1197
+ console.log("type为MultiPolygon的coordinates格式不对-->", geometry);
1198
+ return "";
1199
+ }
1200
+ for (let j = 0; j < item.length; j++) {
1201
+ const ele = item[j];
1202
+ const ringCoords = [];
1203
+ if (!(ele instanceof Array)) {
1204
+ console.log("type为MultiPolygon的coordinates格式不对-->", geometry);
1205
+ return "";
1206
+ }
1207
+ for (let k = 0; k < ele.length; k++) {
1208
+ const mem = ele[k];
1209
+ if (!(mem instanceof Array) || mem.length < 2) {
1210
+ console.log("type为MultiPolygon的coordinates格式不对-->", geometry);
1211
+ return "";
1212
+ }
1213
+ for (let n = 0; n < mem.length; n++) {
1214
+ if (typeof mem[n] !== "number" || isNaN(mem[n])) {
1215
+ console.log("type为Polygon或MultiLineString的coordinates格式不对-->", geometry);
1216
+ return "";
1217
+ }
1218
+ }
1219
+ ringCoords.push(mem.slice(0, 2).join(" "));
1220
+ }
1221
+ polyCoords.push(`(${ringCoords.join(",")})`);
1222
+ }
1223
+ wktCoords.push(`(${polyCoords.join(",")})`);
1224
+ }
1225
+ break;
1226
+ default:
1227
+ console.log(`这个geojson中的type值好像不太对--> type: ${type}`);
1228
+ return "";
1229
+ }
1230
+ return `${type.toUpperCase()}(${wktCoords.join(",")})`;
1231
+ }
1232
+ function geojsonToWkt(geojson) {
1233
+ if (!geojson) {
1234
+ console.log("没有geojson数据");
1235
+ return "";
1236
+ }
1237
+ const { type } = geojson;
1238
+ if (!type) {
1239
+ console.log("这个geojson没有type");
1240
+ return "";
1241
+ }
1242
+ if (typeof type !== "string") {
1243
+ console.log("这个geojson的type不是字符串");
1244
+ return "";
1245
+ }
1246
+ if ([
1247
+ "POINT",
1248
+ "LINESTRING",
1249
+ "POLYGON",
1250
+ "MULTIPOINT",
1251
+ "MULTILINESTRING",
1252
+ "MULTIPOLYGON"
1253
+ ].includes(type.toUpperCase())) {
1254
+ return geometryToWkt(geojson);
1255
+ } else if (type.toUpperCase() === "FEATURE") {
1256
+ const { geometry } = geojson;
1257
+ if (!geometry) {
1258
+ console.log("type为Feature的数据没有geometry-->", geojson);
1259
+ return "";
1260
+ }
1261
+ return geometryToWkt(geometry);
1262
+ } else if (type.toUpperCase() === "GEOMETRYCOLLECTION") {
1263
+ const wkts = [];
1264
+ const { geometries } = geojson;
1265
+ if (!geometries) {
1266
+ console.log("type为GeometryCollection的数据没有geometries-->", geojson);
1267
+ return "";
1268
+ }
1269
+ if (!(geometries instanceof Array)) {
1270
+ console.log("type为GeometryCollection的数据中geometries不是数组-->", geojson);
1271
+ return "";
1272
+ }
1273
+ for (let i = 0; i < geometries.length; i++) {
1274
+ wkts.push(geometryToWkt(geometries[i]));
1275
+ }
1276
+ return `GEOMETRYCOLLECTION(${wkts.join(",")})`;
1277
+ } else if (type.toUpperCase() === "FEATURECOLLECTION") {
1278
+ const wkts = [];
1279
+ const { features } = geojson;
1280
+ if (!features) {
1281
+ console.log("type为FeatureCollection的数据没有features-->", geojson);
1282
+ return "";
1283
+ }
1284
+ if (!(features instanceof Array)) {
1285
+ console.log("type为FeatureCollection的数据中features不是数组-->", geojson);
1286
+ return "";
1287
+ }
1288
+ for (let i = 0; i < features.length; i++) {
1289
+ const item = features[i];
1290
+ const { type: type2 } = item;
1291
+ if (!type2) {
1292
+ console.log("这个feature没有type-->", item);
1293
+ return "";
1294
+ }
1295
+ if (typeof type2 !== "string") {
1296
+ console.log("这个feature的type不是字符串-->", item);
1297
+ return "";
1298
+ }
1299
+ const { geometry } = item;
1300
+ if (!geometry) {
1301
+ console.log("这个feature没有geometry-->", item);
1302
+ return "";
1303
+ }
1304
+ wkts.push(geometryToWkt(geometry));
1305
+ }
1306
+ return `GEOMETRYCOLLECTION(${wkts.join(",")})`;
1307
+ } else {
1308
+ console.log(`这个geojson的type值好像不太对--> type: ${type}`);
1309
+ return "";
1310
+ }
1311
+ }
943
1312
  const potatoMap3dUi2 = {
944
1313
  install: (app) => {
945
1314
  app.component("Map3dT", _sfc_main$9);
@@ -952,6 +1321,10 @@
952
1321
  app.component("ControlFaceNorth", _sfc_main$3);
953
1322
  app.component("ControlSquarelyView", _sfc_main$2);
954
1323
  app.component("ControlBaseMap", _sfc_main$1);
1324
+ },
1325
+ functions: {
1326
+ geojsonToWkt,
1327
+ wktToGeojson
955
1328
  }
956
1329
  };
957
1330
  return potatoMap3dUi2;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "potato-map3d-ui2",
3
3
  "private": false,
4
- "version": "0.0.31",
4
+ "version": "0.0.33",
5
5
  "main": "./dist/map3d-ui2.umd.js",
6
6
  "module": "./dist/map3d-ui2.es.js",
7
7
  "type": "module",
@@ -21,20 +21,11 @@
21
21
  "preview": "vite preview"
22
22
  },
23
23
  "dependencies": {
24
+ "ant-design-vue": "^4.0.0",
24
25
  "axios": "^1.4.0",
25
26
  "vite-plugin-dts": "^2.2.0",
26
- "vue": "^2.0.0 || >=3.0.0",
27
- "vue-demi": "^0.14.5"
28
- },
29
- "peerDependencies": {
30
- "@vue/composition-api": "^1.7.1",
31
27
  "vue": "^2.0.0 || >=3.0.0"
32
28
  },
33
- "peerDependenciesMeta": {
34
- "@vue/composition-api": {
35
- "optional": true
36
- }
37
- },
38
29
  "devDependencies": {
39
30
  "@types/node": "^18.15.11",
40
31
  "@vitejs/plugin-vue": "^4.2.1",