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

qh-map

v0.9.9

Published

A Easy Gaode Map Component for React, Support Lazy load

Downloads

5

Readme

qh-map

A Easy Gaode Map Component for React, Support Lazy load (Build on the Gaode Map SDK)

Installation

npm install qh-map --save 

or

yarn add qh-map

Lazy Load

Now qh-map support real lazy-load feature, the map instance will be initilized right now once the script is loaded!

  // part of source code (helper.js)
  const script = document.createElement('script');
  script.src = url;
  script.defer = 'defer';
  script.onload = () => {
    callback && callback();
  }

you can specify the url props to instead of default script url.

How Does It Work?

See the Chinese Readme: 中文

When You Want to Use a Map to Locate Sitiation, Just Write Component in your render function, like this:

  import Map from "qh-map";
  
  export default class Demo extends React.Component {
    state = {
      longitude: 0,
      latitude: 0
    }
    render() {
      const { longitude, latitude } = this.state;
      return (
        <div>
          <span>longitude: { longitude }<span>
          <span>latitude:  { latitude }<span>

          <Map
            position={[113.326548, 23.125821]} 
            wrapClassName='map-box'
            style={{ 
              width: 1000,
              height: 400, 
              border: "2px solid purple" 
            }}
            errorTips={errorMsg => { 
              console.log(errorMsg); 
            }}
            handleSearchAddress={([longitude, latitude]) => {
              console.log('you will got location:', [longitude, latitude]);
              this.setState({ longitude, latitude });
            }}
            url='https://webapi.amap.com/maps?v=1.4.15&key=your_key' // [NEW] once you pass this params, it will load script from the url instead of default
            plugins={
              toolbar: true,  // [NEW] toolbar plugin on the map left
              scale: false,   // [NEW] scale plugin on the map right-bottom
              overview: false // [NEW] overview plugin
            }
          >
        </div>
      )
    }
  }

And the position props help to initialize component with a begin position, with a format like [longitude, latitude], and then the map should locate the position, and set a marker in center position in this . errorTips props is a useful props to help to show some tips when this component run with some errors, it is not necessary. The handleSearchAddress supply locate result to outter component, the params for callback is as same as position props, you will get [longitude, latitude] finally;

Props:

  • position: initial center position (required)
  • wrapClassName: pass on className for map container style (non-required)
  • style: higher level style for map container style (non-required)
  • errorTips: show error message callback function (non-required)
  • handleSearchAddress: address search callback, it will be called after you called the Map.searchAddress method (required)
  • url: specify your own Gao-de script url address instead of default script url.
  • plugins: turn on three new plugins, include toolbar / scale / overview plugin;

Methods:

  • Map.searchAddress(address: string): [longitude, latitude] : search address and locate it on the map instance, and return the [longitude, latitude] data.
  • Map.loadScript(url: string, scriptId: undefined | string): void : load your own Gao De Map JS-SDK, usually, you don't need to execute it

About Map Mount DOM Class?

Now you can use wrapClassName to define your own map class, and use Inline Style to define style, the wrapClassName and style props is very usefull to control map container style.

Before I Use Map Component

Please notice that when you are using this component, As usual, the component will load GaoDe Map SDK when it is moounted, but you can still use Map.loadScript(url, scriptId) method to load your own script instead, you can replace it with your defination, the scriptId is to help the component to recognize whether the script is loaded. And another usefull method is Map.searchAddress(address), it will help component to locate the address you entered, and the handleSearchAddress props will be called a little later.

License

MIT