npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@uiw/react-baidu-map-with-map

v2.7.2

Published

Baidu Map with-map Components for React.

Downloads

11,334

Readme

withMap

Buy me a coffee npm version Downloads

一个高阶组件,用于将当前上下文的 BMap.Map 实例注入到目标组件中,主要用于实现对地图组件的自定义控制。

import { withMap, APILoader } from '@uiw/react-baidu-map';
// 或者单独安装使用
import withMap from '@uiw/react-baidu-map-with-map';

基本用法

import React from 'react';
import { withMap, APILoader } from '@uiw/react-baidu-map';

class ExampleMap extends React.Component {
  componentDidMount() {
    const { BMap, map, container } = this.props;
    // 启用滚轮放大缩小,默认禁用
    // map.enableScrollWheelZoom();
    // 添加地图类型控件
    map.addControl(new BMap.MapTypeControl({
      mapTypes:[
        BMAP_NORMAL_MAP,
        BMAP_HYBRID_MAP
      ]
    }));
    const point = new BMap.Point(121.458965, 31.238775);
    const marker = new BMap.Marker(point);      // 创建标注
    map.addOverlay(marker);                     // 将标注添加到地图中
    marker.setAnimation(BMAP_ANIMATION_BOUNCE); // 跳动的动画

    // 添加自定义菜单
    const menu = new BMap.ContextMenu()
    const menuItem = [
      { text: '放大', callback: () => map.zoomIn() },
      { text: '缩小', callback: () => map.zoomOut() },
    ]
    for (let i = 0; i < menuItem.length; i++) {
      menu.addItem(new BMap.MenuItem(menuItem[i].text, menuItem[i].callback, 100));
    }
    map.addContextMenu(menu);
  }
  render() {
    return null;
  }
}

const CustomWithMap = withMap(ExampleMap);

const Demo = () => {
  return (
    <div style={{ width: '100%', height: '300px' }}>
      <APILoader akay="eYpCTECSntZmw0WyoQ7zFpCRR9cpgHFG">
        <CustomWithMap
          enableScrollWheelZoom
          zoom={8}
          ref={(instance) => {
            console.log('instance>', instance);
          }}
        />
      </APILoader>
    </div>
  )
};

export default Demo;

高阶组件 withMap 可以作为 Map 组件来使用,继承 Map 可以默认传递 Map 的属性,相关属性参考 <Map>