@heycar/heycars-map 0.1.9 → 0.2.0
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/README.md +30 -7
- package/dist/business-components/StartEndPoint/StartEndPoint.d.ts +18309 -4
- package/dist/components/AmapLoader/AmapLoader.d.ts +5 -20
- package/dist/components/AmapMarker/AmapMarker.d.ts +3 -2
- package/dist/components/Demo/HeycarDemo.d.ts +3 -3
- package/dist/components/Demo/searchResult.d.ts +1 -1
- package/dist/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.d.ts +3 -2
- package/dist/components/GmapLoader/GmapLoader.d.ts +3 -35
- package/dist/components/GmapMarker/GmapMarker.d.ts +3 -2
- package/dist/components/MapProvider/MapProvider.d.ts +4 -5
- package/dist/hooks/useGeoLocation.d.ts +2 -2
- package/dist/hooks/useMap.d.ts +801 -0
- package/dist/hooks/useMapAutoComplete.d.ts +4 -6
- package/dist/hooks/useMapCityBound.d.ts +5 -6
- package/dist/hooks/useMapEventSource.d.ts +5 -0
- package/dist/hooks/useMapFitView.d.ts +4599 -0
- package/dist/hooks/useMapLoader.d.ts +67 -0
- package/dist/hooks/useMapPlace.d.ts +4 -6
- package/dist/hooks/useMapRecomendPlace.d.ts +5 -797
- package/dist/hooks/useMapSupplier.d.ts +8 -0
- package/dist/hooks/useOverlay.d.ts +12 -0
- package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +5 -5
- package/dist/hooks-business/useBusinessMapRecomendPlace.d.ts +4 -3
- package/dist/index.cjs +52 -52
- package/dist/index.js +1153 -1116
- package/dist/types/interface.d.ts +4 -0
- package/package.json +1 -1
- package/src/App.tsx +1 -1
- package/src/api/place.ts +0 -2
- package/src/business-components/AddressBox/AddressBox.tsx +1 -1
- package/src/business-components/AddressLocator/AddressLocator.tsx +1 -1
- package/src/business-components/DrivingLine/DrivingLine.tsx +1 -1
- package/src/business-components/DrivingRoute/DrivingRoute.tsx +2 -3
- package/src/business-components/PassengerCircle/PassengerCircle.tsx +1 -1
- package/src/business-components/PlaceCircle/PlaceCircle.tsx +1 -1
- package/src/business-components/StartEndPoint/StartEndPoint.tsx +23 -7
- package/src/business-components/TaxiCar/TaxiCar.tsx +1 -1
- package/src/business-components/WalkingLine/WalkingLine.tsx +1 -1
- package/src/business-components/WalkingRoute/WalkingRoute.tsx +2 -3
- package/src/business-components/WaveCircle/WaveCircle.tsx +1 -1
- package/src/components/Amap/Amap.ts +1 -1
- package/src/components/AmapInfoWindow/AmapInfoWindow.ts +1 -1
- package/src/components/AmapLoader/AmapLoader.ts +6 -54
- package/src/components/AmapMarker/AmapMarker.ts +5 -2
- package/src/components/AmapPolygon/AmapPolygon.ts +1 -1
- package/src/components/AmapPolyline/AmapPolyline.ts +1 -1
- package/src/components/AmapText/AmapText.ts +1 -1
- package/src/components/Demo/Demo.css.ts +1 -1
- package/src/components/Demo/HeycarDemo.tsx +50 -33
- package/src/components/Demo/SearchDemo.tsx +40 -65
- package/src/components/Demo/searchResult.ts +12888 -1
- package/src/components/Gmap/Gmap.ts +17 -5
- package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +9 -4
- package/src/components/GmapInfoWindow/GmapInfoWindow.ts +1 -1
- package/src/components/GmapLoader/GmapLoader.ts +4 -62
- package/src/components/GmapMarker/GmapMarker.ts +5 -2
- package/src/components/GmapPolygon/GmapPolygon.ts +1 -1
- package/src/components/GmapPolyline/GmapPolyline.ts +1 -1
- package/src/components/MapProvider/MapProvider.tsx +33 -50
- package/src/hooks/useDrivingRoute.ts +1 -1
- package/src/hooks/useGeoLocation.ts +4 -2
- package/src/hooks/useHeycarMap.ts +1 -1
- package/src/hooks/useMap.ts +29 -0
- package/src/hooks/useMapAngle.ts +1 -1
- package/src/hooks/useMapAutoComplete.ts +16 -19
- package/src/hooks/useMapCityBound.ts +36 -24
- package/src/hooks/useMapDrag.ts +1 -1
- package/src/hooks/useMapEventSource.ts +20 -0
- package/src/hooks/useMapFitView.ts +127 -0
- package/src/hooks/useMapLoader.ts +164 -0
- package/src/hooks/useMapPlace.ts +20 -22
- package/src/hooks/useMapRecomendPlace.ts +18 -25
- package/src/{components/MapProvider → hooks}/useMapSupplier.ts +4 -7
- package/src/hooks/useOverlay.ts +22 -0
- package/src/hooks/useWalkingRoute.ts +1 -1
- package/src/hooks-business/useBusinessMapAutoComplete.ts +13 -7
- package/src/hooks-business/useBusinessMapRecomendPlace.ts +10 -10
- package/src/types/interface.ts +5 -0
- package/dist/components/Amap/useAmap.d.ts +0 -399
- package/dist/components/Gmap/useGmap.d.ts +0 -5
- package/dist/components/MapProvider/useMapSupplier.d.ts +0 -11
- package/dist/hooks/useMapReady.d.ts +0 -4
- package/src/components/Amap/useAmap.ts +0 -9
- package/src/components/Gmap/useGmap.ts +0 -7
- package/src/hooks/useMapReady.ts +0 -14
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { computed, h, shallowRef, watchPostEffect } from "vue-demi";
|
|
2
2
|
import type { SetMap } from "../../hooks/useHeycarMap";
|
|
3
|
+
import { provideGmap } from "../../hooks/useMap";
|
|
4
|
+
import { useMapEventSource } from "../../hooks/useMapEventSource";
|
|
3
5
|
import { defineSetup } from "../../types/helper";
|
|
4
6
|
import type { MapEventHandler } from "../../types/mapHelper";
|
|
5
7
|
import {
|
|
6
8
|
watchNoneImmediatePostEffectForDeepOption,
|
|
7
9
|
watchPostEffectForGMapEvent,
|
|
8
10
|
} from "../../utils/compare";
|
|
9
|
-
import { provideGmap } from "./useGmap";
|
|
10
11
|
export interface GmapProps extends google.maps.MapOptions {
|
|
11
12
|
mapRef?: SetMap<google.maps.Map>;
|
|
12
13
|
onDragStart?: MapEventHandler<google.maps.Map>;
|
|
@@ -22,19 +23,30 @@ export const Gmap = defineSetup(function Gmap(props: GmapProps, { slots, emit })
|
|
|
22
23
|
const defaultOptions = options.value;
|
|
23
24
|
const elementRef = shallowRef();
|
|
24
25
|
const mapRef = shallowRef<google.maps.Map>();
|
|
26
|
+
const { executeMapApi } = useMapEventSource();
|
|
25
27
|
const handleDrag: typeof emit = (name) => emit(name as any, { target: mapRef.value! });
|
|
26
28
|
provideGmap(mapRef);
|
|
27
29
|
watchPostEffect(() => {
|
|
28
30
|
// todo 这里是否会因为 mapRef 的赋值导致不停运行?
|
|
29
31
|
if (mapRef.value || !elementRef.value) return;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
let map: google.maps.Map;
|
|
33
|
+
executeMapApi(() => {
|
|
34
|
+
map = new google.maps.Map(elementRef.value, { ...defaultOptions });
|
|
35
|
+
});
|
|
36
|
+
mapRef.value = map!;
|
|
37
|
+
setMap?.(map!);
|
|
33
38
|
});
|
|
39
|
+
// watch(
|
|
40
|
+
// () => options.value.zoom,
|
|
41
|
+
// (zoom) => {
|
|
42
|
+
// if (zoom) mapRef.value?.setZoom(zoom);
|
|
43
|
+
// },
|
|
44
|
+
// { flush: "post" }
|
|
45
|
+
// );
|
|
34
46
|
watchNoneImmediatePostEffectForDeepOption(
|
|
35
47
|
() => options.value,
|
|
36
48
|
(options) => {
|
|
37
|
-
mapRef.value?.setOptions({ ...options });
|
|
49
|
+
executeMapApi(() => mapRef.value?.setOptions({ ...options }));
|
|
38
50
|
}
|
|
39
51
|
);
|
|
40
52
|
watchPostEffectForGMapEvent(mapRef, props, handleDrag, ["onDragStart", "onDragEnd"]);
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { onMounted, onUnmounted, shallowRef, watch, watchPostEffect } from "vue-demi";
|
|
2
|
+
import { useGmap } from "../../hooks/useMap";
|
|
3
|
+
import { GmapOverlay, MapRegisterOverlayProps, useMapOverlay } from "../../hooks/useOverlay";
|
|
2
4
|
import { defineSetup } from "../../types/helper";
|
|
3
5
|
import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
|
|
4
|
-
import { useGmap } from "../Gmap/useGmap";
|
|
5
6
|
|
|
6
|
-
export type GmapAdvancedMarkerViewProps = google.maps.marker.AdvancedMarkerViewOptions
|
|
7
|
+
export type GmapAdvancedMarkerViewProps = google.maps.marker.AdvancedMarkerViewOptions &
|
|
8
|
+
MapRegisterOverlayProps<GmapOverlay>;
|
|
7
9
|
|
|
8
10
|
export const GmapAdvancedMarkerView = defineSetup(function GmapAdvancedMarkerView(
|
|
9
11
|
props: GmapAdvancedMarkerViewProps
|
|
10
12
|
) {
|
|
13
|
+
const { registerOverlay } = props;
|
|
11
14
|
const markerRef = shallowRef<google.maps.marker.AdvancedMarkerView>();
|
|
12
15
|
const mapRef = useGmap();
|
|
16
|
+
useMapOverlay({ registerOverlay, overlayRef: markerRef });
|
|
13
17
|
onMounted(() => {
|
|
14
|
-
|
|
18
|
+
const { registerOverlay, ...markerViewProps } = props;
|
|
19
|
+
markerRef.value = new google.maps.marker.AdvancedMarkerView({ ...markerViewProps });
|
|
15
20
|
});
|
|
16
21
|
onUnmounted(() => {
|
|
17
22
|
if (!markerRef.value) return;
|
|
@@ -24,7 +29,7 @@ export const GmapAdvancedMarkerView = defineSetup(function GmapAdvancedMarkerVie
|
|
|
24
29
|
});
|
|
25
30
|
watchNoneImmediatePostEffectForDeepOption(
|
|
26
31
|
() => {
|
|
27
|
-
const { content, ...restProps } = props;
|
|
32
|
+
const { content, registerOverlay, ...restProps } = props;
|
|
28
33
|
return restProps;
|
|
29
34
|
},
|
|
30
35
|
(props) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computed, onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
|
|
2
|
+
import { useGmap } from "../../hooks/useMap";
|
|
2
3
|
import { defineSetup } from "../../types/helper";
|
|
3
4
|
import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
|
|
4
|
-
import { useGmap } from "../Gmap/useGmap";
|
|
5
5
|
|
|
6
6
|
export interface GmapInfoWindowProps extends google.maps.InfoWindowOptions {
|
|
7
7
|
visible: boolean;
|
|
@@ -1,72 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { computed, shallowRef } from "vue-demi";
|
|
1
|
+
import { GmapLoaderProps, Status, useGmapLoader } from "../../hooks/useMapLoader";
|
|
3
2
|
import { defineSetup, VueNode } from "../../types/helper";
|
|
4
|
-
import { watchPostEffectForDeepOption } from "../../utils/compare";
|
|
5
|
-
|
|
6
|
-
export enum Status {
|
|
7
|
-
LOADING = "LOADING",
|
|
8
|
-
FAILURE = "FAILURE",
|
|
9
|
-
SUCCESS = "SUCCESS",
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface GmapLoaderProps extends LoaderOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Render prop used to switch to loading component.
|
|
15
|
-
*/
|
|
16
|
-
loading?: () => VueNode;
|
|
17
|
-
/**
|
|
18
|
-
* Render prop used to switch to error fallback component.
|
|
19
|
-
*/
|
|
20
|
-
fallback?: () => VueNode;
|
|
21
|
-
/**
|
|
22
|
-
* Callback prop used to access `@googlemaps/js-api-loader` and `Status`.
|
|
23
|
-
*
|
|
24
|
-
* Note: The callback be executed multiple times in the lifecycle of the component.
|
|
25
|
-
*/
|
|
26
|
-
onChange?: (status: Status) => void;
|
|
27
|
-
}
|
|
28
3
|
|
|
29
4
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* ```
|
|
33
|
-
* const MyApp = () => (
|
|
34
|
-
* <GmapLoader apiKey={'YOUR_API_KEY'}>
|
|
35
|
-
* <MyMapComponent />
|
|
36
|
-
* </GmapLoader>
|
|
37
|
-
* );
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @param props
|
|
5
|
+
* Deprecated
|
|
41
6
|
*/
|
|
42
|
-
export const GmapLoader = defineSetup(function GmapLoader(props: GmapLoaderProps, { slots
|
|
43
|
-
const statusRef =
|
|
44
|
-
const options = computed(() => {
|
|
45
|
-
const { onChange, fallback, loading, ...options } = props;
|
|
46
|
-
return options;
|
|
47
|
-
});
|
|
48
|
-
watchPostEffectForDeepOption(
|
|
49
|
-
() => options.value,
|
|
50
|
-
(options) => {
|
|
51
|
-
const loader = new Loader(options);
|
|
52
|
-
|
|
53
|
-
const setStatusAndExecuteCallback = (status: Status) => {
|
|
54
|
-
emit("change", status);
|
|
55
|
-
statusRef.value = status;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
setStatusAndExecuteCallback(Status.LOADING);
|
|
59
|
-
|
|
60
|
-
loader.load().then(
|
|
61
|
-
() => setStatusAndExecuteCallback(Status.SUCCESS),
|
|
62
|
-
() => setStatusAndExecuteCallback(Status.FAILURE)
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
);
|
|
7
|
+
export const GmapLoader = defineSetup(function GmapLoader(props: GmapLoaderProps, { slots }) {
|
|
8
|
+
const { statusRef } = useGmapLoader(props);
|
|
66
9
|
return () => {
|
|
67
10
|
switch (statusRef.value) {
|
|
68
11
|
case Status.SUCCESS:
|
|
69
|
-
// todo: 由于 class 无法禁止传递,所以不用 div 包裹。目前 GmapLoader 只在 HeycarMap 内部使用,能确保 slot.default 是单节点, 如果将来要开放去处,这里需要做处理
|
|
70
12
|
return slots.default?.() as VueNode;
|
|
71
13
|
case Status.LOADING:
|
|
72
14
|
return slots.loading?.();
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
|
|
2
|
+
import { useGmap } from "../../hooks/useMap";
|
|
3
|
+
import { GmapOverlay, MapRegisterOverlayProps, useMapOverlay } from "../../hooks/useOverlay";
|
|
2
4
|
import { defineSetup } from "../../types/helper";
|
|
3
5
|
import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
|
|
4
|
-
import { useGmap } from "../Gmap/useGmap";
|
|
5
6
|
|
|
6
|
-
export type GmapMarkerProps = google.maps.MarkerOptions
|
|
7
|
+
export type GmapMarkerProps = google.maps.MarkerOptions & MapRegisterOverlayProps<GmapOverlay>;
|
|
7
8
|
|
|
8
9
|
export const GmapMarker = defineSetup(function GmapMarker(props: GmapMarkerProps) {
|
|
10
|
+
const { registerOverlay } = props;
|
|
9
11
|
const markerRef = shallowRef<google.maps.Marker>();
|
|
10
12
|
const mapRef = useGmap();
|
|
11
13
|
onMounted(() => {
|
|
@@ -14,6 +16,7 @@ export const GmapMarker = defineSetup(function GmapMarker(props: GmapMarkerProps
|
|
|
14
16
|
onUnmounted(() => {
|
|
15
17
|
markerRef.value?.setMap(null);
|
|
16
18
|
});
|
|
19
|
+
useMapOverlay({ registerOverlay, overlayRef: markerRef });
|
|
17
20
|
watchPostEffect(() => {
|
|
18
21
|
const map = mapRef?.value;
|
|
19
22
|
if (!map) return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
|
|
2
|
+
import { useGmap } from "../../hooks/useMap";
|
|
2
3
|
import { defineSetup } from "../../types/helper";
|
|
3
4
|
import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
|
|
4
|
-
import { useGmap } from "../Gmap/useGmap";
|
|
5
5
|
|
|
6
6
|
export type GmapPolygonProps = google.maps.PolygonOptions;
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
|
|
2
|
+
import { useGmap } from "../../hooks/useMap";
|
|
2
3
|
import { defineSetup } from "../../types/helper";
|
|
3
4
|
import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
|
|
4
|
-
import { useGmap } from "../Gmap/useGmap";
|
|
5
5
|
|
|
6
6
|
export type GmapPolylineProps = google.maps.PolylineOptions;
|
|
7
7
|
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import type { SetMap } from "../../hooks/useHeycarMap";
|
|
2
|
+
import { GmapLoaderProps, Status, useMapLoader, UseMapLoaderProps } from "../../hooks/useMapLoader";
|
|
3
|
+
import { MapSupplierPayolad, provideMapSupplier, useMapSupplier } from "../../hooks/useMapSupplier";
|
|
2
4
|
import { defineLagecySetup } from "../../types/helper";
|
|
3
5
|
import { language2vectorMapForeign, vec2lnglat } from "../../utils/transform";
|
|
4
6
|
import { Amap, AmapProps } from "../Amap";
|
|
5
|
-
import { AmapLoader } from "../AmapLoader";
|
|
6
7
|
import { Gmap, GmapProps } from "../Gmap";
|
|
7
|
-
import { GmapLoader, GmapLoaderProps } from "../GmapLoader";
|
|
8
|
-
import { MapSupplierPayolad, provideMapSupplier, useMapSupplier } from "./useMapSupplier";
|
|
9
8
|
|
|
10
|
-
export type MapProviderProps = MapSupplierPayolad
|
|
9
|
+
export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId">;
|
|
11
10
|
export const MapProvider = defineLagecySetup(function MapProvider(
|
|
12
11
|
props: MapProviderProps,
|
|
13
12
|
{ slots }
|
|
14
13
|
) {
|
|
15
|
-
|
|
14
|
+
const { statusRef, readyPromise } = useMapLoader(props);
|
|
15
|
+
const context = new Proxy<MapSupplierPayolad>(props as MapSupplierPayolad, {
|
|
16
|
+
get(target, name, receiver) {
|
|
17
|
+
if (name === "status") return statusRef.value;
|
|
18
|
+
if (name === "readyPromise") return readyPromise;
|
|
19
|
+
return Reflect.get(target, name, receiver);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
provideMapSupplier(context);
|
|
16
23
|
return () => <div>{slots.default?.()}</div>;
|
|
17
|
-
}).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapKey", "supplier"]);
|
|
24
|
+
}).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapKey", "supplier", "language"]);
|
|
18
25
|
|
|
19
26
|
export interface HeycarMapProps
|
|
20
27
|
extends Pick<GmapLoaderProps, "fallback" | "loading">,
|
|
21
28
|
Pick<AmapProps, "center" | "zoom"> {
|
|
22
|
-
language?: "en" | "zh";
|
|
23
29
|
mapRef?: SetMap<AMap.Map> | SetMap<google.maps.Map>;
|
|
24
30
|
onDragEnd?: (value: [number, number]) => any;
|
|
25
31
|
}
|
|
@@ -37,58 +43,35 @@ export const HeycarMap = defineLagecySetup(function HeycarMap(
|
|
|
37
43
|
emit("dragEnd", [lng, lat]);
|
|
38
44
|
};
|
|
39
45
|
return () => {
|
|
40
|
-
const {
|
|
41
|
-
const { mapRef: setMap, center, zoom
|
|
42
|
-
|
|
46
|
+
const { supplier, gmapId, language = "zh", status } = payload;
|
|
47
|
+
const { mapRef: setMap, center, zoom } = props;
|
|
48
|
+
if (status === Status.LOADING) return slots.loading?.();
|
|
49
|
+
if (status === Status.FAILURE) return slots.fallback?.();
|
|
43
50
|
const children = slots.default?.();
|
|
44
51
|
switch (supplier) {
|
|
45
52
|
case "gmap":
|
|
46
53
|
return (
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
fallback={fallback}
|
|
54
|
+
<Gmap
|
|
55
|
+
mapRef={setMap as SetMap<google.maps.Map>}
|
|
56
|
+
mapId={gmapId}
|
|
57
|
+
center={center ? vec2lnglat(center) : undefined}
|
|
58
|
+
zoom={zoom}
|
|
59
|
+
onDragEnd={gmapDebouncedEmit}
|
|
54
60
|
>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
mapId={gmapId}
|
|
58
|
-
center={center ? vec2lnglat(center) : undefined}
|
|
59
|
-
zoom={zoom}
|
|
60
|
-
onDragEnd={gmapDebouncedEmit}
|
|
61
|
-
>
|
|
62
|
-
{children}
|
|
63
|
-
</Gmap>
|
|
64
|
-
</GmapLoader>
|
|
61
|
+
{children}
|
|
62
|
+
</Gmap>
|
|
65
63
|
);
|
|
66
64
|
default:
|
|
67
65
|
return (
|
|
68
|
-
<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"AMap.Geocoder",
|
|
75
|
-
"AMap.PlaceSearch",
|
|
76
|
-
"AMap.Driving",
|
|
77
|
-
"AMap.Walker",
|
|
78
|
-
]}
|
|
79
|
-
loading={loading}
|
|
80
|
-
fallback={fallback}
|
|
66
|
+
<Amap
|
|
67
|
+
mapRef={setMap as SetMap<AMap.Map>}
|
|
68
|
+
vectorMapForeign={language2vectorMapForeign(language)}
|
|
69
|
+
center={center}
|
|
70
|
+
zoom={zoom}
|
|
71
|
+
onDragEnd={amapDebounceEmit}
|
|
81
72
|
>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
vectorMapForeign={language2vectorMapForeign(language)}
|
|
85
|
-
center={center}
|
|
86
|
-
zoom={zoom}
|
|
87
|
-
onDragEnd={amapDebounceEmit}
|
|
88
|
-
>
|
|
89
|
-
{children}
|
|
90
|
-
</Amap>
|
|
91
|
-
</AmapLoader>
|
|
73
|
+
{children}
|
|
74
|
+
</Amap>
|
|
92
75
|
);
|
|
93
76
|
}
|
|
94
77
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ShallowRef, shallowRef } from "vue-demi";
|
|
2
|
-
import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
|
|
3
2
|
import type { Point } from "../types/interface";
|
|
4
3
|
import { watchPostEffectForDeepOption } from "../utils/compare";
|
|
4
|
+
import { useMapSupplier } from "./useMapSupplier";
|
|
5
5
|
|
|
6
6
|
export interface UseDrivingRouteProps {
|
|
7
7
|
from: Point;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ref, watch } from "vue-demi";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Point } from "../types/interface";
|
|
3
3
|
|
|
4
4
|
export interface UseGeoLocationProps {
|
|
5
|
-
mapRef: MapShallowRef;
|
|
6
5
|
onChange?: (value: { position: Point; coordinate: GeolocationCoordinates }) => any;
|
|
7
6
|
onLoad?: (value: { position: Point; coordinate: GeolocationCoordinates }) => any;
|
|
8
7
|
}
|
|
9
8
|
export const useGeoLocation = (props: UseGeoLocationProps) => {
|
|
10
9
|
const { onChange, onLoad } = props;
|
|
11
10
|
const loading = ref(false);
|
|
11
|
+
const readyRef = ref(false);
|
|
12
12
|
const errorRef = ref<GeolocationPositionError>();
|
|
13
13
|
const coordinateRef = ref<GeolocationCoordinates>({
|
|
14
14
|
accuracy: 0,
|
|
@@ -32,6 +32,7 @@ export const useGeoLocation = (props: UseGeoLocationProps) => {
|
|
|
32
32
|
positionRef.value = point;
|
|
33
33
|
if (loading.value) {
|
|
34
34
|
loading.value = false;
|
|
35
|
+
readyRef.value = true;
|
|
35
36
|
onLoad?.({ position: point, coordinate });
|
|
36
37
|
}
|
|
37
38
|
onChange?.({ position: point, coordinate });
|
|
@@ -53,5 +54,6 @@ export const useGeoLocation = (props: UseGeoLocationProps) => {
|
|
|
53
54
|
geoPosition: positionRef,
|
|
54
55
|
geoCoordinate: coordinateRef,
|
|
55
56
|
geoLoading: loading,
|
|
57
|
+
geoReady: readyRef,
|
|
56
58
|
};
|
|
57
59
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { inject, provide, ShallowRef } from "vue-demi";
|
|
2
|
+
import type { MapShallowRef } from "../types/interface";
|
|
3
|
+
import { useMapSupplier } from "./useMapSupplier";
|
|
4
|
+
|
|
5
|
+
export const amapContext = Symbol("amap");
|
|
6
|
+
|
|
7
|
+
export const useAmap = () => {
|
|
8
|
+
return inject<ShallowRef<AMap.Map | undefined>>(amapContext);
|
|
9
|
+
};
|
|
10
|
+
export const provideAmap = (mapRef: ShallowRef<AMap.Map | undefined>) =>
|
|
11
|
+
provide(amapContext, mapRef);
|
|
12
|
+
|
|
13
|
+
export const gmapContext = Symbol("gmap");
|
|
14
|
+
|
|
15
|
+
export const useGmap = () => inject<ShallowRef<google.maps.Map | undefined>>(gmapContext);
|
|
16
|
+
export const provideGmap = (mapRef: ShallowRef<google.maps.Map | undefined>) =>
|
|
17
|
+
provide(gmapContext, mapRef);
|
|
18
|
+
|
|
19
|
+
export const useMap = () => {
|
|
20
|
+
const { supplier } = useMapSupplier();
|
|
21
|
+
const result = supplier === "gmap" ? useGmap() : useAmap();
|
|
22
|
+
return result as MapShallowRef;
|
|
23
|
+
};
|
|
24
|
+
export const provideMap = (mapRef: MapShallowRef) => {
|
|
25
|
+
const { supplier } = useMapSupplier();
|
|
26
|
+
return supplier === "gmap"
|
|
27
|
+
? provideGmap(mapRef as MapShallowRef<google.maps.Map>)
|
|
28
|
+
: provideAmap(mapRef as MapShallowRef<AMap.Map>);
|
|
29
|
+
};
|
package/src/hooks/useMapAngle.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computed } from "vue-demi";
|
|
2
|
-
import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
|
|
3
2
|
import type { Point } from "../types/interface";
|
|
4
3
|
import { vec2lnglat } from "../utils/transform";
|
|
4
|
+
import { useMapSupplier } from "./useMapSupplier";
|
|
5
5
|
|
|
6
6
|
const amapComputeHeading = (from: Point, to: Point, map?: AMap.Map) => {
|
|
7
7
|
if (!map) return 0;
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { ref, watch } from "vue-demi";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { useMapReady } from "./useMapReady";
|
|
2
|
+
import type { AutoCompletePlace, City } from "../types/interface";
|
|
3
|
+
import { useMapSupplier } from "./useMapSupplier";
|
|
5
4
|
import { useUpdate } from "./useUdate";
|
|
6
5
|
|
|
7
|
-
export interface UseMapAutoCompleteProps
|
|
8
|
-
mapRef: MapShallowRef<M>;
|
|
6
|
+
export interface UseMapAutoCompleteProps {
|
|
9
7
|
city: City;
|
|
10
8
|
}
|
|
11
9
|
|
|
12
|
-
export const useAmapAutoComplete = (props: UseMapAutoCompleteProps
|
|
13
|
-
const { city
|
|
10
|
+
export const useAmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
11
|
+
const { city } = props;
|
|
14
12
|
const cityRef = ref(city);
|
|
15
|
-
const {
|
|
13
|
+
const { readyPromise } = useMapSupplier();
|
|
16
14
|
const keywordRef = ref("");
|
|
17
15
|
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
18
16
|
const { update, idx: updateKey } = useUpdate();
|
|
@@ -26,11 +24,11 @@ export const useAmapAutoComplete = (props: UseMapAutoCompleteProps<AMap.Map>) =>
|
|
|
26
24
|
};
|
|
27
25
|
watch(
|
|
28
26
|
() => updateKey.value,
|
|
29
|
-
() => {
|
|
30
|
-
if (!
|
|
27
|
+
async () => {
|
|
28
|
+
if (!keywordRef.value) return;
|
|
29
|
+
await readyPromise;
|
|
31
30
|
const amapPlaceSearch = new AMap.PlaceSearch({ city: cityRef.value.name });
|
|
32
31
|
amapPlaceSearch.search(keywordRef.value, (status, result) => {
|
|
33
|
-
console.log("status, result = ", status, result);
|
|
34
32
|
switch (status) {
|
|
35
33
|
case "complete": {
|
|
36
34
|
autoCompletePlacesRef.value = (result as AMap.PlaceSearchResult).poiList.pois.map(
|
|
@@ -58,10 +56,10 @@ export const useAmapAutoComplete = (props: UseMapAutoCompleteProps<AMap.Map>) =>
|
|
|
58
56
|
return { setKeyword, setCity, autoCompletePlaces: autoCompletePlacesRef };
|
|
59
57
|
};
|
|
60
58
|
|
|
61
|
-
export const useGmapAutoComplete = (props: UseMapAutoCompleteProps
|
|
62
|
-
const { city
|
|
63
|
-
const cityRef = ref(city);
|
|
64
|
-
const {
|
|
59
|
+
export const useGmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
60
|
+
const { city } = props;
|
|
61
|
+
const cityRef = ref({ ...city });
|
|
62
|
+
const { readyPromise } = useMapSupplier();
|
|
65
63
|
const keywordRef = ref("");
|
|
66
64
|
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
67
65
|
const { update, idx: updateKey } = useUpdate();
|
|
@@ -77,7 +75,8 @@ export const useGmapAutoComplete = (props: UseMapAutoCompleteProps<google.maps.M
|
|
|
77
75
|
watch(
|
|
78
76
|
() => updateKey.value,
|
|
79
77
|
async () => {
|
|
80
|
-
if (!
|
|
78
|
+
if (!keywordRef.value) return;
|
|
79
|
+
await readyPromise;
|
|
81
80
|
const gmapPlacesService = new google.maps.places.PlacesService(div);
|
|
82
81
|
gmapPlacesService.textSearch(
|
|
83
82
|
{
|
|
@@ -110,7 +109,5 @@ export const useGmapAutoComplete = (props: UseMapAutoCompleteProps<google.maps.M
|
|
|
110
109
|
|
|
111
110
|
export const useMapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
112
111
|
const { supplier } = useMapSupplier();
|
|
113
|
-
return supplier === "gmap"
|
|
114
|
-
? useGmapAutoComplete(props as UseMapAutoCompleteProps<google.maps.Map>)
|
|
115
|
-
: useAmapAutoComplete(props as UseMapAutoCompleteProps<AMap.Map>);
|
|
112
|
+
return supplier === "gmap" ? useGmapAutoComplete(props) : useAmapAutoComplete(props);
|
|
116
113
|
};
|
|
@@ -1,25 +1,42 @@
|
|
|
1
|
-
import { reactive, watchEffect } from "vue-demi";
|
|
2
|
-
import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
|
|
1
|
+
import { reactive, Ref, watch, watchEffect } from "vue-demi";
|
|
3
2
|
import { LANGUAGE } from "../types/helper";
|
|
4
|
-
import type { City
|
|
5
|
-
import {
|
|
3
|
+
import type { City } from "../types/interface";
|
|
4
|
+
import { useMapSupplier } from "./useMapSupplier";
|
|
6
5
|
|
|
7
|
-
export interface UseMapCityBoundProps
|
|
8
|
-
|
|
9
|
-
cityName: string;
|
|
6
|
+
export interface UseMapCityBoundProps {
|
|
7
|
+
cityNameRef: Ref<string | undefined>;
|
|
10
8
|
onChange?: (value: City) => any;
|
|
11
9
|
}
|
|
10
|
+
export const useAmapBoundCity = (props: UseMapCityBoundProps): City => {
|
|
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
|
+
|
|
12
24
|
export const useGmapBoundCity = (props: UseMapCityBoundProps): City => {
|
|
13
|
-
const {
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
const { cityNameRef, onChange } = props;
|
|
26
|
+
const { readyPromise } = useMapSupplier();
|
|
27
|
+
const city = reactive<City>({
|
|
28
|
+
name: cityNameRef.value ?? "",
|
|
29
|
+
bound: {
|
|
30
|
+
east: 0,
|
|
31
|
+
north: 0,
|
|
32
|
+
south: 0,
|
|
33
|
+
west: 0,
|
|
34
|
+
},
|
|
20
35
|
});
|
|
21
36
|
watchEffect(async () => {
|
|
22
|
-
|
|
37
|
+
const cityName = cityNameRef.value;
|
|
38
|
+
if (!cityName) return;
|
|
39
|
+
await readyPromise;
|
|
23
40
|
const geocoder = new google.maps.Geocoder();
|
|
24
41
|
// todo 这里不是唯一的
|
|
25
42
|
const { results } = await geocoder.geocode({
|
|
@@ -34,19 +51,14 @@ export const useGmapBoundCity = (props: UseMapCityBoundProps): City => {
|
|
|
34
51
|
}
|
|
35
52
|
const { geometry } = results[0];
|
|
36
53
|
const cityBound = geometry.bounds?.toJSON() ?? geometry.viewport.toJSON();
|
|
37
|
-
|
|
54
|
+
city.name = cityName;
|
|
55
|
+
city.bound = cityBound;
|
|
38
56
|
onChange?.({ name: cityName, bound: cityBound });
|
|
39
57
|
});
|
|
40
|
-
return
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const useAmapBoundCity = (props: UseMapCityBoundProps): City => {
|
|
44
|
-
return { name: props.cityName };
|
|
58
|
+
return city;
|
|
45
59
|
};
|
|
46
60
|
|
|
47
61
|
export const useMapBoundCity = (props: UseMapCityBoundProps) => {
|
|
48
62
|
const { supplier } = useMapSupplier();
|
|
49
|
-
return supplier === "gmap"
|
|
50
|
-
? useGmapBoundCity(props as UseMapCityBoundProps<google.maps.Map>)
|
|
51
|
-
: useAmapBoundCity(props as UseMapCityBoundProps<AMap.Map>);
|
|
63
|
+
return supplier === "gmap" ? useGmapBoundCity(props) : useAmapBoundCity(props);
|
|
52
64
|
};
|
package/src/hooks/useMapDrag.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ref, type ShallowRef } from "vue-demi";
|
|
2
2
|
import type { AmapProps } from "../components/Amap";
|
|
3
3
|
import type { GmapProps } from "../components/Gmap";
|
|
4
|
-
import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
|
|
5
4
|
import type { SetupContextEmitHandler } from "../types/helper";
|
|
6
5
|
import type { Point } from "../types/interface";
|
|
7
6
|
import { watchPostEffectForAMapEvent, watchPostEffectForGMapEvent } from "../utils/compare";
|
|
8
7
|
import { pipeAsync } from "../utils/transform";
|
|
8
|
+
import { useMapSupplier } from "./useMapSupplier";
|
|
9
9
|
|
|
10
10
|
export const ON_CHANGE_CENTER_INTERVAL = 200;
|
|
11
11
|
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
};
|