Comments (12)
@CodeMonkeyLin 请使用 https://codesandbox.io 提供示例
from react-amap.
from react-amap.
@CodeMonkeyLin 请提供示例
from react-amap.
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>
);
}
from react-amap.
@jaywcjlove https://codesandbox.io/ 我刚才一直打不开,上面的案例直接复制粘贴就可以,麻烦看下,谢谢
from react-amap.
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案例
from react-amap.
@CodeMonkeyLin 你这API 都用错了吧 第二个参数是个 object 对象
from react-amap.
你好,为什么我在ts中使用时,它告诉我
然后我去查看了方法的ts类型
/**
- 用于实现点标记沿线段或者路径轨迹移动的动画基类,可用于满足轨迹回放、实时轨迹等场景。
- MoveAnimation无需单独声明或初始化,Marker、Text、LabelMarker均已继承了 MoveAnimation的实现。
/
class MoveAnimation {
/* 重新启动点标记动画,加载 AMap.MoveAnimation 后可以使用 /
resumeMove(): void;
/* 停止点标记动画,加载 AMap.MoveAnimation 后可以使用 /
stopMove(): void;
/* 开启点标记动画,加载 AMap.MoveAnimation 后可以使用 /
startMove(): void;
/* 以给定时间移动点标记到指定位置,加载 AMap.MoveAnimation 后可以使用 /
moveTo(targetPosition: MoveToOptions, opts?: MoveAlongOptions): void;
}
interface MoveAlongObj { }
type MoveToOptions = {
/* 每段动画持续时长, 单位:ms /
duration?: number;
/* 动画速度,已废弃 /
speed?: number;
/* easing 时间函数 /
easing?: EasingCallback;
/* 覆盖物是否沿路径旋转 /
autoRotation?: boolean;
}
/* 时间函数回调 /
type EasingCallback = (passedTime: number) => number;
/* MoveAnimation 回调函数 /
type AnimationCallback = (index: number, data: LngLat) => number;
interface MoveAlongOptions {
/* 每段动画持续时长, 单位:ms /
duration?: number | AnimationCallback;
/* 每段动画速度,已废弃 /
speed?: number | AnimationCallback;
/* easing 时间函数 /
easing?: EasingCallback;
/* 动画是否循环 /
circlable?: boolean;
/* 延迟动画时长 /
delay?: number | AnimationCallback;
/* 每段完整动画间隔时长 /
aniInterval?: number;
/* 覆盖物是否沿路径旋转 */
autoRotation?: boolean;
}
moveTo()方法的入参类型根本不能传坐标,这和官方给的案例完全是错误的
from react-amap.
@jz-9527 类型复制来源于官网,示例中可以是 坐标参数?
react-amap/packages/types/src/overlay.d.ts
Line 161 in 879d6cd
from react-amap.
高德官网的解释是第一个参数是目标经纬度,第二个参数是时间动画等相关属性的对象,但是在这个插件中使用,ts是完全错误的
from react-amap.
@jz-9527 升级到 v5.0.4
还有问题吗
from react-amap.
换了种实现方式,没试这种了
from react-amap.
Related Issues (20)
- 为什么MassMarks的透明度默认0.8 HOT 2
- Umi引入@uiw/react-amap-mass-marks不生效 HOT 5
- 控制多边形圆形等的内部颜色,边框颜色等,都不是响应式 HOT 3
- 使用数组循环渲染polyline组件,清除数组后发现polyline没有从地图中自动清除 HOT 10
- MassMarkersDataOptions能否添加自定义键值对? HOT 6
- 添加行政区域图层不显示 HOT 1
- 版本5.0.10开始PolygonEditor编辑器失效 HOT 1
- ts5+环境 ,全屏飘红 ,为了效率 建议项目转js HOT 5
- 请问是否支持AMapUI组件库 HOT 1
- 5.0.14 版本 polygon 卸载时失效问题 HOT 5
- ContextMenu导出错误 HOT 1
- 为什么labelMarker的event是小写的,而其他的是大写的 HOT 3
- 点击MarkerCluster聚合点获取的数组长度与实际不符 HOT 2
- polygon,react组件在初始化的时候被销毁,会导致高德地图polygon无法被销毁 HOT 7
- labelMarker应该有默认的icon嘛 HOT 7
- Circle 销毁逻辑无效 HOT 1
- map的clone会导致重复render HOT 5
- 【求助】微前端qiankun子应用中无法打开
- 为什么只要使用任何组件都会出现下面这种报错呢? HOT 2
- API loader 如何添加重试 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-amap.