Open CodeMonkeyLin opened 2 years ago
@CodeMonkeyLin 请使用 https://codesandbox.io 提供示例
我使用moveAlong,一直报这个错
@CodeMonkeyLin 请提供示例
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>
);
}
@jaywcjlove https://codesandbox.io/ 我刚才一直打不开,上面的案例直接复制粘贴就可以,麻烦看下,谢谢
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案例
@CodeMonkeyLin 你这API 都用错了吧 第二个参数是个 object 对象
你好,为什么我在ts中使用时,它告诉我 然后我去查看了方法的ts类型 /**
@jz-9527 类型复制来源于官网,示例中可以是 坐标参数?
高德官网的解释是第一个参数是目标经纬度,第二个参数是时间动画等相关属性的对象,但是在这个插件中使用,ts是完全错误的
@jz-9527 升级到 v5.0.4
还有问题吗
换了种实现方式,没试这种了
marker.moveTo(new AMap.LngLat(116, 38), 200); marker.moveAlong([new AMap.LngLat(116, 38)], 200);