@heycar/heycars-map 0.1.3 → 0.1.4
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/components/Amap/Amap.d.ts +3 -1
- package/dist/components/MapProvider/MapProvider.d.ts +1 -0
- package/dist/index.cjs +27 -27
- package/dist/index.js +275 -246
- package/dist/utils/transform.d.ts +2 -0
- package/package.json +1 -1
- package/src/business-components/DrivingLine/DrivingLine.tsx +1 -0
- package/src/business-components/DrivingRoute/DrivingRoute.tsx +9 -4
- package/src/components/Amap/Amap.ts +15 -3
- package/src/components/AmapLoader/AmapLoader.ts +1 -1
- package/src/components/MapProvider/MapProvider.tsx +6 -2
- package/src/hooks/useDrivingRoute.ts +0 -1
- package/src/utils/transform.ts +10 -0
|
@@ -7,3 +7,5 @@ export interface AsteriskItem {
|
|
|
7
7
|
export declare const decodeAsterisk: (encodedValue: string) => AsteriskItem[];
|
|
8
8
|
export declare const property2emitEventName: (propertyName: string) => string;
|
|
9
9
|
export declare const property2mapEventName: (propertyName: string) => string;
|
|
10
|
+
export type VectorMapForeign = "style_en" | "style_local" | "style_zh_cn";
|
|
11
|
+
export declare const language2vectorMapForeign: (lang: "en" | "zh") => VectorMapForeign;
|
package/package.json
CHANGED
|
@@ -124,6 +124,7 @@ export const GDrivingLine = defineSetup(function GDrivingLine(props: DrivingLine
|
|
|
124
124
|
export const DrivingLine = defineSetup(function DrivingLine(props: DrivingLineProps) {
|
|
125
125
|
const payload = useMapSupplier();
|
|
126
126
|
return () => {
|
|
127
|
+
if (!props.path.length) return null;
|
|
127
128
|
return createElement(payload.supplier === "gmap" ? GDrivingLine : ADrivingLine, {
|
|
128
129
|
attrs: props,
|
|
129
130
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Ref, ShallowRef } from "vue-demi";
|
|
1
|
+
import type { Ref, ShallowRef, VNodeData } from "vue-demi";
|
|
2
2
|
import { useAmap } from "../../components/Amap/useAmap";
|
|
3
3
|
import { useGmap } from "../../components/Gmap/useGmap";
|
|
4
4
|
import { useMapSupplier } from "../../components/MapProvider/useMapSupplier";
|
|
@@ -24,7 +24,8 @@ export const ADrivingRoute = defineSetup(function DrivingRoute(
|
|
|
24
24
|
const mapRef = useAmap();
|
|
25
25
|
const pathRef = useADrivingRoute(props);
|
|
26
26
|
const angleRef = useAmapAngle({ pathRef, mapRef });
|
|
27
|
-
|
|
27
|
+
debugger;
|
|
28
|
+
return () => <div id="qyc">{slots.render?.({ pathRef, angleRef })}</div>;
|
|
28
29
|
});
|
|
29
30
|
|
|
30
31
|
export const GDrivingRoute = defineSetup(function DrivingRoute(
|
|
@@ -37,7 +38,11 @@ export const GDrivingRoute = defineSetup(function DrivingRoute(
|
|
|
37
38
|
return () => <div>{slots.render?.({ pathRef, angleRef })}</div>;
|
|
38
39
|
});
|
|
39
40
|
|
|
40
|
-
export const DrivingRoute = defineSetup(function DrivingRoute(props: DrivingRouteProps) {
|
|
41
|
+
export const DrivingRoute = defineSetup(function DrivingRoute(props: DrivingRouteProps, { slots }) {
|
|
41
42
|
const { supplier } = useMapSupplier();
|
|
42
|
-
return () =>
|
|
43
|
+
return () =>
|
|
44
|
+
createElement(supplier === "gmap" ? GDrivingRoute : ADrivingRoute, {
|
|
45
|
+
attrs: props,
|
|
46
|
+
scopedSlots: slots as VNodeData["scopedSlots"],
|
|
47
|
+
});
|
|
43
48
|
});
|
|
@@ -7,17 +7,25 @@ import {
|
|
|
7
7
|
watchNoneImmediatePostEffectForMapProperty,
|
|
8
8
|
watchPostEffectForAMapEvent,
|
|
9
9
|
} from "../../utils/compare";
|
|
10
|
+
import type { VectorMapForeign } from "../../utils/transform";
|
|
10
11
|
import * as css from "./Amap.css";
|
|
11
12
|
import { provideAmap } from "./useAmap";
|
|
12
13
|
|
|
13
|
-
export interface AmapProps extends AMap.MapOptions {
|
|
14
|
+
export interface AmapProps extends Omit<AMap.MapOptions, "vectorMapForeign"> {
|
|
15
|
+
vectorMapForeign?: VectorMapForeign;
|
|
14
16
|
mapRef?: SetMap<AMap.Map>;
|
|
15
17
|
onDragStart?: MapEventHandler<AMap.Map>;
|
|
16
18
|
onDragEnd?: MapEventHandler<AMap.Map>;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export const Amap = defineSetup(function Amap(props: AmapProps, { slots, emit }) {
|
|
20
|
-
const {
|
|
22
|
+
const {
|
|
23
|
+
onDragStart,
|
|
24
|
+
onDragEnd,
|
|
25
|
+
mapRef: setMap,
|
|
26
|
+
vectorMapForeign = "style_zh_cn",
|
|
27
|
+
...defaultOptions
|
|
28
|
+
} = props;
|
|
21
29
|
const statusOptions = computed(() => {
|
|
22
30
|
return {
|
|
23
31
|
dragEnable: !!props.dragEnable,
|
|
@@ -35,7 +43,11 @@ export const Amap = defineSetup(function Amap(props: AmapProps, { slots, emit })
|
|
|
35
43
|
watchPostEffect(() => {
|
|
36
44
|
// todo 这里是否会因为 mapRef 的赋值导致不停运行?
|
|
37
45
|
if (mapRef.value || !elementRef.value) return;
|
|
38
|
-
const map = new AMap.Map(elementRef.value, {
|
|
46
|
+
const map = new AMap.Map(elementRef.value, {
|
|
47
|
+
...defaultOptions,
|
|
48
|
+
vectorMapForeign: vectorMapForeign as any,
|
|
49
|
+
mapStyle: "amap://styles/95498a904992a4c0b866a3e4d7729682",
|
|
50
|
+
});
|
|
39
51
|
mapRef.value = map;
|
|
40
52
|
setMap?.(map);
|
|
41
53
|
});
|
|
@@ -29,7 +29,7 @@ export const AmapLoader = defineSetup(function AmapLoader(props: AmapLoaderProps
|
|
|
29
29
|
const optionsRef = computed(() => {
|
|
30
30
|
const { onChange, loading, fallback, apiKey, apiSecret, apiServiceHost, version, ...options } =
|
|
31
31
|
props;
|
|
32
|
-
return { ...options, key: apiKey, version: version ?? "2.0" };
|
|
32
|
+
return { ...options, key: apiKey, version: version ?? "2.0.5.16" };
|
|
33
33
|
});
|
|
34
34
|
watchPostEffectForDeepOption(
|
|
35
35
|
() => optionsRef.value,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SetMap } from "../../hooks/useHeycarMap";
|
|
2
2
|
import { defineLagecySetup } from "../../types/helper";
|
|
3
|
-
import { vec2lnglat } from "../../utils/transform";
|
|
3
|
+
import { language2vectorMapForeign, vec2lnglat } from "../../utils/transform";
|
|
4
4
|
import { Amap, AmapProps } from "../Amap";
|
|
5
5
|
import { AmapLoader } from "../AmapLoader";
|
|
6
6
|
import { Gmap, GmapProps } from "../Gmap";
|
|
@@ -19,6 +19,7 @@ export const MapProvider = defineLagecySetup(function MapProvider(
|
|
|
19
19
|
export interface HeycarMapProps
|
|
20
20
|
extends Pick<GmapLoaderProps, "fallback" | "loading">,
|
|
21
21
|
Pick<AmapProps, "center" | "zoom"> {
|
|
22
|
+
language?: "en" | "zh";
|
|
22
23
|
mapRef?: SetMap<AMap.Map> | SetMap<google.maps.Map>;
|
|
23
24
|
onDragEnd?: (value: [number, number]) => any;
|
|
24
25
|
}
|
|
@@ -37,13 +38,15 @@ export const HeycarMap = defineLagecySetup(function HeycarMap(
|
|
|
37
38
|
};
|
|
38
39
|
return () => {
|
|
39
40
|
const { gmapKey, amapKey, amapSecret, amapServiceHost, supplier, gmapId } = payload;
|
|
40
|
-
const { mapRef: setMap,
|
|
41
|
+
const { mapRef: setMap, center, zoom, language = "zh" } = props;
|
|
42
|
+
const { fallback, loading } = slots;
|
|
41
43
|
const children = slots.default?.();
|
|
42
44
|
switch (supplier) {
|
|
43
45
|
case "gmap":
|
|
44
46
|
return (
|
|
45
47
|
<GmapLoader
|
|
46
48
|
apiKey={gmapKey}
|
|
49
|
+
language={language}
|
|
47
50
|
version="beta"
|
|
48
51
|
libraries={["marker", "places", "geometry"]}
|
|
49
52
|
loading={loading}
|
|
@@ -78,6 +81,7 @@ export const HeycarMap = defineLagecySetup(function HeycarMap(
|
|
|
78
81
|
>
|
|
79
82
|
<Amap
|
|
80
83
|
mapRef={setMap as SetMap<AMap.Map>}
|
|
84
|
+
vectorMapForeign={language2vectorMapForeign(language)}
|
|
81
85
|
center={center}
|
|
82
86
|
zoom={zoom}
|
|
83
87
|
onDragEnd={amapDebounceEmit}
|
package/src/utils/transform.ts
CHANGED
|
@@ -25,3 +25,13 @@ export const property2emitEventName = (propertyName: string) => {
|
|
|
25
25
|
export const property2mapEventName = (propertyName: string) => {
|
|
26
26
|
return propertyName.slice(2).toLowerCase();
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export type VectorMapForeign = "style_en" | "style_local" | "style_zh_cn";
|
|
30
|
+
export const language2vectorMapForeign = (lang: "en" | "zh"): VectorMapForeign => {
|
|
31
|
+
switch (lang) {
|
|
32
|
+
case "en":
|
|
33
|
+
return "style_en";
|
|
34
|
+
case "zh":
|
|
35
|
+
return "style_zh_cn";
|
|
36
|
+
}
|
|
37
|
+
};
|