GithubHelp home page GithubHelp logo

pansyjs / react-amap Goto Github PK

View Code? Open in Web Editor NEW
98.0 5.0 17.0 28.94 MB

基于 React 封装的高德地图组件,助你轻松的接入高德地图到 React 项目中。

Home Page: https://amap.xingkang.wang

License: MIT License

TypeScript 99.94% JavaScript 0.01% Less 0.06%
map amap react component react-component typescript

react-amap's Introduction

React AMap

基于 React 封装的高德地图组件,助你轻松的接入高德地图到 React 项目中。

Forks Stars npm version

本仓库提供了常用的地图组件,如不满足您的需求:

  1. 请在 issues 提出需求。
  2. 提 PR 扩展组件。
  3. 使用提供的自定义组件的能力,自己封装。

注意

由于高德APIv1v2兼容性问题,本仓库提供对应的版本

  • v1.x.x 对应 amap v1
  • v2.x.x 对应 amap v2

✨ 特性

  • 📦 开箱即用,封装了大部分常用的地图组件
  • 🎉 可扩展,支持自定义地图组件
  • 💻 使用 TypeScript 编写,提供完善的类型定义,包含高德地图 JS SDK 类型声明

🏗 安装

# npm install
$ npm install @pansy/react-amap --save

# yarn install
$ yarn add @pansy/react-amap

# pnpm install
$ pnpm i @pansy/react-amap

🔨 使用

<div id="app"></div>
#app {
  width: 600px;
  height: 400px;
}
import React from 'react';
import ReactDOM from 'react-dom';
import { Map } from '@pansy/react-amap';

ReactDOM.render(
  <Map mapKey={YOUR_AMAP_KEY} />,
  document.querySelector('#app')
)

🎉 组件列表

地图

名称 说明
APILoader JS API加载
Map 地图组件

图层

名称 说明
Heatmap 热力图
Satellite 卫星图
Traffic 实时交通图层

点标记

名称 说明
ElasticMarker 灵活点标记
Marker 点标记
MarkerCluster 点聚合
MassMarks 海量点类

信息窗体

名称 说明
InfoWindow 信息窗体

右键菜单

名称 说明
ContextMenu 右键菜单

矢量图形

名称 说明
BezierCurve 贝塞尔曲线
Circle 圆形
CircleMarker 圆点标记
Ellipse 椭圆
Polygon 多边形
Polyline 折线
Rectangle 矩形

工具

名称 说明
MouseTool 鼠标工具
RangingTool 距离量测
BezierCurveEditor 贝瑟尔曲线编辑
CircleEditor 圆形编辑
EllipseEditor 椭圆编辑
PolyEditor 折线/多边形编辑
PolygonEditor 多边形编辑
PolylineEditor 折线编辑
RectangleEditor 矩形编辑

地图控件

名称 说明
ControlBar 3D控制组件
HawkEye 地图鹰眼
MapType 地图类型切换
Scale 比例尺
ToolBar 工具条

搜索

名称 说明
AutoComplete 关键字搜索
DistrictSearch 行政区查询

地理编码

名称 说明
Geocoder 地理编码与逆地理编码服务

AMapUI

名称 说明
PathNavigator 轨迹巡航控制
PointSimplifier 海量点展示

Loca

名称 说明
ScatterLayer 动画图层
PulseLinkLayer 连接飞线图层

👥 社区互助

Github Issue 钉钉群 微信群
issues

react-amap's People

Contributors

aiden-leong avatar brain777777 avatar chj-damon avatar renovate-bot avatar wangxingkang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-amap's Issues

判断maker是否在当前地图可视区域内

运用AMap.GeometryUtil.isPointInRing判断是否在地图可视区域内,
const bounds = map.getBounds();
const NorthEast = bounds.getNorthEast();
const SouthWest = bounds.getSouthWest();
const SouthEast = bounds.getSouthEast();
const NorthWest = bounds.getNorthWest();
const mapPath = [NorthEast, SouthEast, SouthWest, NorthWest].map((point) => [
point.lng,
point.lat,
]);
const isPointInRing = AMap.GeometryUtil.isPointInRing(
[record.gps.longitude, record.gps.latitude],
mapPath,
);
if (!isPointInRing) {
map.setZoomAndCenter(5, [record.origin.longitude, record.origin.latitude]);
}
mapPath,里经纬度返回超出正常范围,导致无法定位到当前maker](url),mapPath如下图所示

lQLPJxZn46WUAEbNAQTNA-qwB2F5KhrcP38Cq0dIakD2AA_1002_260

TS类型编译时检查报错

使用环境:

系统:Windows 10 21H2
node版本:v16.13.0
npm版本:8.1.3
npm源:https://registry.npmmirror.com/

问题描述:

我在使用vite作为构建工具进行react-ts项目开发,使用到了@pansy/react-amap。
在运行tsc进行类型检查时@pansy/react-amap发生如下报错:
QQ截图20211203223136.jpg

这里是复现仓库:https://github.com/wuxudongxd/react-amap-demo

复现步骤:

git clone https://github.com/wuxudongxd/react-amap-demo

cd .\react-amap-demo\

npm install

npm run build

问题分析:

vite的react-ts模板中tsconfig.json默认将skipLibCheck设为false,对所有声明文件( *.d.ts)进行了类型检查。
从报错信息来看是 loadUI的类型定义没加返回类型;TileLayer.d.ts 导入Layer.d.ts时首字母小写与文件名不一致。

我暂时通过开启skipLibCheck,跳过对声明文件检查来完成编译。对项目不熟悉加上个人能力有限只能先提个issue,作者大大有时间可以看下是否有调整代码的必要。比心❤️

InfoWindow设置avoid无效

看源代码没有对这个属性传到InfoWindow的option里面,希望可以加上这个属性
image
这里面没有avoid属性
image
image

marker点的extdata属性未更新

const markList = [
{ lnt:111.111,lat:111.111 , id:1, name:'zhangsan' },
{ lnt:112.111,lat:114.111 , id:2, name:'lisi' }
]

	{markList.map(item)=>(
		<Marker
					key={item.id}
					position={item.position}
					extData={item}
					offset={[-25, -25]} // 宽高的一半
					events={{
						click: onClickMark1
					}}
			>
	)}

如果更修改了markList的数据(增加一条/更换数据) 渲染是正常的, 但是在点击mark的时候 通过e.target.w.extData里的数据是上一次的

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/deploy.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • pnpm/action-setup v2
  • peaceiris/actions-gh-pages v3
.github/workflows/test.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • pnpm/action-setup v2.2.4
npm
package.json
  • @ant-design/icons ^5.1.0
  • @types/react ^18.0.31
  • @types/react-dom ^18.0.11
  • @walrus/cli 1.3.4
  • @walrus/commit 1.2.2
  • @walrus/plugin-release 1.14.3
  • antd ^5.11.3
  • lerna ^6.6.2
  • react ^18.2.0
  • react-dom ^18.2.0
  • redbud ^1.6.0
  • typescript ^5.0.4
packages/amap-loca/package.json
  • @pansy/amap-types 2.22.0
  • @pansy/react-amap-core 1.3.14
  • @pansy/react-amap ^2
packages/amap-ui/package.json
  • @pansy/amap-types 2.22.0
  • @pansy/react-amap-core 1.3.14
  • @pansy/react-amap ^2
packages/amap/package.json
  • @pansy/amap-api-loader 0.4.10
  • @pansy/amap-types 2.22.0
  • @pansy/react-amap-core 1.3.14
  • @pansy/use-portal ^0.2.2
packages/api-loader/package.json
  • @pansy/amap-types 2.22.0
packages/core/package.json
  • @pansy/amap-types 2.22.0
packages/types/package.json

  • Check this box to trigger a request for Renovate to run again on this repository

MarkerCluster

        <MarkerCluster
          data={vehicleMarkers}
          render={(props) => {
            return <></>;
          }}
          renderCluster={({ count, list = [] }) => {
            return <Avatar style={{ backgroundColor: '#87d068' }}>{count}</Avatar>;
          }}
        />

redner 方法中,有没有办法传递更多的数据?这边要根据数据添加图标 label

npm install @pansy/react-amap安装时出错

我在安装npm install @pansy/react-amap时出现错误,但是yarn add @pansy/react-amap可以,而项目中必须使用npm。错误信息:
npm error Unable to resolve reference $react

npm error A complete log of this run can be found in: /Users/xzs/.npm/_logs/2024-05-17T00_07_13_897Z-debug-0.log
log文件:
0 verbose cli /usr/local/bin/node /usr/local/bin/npm
1 info using [email protected]
2 info using [email protected]
3 silly config:load:file:/usr/local/lib/node_modules/npm/npmrc
4 silly config:load:file:/Users/xzs/my-hilla-app/.npmrc
5 silly config:load:file:/Users/xzs/.npmrc
6 silly config:load:file:/usr/local/etc/npmrc
7 verbose title npm install @pansy/react-amap
8 verbose argv "install" "@pansy/react-amap"
9 verbose logfile logs-max:10 dir:/Users/xzs/.npm/_logs/2024-05-17T00_07_13_897Z-
10 verbose logfile /Users/xzs/.npm/_logs/2024-05-17T00_07_13_897Z-debug-0.log
11 silly logfile start cleaning logs, removing 1 files
12 silly logfile done cleaning log files
13 silly idealTree buildDeps
14 silly fetch manifest @pansy/react-amap@^2.20.1
15 http fetch GET 200 https://registry.npmjs.org/@pansy%2freact-amap 1136ms (cache revalidated)
16 silly placeDep ROOT @pansy/[email protected] OK for: want: ^2.20.1
17 silly fetch manifest @pansy/[email protected]
18 silly fetch manifest @pansy/[email protected]
19 silly fetch manifest @pansy/[email protected]
20 silly fetch manifest @pansy/use-portal@^0.2.2
21 http fetch GET 200 https://registry.npmjs.org/@pansy%2famap-api-loader 425ms (cache revalidated)
22 http fetch GET 200 https://registry.npmjs.org/@pansy%2fuse-portal 1025ms (cache revalidated)
23 http fetch GET 200 https://registry.npmjs.org/@pansy%2famap-types 1127ms (cache revalidated)
24 http fetch GET 200 https://registry.npmjs.org/@pansy%2freact-amap-core 1477ms (cache revalidated)
25 verbose stack Error: Unable to resolve reference $react
25 verbose stack at get spec (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/edge.js:202:15)
25 verbose stack at #nodeFromEdge (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1054:46)
25 verbose stack at #loadPeerSet (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1320:35)
25 verbose stack at #nodeFromEdge (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1097:29)
25 verbose stack at async #buildDepStep (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:923:11)
25 verbose stack at async Arborist.buildIdealTree (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:203:7)
25 verbose stack at async Promise.all (index 1)
25 verbose stack at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:131:5)
25 verbose stack at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:150:5)
25 verbose stack at async module.exports (/usr/local/lib/node_modules/npm/lib/cli/entry.js:74:5)
26 verbose cwd /Users/xzs/my-hilla-app
27 verbose Darwin 23.4.0
28 verbose node v22.2.0
29 verbose npm v10.7.0
30 error Unable to resolve reference $react
31 verbose exit 1
32 verbose code 1
33 silly unfinished npm timer reify 1715904434074
34 silly unfinished npm timer reify:loadTrees 1715904434076
35 silly unfinished npm timer idealTree:buildDeps 1715904434209
36 silly unfinished npm timer idealTree:node_modules/@pansy/react-amap 1715904436834
37 error A complete log of this run can be found in: /Users/xzs/.npm/_logs/2024-05-17T00_07_13_897Z-debug-0.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.