diff --git a/src/components/ProFromMap/index.tsx b/src/components/ProFromMap/index.tsx index b9de4f7..96c1749 100644 --- a/src/components/ProFromMap/index.tsx +++ b/src/components/ProFromMap/index.tsx @@ -23,6 +23,10 @@ export const aMapConfig = { securityJsCode: '7b16386c7f744c3ca05595965f2b037f', }; +/** 石河子市地图默认中心点与行政区划编码 */ +export const SHIHEZI_MAP_CENTER: [number, number] = [86.041075, 44.305886]; +export const SHIHEZI_CITY_CODE = '659001'; + const ProFromMap: React.FC = ({ open, onSelect, onCancel }) => { const mapRef = useRef(null); const geocoderRef = useRef(null); @@ -50,9 +54,9 @@ const ProFromMap: React.FC = ({ open, onSelect, onCancel }) => { // 设置地图容器id viewMode: '3D', // 是否为3D地图模式 zoom: 11, // 初始化地图级别 - center: [120.384599, 36.062687], // 初始化地图中心点位置 + center: SHIHEZI_MAP_CENTER, // 默认展示石河子市 }); - // 浏览器定位 + // 浏览器定位(仅提供手动定位按钮,不自动跳转以免覆盖默认区域) AMap.plugin('AMap.Geolocation', function () { var geolocation = new AMap.Geolocation({ enableHighAccuracy: false, //是否使用高精度定位,默认:true @@ -62,14 +66,13 @@ const ProFromMap: React.FC = ({ open, onSelect, onCancel }) => { zoomToAccuracy: true, //定位成功后是否自动调整地图视野到定位点 }); mapRef.current.addControl(geolocation); - geolocation.getCurrentPosition(); }); // 添加插件 AMap.plugin('AMap.AutoComplete', function () { // 注意:输入提示插件2.0版本需引入AMap.AutoComplete,而1.4版本应使用AMap.Autocomplete // 实例化AutoComplete autoCompleteRef.current = new AMap.AutoComplete({ - city: '370200', // 青岛市 + city: SHIHEZI_CITY_CODE, citylimit: false, }); }); @@ -79,7 +82,7 @@ const ProFromMap: React.FC = ({ open, onSelect, onCancel }) => { geocoderRef.current = new AMap.Geocoder({ extensions: 'base', batch: false, - city: '370200', // 青岛市 + city: SHIHEZI_CITY_CODE, }); }); @@ -155,7 +158,7 @@ const ProFromMap: React.FC = ({ open, onSelect, onCancel }) => { } const searchLocation = async (keyWords: string) => { - const keywordsToSearch = keyWords || '青岛'; + const keywordsToSearch = keyWords || '石河子'; const resData = await autoInput(keywordsToSearch); locationList.current = resData; setLocationOptions(resData);