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 🙏

© 2026 – Pkg Stats / Ryan Hefner

qm-map-maplibre-gl

v0.0.9

Published

基于 MapLibre GL 和 React 的地图组件库,提供丰富的地图交互组件。

Readme

qm-map-maplibre-gl

基于 MapLibre GL 和 React 的地图组件库,提供丰富的地图交互组件。

安装

npm install qm-map-maplibre-gl
# 或
yarn add qm-map-maplibre-gl

依赖

  • React >= 19.0.0
  • React DOM >= 19.0.0
  • MapLibre GL >= 5.0.0

快速开始

import { MapWidget, LayerList, Legend } from 'qm-map-maplibre-gl';
import 'qm-map-maplibre-gl/dist/qm-map.css'
import type { LngLatLike } from 'maplibre-gl';

function App() {
  const mapOptions = {
    id: 'myMap',
    center: [115.415, 33.254] as LngLatLike,
    zoom: 9.5,
    maxZoom: 18,
  };

  return (
    <MapWidget mapOptions={mapOptions} mapLayerSettting={layerSetting}>
      <LayerList position={{ top: 10, left: 10 }} />
      <Legend position={{ bottom: 10, left: 10 }} />
    </MapWidget>
  );
}

组件列表

MapWidget

地图容器组件,所有其他组件必须包裹在其中。

interface TMapProps {
  mapOptions: TMapOptions;
  mapLayerSettting: TMapLayerSettting;
  children?: React.ReactNode;
}

LayerList

图层列表组件,显示和控制地图图层可见性。

<LayerList position={{ top: 10, left: 10 }} />

Legend

图例组件,显示地图图例信息。

<Legend position={{ bottom: 10, left: 10 }} />

Draw

地图绘制组件,支持绘制点、线、面并计算面积。

import DrawWidget, { type TDrawResult, type TDrawModeType } from 'qm-map-maplibre-gl';

const onDraw = (res: TDrawResult) => {
  console.log('绘制数据:', res.data);
  console.log('总面积:', res.area);
};

// 基础用法
<DrawWidget 
  position={{ bottom: 10, right: 10 }} 
  onDraw={onDraw} 
/>

// 限制绘制模式
<DrawWidget 
  modes={['draw_point', 'draw_polygon']}
  position={{ bottom: 10, right: 10 }} 
  onDraw={onDraw} 
/>

Props:

| 属性 | 类型 | 必填 | 说明 | |------|------|------|------| | position | TWidgetPosition | 是 | 控件位置 | | onDraw | (result: TDrawResult) => void | 是 | 绘制完成回调 | | modes | TDrawModeType[] | 否 | 允许的绘制模式 | | initFeature | FeatureCollection | 否 | 初始绘制数据 |

绘制模式:

  • 'draw_point' - 绘制点
  • 'draw_line_string' - 绘制线
  • 'draw_polygon' - 绘制多边形
  • 'simple_select' - 选择模式

Swipe

地图分屏对比组件。

<Swipe position={{ top: 190, right: 10 }} />

Print

地图打印组件。

<Print position={{ top: 10, right: 10 }} />

类型导出

import type { 
  TWidgetPosition,
  TDrawResult, 
  TDrawModeType,
  TMapOptions,
  TMapLayerSettting 
} from 'qm-map-maplibre-gl';

工具 Hooks

useMap

获取地图实例上下文。

import { useMap } from 'qm-map-maplibre-gl';

function MyComponent() {
  const { map } = useMap();
  
  // 使用 map 实例
  const handleClick = () => {
    map?.flyTo({ center: [116, 39], zoom: 10 });
  };
  
  return <button onClick={handleClick}>飞行到</button>;
}

样式

组件库已内置样式,无需额外引入 CSS 文件。

License

MIT