首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有扩展react-leaflet Map组件来使用leaflet.contextmenu的例子?

有没有扩展react-leaflet Map组件来使用leaflet.contextmenu的例子?
EN

Stack Overflow用户
提问于 2019-11-12 22:29:26
回答 1查看 728关注 0票数 5

react-leaflet-context-menu是leaflet.contextmenu的react版本。但是,它在react中使用了原始的leaflet地图来实现插件,而不是使用react-leaflet。

我在我的应用中采用了react-leaflet,使用的是组件。我通过互联网,但没有多少例子来展示如何正确地扩展地图。

以下是我的应用程序中地图的代码:

代码语言:javascript
复制
<LeafletMap
        ref={m => {this.leafletMap = m;}}
        center={this.state.center}
        zoom={this.state.zoom}
        maxZoom={this.state.maxZoom}
        preferCanvas={this.state.preferCanvas}
        contextmenu={this.state.contextmenu}
        contextmenuWidth={this.state.contextmenuWidth}
        contextmenuItems={this.state.contextmenuItems}>
        <TileLayer
          url={mapsource}
          />
        <MarkerClusterGroup showCoverageOnHover={false} zoomToBoundsOnClick={false} maxClusterRadius={30}>
          {CamMarkers}
        </MarkerClusterGroup>
        <ScaleControl imperial={false} metric={true}/>
</LeafletMap>

我希望通过扩展react-leaflet的组件,它可以直接支持leaflet.contextmenu。props contextmenu、contextmenuWidth、contextmenuItems将被输入到扩展组件中,并在地图上单击鼠标右键时显示一些控件。

EN

回答 1

Stack Overflow用户

发布于 2020-07-17 19:48:14

在你的应用中安装leaflet-contextmenu,然后在你的代码中添加如下内容:

代码语言:javascript
复制
import "leaflet-contextmenu";
import "leaflet-contextmenu/dist/leaflet.contextmenu.css";

看起来不错。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58820699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档