xy-map 1.1.56 → 1.1.58
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.
- package/package.json +1 -1
- package/xy-map.common.js +42 -3
- package/xy-map.umd.js +42 -3
- package/xy-map.umd.min.js +3 -3
package/package.json
CHANGED
package/xy-map.common.js
CHANGED
|
@@ -70735,13 +70735,13 @@ const geometryCollectionToFeatureCollection = geometryCollection => {
|
|
|
70735
70735
|
const wgs84ToGcj02 = coord => {
|
|
70736
70736
|
// 输入检查
|
|
70737
70737
|
if (!Array.isArray(coord) || coord.length !== 2) {
|
|
70738
|
-
throw new Error('
|
|
70738
|
+
throw new Error('输入必须是包含经度和纬度的数组');
|
|
70739
70739
|
}
|
|
70740
70740
|
let [lng, lat] = coord.map(Number);
|
|
70741
70741
|
|
|
70742
70742
|
// 检查输入是否为有效数字
|
|
70743
70743
|
if (isNaN(lng) || isNaN(lat)) {
|
|
70744
|
-
throw new Error('
|
|
70744
|
+
throw new Error('坐标必须是有效的数字');
|
|
70745
70745
|
}
|
|
70746
70746
|
|
|
70747
70747
|
// 如果不在中国范围内,直接返回原坐标
|
|
@@ -70761,6 +70761,43 @@ const wgs84ToGcj02 = coord => {
|
|
|
70761
70761
|
return [gcjLng, gcjLat];
|
|
70762
70762
|
};
|
|
70763
70763
|
|
|
70764
|
+
//高德坐标系Gcj02转换 WGS84
|
|
70765
|
+
const gcj02ToWgs84 = coord => {
|
|
70766
|
+
// 输入检查
|
|
70767
|
+
if (!Array.isArray(coord) || coord.length !== 2) {
|
|
70768
|
+
throw new Error('输入必须是包含经度和纬度的数组');
|
|
70769
|
+
}
|
|
70770
|
+
let [lng, lat] = coord.map(Number);
|
|
70771
|
+
|
|
70772
|
+
// 检查输入是否为有效数字
|
|
70773
|
+
if (isNaN(lng) || isNaN(lat)) {
|
|
70774
|
+
throw new Error('坐标必须是有效的数字');
|
|
70775
|
+
}
|
|
70776
|
+
|
|
70777
|
+
// 如果不在中国范围内,直接返回原坐标
|
|
70778
|
+
if (outOfChina(lng, lat)) {
|
|
70779
|
+
return [lng, lat];
|
|
70780
|
+
}
|
|
70781
|
+
|
|
70782
|
+
// 增加迭代次数到10次提高精度
|
|
70783
|
+
for (let i = 0; i < 10; i++) {
|
|
70784
|
+
// 使用wgs84ToGcj02获取当前估计值对应的gcj02坐标
|
|
70785
|
+
let [gcjLng, gcjLat] = wgs84ToGcj02([mLng, mLat]);
|
|
70786
|
+
// 计算差值
|
|
70787
|
+
dLng = gcjLng - lng;
|
|
70788
|
+
dLat = gcjLat - lat;
|
|
70789
|
+
// 更新估计值
|
|
70790
|
+
mLng = mLng - dLng;
|
|
70791
|
+
mLat = mLat - dLat;
|
|
70792
|
+
|
|
70793
|
+
// 如果精度已经足够高,提前退出循环
|
|
70794
|
+
if (Math.abs(dLng) < 0.000000001 && Math.abs(dLat) < 0.000000001) {
|
|
70795
|
+
break;
|
|
70796
|
+
}
|
|
70797
|
+
}
|
|
70798
|
+
return [mLng, mLat];
|
|
70799
|
+
};
|
|
70800
|
+
|
|
70764
70801
|
// 3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
|
|
70765
70802
|
const mercatorTolonlat = Json => {
|
|
70766
70803
|
Json.features.forEach(item => {
|
|
@@ -122080,7 +122117,9 @@ const mapTools = {
|
|
|
122080
122117
|
GeoAddress: GeoAddress,
|
|
122081
122118
|
Geolocation: Geolocation,
|
|
122082
122119
|
getElevation: getElevation,
|
|
122083
|
-
geometryCollectionToFeatureCollection: geometryCollectionToFeatureCollection
|
|
122120
|
+
geometryCollectionToFeatureCollection: geometryCollectionToFeatureCollection,
|
|
122121
|
+
wgs84ToGcj02: wgs84ToGcj02,
|
|
122122
|
+
gcj02ToWgs84: gcj02ToWgs84
|
|
122084
122123
|
};
|
|
122085
122124
|
|
|
122086
122125
|
// 地图事件
|
package/xy-map.umd.js
CHANGED
|
@@ -70753,13 +70753,13 @@ const geometryCollectionToFeatureCollection = geometryCollection => {
|
|
|
70753
70753
|
const wgs84ToGcj02 = coord => {
|
|
70754
70754
|
// 输入检查
|
|
70755
70755
|
if (!Array.isArray(coord) || coord.length !== 2) {
|
|
70756
|
-
throw new Error('
|
|
70756
|
+
throw new Error('输入必须是包含经度和纬度的数组');
|
|
70757
70757
|
}
|
|
70758
70758
|
let [lng, lat] = coord.map(Number);
|
|
70759
70759
|
|
|
70760
70760
|
// 检查输入是否为有效数字
|
|
70761
70761
|
if (isNaN(lng) || isNaN(lat)) {
|
|
70762
|
-
throw new Error('
|
|
70762
|
+
throw new Error('坐标必须是有效的数字');
|
|
70763
70763
|
}
|
|
70764
70764
|
|
|
70765
70765
|
// 如果不在中国范围内,直接返回原坐标
|
|
@@ -70779,6 +70779,43 @@ const wgs84ToGcj02 = coord => {
|
|
|
70779
70779
|
return [gcjLng, gcjLat];
|
|
70780
70780
|
};
|
|
70781
70781
|
|
|
70782
|
+
//高德坐标系Gcj02转换 WGS84
|
|
70783
|
+
const gcj02ToWgs84 = coord => {
|
|
70784
|
+
// 输入检查
|
|
70785
|
+
if (!Array.isArray(coord) || coord.length !== 2) {
|
|
70786
|
+
throw new Error('输入必须是包含经度和纬度的数组');
|
|
70787
|
+
}
|
|
70788
|
+
let [lng, lat] = coord.map(Number);
|
|
70789
|
+
|
|
70790
|
+
// 检查输入是否为有效数字
|
|
70791
|
+
if (isNaN(lng) || isNaN(lat)) {
|
|
70792
|
+
throw new Error('坐标必须是有效的数字');
|
|
70793
|
+
}
|
|
70794
|
+
|
|
70795
|
+
// 如果不在中国范围内,直接返回原坐标
|
|
70796
|
+
if (outOfChina(lng, lat)) {
|
|
70797
|
+
return [lng, lat];
|
|
70798
|
+
}
|
|
70799
|
+
|
|
70800
|
+
// 增加迭代次数到10次提高精度
|
|
70801
|
+
for (let i = 0; i < 10; i++) {
|
|
70802
|
+
// 使用wgs84ToGcj02获取当前估计值对应的gcj02坐标
|
|
70803
|
+
let [gcjLng, gcjLat] = wgs84ToGcj02([mLng, mLat]);
|
|
70804
|
+
// 计算差值
|
|
70805
|
+
dLng = gcjLng - lng;
|
|
70806
|
+
dLat = gcjLat - lat;
|
|
70807
|
+
// 更新估计值
|
|
70808
|
+
mLng = mLng - dLng;
|
|
70809
|
+
mLat = mLat - dLat;
|
|
70810
|
+
|
|
70811
|
+
// 如果精度已经足够高,提前退出循环
|
|
70812
|
+
if (Math.abs(dLng) < 0.000000001 && Math.abs(dLat) < 0.000000001) {
|
|
70813
|
+
break;
|
|
70814
|
+
}
|
|
70815
|
+
}
|
|
70816
|
+
return [mLng, mLat];
|
|
70817
|
+
};
|
|
70818
|
+
|
|
70782
70819
|
// 3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
|
|
70783
70820
|
const mercatorTolonlat = Json => {
|
|
70784
70821
|
Json.features.forEach(item => {
|
|
@@ -122098,7 +122135,9 @@ const mapTools = {
|
|
|
122098
122135
|
GeoAddress: GeoAddress,
|
|
122099
122136
|
Geolocation: Geolocation,
|
|
122100
122137
|
getElevation: getElevation,
|
|
122101
|
-
geometryCollectionToFeatureCollection: geometryCollectionToFeatureCollection
|
|
122138
|
+
geometryCollectionToFeatureCollection: geometryCollectionToFeatureCollection,
|
|
122139
|
+
wgs84ToGcj02: wgs84ToGcj02,
|
|
122140
|
+
gcj02ToWgs84: gcj02ToWgs84
|
|
122102
122141
|
};
|
|
122103
122142
|
|
|
122104
122143
|
// 地图事件
|