@heycar/heycars-map 0.5.8 → 0.6.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/dist/index.js CHANGED
@@ -935,18 +935,6 @@ const pipeOnlyLastEffect = (fn) => {
935
935
  });
936
936
  };
937
937
  };
938
- const geocoderResult2cityName = (value) => {
939
- const { address_components } = value;
940
- const address = address_components.find(
941
- (item) => item.types[0] === "administrative_area_level_1" || item.types[0] === "administrative_area_level_2"
942
- );
943
- if (address)
944
- return address.long_name;
945
- const countryIdx = address_components.findIndex((item) => item.types[0] === "country");
946
- if (countryIdx > 0)
947
- return address_components[countryIdx - 1].long_name;
948
- return void 0;
949
- };
950
938
  const isPlaceEqual = (p1, p2) => {
951
939
  return p1.lng === (p2 == null ? void 0 : p2.lng) && p1.lat === (p2 == null ? void 0 : p2.lat);
952
940
  };
@@ -2111,7 +2099,7 @@ const HeycarMap = defineLagecySetup(function HeycarMap2(props, {
2111
2099
  "disableDoubleClickZoom": touchEnable,
2112
2100
  "gestureHandling": touchEnable ? "auto" : "none",
2113
2101
  "keyboardShortcuts": touchEnable,
2114
- "rotateControl": touchEnable,
2102
+ "rotateControl": false,
2115
2103
  "zoomControl": touchEnable,
2116
2104
  "scaleControl": touchEnable,
2117
2105
  "panControl": touchEnable
@@ -2129,7 +2117,7 @@ const HeycarMap = defineLagecySetup(function HeycarMap2(props, {
2129
2117
  "zoom": zoom,
2130
2118
  "dragEnable": touchEnable,
2131
2119
  "zoomEnable": touchEnable,
2132
- "rotateEnable": touchEnable,
2120
+ "rotateEnable": false,
2133
2121
  "doubleClickZoom": touchEnable,
2134
2122
  "scrollWheel": touchEnable,
2135
2123
  "touchZoom": touchEnable,
@@ -3162,29 +3150,56 @@ const useHeycarMap = () => {
3162
3150
  const { supplier } = useMapSupplier();
3163
3151
  return supplier === "gmap" ? useHeycarGamp() : useHeycarAmap();
3164
3152
  };
3153
+ const DRAGEND_DETECTING_ANIMATION_DELAY = 50;
3165
3154
  const useAmapDrag = (props) => {
3166
3155
  const { mapRef, onChange } = props;
3167
3156
  const centerRef = ref([0, 0]);
3168
3157
  const isDragging = ref(false);
3158
+ const isDragEndWaitingMovingEndRef = ref(false);
3159
+ let watchId = void 0;
3169
3160
  const emitDragStart = () => {
3170
3161
  pipeAsync(() => {
3171
3162
  isDragging.value = true;
3172
3163
  })();
3173
3164
  };
3174
- const emitDragEnd = (_, { target }) => {
3165
+ const handleDragEndWithAnimationEnd = (target) => {
3175
3166
  var _a;
3167
+ isDragEndWaitingMovingEndRef.value = false;
3176
3168
  isDragging.value = false;
3177
3169
  const { lng, lat } = target.getCenter();
3178
- spaceLog("dragEnd", "[lng, lat] = ", [lng, lat]);
3170
+ spaceLog("onDragEndWithAnimationEnd", "[lng, lat] = ", [lng, lat]);
3179
3171
  centerRef.value = [lng, lat];
3180
3172
  (_a = pipeAsync(onChange)) == null ? void 0 : _a([lng, lat]);
3181
3173
  };
3174
+ const emitDragEnd = (_, { target }) => {
3175
+ const { lng: baseLng, lat: baseLat } = target.getCenter();
3176
+ isDragEndWaitingMovingEndRef.value = true;
3177
+ if (watchId)
3178
+ clearTimeout(watchId);
3179
+ watchId = setTimeout(() => {
3180
+ watchId = void 0;
3181
+ const { lng, lat } = target.getCenter();
3182
+ if (!isDragEndWaitingMovingEndRef.value)
3183
+ return;
3184
+ if (baseLng !== lng || baseLat !== lat)
3185
+ return;
3186
+ handleDragEndWithAnimationEnd(target);
3187
+ }, DRAGEND_DETECTING_ANIMATION_DELAY);
3188
+ };
3189
+ const handleMoveEnd = (_, { target }) => {
3190
+ if (!isDragEndWaitingMovingEndRef.value)
3191
+ return;
3192
+ handleDragEndWithAnimationEnd(target);
3193
+ };
3182
3194
  watchPostEffectForAMapEvent(mapRef, {}, emitDragStart, [
3183
3195
  "onDragStart"
3184
3196
  ]);
3185
3197
  watchPostEffectForAMapEvent(mapRef, {}, emitDragEnd, [
3186
3198
  "onDragEnd"
3187
3199
  ]);
3200
+ watchPostEffectForAMapEvent(mapRef, {}, handleMoveEnd, [
3201
+ "onMoveend"
3202
+ ]);
3188
3203
  return { centerRef, isDragging };
3189
3204
  };
3190
3205
  const useGmapDrag = (props) => {
@@ -3225,7 +3240,7 @@ const useUpdate = () => {
3225
3240
  return { idx, update };
3226
3241
  };
3227
3242
  const useAmapPlace = (props) => {
3228
- const { onChange, onChangeCity, emptyPlaceName } = props;
3243
+ const { onChange, emptyPlaceName } = props;
3229
3244
  const defaultPoint = [...props.pointRef.value];
3230
3245
  const pointRef = ref(defaultPoint);
3231
3246
  const { readyPromise } = useMapSupplier();
@@ -3235,19 +3250,6 @@ const useAmapPlace = (props) => {
3235
3250
  name: ""
3236
3251
  });
3237
3252
  const { idx: placeKey, update } = useUpdate();
3238
- const updateCity = (value) => {
3239
- const geocoder = new AMap.Geocoder({ lang: LANGUAGE });
3240
- const { lng, lat } = value;
3241
- geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
3242
- if (status !== "complete")
3243
- return;
3244
- const { formattedAddress, addressComponent } = result.regeocode;
3245
- const name = formattedAddress ? formattedAddress : emptyPlaceName;
3246
- const cityName = addressComponent.city ? addressComponent.city : addressComponent.province;
3247
- const cityParentName = addressComponent.province;
3248
- onChangeCity == null ? void 0 : onChangeCity({ name, lng, lat, cityName, cityParentName, countryName: "" });
3249
- });
3250
- };
3251
3253
  const updatePlace = (value) => {
3252
3254
  pointRef.value = value;
3253
3255
  update();
@@ -3266,15 +3268,12 @@ const useAmapPlace = (props) => {
3266
3268
  geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
3267
3269
  switch (status) {
3268
3270
  case "complete": {
3269
- const { formattedAddress, addressComponent } = result.regeocode;
3270
- const cityName = addressComponent.city ? addressComponent.city : addressComponent.province;
3271
- const cityParentName = addressComponent.province;
3271
+ const { formattedAddress } = result.regeocode;
3272
3272
  const name = formattedAddress ? formattedAddress : emptyPlaceName;
3273
3273
  place.name = name;
3274
3274
  place.lng = lng;
3275
3275
  place.lat = lat;
3276
3276
  onChange == null ? void 0 : onChange({ lng, lat, name });
3277
- onChangeCity == null ? void 0 : onChangeCity({ name, lng, lat, cityName, cityParentName, countryName: "" });
3278
3277
  return;
3279
3278
  }
3280
3279
  case "no_data":
@@ -3282,14 +3281,6 @@ const useAmapPlace = (props) => {
3282
3281
  place.lng = lng;
3283
3282
  place.lat = lat;
3284
3283
  onChange == null ? void 0 : onChange({ lng, lat, name: "" });
3285
- onChangeCity == null ? void 0 : onChangeCity({
3286
- name: "",
3287
- lng,
3288
- lat,
3289
- cityName: "",
3290
- cityParentName: "",
3291
- countryName: ""
3292
- });
3293
3284
  return;
3294
3285
  case "error":
3295
3286
  throw result;
@@ -3297,10 +3288,10 @@ const useAmapPlace = (props) => {
3297
3288
  });
3298
3289
  }
3299
3290
  );
3300
- return { place, updatePlace, setPlace, updateCity };
3291
+ return { place, updatePlace, setPlace };
3301
3292
  };
3302
3293
  const useGmapPlace = (props) => {
3303
- const { onChange, onChangeCity, emptyPlaceName } = props;
3294
+ const { onChange, emptyPlaceName } = props;
3304
3295
  const defaultPoint = [...props.pointRef.value];
3305
3296
  const pointRef = ref(defaultPoint);
3306
3297
  const { readyPromise } = useMapSupplier();
@@ -3319,16 +3310,6 @@ const useGmapPlace = (props) => {
3319
3310
  place.lat = value.lat;
3320
3311
  place.name = value.name;
3321
3312
  };
3322
- const updateCity = async (value) => {
3323
- const geocoder = new google.maps.Geocoder();
3324
- const { lng, lat } = value;
3325
- const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
3326
- const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
3327
- const cityName = geocoderResult2cityName(results[0]);
3328
- const cityParentName = results.slice(-2)[0].address_components[0].long_name;
3329
- const countryName = results.slice(-1)[0].address_components[0].long_name;
3330
- onChangeCity == null ? void 0 : onChangeCity({ name, lng, lat, cityName, cityParentName, countryName });
3331
- };
3332
3313
  watch(
3333
3314
  () => placeKey.value,
3334
3315
  async () => {
@@ -3337,17 +3318,13 @@ const useGmapPlace = (props) => {
3337
3318
  const [lng, lat] = pointRef.value;
3338
3319
  const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
3339
3320
  const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
3340
- const cityName = geocoderResult2cityName(results[0]);
3341
- const cityParentName = results.slice(-2)[0].address_components[0].long_name;
3342
- const countryName = results.slice(-1)[0].address_components[0].long_name;
3343
3321
  place.lng = lng;
3344
3322
  place.lat = lat;
3345
3323
  place.name = name;
3346
3324
  onChange == null ? void 0 : onChange({ lng, lat, name });
3347
- onChangeCity == null ? void 0 : onChangeCity({ name, lng, lat, cityName, cityParentName, countryName });
3348
3325
  }
3349
3326
  );
3350
- return { place, updatePlace, setPlace, updateCity };
3327
+ return { place, updatePlace, setPlace };
3351
3328
  };
3352
3329
  const useMapPlace = (props) => {
3353
3330
  const { supplier } = useMapSupplier();
@@ -3378,25 +3355,15 @@ const findGmapNearestPlace = (place, candidates) => {
3378
3355
  return { shortestPlace, shortestDistance };
3379
3356
  };
3380
3357
  const useAmapRecomendPlace = (props) => {
3381
- const {
3382
- pointRef,
3383
- getRecomendPlace,
3384
- getLimit,
3385
- context: context2,
3386
- emptyPlaceName,
3387
- onChange,
3388
- onChangePlace,
3389
- onChangeCity
3390
- } = props;
3358
+ const { pointRef, getRecomendPlace, getLimit, context: context2, emptyPlaceName, onChange, onChangePlace } = props;
3391
3359
  const availableRef = ref(true);
3392
3360
  const placeCandidatesRef = ref([]);
3393
3361
  const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
3394
3362
  const { readyPromise } = useMapSupplier();
3395
- const { place, updatePlace, setPlace, updateCity } = useAmapPlace({
3363
+ const { place, updatePlace, setPlace } = useAmapPlace({
3396
3364
  emptyPlaceName,
3397
3365
  pointRef,
3398
- onChange: onChangePlace,
3399
- onChangeCity
3366
+ onChange: onChangePlace
3400
3367
  });
3401
3368
  const recomendPlace = reactive({ ...place });
3402
3369
  const isElectedRef = computed(() => {
@@ -3439,30 +3406,19 @@ const useAmapRecomendPlace = (props) => {
3439
3406
  updateRecomandPlace,
3440
3407
  updatePlaceCandidates,
3441
3408
  updatePlace,
3442
- setPlace,
3443
- updateCity
3409
+ setPlace
3444
3410
  };
3445
3411
  };
3446
3412
  const useGmapRecomendPlace = (props) => {
3447
- const {
3448
- pointRef,
3449
- getRecomendPlace,
3450
- getLimit,
3451
- context: context2,
3452
- emptyPlaceName,
3453
- onChange,
3454
- onChangePlace,
3455
- onChangeCity
3456
- } = props;
3413
+ const { pointRef, getRecomendPlace, getLimit, context: context2, emptyPlaceName, onChange, onChangePlace } = props;
3457
3414
  const availableRef = ref(true);
3458
3415
  const placeCandidatesRef = ref([]);
3459
3416
  const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
3460
3417
  const { readyPromise } = useMapSupplier();
3461
- const { place, updatePlace, setPlace, updateCity } = useGmapPlace({
3418
+ const { place, updatePlace, setPlace } = useGmapPlace({
3462
3419
  emptyPlaceName,
3463
3420
  pointRef,
3464
- onChange: onChangePlace,
3465
- onChangeCity
3421
+ onChange: onChangePlace
3466
3422
  });
3467
3423
  const recomendPlace = reactive({ ...place });
3468
3424
  const isElectedRef = computed(() => {
@@ -3505,8 +3461,7 @@ const useGmapRecomendPlace = (props) => {
3505
3461
  updateRecomandPlace,
3506
3462
  updatePlaceCandidates,
3507
3463
  updatePlace,
3508
- setPlace,
3509
- updateCity
3464
+ setPlace
3510
3465
  };
3511
3466
  };
3512
3467
  const useMapRecomendPlace = (props) => {
@@ -3556,25 +3511,6 @@ const useMapZoom = (props) => {
3556
3511
  const { supplier } = useMapSupplier();
3557
3512
  return supplier === "gmap" ? useGmapZoom(props) : useAmapZoom(props);
3558
3513
  };
3559
- const useWaitTimer = (props) => {
3560
- const { interval } = props;
3561
- let timer = void 0;
3562
- const timerStop = {
3563
- promise: Promise.resolve(),
3564
- resolve: void 0
3565
- };
3566
- const timerStart = () => {
3567
- var _a;
3568
- if (timer)
3569
- clearTimeout(timer);
3570
- (_a = timerStop.resolve) == null ? void 0 : _a.call(timerStop);
3571
- timerStop.promise = new Promise((resolve) => {
3572
- timerStop.resolve = resolve;
3573
- timer = setTimeout(resolve, interval);
3574
- });
3575
- };
3576
- return { timerStart, timerStop };
3577
- };
3578
3514
  const imgPassengerCircle = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjEiIGhlaWdodD0iNjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzPjxmaWx0ZXIgeD0iLTcuMSUiIHk9Ii03LjElIiB3aWR0aD0iMTE0LjMlIiBoZWlnaHQ9IjExNC4zJSIgZmlsdGVyVW5pdHM9Im9iamVjdEJvdW5kaW5nQm94IiBpZD0icHJlZml4X19hIj48ZmVPZmZzZXQgaW49IlNvdXJjZUFscGhhIiByZXN1bHQ9InNoYWRvd09mZnNldE91dGVyMSIvPjxmZUdhdXNzaWFuQmx1ciBzdGREZXZpYXRpb249Ii41IiBpbj0ic2hhZG93T2Zmc2V0T3V0ZXIxIiByZXN1bHQ9InNoYWRvd0JsdXJPdXRlcjEiLz48ZmVDb21wb3NpdGUgaW49InNoYWRvd0JsdXJPdXRlcjEiIGluMj0iU291cmNlQWxwaGEiIG9wZXJhdG9yPSJvdXQiIHJlc3VsdD0ic2hhZG93Qmx1ck91dGVyMSIvPjxmZUNvbG9yTWF0cml4IHZhbHVlcz0iMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMC4yNzc0NTMwMTYgMCIgaW49InNoYWRvd0JsdXJPdXRlcjEiLz48L2ZpbHRlcj48Y2lyY2xlIGlkPSJwcmVmaXhfX2IiIGN4PSIzMCIgY3k9IjMwIiByPSIxMC41Ii8+PC9kZWZzPjxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKC40MDUgLjI2NCkiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+PGNpcmNsZSBzdHJva2Utb3BhY2l0eT0iLjEiIHN0cm9rZT0iIzAwM0RGRiIgZmlsbC1vcGFjaXR5PSIuMTUiIGZpbGw9IiM0ODczRkUiIGN4PSIzMCIgY3k9IjMwIiByPSIyOS41Ii8+PHVzZSBmaWxsPSIjMDAwIiBmaWx0ZXI9InVybCgjcHJlZml4X19hKSIgeGxpbms6aHJlZj0iI3ByZWZpeF9fYiIvPjxjaXJjbGUgc3Ryb2tlPSIjRkZGIiBzdHJva2Utd2lkdGg9IjIuNCIgc3Ryb2tlLWxpbmVqb2luPSJzcXVhcmUiIGZpbGw9IiM0ODcxRjEiIGN4PSIzMCIgY3k9IjMwIiByPSI5LjMiLz48L2c+PC9zdmc+";
3579
3515
  const imgPassengerSmall = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjgiIGhlaWdodD0iMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzPjxmaWx0ZXIgeD0iLTMwJSIgeT0iLTMwJSIgd2lkdGg9IjE2MCUiIGhlaWdodD0iMTYwJSIgZmlsdGVyVW5pdHM9Im9iamVjdEJvdW5kaW5nQm94IiBpZD0icHJlZml4X19hIj48ZmVPZmZzZXQgaW49IlNvdXJjZUFscGhhIiByZXN1bHQ9InNoYWRvd09mZnNldE91dGVyMSIvPjxmZUdhdXNzaWFuQmx1ciBzdGREZXZpYXRpb249IjIiIGluPSJzaGFkb3dPZmZzZXRPdXRlcjEiIHJlc3VsdD0ic2hhZG93Qmx1ck91dGVyMSIvPjxmZUNvbXBvc2l0ZSBpbj0ic2hhZG93Qmx1ck91dGVyMSIgaW4yPSJTb3VyY2VBbHBoYSIgb3BlcmF0b3I9Im91dCIgcmVzdWx0PSJzaGFkb3dCbHVyT3V0ZXIxIi8+PGZlQ29sb3JNYXRyaXggdmFsdWVzPSIwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwLjI0IDAiIGluPSJzaGFkb3dCbHVyT3V0ZXIxIi8+PC9maWx0ZXI+PGNpcmNsZSBpZD0icHJlZml4X19iIiBjeD0iMTU3IiBjeT0iMzUyIiByPSIxMCIvPjwvZGVmcz48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMTQzIC0zMzgpIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjx1c2UgZmlsbD0iIzAwMCIgZmlsdGVyPSJ1cmwoI3ByZWZpeF9fYSkiIHhsaW5rOmhyZWY9IiNwcmVmaXhfX2IiLz48Y2lyY2xlIHN0cm9rZT0iI0ZGRiIgc3Ryb2tlLXdpZHRoPSIyLjQiIHN0cm9rZS1saW5lam9pbj0ic3F1YXJlIiBmaWxsPSIjNDg3MUYxIiBjeD0iMTU3IiBjeT0iMzUyIiByPSI4LjgiLz48L2c+PC9zdmc+";
3580
3516
  const PassengerCircle_css_ts_vanilla = "";
@@ -3908,7 +3844,6 @@ const useFirstWorkflowRecomendLoading = () => {
3908
3844
  };
3909
3845
  const RECOMMEND_PLACE_DRAG_LIMIT = 10;
3910
3846
  const RECOMMEND_PLACE_LARGE_LIMIT = 100;
3911
- const MAP_DRAG_END_WAIT_ANIMATION = 500;
3912
3847
  const RECOMMEND_PLACE_ZOOM_MIN = 13;
3913
3848
  const DEFAULT_PLACE_NAME = "当前位置";
3914
3849
  const DEFAULT_ZOOM = 8;
@@ -3922,6 +3857,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
3922
3857
  geoDefaultPosition,
3923
3858
  getRecomendPlace,
3924
3859
  getDefaultCenterPlace,
3860
+ onChangePlace,
3925
3861
  mapContext
3926
3862
  } = props;
3927
3863
  const pipedGetRecomendPlace = pipeOnlyLastEffect(getRecomendPlace);
@@ -3940,12 +3876,6 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
3940
3876
  mapRef,
3941
3877
  defaultValue: DEFAULT_ZOOM
3942
3878
  });
3943
- const {
3944
- timerStart,
3945
- timerStop
3946
- } = useWaitTimer({
3947
- interval: MAP_DRAG_END_WAIT_ANIMATION
3948
- });
3949
3879
  const {
3950
3880
  isFirstWorkflowRecomendLoadingRef,
3951
3881
  completeFirstWorkflowRecomend
@@ -3968,7 +3898,9 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
3968
3898
  centerPlace.lng = place.lng;
3969
3899
  centerPlace.lat = place.lat;
3970
3900
  centerPlace.name = place.name;
3971
- updateCity(place);
3901
+ onChangePlace == null ? void 0 : onChangePlace({
3902
+ ...place
3903
+ });
3972
3904
  updatePlaceCandidates(place);
3973
3905
  await pipeDefer(setZoom)(READY_ZOOM);
3974
3906
  };
@@ -4024,14 +3956,12 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
4024
3956
  mapRef,
4025
3957
  onChange: (point) => {
4026
3958
  centerSource.source = "drag";
4027
- timerStart();
4028
3959
  updatePlace(point);
4029
3960
  emit("changeByDrag", point);
4030
3961
  }
4031
3962
  });
4032
3963
  const {
4033
3964
  updatePlace,
4034
- updateCity,
4035
3965
  updateRecomandPlace,
4036
3966
  updatePlaceCandidates,
4037
3967
  placeCandidates,
@@ -4062,7 +3992,6 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
4062
3992
  emit("changePlace", place);
4063
3993
  },
4064
3994
  onChange: async (place) => {
4065
- await timerStop.promise;
4066
3995
  centerSource.source = "recomend";
4067
3996
  Object.assign(centerPlace, {
4068
3997
  ...place
@@ -4072,9 +4001,6 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
4072
4001
  if (isFirstWorkflowRecomendLoadingRef.value)
4073
4002
  await pipeDefer(setZoom)(READY_ZOOM);
4074
4003
  completeFirstWorkflowRecomend();
4075
- },
4076
- onChangeCity: (value) => {
4077
- emit("changeCity", value);
4078
4004
  }
4079
4005
  });
4080
4006
  watchEffect(() => {
@@ -4640,6 +4566,7 @@ const SectionDriverStartService = defineSetup(function SectionDriverStartService
4640
4566
  distance,
4641
4567
  duration
4642
4568
  }) => {
4569
+ var _a;
4643
4570
  spaceLog("angleDifference", "carPosition, routeAngle, driverAngle = ", carPosition, angle, carAngle);
4644
4571
  return [h(DrivingLine, {
4645
4572
  "attrs": {
@@ -4647,7 +4574,7 @@ const SectionDriverStartService = defineSetup(function SectionDriverStartService
4647
4574
  }
4648
4575
  }), h(TaxiCar, {
4649
4576
  "attrs": {
4650
- "position": carPosition,
4577
+ "position": (_a = path[0]) != null ? _a : carPosition,
4651
4578
  "angle": angle,
4652
4579
  "title": renderTitle({
4653
4580
  distance,
@@ -4860,6 +4787,7 @@ const SectionInService = defineSetup(function SectionInService2(props) {
4860
4787
  distance,
4861
4788
  duration
4862
4789
  }) => {
4790
+ var _a;
4863
4791
  spaceLog("angleDifference", "carPosition, routeAngle, driverAngle = ", carPosition, angle, carAngle);
4864
4792
  return [h(DrivingLine, {
4865
4793
  "attrs": {
@@ -4867,7 +4795,7 @@ const SectionInService = defineSetup(function SectionInService2(props) {
4867
4795
  }
4868
4796
  }), h(TaxiCar, {
4869
4797
  "attrs": {
4870
- "position": carPosition,
4798
+ "position": (_a = path[0]) != null ? _a : carPosition,
4871
4799
  "angle": angle,
4872
4800
  "title": renderTitle({
4873
4801
  distance,
@@ -5188,193 +5116,6 @@ const BusinessTaxiServiceMap = defineLagecySetup(function BusinessTaxiServiceMap
5188
5116
  )]);
5189
5117
  };
5190
5118
  }).props(["bookDispatchingTitle", "dispatchingTitle", "driverArrivedTitle", "driverStatus", "fallback", "from", "getDriverPosition", "interval", "loading", "mapRef", "renderInServiceTitle", "renderStartSerivceTitle", "to", "registerOverlay"]);
5191
- const useAmapAutoComplete = (props) => {
5192
- const { city } = props;
5193
- const cityRef = ref(city);
5194
- const { readyPromise } = useMapSupplier();
5195
- const { apiMapDistance } = useMapGeometry();
5196
- const { geoPosition } = useGeoLocation();
5197
- const keywordRef = ref("");
5198
- const autoCompletePlacesRef = ref([]);
5199
- const { update, idx: updateKey } = useUpdate();
5200
- const setCity = (value) => {
5201
- cityRef.value = value;
5202
- update();
5203
- };
5204
- const setKeyword = (value) => {
5205
- keywordRef.value = value;
5206
- update();
5207
- };
5208
- watch(
5209
- () => updateKey.value,
5210
- async () => {
5211
- if (!keywordRef.value)
5212
- return;
5213
- await readyPromise;
5214
- const amapPlaceSearch = new AMap.PlaceSearch({ city: cityRef.value.name });
5215
- amapPlaceSearch.search(keywordRef.value, (status, result) => {
5216
- const from = geoPosition.value;
5217
- switch (status) {
5218
- case "complete": {
5219
- autoCompletePlacesRef.value = result.poiList.pois.map(
5220
- (poi) => {
5221
- const { lat, lng } = poi.location;
5222
- return {
5223
- lat,
5224
- lng,
5225
- name: poi.name,
5226
- description: poi.address,
5227
- distance: from ? apiMapDistance(from, [lng, lat]) : void 0
5228
- };
5229
- }
5230
- );
5231
- return;
5232
- }
5233
- case "no_data":
5234
- autoCompletePlacesRef.value = [];
5235
- return;
5236
- default:
5237
- throw result;
5238
- }
5239
- });
5240
- },
5241
- {
5242
- immediate: true
5243
- }
5244
- );
5245
- return { setKeyword, setCity, autoCompletePlaces: autoCompletePlacesRef };
5246
- };
5247
- const useGmapAutoComplete = (props) => {
5248
- const { city } = props;
5249
- const cityRef = ref({ ...city });
5250
- const { readyPromise } = useMapSupplier();
5251
- const { apiMapDistance } = useMapGeometry();
5252
- const { geoPosition } = useGeoLocation();
5253
- const keywordRef = ref("");
5254
- const autoCompletePlacesRef = ref([]);
5255
- const { update, idx: updateKey } = useUpdate();
5256
- const setCity = (value) => {
5257
- cityRef.value = value;
5258
- update();
5259
- };
5260
- const setKeyword = (value) => {
5261
- keywordRef.value = value;
5262
- update();
5263
- };
5264
- const div = document.createElement("div");
5265
- watch(
5266
- () => updateKey.value,
5267
- async () => {
5268
- if (!keywordRef.value)
5269
- return;
5270
- await readyPromise;
5271
- const gmapPlacesService = new google.maps.places.PlacesService(div);
5272
- gmapPlacesService.textSearch(
5273
- {
5274
- query: keywordRef.value,
5275
- bounds: cityRef.value.bound
5276
- },
5277
- (result, status) => {
5278
- const from = geoPosition.value;
5279
- switch (status) {
5280
- case google.maps.places.PlacesServiceStatus.OK:
5281
- autoCompletePlacesRef.value = result.map(({ geometry, name, formatted_address }) => {
5282
- var _a, _b, _c, _d;
5283
- const lng = (_b = (_a = geometry == null ? void 0 : geometry.location) == null ? void 0 : _a.lng()) != null ? _b : 0;
5284
- const lat = (_d = (_c = geometry == null ? void 0 : geometry.location) == null ? void 0 : _c.lat()) != null ? _d : 0;
5285
- return {
5286
- lng,
5287
- lat,
5288
- name: name != null ? name : "",
5289
- description: formatted_address != null ? formatted_address : "",
5290
- distance: from ? apiMapDistance(from, [lng, lat]) : void 0
5291
- };
5292
- });
5293
- return;
5294
- case google.maps.places.PlacesServiceStatus.ZERO_RESULTS:
5295
- case google.maps.places.PlacesServiceStatus.NOT_FOUND:
5296
- autoCompletePlacesRef.value = [];
5297
- return;
5298
- }
5299
- }
5300
- );
5301
- }
5302
- );
5303
- return { setKeyword, setCity, autoCompletePlaces: autoCompletePlacesRef };
5304
- };
5305
- const useMapAutoComplete = (props) => {
5306
- const { supplier } = useMapSupplier();
5307
- return supplier === "gmap" ? useGmapAutoComplete(props) : useAmapAutoComplete(props);
5308
- };
5309
- const useAmapBoundCity = (props) => {
5310
- var _a;
5311
- const { cityNameRef, onChange } = props;
5312
- const city = reactive({ name: (_a = cityNameRef.value) != null ? _a : "" });
5313
- watch(
5314
- () => cityNameRef.value,
5315
- (cityName) => {
5316
- const name = cityName != null ? cityName : "";
5317
- city.name = name;
5318
- onChange == null ? void 0 : onChange({ name });
5319
- }
5320
- );
5321
- return city;
5322
- };
5323
- const useGmapBoundCity = (props) => {
5324
- var _a;
5325
- const { cityNameRef, onChange } = props;
5326
- const { readyPromise } = useMapSupplier();
5327
- const city = reactive({
5328
- name: (_a = cityNameRef.value) != null ? _a : "",
5329
- bound: {
5330
- east: 0,
5331
- north: 0,
5332
- south: 0,
5333
- west: 0
5334
- }
5335
- });
5336
- watchEffect(async () => {
5337
- var _a2, _b;
5338
- const cityName = cityNameRef.value;
5339
- if (!cityName)
5340
- return;
5341
- await readyPromise;
5342
- const geocoder = new google.maps.Geocoder();
5343
- const { results } = await geocoder.geocode({
5344
- address: cityName,
5345
- componentRestrictions: {
5346
- administrativeArea: "administrative_area_level_1"
5347
- },
5348
- language: LANGUAGE
5349
- });
5350
- if (results.length !== 1) {
5351
- throw new Error("MyError: multiple city found");
5352
- }
5353
- const { geometry } = results[0];
5354
- const cityBound = (_b = (_a2 = geometry.bounds) == null ? void 0 : _a2.toJSON()) != null ? _b : geometry.viewport.toJSON();
5355
- city.name = cityName;
5356
- city.bound = cityBound;
5357
- onChange == null ? void 0 : onChange({ name: cityName, bound: cityBound });
5358
- });
5359
- return city;
5360
- };
5361
- const useMapBoundCity = (props) => {
5362
- const { supplier } = useMapSupplier();
5363
- return supplier === "gmap" ? useGmapBoundCity(props) : useAmapBoundCity(props);
5364
- };
5365
- const useBusinessMapAutoComplete = (props) => {
5366
- const { cityNameRef } = props;
5367
- const city = useMapBoundCity({
5368
- cityNameRef,
5369
- onChange: (v) => setCity(v)
5370
- });
5371
- const { autoCompletePlaces, setKeyword, setCity } = useMapAutoComplete({ city });
5372
- const handleKeywordInput = (e) => {
5373
- const target = e.target;
5374
- setKeyword(target.value);
5375
- };
5376
- return { autoCompletePlaces, setKeyword, setCity, handleKeywordInput };
5377
- };
5378
5119
  const useBusinessQuotingMap = () => {
5379
5120
  const { setMap, mapRef } = useHeycarMap();
5380
5121
  const { registerFitVeiw, setFitView } = useMapFitView({
@@ -5444,7 +5185,6 @@ export {
5444
5185
  WalkingLine,
5445
5186
  WalkingRoute,
5446
5187
  WaveCircle,
5447
- useBusinessMapAutoComplete,
5448
5188
  useBusinessQuotingMap,
5449
5189
  useBusinessRecomendPlaceMap,
5450
5190
  useBusinessTaxiServiceMap,
@@ -6,23 +6,6 @@ export type Place = {
6
6
  lng: number;
7
7
  lat: number;
8
8
  name: string;
9
- cityName?: string;
10
- cityParentName?: string;
11
- countryName?: string;
12
- };
13
- export interface AutoCompletePlace extends Place {
14
- placeId?: string;
15
- description: string;
16
- distance?: number;
17
- }
18
- export type Region = {
19
- bound?: {
20
- east: number;
21
- north: number;
22
- south: number;
23
- west: number;
24
- };
25
- name: string;
26
9
  };
27
10
  export interface RegisterOverlay<T> {
28
11
  add: (overlay: T) => void;
@@ -14,6 +14,5 @@ export declare const place2point: (place: Place) => Point;
14
14
  export declare const pipeAsync: <P extends any[]>(fn?: ((...args: P) => any) | undefined) => (...args: P) => void;
15
15
  export declare const pipeDefer: <P extends any[], R>(fn: (...args: P) => R) => (...args: P) => Promise<R>;
16
16
  export declare const pipeOnlyLastEffect: <P extends any[], R>(fn: (...arg: P) => Promise<R>) => (...args: P) => Promise<R>;
17
- export declare const geocoderResult2cityName: (value: google.maps.GeocoderResult) => string | undefined;
18
17
  export declare const isPlaceEqual: (p1: Place, p2?: Place) => boolean;
19
18
  export declare const isPointEqual: (p1: Point, p2?: Point) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",
package/todo.md CHANGED
@@ -101,3 +101,8 @@ https://dawchihliou.github.io/articles/building-custom-google-maps-marker-react-
101
101
  0.5.6
102
102
 
103
103
  - 5455
104
+
105
+ 0.5.9
106
+
107
+ - 5500
108
+ - 5524