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

@zjjw/vue-tianditu

v2.7.9

Published

vue-tianditu

Downloads

358

Readme

vue-tianditu

2.7.7: fork 主要是作者很久没更新了,我需要解决 vue2.7 的兼容性问题,发布到 npm 是因为简单尝试了下 patch-package 似乎并不能给 package.json 打补丁。 2.7.8: 修复了搜索问题 2.7.9: 修复了搜索问题x2

安装

npm i @zjjw/vue-tianditu
# or
yarn add @zjjw/vue-tianditu

快速上手

全局引入

全部引入,解放双手

// main.ts
import { createApp } from "vue";
import App from "./App.vue";
import VueTianditu from "@zjjw/vue-tianditu";

const app = createApp(App);
app.use(VueTianditu, {
  v: "4.0", //目前只支持4.0版本
  tk: "your map token"
});
app.mount("#app");
<!-- App.vue -->
<template>
  <div class="mapDiv">
    <tdt-map :center="state.center" :zoom="state.zoom"></tdt-map>
  </div>
</template>

<script lang="ts" setup>
  import { reactive } from "vue";
  import { TdtMap } from "@zjjw/vue-tianditu";
  const state = reactive({
    center: [113.280637, 23.125178],
    zoom: 12
  });
</script>

<style>
  .mapDiv {
    width: 100%;
    height: 100%;
  }
</style>

按需引入

按需引入,配合 ts 获得类型提示

App.vue

<template>
  <div class="mapDiv">
    <tdt-map :center="state.center" :zoom="state.zoom" :loadConfig="loadScript"></tdt-map>
  </div>
</template>

<script lang="ts" setup>
  import { reactive } from "vue";
  import { TdtMap } from "@zjjw/vue-tianditu";
  const loadConfig = { v: "4.0", tk: "your map token" };
  const state = reactive({
    center: [113.280637, 23.125178],
    zoom: 12
  });
</script>

<style>
  .mapDiv {
    width: 100%;
    height: 100%;
  }
</style>

API 加载器

甚至可以把它当作无情的 API 加载工具

import { useApiLoader } from "@zjjw/vue-tianditu";

useApiLoader({
  v: "4.0",
  tk: "your map token",
  plugins: ["D3", "CarTrack", "HeatmapOverlay", "BufferTool", "ImageOverLayer"]
}).then(() => {
  new T.Map({...});
});

辅助函数

import { toLngLat, toBounds, toPoint, toIcon } from "@zjjw/vue-tianditu";

说明

| 函数名 | 返回值 | 描述 | | --- | --- | --- | | toLngLat(lnglat:[number,number]) | T.LngLat | 转换为经纬度对象。参数说明:lnglat:经纬度数组 | | toBounds(bounds:[[number,number],[number,number]]) | T.Bounds | 转换为地理范围对象。参数说明:bounds:地理范围数组 | | toPoint(point:[number,number]) | T.Point | 转换为像素坐标点对象。参数说明:point:像素坐标点数组 | | toIcon(icon:IconOption|string) | T.Icon | 转换为图标对象。参数说明:icon:string//图片地址{iconUrl:string,//图片地址iconSize:[number,number],//图片大小iconAnchor:[number,number]//偏移} |

调用原生API

由于API是通过useApiLoader异步加载的,所以需要在API加载完成后才能使用天地图原生的API,有以下三种方式:

  • 不使用组件,只使用API加载器
<template>
  <div id="mapContainer"></div>
</template>

<script>
import { useApiLoader } from "@zjjw/vue-tianditu";
// 加载API
useApiLoader({
  v: "4.0",
  tk: "your map token",
  plugins: ["D3", "CarTrack", "HeatmapOverlay", "BufferTool", "ImageOverLayer"]
}).then(() => {
  const map = new T.Map("mapContainer", {...});
  const marker = new T.Marker({...});
  map.addOverlay(marker);
});
</script>
  • 使用组件,监听组件的初始化事件
<template>
  <tdt-map @init="mapInit"></tdt-map>
</template>

<script>
function mapInit(map){
  // 此时原生API中的T已存在window中
  const marker = new T.Marker({...})
  map.addOverlay(marker);
}
</script>
  • 注册了组件,使用API加载器异步等待API加载完成
// 不用传参数,异步等待之前注册组件时带参数加载的API加载完成
useApiLoader({}).then(() => {
  const marker = new T.Marker({...});
});

如果项目中用到了eslint,则需要在eslintrc配置文件中加入

{
  ...
  globals: {
    ...
    T: "readonly"
  }
}