uiwjs / react-amap

基于 React 封装的高德地图组件,帮助你轻松的接入地图到 React 项目中。
https://uiwjs.github.io/react-amap
MIT License
424 stars 69 forks source link

使用marker轨迹回放的moveAlong直接报错,使用moveTo直接跳到目标位置 #216

Open CodeMonkeyLin opened 2 years ago

CodeMonkeyLin commented 2 years ago

marker.moveTo(new AMap.LngLat(116, 38), 200); marker.moveAlong([new AMap.LngLat(116, 38)], 200);

jaywcjlove commented 2 years ago

@CodeMonkeyLin 请使用 https://codesandbox.io 提供示例

CodeMonkeyLin commented 2 years ago

我使用moveAlong,一直报这个错 image

jaywcjlove commented 2 years ago

@CodeMonkeyLin 请提供示例

CodeMonkeyLin commented 2 years ago
import React, { useEffect, useRef, useState } from 'react';
import ReactDOM from 'react-dom';
import {
  APILoader,
  Provider,
  useMapContext,
  useMap,
  Map,
  Marker,
} from '@uiw/react-amap';
const MapDemo = () => {
  const warpper = useRef(null);
  const { map, state } = useMapContext();
  const { setContainer } = useMap({
    container: warpper.current,
    center: [104.937478, 35.439575],
    zoom: 5,
  });

  useEffect(() => {
    if (warpper.current) {
      setContainer(warpper.current);
    }
  }, [warpper.current]);

  return (
    <div ref={warpper}>
      <Marker
        position={[104.937478, 35.439575]}
        content='<div style="background-color: hsla(180, 100%, 50%, 0.3); height: 18px; width: 18px; border: 1px solid hsl(180, 100%, 40%); border-radius: 12px; box-shadow: hsl(180, 100%, 50%) 0px 0px 3px;"></div>'
        ref={(instance) => {
          if (instance?.marker) {
            console.log(instance?.marker.moveAlong);
            instance?.marker.moveAlong([new AMap.LngLat(116, 38)], 200);
          }
        }}
      ></Marker>
    </div>
  );
};

export default function App() {
  return (
    <div style={{ height: 800 }}>
      <APILoader
        plugin={['AMap.MoveAnimation']}
        akay="a7a90e05a37d3f6bf76d4a9032fc9129"
      >
        <Provider>
          <MapDemo />
        </Provider>
      </APILoader>
    </div>
  );
}
CodeMonkeyLin commented 2 years ago

@jaywcjlove https://codesandbox.io/ 我刚才一直打不开,上面的案例直接复制粘贴就可以,麻烦看下,谢谢

CodeMonkeyLin commented 2 years ago
import React, { useEffect, useRef, useState } from 'react';
import ReactDOM from 'react-dom';
import {
  APILoader,
  Provider,
  useMapContext,
  useMap,
  Map,
  Marker,
} from '@uiw/react-amap';
const MapDemo = () => {
  const warpper = useRef(null);
  const { map, state } = useMapContext();
  const { setContainer } = useMap({
    container: warpper.current,
    center: [104.937478, 35.439575],
    zoom: 5,
  });

  useEffect(() => {
    if (warpper.current) {
      setContainer(warpper.current);
    }
  }, [warpper.current]);

  return (
    <div ref={warpper}>
      <Marker
        position={[104.937478, 35.439575]}
        content='<div style="background-color: hsla(180, 100%, 50%, 0.3); height: 18px; width: 18px; border: 1px solid hsl(180, 100%, 40%); border-radius: 12px; box-shadow: hsl(180, 100%, 50%) 0px 0px 3px;"></div>'
        ref={(instance) => {
          if (instance?.marker) {
            console.log(instance?.marker.moveAlong);
            instance?.marker.moveTo(new AMap.LngLat(116, 38), 200);
          }
        }}
      ></Marker>
    </div>
  );
};

export default function App() {
  return (
    <div style={{ height: 800 }}>
      <APILoader
        plugin={['AMap.MoveAnimation']}
        akay="a7a90e05a37d3f6bf76d4a9032fc9129"
      >
        <Provider>
          <MapDemo />
        </Provider>
      </APILoader>
    </div>
  );
}

这个是moveTo案例

jaywcjlove commented 2 years ago
image

@CodeMonkeyLin 你这API 都用错了吧 第二个参数是个 object 对象

jz-9527 commented 1 year ago

你好,为什么我在ts中使用时,它告诉我 image 然后我去查看了方法的ts类型 /**

jaywcjlove commented 1 year ago

@jz-9527 类型复制来源于官网,示例中可以是 坐标参数?

https://github.com/uiwjs/react-amap/blob/879d6cdd07caf08a394a0d031ad6d645d443ed92/packages/types/src/overlay.d.ts#L161

jz-9527 commented 1 year ago

高德官网的解释是第一个参数是目标经纬度,第二个参数是时间动画等相关属性的对象,但是在这个插件中使用,ts是完全错误的

jaywcjlove commented 1 year ago

@jz-9527 升级到 v5.0.4 还有问题吗

jz-9527 commented 1 year ago

换了种实现方式,没试这种了