125 lines
3.3 KiB
TypeScript
125 lines
3.3 KiB
TypeScript
import { mapIcon1, mapIcon11, mapIcon3, mapIcon4, mapIcon41, mapIcon5, mapIcon51, watchIconR } from '/@/components/chinaMap/chinaHooks.ts';
|
|
import * as turf from '@turf/turf';
|
|
|
|
/**
|
|
* @desc 创建icon
|
|
* */
|
|
export function createIcon({ icon, iconSize, imageSize }) {
|
|
return new AMap.Icon({
|
|
// 图标尺寸
|
|
size: new AMap.Size(...iconSize),
|
|
// 图标的取图地址
|
|
image: icon,
|
|
// 图标所用图片大小
|
|
imageSize: new AMap.Size(...imageSize),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @desc 根据类型创建Icon
|
|
* @type 1:油田医院,2:健康小屋,4:AED
|
|
*/
|
|
export function typeToIcon(type: string) {
|
|
// const iconSize = [28, 49];
|
|
// const imageSize = [28, 49];
|
|
if (type == '1') {
|
|
// return createIcon({ icon: mapIcon1, iconSize, imageSize });
|
|
return mapIcon1;
|
|
}
|
|
if (type == '3') {
|
|
// return createIcon({ icon: mapIcon5, iconSize, imageSize });
|
|
return mapIcon5;
|
|
}
|
|
if (type == '4') {
|
|
// return createIcon({ icon: mapIcon4, iconSize, imageSize });
|
|
return mapIcon4;
|
|
}
|
|
if (type == '5') {
|
|
// return createIcon({ icon: mapIcon3, iconSize, imageSize });
|
|
return mapIcon3;
|
|
}
|
|
if (type === 'user') {
|
|
// return createIcon({ icon: watchIconR, iconSize, imageSize });
|
|
return watchIconR;
|
|
}
|
|
}
|
|
export function typeToIcon1(type: string) {
|
|
const iconSize = [21, 52];
|
|
const imageSize = [21, 52];
|
|
if (type == '1') {
|
|
const iconS = [28, 65];
|
|
const imageS = [28, 65];
|
|
return createIcon({ icon: mapIcon11, iconSize: iconS, imageSize: imageS });
|
|
}
|
|
if (type == '3') {
|
|
return createIcon({ icon: mapIcon51, iconSize, imageSize });
|
|
}
|
|
if (type == '4') {
|
|
return createIcon({ icon: mapIcon41, iconSize, imageSize });
|
|
}
|
|
if (type == '5') {
|
|
return createIcon({ icon: mapIcon3, iconSize, imageSize });
|
|
}
|
|
if (type === 'user') {
|
|
const iconS = [36, 88];
|
|
const imageS = [36, 88];
|
|
return createIcon({ icon: watchIconR, iconSize: iconS, imageSize: imageS });
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
export function createCircle(option) {
|
|
const { lon, lat } = option;
|
|
return new AMap.Circle({
|
|
center: [lon, lat],
|
|
radius: 100000, //半径
|
|
borderWeight: 3,
|
|
strokeColor: '#FF33FF',
|
|
// strokeWeight: 6,
|
|
strokeOpacity: 0.2,
|
|
fillOpacity: 0.4,
|
|
strokeStyle: 'dashed',
|
|
strokeDasharray: [10, 10],
|
|
// 线样式还支持 'dashed'
|
|
fillColor: '#1791fc',
|
|
zIndex: 50,
|
|
...option,
|
|
});
|
|
}
|
|
|
|
export function getLonLat(result = []) {
|
|
let arr = [];
|
|
for (let i = 0; i < result.length; i++) {
|
|
let { lon, lat, lng, longitude, latitude } = result[i];
|
|
if (longitude) {
|
|
lon = longitude;
|
|
}
|
|
if (latitude) {
|
|
lat = latitude;
|
|
}
|
|
if (!longitude || !latitude) {
|
|
continue;
|
|
}
|
|
let point = turf.point([lon * 1, lat * 1]);
|
|
arr.push(point);
|
|
}
|
|
return arr;
|
|
}
|
|
|
|
/**
|
|
* @desc 根据多点算中心点
|
|
*/
|
|
export function getCenter(list = []) {
|
|
if (!list || !Array.isArray(list)) {
|
|
return undefined;
|
|
}
|
|
if (list.length < 1) {
|
|
return undefined;
|
|
}
|
|
let features = turf.featureCollection(list);
|
|
let centerObj = turf.center(features);
|
|
return centerObj?.geometry?.coordinates;
|
|
}
|