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-ground-overlay

v2.7.1

Published

Baidu Map ground-overlay Components for React.

Downloads

5,941

Readme

GroundOverlay 地面叠加层

Buy me a coffee npm version Downloads

地图上的地面叠加层。

import { GroundOverlay, useGroundOverlay } from '@uiw/react-baidu-map';
// 或者单独安装使用
import GroundOverlay, { useGroundOverlay } from '@uiw/react-baidu-map-ground-overlay';

基本用法

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

const Example = () => {
  const [visiable, setVisiable] = useState(true);
  const bounds = new BMap.Bounds(
    new BMap.Point(116.29579,39.837146),
    new BMap.Point(116.475451,39.9764)
  );
  function groundRef(props) {
    if (props && props.groundOverlay) {
      console.log('groundOverlay:', props.groundOverlay);
    }
  }
  return (
    <>
      <button onClick={() => setVisiable(!visiable)}>{visiable ? '隐藏' : '显示'}</button>
      <Map center="北京" zoom={11} widget={['NavigationControl']} style={{ height: 350 }}>
        {visiable && (
          <GroundOverlay
            ref={groundRef}
            bounds={bounds}
            imageURL="http://lbsyun.baidu.com/jsdemo/img/si-huan.png"
            opacity={1}
            displayOnMinLevel={10}
            displayOnMaxLevel={14}
          />
        )}
      </Map>
    </>
  );
}

const Demo = () => (
  <div style={{ width: '100%' }}>
    <APILoader akay="eYpCTECSntZmw0WyoQ7zFpCRR9cpgHFG">
      <Example />
    </APILoader>
  </div>
);

export default Demo;

使用 hooks

groundOverlay, useGroundOverlay

⚠️ 不知为何 showhide 方法存在但不起作用,理论上是继承 Overlay 类就会有 show()hide() 方法。

import React from 'react';
import { useRef, useEffect, useState } from 'react';
import { Map, Provider, APILoader, useMap, useGroundOverlay } from '@uiw/react-baidu-map';

const Example = () => {
  const divElm = useRef(null);
  const [visiable, setVisiable] = useState(true);
  const bounds = new BMap.Bounds(
    new BMap.Point(116.29579,39.837146),
    new BMap.Point(116.475451,39.9764)
  );
  const { map, setContainer } = useMap({ center: '北京', zoom: 11, widget: ['GeolocationControl', 'NavigationControl'] });
  const { groundOverlay, setGroundOverlay } = useGroundOverlay({ map, bounds, visiable, imageURL: 'http://lbsyun.baidu.com/jsdemo/img/si-huan.png',
    onClick: () => {
      console.log('点击事件!');
    },
  });

  useEffect(() => {
    if (divElm.current) {
      setContainer(divElm.current);
    }
  });
  useEffect(() => {
    if (groundOverlay && map) {
      // 不知为何 方法存在但不起作用,
      // 理论上是继承 Overlay 类就会有 `show` 和 `hide` 方法。
      console.log('groundOverlay:hide:', visiable, groundOverlay.hide);
      console.log('groundOverlay:show:', visiable, groundOverlay.show);
      visiable ? groundOverlay.hide() : groundOverlay.show();
    }
  }, [visiable]);
  return (
    <>
      <button onClick={() => setVisiable(!visiable)}>{visiable ? '隐藏' : '显示'}</button>
      <div ref={divElm} style={{ height: '100%' }} />
    </>
  )
}

const Demo = () => (
  <div style={{ width: '100%', height: '300px' }}>
    <APILoader akay="eYpCTECSntZmw0WyoQ7zFpCRR9cpgHFG">
      <Provider>
        <Example />
      </Provider>
    </APILoader>
  </div>
);

export default Demo;

Props

| 参数 | 说明 | 类型 | 默认值 | | ----- | ----- | ----- | ----- | | bounds | 必填 图层显示的矩形区域 | BMap.Bounds(sw: Point, ne: Point) | - | | imageURL | 必填 图层地址 | string | - | | opacity | 图层透明度 | number | - | | displayOnMinLevel | 图层显示的最小级别 | number | - | | displayOnMaxLevel | 图层显示的最小级别 | number | - |

const bounds = new BMap.Bounds(
  new BMap.Point(116.29579,39.837146),
  new BMap.Point(116.475451,39.9764)
);

事件

| 参数 | 说明 | 类型 | 默认值 | | ----- | ----- | ----- | ----- | | onClick | 鼠标点击图层后会触发此事件 | (event: { type: string, target: any }) => void; | - | | onDblClick | 鼠标双击图层后会触发此事件 | (event: { type: string, target: any }) => void; | - |