|
|
@@ -118,7 +118,6 @@ const instance = getCurrentInstance();
|
|
|
const mapCtx = uni.createMapContext('prevMap', instance);
|
|
|
|
|
|
const selectedRegion = ref<number>();
|
|
|
-const nextNeedAutoFocus = ref(false);
|
|
|
const villageData = new Map<number, VillageListItem>();
|
|
|
|
|
|
const ready = ref(false);
|
|
|
@@ -131,6 +130,7 @@ const emit = defineEmits([
|
|
|
'getCurrentLonlat',
|
|
|
'update:isLightMode',
|
|
|
'update:lonlat',
|
|
|
+ 'update:district',
|
|
|
'selectVillage',
|
|
|
'regionChanged',
|
|
|
'lightVillage',
|
|
|
@@ -225,40 +225,38 @@ const mapLoader = useSimpleDataLoader<MapMarker[]>(async () => {
|
|
|
);
|
|
|
asyncAddMarkers(list);
|
|
|
|
|
|
- if (nextNeedAutoFocus.value) {
|
|
|
- if (res.length == 1) {
|
|
|
- mapCtx.moveToLocation({
|
|
|
- latitude: Number(list[0].latitude),
|
|
|
- longitude: Number(list[0].longitude),
|
|
|
+ if (res.length == 1) {
|
|
|
+ mapCtx.moveToLocation({
|
|
|
+ latitude: Number(list[0].latitude),
|
|
|
+ longitude: Number(list[0].longitude),
|
|
|
+ });
|
|
|
+ } else if (res.length > 1) {
|
|
|
+ setTimeout(() => {
|
|
|
+ mapCtx.includePoints({
|
|
|
+ points: list.map(p => {
|
|
|
+ if (!p.longitude || !p.latitude) {
|
|
|
+ p.longitude = AppCofig.defaultLonLat[0];
|
|
|
+ p.latitude = AppCofig.defaultLonLat[1];
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ latitude: p.latitude,
|
|
|
+ longitude: p.longitude,
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ padding: [20, 20, 20, 20],
|
|
|
});
|
|
|
- } else if (res.length > 1) {
|
|
|
- setTimeout(() => {
|
|
|
- mapCtx.includePoints({
|
|
|
- points: list.map(p => {
|
|
|
- if (!p.longitude || !p.latitude) {
|
|
|
- p.longitude = AppCofig.defaultLonLat[0];
|
|
|
- p.latitude = AppCofig.defaultLonLat[1];
|
|
|
- }
|
|
|
- return {
|
|
|
- latitude: p.latitude,
|
|
|
- longitude: p.longitude,
|
|
|
- }
|
|
|
- }),
|
|
|
- padding: [20, 20, 20, 20],
|
|
|
+ }, 200);
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ const currentRegion = regionLoader.content.value?.find(p => p.id == selectedRegion.value);
|
|
|
+ if (currentRegion) {
|
|
|
+ mapCtx.moveToLocation({
|
|
|
+ latitude: Number(currentRegion.latitude),
|
|
|
+ longitude: Number(currentRegion.longitude),
|
|
|
});
|
|
|
- }, 200);
|
|
|
- } else {
|
|
|
- try {
|
|
|
- const currentRegion = regionLoader.content.value?.find(p => p.id == selectedRegion.value);
|
|
|
- if (currentRegion) {
|
|
|
- mapCtx.moveToLocation({
|
|
|
- latitude: Number(currentRegion.latitude),
|
|
|
- longitude: Number(currentRegion.longitude),
|
|
|
- });
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error(error);
|
|
|
}
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
}
|
|
|
}
|
|
|
ready.value = true;
|
|
|
@@ -303,8 +301,8 @@ function onMarkerTap(e: any) {
|
|
|
}
|
|
|
function onSelectedRegion(regionId: number) {
|
|
|
selectedRegion.value = regionId;
|
|
|
- nextNeedAutoFocus.value = true;
|
|
|
mapLoader.reload();
|
|
|
+ emit('update:district', regionLoader.content.value?.find(p => p.id === regionId)?.name);
|
|
|
emit('regionChanged', regionId);
|
|
|
}
|
|
|
function setCurrentRegion(regionAreaCode: number) {
|
|
|
@@ -332,7 +330,6 @@ function loadFirstRegion() {
|
|
|
function showSearch() {
|
|
|
if (searchKeyword.value) {
|
|
|
searchKeyword.value = '';
|
|
|
- nextNeedAutoFocus.value = true;
|
|
|
mapLoader.reload();
|
|
|
} else {
|
|
|
searchDialogShow.value = true;
|
|
|
@@ -345,7 +342,6 @@ async function searchConfirm() {
|
|
|
toast('请输入搜索关键词');
|
|
|
return;
|
|
|
}
|
|
|
- nextNeedAutoFocus.value = true;
|
|
|
await mapLoader.reload();
|
|
|
if (mapLoader.content.value?.length === 0) {
|
|
|
toast('未搜索到相关村社,换个关键词再试试吧');
|