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

bmap-jsapi-loader

v1.0.2

Published

一个小巧的加载百度地图以及百度地图工具库的 js 插件

Downloads

7

Readme

bmap-jsapi-loader

bmap-jsapi-loader 是一个小巧的易于加载百度地图以及地图开源工具库的插件, bmap-jsapi-loader 的灵感来源于 @googlemaps/js-api-loader

特点

  • 🎨 支持以 UMD 和 ESM 两种模块方式使用
  • 🪄 为 TypeScript 用户提供完善的类型支持
  • ⚡ 异步加载百度地图脚本
  • 💌 可加载 bmap 3.0 或者 bmap-gl 两个版本
  • 💡 支持加载百度地图开源库
  • 📦 提供完善的单元测试

安装

以包管理工具的方式安装

使用 NPM:

$ npm install bmap-jsapi-loader --save

使用 Yarn:

$ yarn add bmap-jsapi-loader --save

使用 PNPM:

$ pnpm install bmap-jsapi-loader --save

以 CDN 的方式使用

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.umd.js"></script>

快速开始

示例

import { loader } from "bmap-jsapi-loader";

// 安装 Javascrtip-API 3.0 版本的百度地图
loader({
    v: "3.0",
    ak: "填写你的ak密钥",
}).then(() => {
    // 在 then 函数中 BMap 对象已经挂载到了 window 对象上,所以我们可以安全的访问 BMap 对象的属性和方法
    const map = new BMap.Map("map");
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
    map.addControl(
        new BMap.MapTypeControl({
            mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP],
        })
    );
    map.enableScrollWheelZoom(true);
}).catch(error => {
    alert(error);
})

// 安装 Javascrtip-API GL 版本的百度地图
loader({
    v: "1.0",
    type: "webgl"
    ak: "填写你的ak密钥",
}).then(() => {
    const map = new BMapGL.Map("map");
    map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);
    map.addControl(
        new BMapGL.MapTypeControl({
            mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP],
        })
    );
    map.enableScrollWheelZoom(true);
});

使用地图工具库

百度地图 GL 版本的开源库不需要指定版本,但是安装适用于 bmap 3.0 的开源库需要设置库的版本.

点击链接查看 bmap 3.0 的开源库列表

点击链接查看 bmap GL 版本的开源库列表

BMapLoader({
    v: "3.0",
    ak: "填写你的ak密钥",
    // 加载百度地图的工具库
    library: [
        {
            lib: "DrawingManager",
            version: "1.5",
        },
        {
            lib: "MarkerClusterer",
            version: "1.2",
            // bmap-loader 默认请求开源库的压缩后的脚本文件,如果需要请求未压缩的源文件,设置 `disableZip: true` 即可。
            disableZip: true,
        },
    ],
});

👉 在线 DEMO

🐛 提交 issue

提交 issue 前,请尽可能的能提供一个可复现的 demo 链接放在 issue 中。

结尾

如果你觉得这个插件还不错,请给我一个 ⭐ 支持下我。

License

MIT © 2023-PRESENT Wonder Dai