update
This commit is contained in:
+21
-20
@@ -1,17 +1,12 @@
|
||||
import AMapLoader from '@amap/amap-jsapi-loader';
|
||||
import china from '/@/assets/lngLat/china.ts';
|
||||
import chinaInner from '/@/assets/lngLat/chinaInner.ts';
|
||||
import { createCircle, createIcon, typeToIcon } from '/@/assets/mapUtils/commonFun.ts';
|
||||
import { createCircle, createIcon, getCenter, getLonLat, typeToIcon } from '/@/assets/mapUtils/commonFun.ts';
|
||||
import { aircraftContent, alarmIcon } from '/@/components/chinaMap/chinaHooks.ts';
|
||||
import { isFunction } from '/@/utils/is.ts';
|
||||
import { Callback, ExtDataType, InitMap, MarkerOption, ResultType } from '/@/assets/mapUtils/mapFunTypes.ts';
|
||||
import { defaultOption, getZoom, mapKey, mapPlugin } from '/@/assets/mapUtils/mapConstant.ts';
|
||||
|
||||
export const defaultOption = {
|
||||
center: [106.3, 37.87], //地图中心点
|
||||
zoom: 4.3, //地图显示的缩放级别
|
||||
mapStyle: 'darkblue', //地图样式
|
||||
};
|
||||
export const mapPlugin = ['AMap.ToolBar', 'AMap.Driving', 'AMap.GeoJSON', 'AMap.MarkerCluster', 'AMap.PlaceSearch'];
|
||||
let AMap = null;
|
||||
export const Map = {
|
||||
map: null,
|
||||
@@ -29,7 +24,7 @@ export const Map = {
|
||||
initMap({ el, option }: InitMap) {
|
||||
return new Promise((resolve) => {
|
||||
AMapLoader.load({
|
||||
key: '4bbcb216b889f2d612cbed05ae6979c8', // 申请好的Web端开发者Key,首次调用 load 时必填
|
||||
key: mapKey, // 申请好的Web端开发者Key,首次调用 load 时必填
|
||||
version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
||||
plugins: mapPlugin, // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
||||
}).then((res) => {
|
||||
@@ -40,7 +35,7 @@ export const Map = {
|
||||
resizeEnable: true,
|
||||
center: center,
|
||||
zoom: zoom,
|
||||
mapStyle: 'amap://styles/darkblue',
|
||||
mapStyle: 'amap://styles/' + mapStyle,
|
||||
version: '2.0',
|
||||
});
|
||||
// 异步同时加载多个插件
|
||||
@@ -105,6 +100,7 @@ export const Map = {
|
||||
if (this.airMarkerList) {
|
||||
this.airMarkerList = [];
|
||||
}
|
||||
this.clearActiveHospital();
|
||||
// this.map.remove(this.airMarkerList);
|
||||
}, //
|
||||
/**
|
||||
@@ -116,6 +112,10 @@ export const Map = {
|
||||
createOverlay(result: ResultType[], extData?: ExtDataType, callback?: Callback) {
|
||||
this.removeOverlayGroup();
|
||||
this.overlayGroup = new AMap.OverlayGroup();
|
||||
let list = getLonLat(result);
|
||||
let center = getCenter(list);
|
||||
let zoom = getZoom(list);
|
||||
this.setZoomCenter(center, zoom);
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
let { type, lon, lat, lng } = result[i];
|
||||
if (lng) {
|
||||
@@ -231,23 +231,24 @@ export const Map = {
|
||||
this.removeOverlayGroup();
|
||||
this.clearActiveHospital();
|
||||
if (!cityCode) return;
|
||||
this.placeSearch = new AMap.PlaceSearch({
|
||||
pageSize: 30, // 单页显示结果条数
|
||||
pageIndex: 1, // 页码
|
||||
city: cityCode, // 兴趣点城市
|
||||
citylimit: true, //是否强制限制在设置的城市内搜索
|
||||
map: this.map, // 展现结果的地图实例
|
||||
// panel: 'map_hospital', // 结果列表将在此容器中进行展示。
|
||||
autoFitView: false, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
|
||||
});
|
||||
if (!this.placeSearch) {
|
||||
this.placeSearch = new AMap.PlaceSearch({
|
||||
pageSize: 30, // 单页显示结果条数
|
||||
pageIndex: 1, // 页码
|
||||
city: cityCode, // 兴趣点城市
|
||||
citylimit: true, //是否强制限制在设置的城市内搜索
|
||||
map: this.map, // 展现结果的地图实例
|
||||
// panel: 'map_hospital', // 结果列表将在此容器中进行展示。
|
||||
autoFitView: false, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
|
||||
});
|
||||
}
|
||||
this.placeSearch.setCity(cityCode);
|
||||
//关键字查询
|
||||
this.placeSearch.search(keywords);
|
||||
},
|
||||
clearActiveHospital() {
|
||||
if (this.placeSearch) {
|
||||
// debugger;
|
||||
this.placeSearch.clear();
|
||||
this.placeSearch = null;
|
||||
}
|
||||
},
|
||||
createMarker(option: MarkerOption, callbck?: Callback) {
|
||||
|
||||
Reference in New Issue
Block a user