@heycar/heycars-map 0.3.7 → 0.3.8
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/dist/business-components/AbsoluteAddressBox/AbsoluteAddressBox.d.ts +1 -2
- package/dist/business-components/AddressBox/AddressBox.d.ts +1 -2
- package/dist/business-components/BusinessQuotingMap/BusinessQuotingMap.d.ts +1 -0
- package/dist/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +1 -2
- package/dist/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.d.ts +1 -2
- package/dist/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +2 -3
- package/dist/business-components/DrivingLine/DrivingLine.d.ts +1 -2
- package/dist/business-components/DrivingRoute/DrivingRoute.d.ts +1 -2
- package/dist/business-components/PassengerCircle/PassengerCircle.d.ts +1 -2
- package/dist/business-components/PickupPoints/PickupPoints.d.ts +1 -2
- package/dist/business-components/PlaceCircle/PlaceCircle.d.ts +1 -2
- package/dist/business-components/StartEndPoint/StartEndPoint.d.ts +1 -2
- package/dist/business-components/TaxiCar/TaxiCar.d.ts +1 -2
- package/dist/business-components/WalkingLine/WalkingLine.d.ts +1 -2
- package/dist/business-components/WalkingRoute/WalkingRoute.d.ts +1 -2
- package/dist/business-components/WaveCircle/WaveCircle.d.ts +1 -2
- package/dist/components/Gmap/Gmap.d.ts +0 -2
- package/dist/components/MapProvider/MapProvider.d.ts +1 -4
- package/dist/hooks/useMapAutoComplete.d.ts +1 -2
- package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +1 -2
- package/dist/index.cjs +55 -55
- package/dist/index.js +1966 -2061
- package/package.json +1 -1
- package/todo.md +16 -4
- package/dist/Demo/CityBound/SearchDemo.d.ts +0 -1
- package/dist/Demo/CityBound/country.d.ts +0 -5
- package/dist/Demo/CityBound/searchResult.d.ts +0 -8
- package/dist/hooks/useMapLog.d.ts +0 -5
- package/src/App.tsx +0 -27
- package/src/Demo/CityBound/SearchDemo.tsx +0 -142
- package/src/Demo/CityBound/country.ts +0 -4179
- package/src/Demo/CityBound/searchResult.ts +0 -21122
- package/src/Demo/Demo.css.ts +0 -6
- package/src/Demo/Demo.tsx +0 -97
- package/src/Demo/DemoBusinessQuoting.tsx +0 -18
- package/src/Demo/DemoBusinessRecomendPlace.tsx +0 -89
- package/src/Demo/DemoBusinessTaxiEnd.tsx +0 -38
- package/src/Demo/DemoBusinessTaxiService.tsx +0 -58
- package/src/Demo/sample.json +0 -793
- package/src/api/contants.ts +0 -3
- package/src/api/driving.ts +0 -87
- package/src/api/geocoder.ts +0 -88
- package/src/api/geometry.ts +0 -44
- package/src/api/place.ts +0 -105
- package/src/assets/icons/svg/address-locator.svg +0 -1
- package/src/assets/icons/svg/arrow-right.svg +0 -1
- package/src/assets/icons/svg/end-point.svg +0 -1
- package/src/assets/icons/svg/passenger-circle.svg +0 -1
- package/src/assets/icons/svg/place-circle.svg +0 -22
- package/src/assets/icons/svg/start-point.svg +0 -1
- package/src/assets/icons/svg/taxi-car.svg +0 -1
- package/src/assets/icons/svg/wave-circle.svg +0 -1
- package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.css.ts +0 -68
- package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.tsx +0 -50
- package/src/business-components/AbsoluteAddressBox/index.ts +0 -1
- package/src/business-components/AddressBox/AddressBox.css.ts +0 -55
- package/src/business-components/AddressBox/AddressBox.tsx +0 -76
- package/src/business-components/AddressBox/index.ts +0 -1
- package/src/business-components/AddressLocator/AddressLocator.css.ts +0 -7
- package/src/business-components/AddressLocator/AddressLocator.tsx +0 -40
- package/src/business-components/AddressLocator/index.ts +0 -1
- package/src/business-components/BusinessQuotingMap/BusinessQuotingMap.tsx +0 -49
- package/src/business-components/BusinessQuotingMap/index.ts +0 -1
- package/src/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.tsx +0 -218
- package/src/business-components/BusinessRecomendPlaceMap/index.ts +0 -1
- package/src/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.tsx +0 -43
- package/src/business-components/BusinessTaxiEndMap/index.ts +0 -1
- package/src/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.tsx +0 -453
- package/src/business-components/BusinessTaxiServiceMap/index.ts +0 -1
- package/src/business-components/DrivingLine/DrivingLine.css.ts +0 -10
- package/src/business-components/DrivingLine/DrivingLine.tsx +0 -135
- package/src/business-components/DrivingLine/index.ts +0 -1
- package/src/business-components/DrivingRoute/DrivingRoute.tsx +0 -52
- package/src/business-components/DrivingRoute/index.ts +0 -1
- package/src/business-components/FitView/FitView.tsx +0 -22
- package/src/business-components/FitView/index.ts +0 -1
- package/src/business-components/PassengerCircle/PassengerCircle.css.ts +0 -21
- package/src/business-components/PassengerCircle/PassengerCircle.tsx +0 -69
- package/src/business-components/PassengerCircle/index.ts +0 -1
- package/src/business-components/PickupPoints/PickupPoints.tsx +0 -38
- package/src/business-components/PickupPoints/index.ts +0 -1
- package/src/business-components/PlaceCircle/PlaceCircle.css.ts +0 -76
- package/src/business-components/PlaceCircle/PlaceCircle.tsx +0 -110
- package/src/business-components/PlaceCircle/index.ts +0 -1
- package/src/business-components/StartEndPoint/StartEndPoint.css.ts +0 -70
- package/src/business-components/StartEndPoint/StartEndPoint.tsx +0 -122
- package/src/business-components/StartEndPoint/index.ts +0 -1
- package/src/business-components/TaxiCar/TaxiCar.css.ts +0 -16
- package/src/business-components/TaxiCar/TaxiCar.tsx +0 -93
- package/src/business-components/TaxiCar/index.ts +0 -1
- package/src/business-components/WalkingLine/WalkingLine.tsx +0 -80
- package/src/business-components/WalkingLine/index.ts +0 -1
- package/src/business-components/WalkingRoute/WalkingRoute.tsx +0 -43
- package/src/business-components/WalkingRoute/index.ts +0 -1
- package/src/business-components/WaveCircle/WaveCircle.css.ts +0 -54
- package/src/business-components/WaveCircle/WaveCircle.tsx +0 -59
- package/src/business-components/WaveCircle/index.ts +0 -1
- package/src/components/Amap/Amap.css.ts +0 -5
- package/src/components/Amap/Amap.ts +0 -76
- package/src/components/Amap/index.ts +0 -1
- package/src/components/AmapInfoWindow/AmapInfoWindow.ts +0 -45
- package/src/components/AmapInfoWindow/index.ts +0 -1
- package/src/components/AmapLoader/AmapLoader.ts +0 -20
- package/src/components/AmapLoader/index.ts +0 -1
- package/src/components/AmapMarker/AmapMarker.ts +0 -48
- package/src/components/AmapMarker/index.ts +0 -1
- package/src/components/AmapPolygon/AmapPolygon.ts +0 -41
- package/src/components/AmapPolygon/index.ts +0 -1
- package/src/components/AmapPolyline/AmapPolyline.ts +0 -40
- package/src/components/AmapPolyline/index.ts +0 -1
- package/src/components/AmapText/AmapText.ts +0 -39
- package/src/components/AmapText/index.ts +0 -1
- package/src/components/Gmap/Gmap.css.ts +0 -10
- package/src/components/Gmap/Gmap.ts +0 -54
- package/src/components/Gmap/index.ts +0 -1
- package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +0 -63
- package/src/components/GmapAdvancedMarkerView/index.ts +0 -1
- package/src/components/GmapInfoWindow/GmapInfoWindow.ts +0 -38
- package/src/components/GmapInfoWindow/index.ts +0 -1
- package/src/components/GmapLoader/GmapLoader.ts +0 -21
- package/src/components/GmapLoader/index.ts +0 -1
- package/src/components/GmapMarker/GmapMarker.ts +0 -34
- package/src/components/GmapMarker/index.ts +0 -1
- package/src/components/GmapPolygon/GmapPolygon.ts +0 -29
- package/src/components/GmapPolygon/index.ts +0 -1
- package/src/components/GmapPolyline/GmapPolyline.ts +0 -29
- package/src/components/GmapPolyline/index.ts +0 -1
- package/src/components/MapProvider/MapProvider.tsx +0 -83
- package/src/components/MapProvider/index.ts +0 -1
- package/src/hooks/useDrivingRoute.ts +0 -106
- package/src/hooks/useGeoLocation.ts +0 -70
- package/src/hooks/useHeycarMap.ts +0 -28
- package/src/hooks/useMap.ts +0 -43
- package/src/hooks/useMapAngle.ts +0 -42
- package/src/hooks/useMapAutoComplete.ts +0 -130
- package/src/hooks/useMapCityBound.ts +0 -64
- package/src/hooks/useMapDrag.ts +0 -72
- package/src/hooks/useMapEventSource.ts +0 -20
- package/src/hooks/useMapFitView.ts +0 -135
- package/src/hooks/useMapGeometry.ts +0 -27
- package/src/hooks/useMapLngLatToVw.ts +0 -31
- package/src/hooks/useMapLoader.ts +0 -164
- package/src/hooks/useMapLog.ts +0 -24
- package/src/hooks/useMapPlace.ts +0 -138
- package/src/hooks/useMapRecomendPlace.ts +0 -150
- package/src/hooks/useMapSupplier.ts +0 -16
- package/src/hooks/useOverlay.ts +0 -23
- package/src/hooks/usePlacesLabelDirection.ts +0 -61
- package/src/hooks/useUdate.ts +0 -9
- package/src/hooks/useWaitTimer.ts +0 -25
- package/src/hooks/useWalkingRoute.ts +0 -87
- package/src/hooks-business/useBusinessMapAutoComplete.ts +0 -22
- package/src/hooks-business/useBusinessQuotingMap.ts +0 -11
- package/src/hooks-business/useBusinessRecomendPlaceMap.ts +0 -45
- package/src/hooks-business/useBusinessTaxiServiceMap.ts +0 -12
- package/src/index.ts +0 -33
- package/src/main.ts +0 -6
- package/src/style.css +0 -0
- package/src/types/amap/autocomplete.d.ts +0 -64
- package/src/types/amap/driving.d.ts +0 -170
- package/src/types/amap/geocoder.d.ts +0 -217
- package/src/types/amap/marker.ts +0 -11
- package/src/types/amap/place.d.ts +0 -114
- package/src/types/amap/plugin.d.ts +0 -27
- package/src/types/amap/walking.d.ts +0 -78
- package/src/types/global.d.ts +0 -10
- package/src/types/helper.ts +0 -172
- package/src/types/interface.ts +0 -62
- package/src/types/mapHelper.ts +0 -1
- package/src/utils/compare.ts +0 -189
- package/src/utils/dom.ts +0 -14
- package/src/utils/helper.ts +0 -5
- package/src/utils/transform.ts +0 -68
- package/src/vite-env.d.ts +0 -12
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { ref, watch } from "vue-demi";
|
|
2
|
-
import type { AutoCompletePlace, Region } from "../types/interface";
|
|
3
|
-
import { useGeoLocation } from "./useGeoLocation";
|
|
4
|
-
import { useMapGeometry } from "./useMapGeometry";
|
|
5
|
-
import { MapLogProps, useMapLogVariable } from "./useMapLog";
|
|
6
|
-
import { useMapSupplier } from "./useMapSupplier";
|
|
7
|
-
import { useUpdate } from "./useUdate";
|
|
8
|
-
|
|
9
|
-
export interface UseMapAutoCompleteProps extends MapLogProps {
|
|
10
|
-
city: Region;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const useAmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
14
|
-
const { city } = props;
|
|
15
|
-
const cityRef = ref(city);
|
|
16
|
-
useMapLogVariable(props, "useAmapAutoComplete", cityRef, "cityRef");
|
|
17
|
-
const { readyPromise } = useMapSupplier();
|
|
18
|
-
const { apiMapDistance } = useMapGeometry();
|
|
19
|
-
const { geoPosition } = useGeoLocation();
|
|
20
|
-
const keywordRef = ref("");
|
|
21
|
-
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
22
|
-
const { update, idx: updateKey } = useUpdate();
|
|
23
|
-
const setCity = (value: Region) => {
|
|
24
|
-
cityRef.value = value;
|
|
25
|
-
update();
|
|
26
|
-
};
|
|
27
|
-
const setKeyword = (value: string) => {
|
|
28
|
-
keywordRef.value = value;
|
|
29
|
-
update();
|
|
30
|
-
};
|
|
31
|
-
watch(
|
|
32
|
-
() => updateKey.value,
|
|
33
|
-
async () => {
|
|
34
|
-
if (!keywordRef.value) return;
|
|
35
|
-
await readyPromise;
|
|
36
|
-
const amapPlaceSearch = new AMap.PlaceSearch({ city: cityRef.value.name });
|
|
37
|
-
amapPlaceSearch.search(keywordRef.value, (status, result) => {
|
|
38
|
-
const from = geoPosition.value;
|
|
39
|
-
switch (status) {
|
|
40
|
-
case "complete": {
|
|
41
|
-
autoCompletePlacesRef.value = (result as AMap.PlaceSearchResult).poiList.pois.map(
|
|
42
|
-
(poi) => {
|
|
43
|
-
const { lat, lng } = poi.location;
|
|
44
|
-
return {
|
|
45
|
-
lat,
|
|
46
|
-
lng,
|
|
47
|
-
name: poi.name,
|
|
48
|
-
description: poi.address,
|
|
49
|
-
distance: from ? apiMapDistance(from, [lng, lat]) : undefined,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
case "no_data":
|
|
56
|
-
autoCompletePlacesRef.value = [];
|
|
57
|
-
return;
|
|
58
|
-
default:
|
|
59
|
-
throw result;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
immediate: true,
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
return { setKeyword, setCity, autoCompletePlaces: autoCompletePlacesRef };
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const useGmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
71
|
-
const { city } = props;
|
|
72
|
-
const cityRef = ref({ ...city });
|
|
73
|
-
const { readyPromise } = useMapSupplier();
|
|
74
|
-
const { apiMapDistance } = useMapGeometry();
|
|
75
|
-
const { geoPosition } = useGeoLocation();
|
|
76
|
-
const keywordRef = ref("");
|
|
77
|
-
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
78
|
-
const { update, idx: updateKey } = useUpdate();
|
|
79
|
-
const setCity = (value: Region) => {
|
|
80
|
-
cityRef.value = value;
|
|
81
|
-
update();
|
|
82
|
-
};
|
|
83
|
-
const setKeyword = (value: string) => {
|
|
84
|
-
keywordRef.value = value;
|
|
85
|
-
update();
|
|
86
|
-
};
|
|
87
|
-
const div = document.createElement("div");
|
|
88
|
-
watch(
|
|
89
|
-
() => updateKey.value,
|
|
90
|
-
async () => {
|
|
91
|
-
if (!keywordRef.value) return;
|
|
92
|
-
await readyPromise;
|
|
93
|
-
const gmapPlacesService = new google.maps.places.PlacesService(div);
|
|
94
|
-
gmapPlacesService.textSearch(
|
|
95
|
-
{
|
|
96
|
-
query: keywordRef.value,
|
|
97
|
-
bounds: cityRef.value.bound,
|
|
98
|
-
},
|
|
99
|
-
(result, status) => {
|
|
100
|
-
const from = geoPosition.value;
|
|
101
|
-
switch (status) {
|
|
102
|
-
case google.maps.places.PlacesServiceStatus.OK:
|
|
103
|
-
autoCompletePlacesRef.value = result!.map(({ geometry, name, formatted_address }) => {
|
|
104
|
-
const lng = geometry?.location?.lng() ?? 0;
|
|
105
|
-
const lat = geometry?.location?.lat() ?? 0;
|
|
106
|
-
return {
|
|
107
|
-
lng,
|
|
108
|
-
lat,
|
|
109
|
-
name: name ?? "",
|
|
110
|
-
description: formatted_address ?? "",
|
|
111
|
-
distance: from ? apiMapDistance(from, [lng, lat]) : undefined,
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
return;
|
|
115
|
-
case google.maps.places.PlacesServiceStatus.ZERO_RESULTS:
|
|
116
|
-
case google.maps.places.PlacesServiceStatus.NOT_FOUND:
|
|
117
|
-
autoCompletePlacesRef.value = [];
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
return { setKeyword, setCity, autoCompletePlaces: autoCompletePlacesRef };
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export const useMapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
128
|
-
const { supplier } = useMapSupplier();
|
|
129
|
-
return supplier === "gmap" ? useGmapAutoComplete(props) : useAmapAutoComplete(props);
|
|
130
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { reactive, Ref, watch, watchEffect } from "vue-demi";
|
|
2
|
-
import { LANGUAGE } from "../types/helper";
|
|
3
|
-
import type { Region } from "../types/interface";
|
|
4
|
-
import { useMapSupplier } from "./useMapSupplier";
|
|
5
|
-
|
|
6
|
-
export interface UseMapCityBoundProps {
|
|
7
|
-
cityNameRef: Ref<string | undefined>;
|
|
8
|
-
onChange?: (value: Region) => any;
|
|
9
|
-
}
|
|
10
|
-
export const useAmapBoundCity = (props: UseMapCityBoundProps): Region => {
|
|
11
|
-
const { cityNameRef, onChange } = props;
|
|
12
|
-
const city = reactive({ name: cityNameRef.value ?? "" });
|
|
13
|
-
watch(
|
|
14
|
-
() => cityNameRef.value,
|
|
15
|
-
(cityName) => {
|
|
16
|
-
const name = cityName ?? "";
|
|
17
|
-
city.name = name;
|
|
18
|
-
onChange?.({ name });
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
return city;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const useGmapBoundCity = (props: UseMapCityBoundProps): Region => {
|
|
25
|
-
const { cityNameRef, onChange } = props;
|
|
26
|
-
const { readyPromise } = useMapSupplier();
|
|
27
|
-
const city = reactive<Region>({
|
|
28
|
-
name: cityNameRef.value ?? "",
|
|
29
|
-
bound: {
|
|
30
|
-
east: 0,
|
|
31
|
-
north: 0,
|
|
32
|
-
south: 0,
|
|
33
|
-
west: 0,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
watchEffect(async () => {
|
|
37
|
-
const cityName = cityNameRef.value;
|
|
38
|
-
if (!cityName) return;
|
|
39
|
-
await readyPromise;
|
|
40
|
-
const geocoder = new google.maps.Geocoder();
|
|
41
|
-
// todo 这里不是唯一的
|
|
42
|
-
const { results } = await geocoder.geocode({
|
|
43
|
-
address: cityName,
|
|
44
|
-
componentRestrictions: {
|
|
45
|
-
administrativeArea: "administrative_area_level_1",
|
|
46
|
-
},
|
|
47
|
-
language: LANGUAGE,
|
|
48
|
-
});
|
|
49
|
-
if (results.length !== 1) {
|
|
50
|
-
throw new Error("MyError: multiple city found");
|
|
51
|
-
}
|
|
52
|
-
const { geometry } = results[0];
|
|
53
|
-
const cityBound = geometry.bounds?.toJSON() ?? geometry.viewport.toJSON();
|
|
54
|
-
city.name = cityName;
|
|
55
|
-
city.bound = cityBound;
|
|
56
|
-
onChange?.({ name: cityName, bound: cityBound });
|
|
57
|
-
});
|
|
58
|
-
return city;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const useMapBoundCity = (props: UseMapCityBoundProps) => {
|
|
62
|
-
const { supplier } = useMapSupplier();
|
|
63
|
-
return supplier === "gmap" ? useGmapBoundCity(props) : useAmapBoundCity(props);
|
|
64
|
-
};
|
package/src/hooks/useMapDrag.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { ref, type ShallowRef } from "vue-demi";
|
|
2
|
-
import type { AmapProps } from "../components/Amap";
|
|
3
|
-
import type { GmapProps } from "../components/Gmap";
|
|
4
|
-
import type { SetupContextEmitHandler } from "../types/helper";
|
|
5
|
-
import type { Point } from "../types/interface";
|
|
6
|
-
import { watchPostEffectForAMapEvent, watchPostEffectForGMapEvent } from "../utils/compare";
|
|
7
|
-
import { pipeAsync } from "../utils/transform";
|
|
8
|
-
import { useMapSupplier } from "./useMapSupplier";
|
|
9
|
-
|
|
10
|
-
export const ON_CHANGE_CENTER_INTERVAL = 200;
|
|
11
|
-
|
|
12
|
-
export interface UseMapDragProps<M = AMap.Map | google.maps.Map> {
|
|
13
|
-
mapRef: ShallowRef<M | undefined>;
|
|
14
|
-
onChange?: (value: Point) => any;
|
|
15
|
-
}
|
|
16
|
-
export const useAmapDrag = (props: UseMapDragProps<AMap.Map>) => {
|
|
17
|
-
const { mapRef, onChange } = props;
|
|
18
|
-
const centerRef = ref<Point>([0, 0]);
|
|
19
|
-
const isDragging = ref(false);
|
|
20
|
-
const emitDragStart: SetupContextEmitHandler<Pick<AmapProps, "onDragStart">> = () => {
|
|
21
|
-
pipeAsync(() => {
|
|
22
|
-
isDragging.value = true;
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
const emitDragEnd: SetupContextEmitHandler<Pick<AmapProps, "onDragEnd">> = (_, { target }) => {
|
|
26
|
-
isDragging.value = false;
|
|
27
|
-
const { lng, lat } = target.getCenter();
|
|
28
|
-
centerRef.value = [lng, lat];
|
|
29
|
-
pipeAsync(onChange)?.([lng, lat]);
|
|
30
|
-
};
|
|
31
|
-
watchPostEffectForAMapEvent(mapRef, {} as Pick<AmapProps, "onDragStart">, emitDragStart, [
|
|
32
|
-
"onDragStart",
|
|
33
|
-
]);
|
|
34
|
-
watchPostEffectForAMapEvent(mapRef, {} as Pick<AmapProps, "onDragEnd">, emitDragEnd, [
|
|
35
|
-
"onDragEnd",
|
|
36
|
-
]);
|
|
37
|
-
return { centerRef, isDragging };
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const useGmapDrag = (props: UseMapDragProps<google.maps.Map>) => {
|
|
41
|
-
const { mapRef, onChange } = props;
|
|
42
|
-
const centerRef = ref<Point>([0, 0]);
|
|
43
|
-
const isDragging = ref(false);
|
|
44
|
-
const emitDragStart: SetupContextEmitHandler<Pick<GmapProps, "onDragStart">> = () => {
|
|
45
|
-
pipeAsync(() => {
|
|
46
|
-
isDragging.value = true;
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
const emitDragEnd: SetupContextEmitHandler<Pick<GmapProps, "onDragEnd">> = async () => {
|
|
50
|
-
isDragging.value = false;
|
|
51
|
-
const center = mapRef.value?.getCenter();
|
|
52
|
-
const lng = center?.lng() as number;
|
|
53
|
-
const lat = center?.lat() as number;
|
|
54
|
-
centerRef.value = [lng, lat];
|
|
55
|
-
pipeAsync(onChange)?.([lng, lat]);
|
|
56
|
-
};
|
|
57
|
-
watchPostEffectForGMapEvent(mapRef!, {} as Pick<GmapProps, "onDragStart">, emitDragStart, [
|
|
58
|
-
"onDragStart",
|
|
59
|
-
]);
|
|
60
|
-
watchPostEffectForGMapEvent(mapRef!, {} as Pick<GmapProps, "onDragEnd">, emitDragEnd, [
|
|
61
|
-
"onDragEnd",
|
|
62
|
-
]);
|
|
63
|
-
return { centerRef, isDragging };
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const useMapDrag = (props: UseMapDragProps) => {
|
|
67
|
-
const { supplier } = useMapSupplier();
|
|
68
|
-
// todo: 这里违反 react hook 规则,但 react 版本应该可以同时调用 useAmap 和 useGmap
|
|
69
|
-
return supplier === "gmap"
|
|
70
|
-
? useGmapDrag(props as UseMapDragProps<google.maps.Map>)
|
|
71
|
-
: useAmapDrag(props as UseMapDragProps<AMap.Map>);
|
|
72
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type MapEventSource = "api" | "user";
|
|
2
|
-
let mapEventSource: MapEventSource = "user";
|
|
3
|
-
|
|
4
|
-
export const getMapEvnetSource = () => mapEventSource;
|
|
5
|
-
|
|
6
|
-
export const useMapEventSource = () => {
|
|
7
|
-
const executeMapApi = (fn: () => void) => {
|
|
8
|
-
mapEventSource = "api";
|
|
9
|
-
try {
|
|
10
|
-
fn();
|
|
11
|
-
setTimeout(() => {
|
|
12
|
-
mapEventSource = "user";
|
|
13
|
-
}, 100);
|
|
14
|
-
} catch (err) {
|
|
15
|
-
mapEventSource = "user";
|
|
16
|
-
throw err;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
return { executeMapApi };
|
|
20
|
-
};
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { debounce } from "lodash-es";
|
|
2
|
-
import type { MapShallowRef, RegisterOverlay } from "../types/interface";
|
|
3
|
-
import type { MapEventHandler } from "../types/mapHelper";
|
|
4
|
-
import { watchPostEffectForAMapEvent, watchPostEffectForGMapEvent } from "../utils/compare";
|
|
5
|
-
import { getMapEvnetSource, useMapEventSource } from "./useMapEventSource";
|
|
6
|
-
import { useMapSupplier } from "./useMapSupplier";
|
|
7
|
-
import type { AmapOverlay, GmapOverlay } from "./useOverlay";
|
|
8
|
-
|
|
9
|
-
const GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT = 20;
|
|
10
|
-
|
|
11
|
-
type UseAmapFitViewPropsForListeners = {
|
|
12
|
-
onDragEnd?: MapEventHandler<AMap.Map>;
|
|
13
|
-
// onZoomEnd?: MapEventHandler<AMap.Map>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export interface UseMapFitViewOutput<L> {
|
|
17
|
-
setFitView: () => void;
|
|
18
|
-
registerFitVeiw: RegisterOverlay<L>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface UseMapFitViewProps<M = AMap.Map | google.maps.Map> {
|
|
22
|
-
mapRef: MapShallowRef<M>;
|
|
23
|
-
padding?: [number, number, number, number];
|
|
24
|
-
autoFitTimeout?: number;
|
|
25
|
-
}
|
|
26
|
-
export const useAmapFitView = (props: UseMapFitViewProps<AMap.Map>) => {
|
|
27
|
-
const { mapRef, autoFitTimeout } = props;
|
|
28
|
-
const overlayGroup: Set<AmapOverlay> = new Set();
|
|
29
|
-
let timer: number | undefined = undefined;
|
|
30
|
-
const setFitView = () => {
|
|
31
|
-
const map = mapRef.value;
|
|
32
|
-
if (!map) return;
|
|
33
|
-
const vw = window.innerWidth / 100;
|
|
34
|
-
const [top, right, bottom, left] = props.padding ?? [0, 0, 0, 0];
|
|
35
|
-
map.setFitView([...overlayGroup], false, [top * vw, bottom * vw, left * vw, right * vw]);
|
|
36
|
-
};
|
|
37
|
-
const registerFitVeiw: RegisterOverlay<AmapOverlay> = {
|
|
38
|
-
add: (overlay: AmapOverlay) => {
|
|
39
|
-
overlayGroup.add(overlay);
|
|
40
|
-
},
|
|
41
|
-
remove: (overlay: AmapOverlay) => {
|
|
42
|
-
overlayGroup.delete(overlay);
|
|
43
|
-
},
|
|
44
|
-
setFitView,
|
|
45
|
-
};
|
|
46
|
-
const handleMoveEndOrZomEnd = () => {
|
|
47
|
-
if (!autoFitTimeout) return;
|
|
48
|
-
if (timer) clearTimeout(timer);
|
|
49
|
-
timer = setTimeout(() => {
|
|
50
|
-
timer = undefined;
|
|
51
|
-
setFitView();
|
|
52
|
-
}, autoFitTimeout);
|
|
53
|
-
};
|
|
54
|
-
watchPostEffectForAMapEvent(
|
|
55
|
-
mapRef,
|
|
56
|
-
{} as UseAmapFitViewPropsForListeners,
|
|
57
|
-
handleMoveEndOrZomEnd,
|
|
58
|
-
["onDragEnd"]
|
|
59
|
-
);
|
|
60
|
-
return { registerFitVeiw, setFitView };
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// 目前需求暂时只需要 marker
|
|
64
|
-
class SimpleGmapOverLayerGroup extends Set<GmapOverlay> {
|
|
65
|
-
getBound() {
|
|
66
|
-
const bound = new google.maps.LatLngBounds();
|
|
67
|
-
for (const overlay of this.values()) {
|
|
68
|
-
const position =
|
|
69
|
-
overlay instanceof google.maps.Marker ? overlay.getPosition() : overlay.position;
|
|
70
|
-
if (position) bound.extend(position);
|
|
71
|
-
}
|
|
72
|
-
return bound;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
type UseGmapFitViewPropsForListeners = {
|
|
77
|
-
onDragEnd?: MapEventHandler<AMap.Map>;
|
|
78
|
-
onZoom_changed?: MapEventHandler<AMap.Map>;
|
|
79
|
-
};
|
|
80
|
-
export const useGmapFitView = (props: UseMapFitViewProps<google.maps.Map>) => {
|
|
81
|
-
const { mapRef, autoFitTimeout } = props;
|
|
82
|
-
const { executeMapApi } = useMapEventSource();
|
|
83
|
-
const overlayGroup = new SimpleGmapOverLayerGroup();
|
|
84
|
-
let timer: number | undefined = undefined;
|
|
85
|
-
const setFitView = () => {
|
|
86
|
-
const map = mapRef.value;
|
|
87
|
-
if (!map) return;
|
|
88
|
-
const vw = window.innerWidth / 100;
|
|
89
|
-
const [top, right, bottom, left] = props.padding ?? [0, 0, 0, 0];
|
|
90
|
-
executeMapApi(() =>
|
|
91
|
-
map.fitBounds(overlayGroup.getBound(), {
|
|
92
|
-
top: top * vw,
|
|
93
|
-
right: right * vw,
|
|
94
|
-
bottom: bottom * vw,
|
|
95
|
-
left: left * vw,
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
};
|
|
99
|
-
const registerFitVeiw: RegisterOverlay<GmapOverlay> = {
|
|
100
|
-
add: (overlay: GmapOverlay) => {
|
|
101
|
-
overlayGroup.add(overlay);
|
|
102
|
-
},
|
|
103
|
-
remove: (overlay: GmapOverlay) => {
|
|
104
|
-
overlayGroup.delete(overlay);
|
|
105
|
-
},
|
|
106
|
-
setFitView,
|
|
107
|
-
};
|
|
108
|
-
const handleMoveEnd = (name: string) => {
|
|
109
|
-
const eventSource = getMapEvnetSource();
|
|
110
|
-
console.log("handleMoveEndOrZomEnd name, eventSource = ", name, eventSource);
|
|
111
|
-
if (!autoFitTimeout || eventSource !== "user") return;
|
|
112
|
-
if (timer) clearTimeout(timer);
|
|
113
|
-
timer = setTimeout(() => {
|
|
114
|
-
timer = undefined;
|
|
115
|
-
setFitView();
|
|
116
|
-
}, autoFitTimeout);
|
|
117
|
-
};
|
|
118
|
-
const handleZoomChange = debounce(handleMoveEnd, GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT);
|
|
119
|
-
watchPostEffectForGMapEvent(mapRef, {} as UseGmapFitViewPropsForListeners, handleMoveEnd, [
|
|
120
|
-
"onDragEnd",
|
|
121
|
-
]);
|
|
122
|
-
watchPostEffectForGMapEvent(mapRef, {} as UseGmapFitViewPropsForListeners, handleZoomChange, [
|
|
123
|
-
"onZoom_changed",
|
|
124
|
-
]);
|
|
125
|
-
return { registerFitVeiw, setFitView };
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export const useMapFitView = (
|
|
129
|
-
props: UseMapFitViewProps
|
|
130
|
-
): UseMapFitViewOutput<AmapOverlay> | UseMapFitViewOutput<GmapOverlay> => {
|
|
131
|
-
const { supplier } = useMapSupplier();
|
|
132
|
-
return supplier === "gmap"
|
|
133
|
-
? useGmapFitView(props as UseMapFitViewProps<google.maps.Map>)
|
|
134
|
-
: useAmapFitView(props as UseMapFitViewProps<AMap.Map>);
|
|
135
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Point } from "../types/interface";
|
|
2
|
-
import { vec2lnglat } from "../utils/transform";
|
|
3
|
-
import { Status } from "./useMapLoader";
|
|
4
|
-
import { useMapSupplier } from "./useMapSupplier";
|
|
5
|
-
|
|
6
|
-
export const useAmapGeometry = () => {
|
|
7
|
-
const payload = useMapSupplier();
|
|
8
|
-
const apiMapDistance = (from: Point, to: Point) => {
|
|
9
|
-
if (payload.status !== Status.SUCCESS) return undefined;
|
|
10
|
-
return AMap.GeometryUtil.distance(from, to);
|
|
11
|
-
};
|
|
12
|
-
return { apiMapDistance };
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const useGmapGeometry = () => {
|
|
16
|
-
const payload = useMapSupplier();
|
|
17
|
-
const apiMapDistance = (from: Point, to: Point) => {
|
|
18
|
-
if (payload.status !== Status.SUCCESS) return undefined;
|
|
19
|
-
return google.maps.geometry.spherical.computeDistanceBetween(vec2lnglat(from), vec2lnglat(to));
|
|
20
|
-
};
|
|
21
|
-
return { apiMapDistance };
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const useMapGeometry = () => {
|
|
25
|
-
const { supplier } = useMapSupplier();
|
|
26
|
-
return supplier === "gmap" ? useGmapGeometry() : useAmapGeometry();
|
|
27
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Point } from "../types/interface";
|
|
2
|
-
import { useAmap, useGmap } from "./useMap";
|
|
3
|
-
import { useMapSupplier } from "./useMapSupplier";
|
|
4
|
-
|
|
5
|
-
export const useAmapLngLatToVw = () => {
|
|
6
|
-
const amap = useAmap();
|
|
7
|
-
const apiMapLngLatToVw = (point: Point) => {
|
|
8
|
-
return amap?.value?.lngLatToContainer(point).toArray() as [number, number];
|
|
9
|
-
};
|
|
10
|
-
return { apiMapLngLatToVw };
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const useGmapLngLatToVw = () => {
|
|
14
|
-
const gmap = useGmap();
|
|
15
|
-
const apiMapLngLatToVw = (point: Point) => {
|
|
16
|
-
const [lng, lat] = point;
|
|
17
|
-
const projection = gmap?.value?.getProjection();
|
|
18
|
-
const worldCoordinate = projection?.fromLatLngToPoint({ lng, lat });
|
|
19
|
-
const x = worldCoordinate?.x ?? 0;
|
|
20
|
-
const y = worldCoordinate?.y ?? 0;
|
|
21
|
-
const zoom = gmap?.value?.getZoom() ?? 0;
|
|
22
|
-
const scale = 2 ** zoom;
|
|
23
|
-
return [x * scale, y * scale] as [number, number];
|
|
24
|
-
};
|
|
25
|
-
return { apiMapLngLatToVw };
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const useMapLngLatToVw = () => {
|
|
29
|
-
const { supplier } = useMapSupplier();
|
|
30
|
-
return supplier === "gmap" ? useGmapLngLatToVw() : useAmapLngLatToVw();
|
|
31
|
-
};
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { load as loadAmap } from "@amap/amap-jsapi-loader";
|
|
2
|
-
import { Loader, LoaderOptions } from "@googlemaps/js-api-loader";
|
|
3
|
-
import { computed, Ref, shallowRef } from "vue-demi";
|
|
4
|
-
import type { VueNode } from "../types/helper";
|
|
5
|
-
import { watchPostEffectForDeepOption } from "../utils/compare";
|
|
6
|
-
|
|
7
|
-
export const DEFAULT_AMAP_PLUGINS: AmapLoaderProps["plugins"] = [
|
|
8
|
-
"AMap.Geolocation",
|
|
9
|
-
"AMap.Geocoder",
|
|
10
|
-
"AMap.PlaceSearch",
|
|
11
|
-
"AMap.Driving",
|
|
12
|
-
"AMap.Walking",
|
|
13
|
-
];
|
|
14
|
-
export const DEFAULT_GMAP_LIBRARIES: LoaderOptions["libraries"] = ["marker", "places", "geometry"];
|
|
15
|
-
|
|
16
|
-
export enum Status {
|
|
17
|
-
LOADING = "LOADING",
|
|
18
|
-
FAILURE = "FAILURE",
|
|
19
|
-
SUCCESS = "SUCCESS",
|
|
20
|
-
}
|
|
21
|
-
type AMapLoaderOptions = Parameters<typeof loadAmap>[0];
|
|
22
|
-
declare global {
|
|
23
|
-
interface Window {
|
|
24
|
-
_AMapSecurityConfig: {
|
|
25
|
-
securityJsCode?: string;
|
|
26
|
-
serviceHost?: string;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export interface AmapLoaderProps
|
|
31
|
-
extends Pick<GmapLoaderProps, "fallback" | "loading" | "onChange">,
|
|
32
|
-
Omit<AMapLoaderOptions, "key" | "version" | "plugins"> {
|
|
33
|
-
apiKey: string;
|
|
34
|
-
apiSecret?: string;
|
|
35
|
-
apiServiceHost?: string;
|
|
36
|
-
version?: string;
|
|
37
|
-
plugins?: `AMap.${AMap.PluginName}`[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const useAmapLoader = (props: AmapLoaderProps) => {
|
|
41
|
-
const { onChange } = props;
|
|
42
|
-
let resolveLoader: () => void;
|
|
43
|
-
let rejectLoader: () => void;
|
|
44
|
-
const readyPromise = new Promise<undefined>((resolve, reject) => {
|
|
45
|
-
resolveLoader = resolve as () => void;
|
|
46
|
-
rejectLoader = reject;
|
|
47
|
-
});
|
|
48
|
-
const statusRef = shallowRef(Status.LOADING);
|
|
49
|
-
const optionsRef = computed(() => {
|
|
50
|
-
const { onChange, loading, fallback, apiKey, apiSecret, apiServiceHost, version, ...options } =
|
|
51
|
-
props;
|
|
52
|
-
return { ...options, key: apiKey, version: version ?? "2.0.5.16" };
|
|
53
|
-
});
|
|
54
|
-
watchPostEffectForDeepOption(
|
|
55
|
-
() => optionsRef.value,
|
|
56
|
-
(options) => {
|
|
57
|
-
const setStatusAndExecuteCallback = (status: Status) => {
|
|
58
|
-
statusRef.value = status;
|
|
59
|
-
if (status === Status.SUCCESS) resolveLoader();
|
|
60
|
-
if (status === Status.FAILURE) rejectLoader();
|
|
61
|
-
onChange?.(statusRef.value);
|
|
62
|
-
};
|
|
63
|
-
setStatusAndExecuteCallback(Status.LOADING);
|
|
64
|
-
|
|
65
|
-
window._AMapSecurityConfig = props.apiServiceHost
|
|
66
|
-
? {
|
|
67
|
-
serviceHost: props.apiServiceHost,
|
|
68
|
-
}
|
|
69
|
-
: { securityJsCode: props.apiSecret };
|
|
70
|
-
|
|
71
|
-
loadAmap(options).then(
|
|
72
|
-
() => setStatusAndExecuteCallback(Status.SUCCESS),
|
|
73
|
-
() => setStatusAndExecuteCallback(Status.FAILURE)
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
return { statusRef, readyPromise };
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export interface GmapLoaderProps extends LoaderOptions {
|
|
81
|
-
/**
|
|
82
|
-
* Render prop used to switch to loading component.
|
|
83
|
-
*/
|
|
84
|
-
loading?: () => VueNode;
|
|
85
|
-
/**
|
|
86
|
-
* Render prop used to switch to error fallback component.
|
|
87
|
-
*/
|
|
88
|
-
fallback?: () => VueNode;
|
|
89
|
-
/**
|
|
90
|
-
* Callback prop used to access `@googlemaps/js-api-loader` and `Status`.
|
|
91
|
-
*
|
|
92
|
-
* Note: The callback be executed multiple times in the lifecycle of the component.
|
|
93
|
-
*/
|
|
94
|
-
onChange?: (status: Status) => void;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export const useGmapLoader = (props: GmapLoaderProps) => {
|
|
98
|
-
const { onChange } = props;
|
|
99
|
-
let resolveLoader: () => void;
|
|
100
|
-
let rejectLoader: () => void;
|
|
101
|
-
const readyPromise = new Promise<undefined>((resolve, reject) => {
|
|
102
|
-
resolveLoader = resolve as () => void;
|
|
103
|
-
rejectLoader = reject;
|
|
104
|
-
});
|
|
105
|
-
const statusRef = shallowRef(Status.LOADING);
|
|
106
|
-
const options = computed(() => {
|
|
107
|
-
const { onChange, fallback, loading, ...options } = props;
|
|
108
|
-
return options;
|
|
109
|
-
});
|
|
110
|
-
watchPostEffectForDeepOption(
|
|
111
|
-
() => options.value,
|
|
112
|
-
(options) => {
|
|
113
|
-
const loader = new Loader(options);
|
|
114
|
-
|
|
115
|
-
const setStatusAndExecuteCallback = (status: Status) => {
|
|
116
|
-
statusRef.value = status;
|
|
117
|
-
if (status === Status.SUCCESS) resolveLoader();
|
|
118
|
-
if (status === Status.FAILURE) rejectLoader();
|
|
119
|
-
onChange?.(statusRef.value);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
setStatusAndExecuteCallback(Status.LOADING);
|
|
123
|
-
|
|
124
|
-
loader.load().then(
|
|
125
|
-
() => setStatusAndExecuteCallback(Status.SUCCESS),
|
|
126
|
-
() => setStatusAndExecuteCallback(Status.FAILURE)
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
return { statusRef, readyPromise };
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
export type MapSupplier = "gmap" | "amap";
|
|
134
|
-
export interface UseMapLoaderOutput {
|
|
135
|
-
statusRef: Ref<Status>;
|
|
136
|
-
readyPromise: Promise<undefined>;
|
|
137
|
-
}
|
|
138
|
-
export interface UseMapLoaderProps {
|
|
139
|
-
gmapKey: string;
|
|
140
|
-
amapKey: string;
|
|
141
|
-
amapSecret?: string;
|
|
142
|
-
amapServiceHost?: string;
|
|
143
|
-
supplier: MapSupplier;
|
|
144
|
-
language?: "en" | "zh";
|
|
145
|
-
onChange?: (status: Status) => any;
|
|
146
|
-
}
|
|
147
|
-
export const useMapLoader = (props: UseMapLoaderProps): UseMapLoaderOutput => {
|
|
148
|
-
const { gmapKey, amapKey, amapSecret, amapServiceHost, supplier, language, onChange } = props;
|
|
149
|
-
return supplier === "gmap"
|
|
150
|
-
? useGmapLoader({
|
|
151
|
-
apiKey: gmapKey,
|
|
152
|
-
language,
|
|
153
|
-
version: "beta",
|
|
154
|
-
libraries: DEFAULT_GMAP_LIBRARIES,
|
|
155
|
-
onChange,
|
|
156
|
-
})
|
|
157
|
-
: useAmapLoader({
|
|
158
|
-
apiKey: amapKey,
|
|
159
|
-
apiSecret: amapSecret,
|
|
160
|
-
apiServiceHost: amapServiceHost,
|
|
161
|
-
plugins: DEFAULT_AMAP_PLUGINS,
|
|
162
|
-
onChange,
|
|
163
|
-
});
|
|
164
|
-
};
|
package/src/hooks/useMapLog.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { watchEffect } from "vue-demi";
|
|
2
|
-
|
|
3
|
-
export interface MapLogProps {
|
|
4
|
-
log?: boolean;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const useMapLog = <P extends MapLogProps>(props: P, prefix: string) => {
|
|
8
|
-
watchEffect(() => {
|
|
9
|
-
if (!props.log) return;
|
|
10
|
-
console.log(`log ${prefix} props = `, { ...props });
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const useMapLogVariable = <P extends MapLogProps>(
|
|
15
|
-
props: P,
|
|
16
|
-
prefix: string,
|
|
17
|
-
variable: any,
|
|
18
|
-
name: string
|
|
19
|
-
) => {
|
|
20
|
-
watchEffect(() => {
|
|
21
|
-
if (!props.log) return;
|
|
22
|
-
console.log(`log ${prefix} ${name} = `, { ...variable });
|
|
23
|
-
});
|
|
24
|
-
};
|