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

admin-tools

v1.0.3

Published

该工具主要用于将行政区划属性数据进行空间化,也可以根据行政区划名称或代码查询该行政区的中心点位置和下一级行政区信息。

Downloads

8

Readme

该工具主要用于将行政区划属性数据进行空间化,也可以根据行政区划名称或代码查询该行政区的中心点位置和下一级行政区信息。

使用方法

安装

npm install admin-tools
import * as AdminTools from 'admin-tools'

let adminCode = '420000'
AdminTools.getAdminDataByCode(adminCode)
// {name:'湖北省', center: [114.298, 30.584], children: { ... }}

API

.getAdminType(code: String)

参数 | 类型 | 是否必须 | 说明 --- | --- | --- | --- code | String | 是 | 行政区划代码,例如"110000"

获取行政区划级别,1 -- 省;2 -- 市;3 -- 县;4 -- 乡镇; 0 -- 全国 -1 -- 无效

.isMunicipality(code: String)

参数 | 类型 | 是否必须 | 说明 --- | --- | --- | --- code | String | 是 | 行政区划代码,例如"110000"

给定的行政区是否为直辖市

.getAdminDataByName(name: String, searchArea: String)

参数 | 类型 | 是否必须 | 说明 --- | --- | --- | --- name | String | 是 | 行政区划名称,例如“武汉市” searchArea | String | 否 | 搜索区域,默认会在全国范围内进行匹配,为避免行政区划名称重名导致匹配错误,可以指定匹配范围

根据名称获取行政区划信息

.getAdminDataByCode(code: String)

参数 | 类型 | 是否必须 | 说明 --- | --- | --- | --- code | String | 是 | 行政区划代码,例如“420100”

根据行政区划代码获取行政区划信息

.convert2geojson(data: Array, options: Object)

参数 | 类型 | 是否必须 | 说明 --- | --- | --- | --- data | Array | 是 | 需要转换的数据 options | Object | 是 | 转换参数

将给定的属性数据,按行政区划字段进行空间化,转为geojson数据

options选项:

  • dataType, 数据类型,可以是点(point)或者线段(line
  • adminField,行政区划字段,该字段可以是行政区划名称,也可以是行政区划代码,会自动识别
  • adminField1, 行政区划字段,当数据类型为“线段”时,adminField为线段起点,adminField1为线段终点
  • searchArea,匹配范围,仅当行政区划字段为名称的时候有效,用于手动指定匹配范围

例如:

let data = [
  {
    name: '武汉市',
    gdp: 1000, // 纯属虚构
    pop: 3000  // 纯属虚构
  },
  {
    name: '黄冈市',
    gdp: 800, // 纯属虚构
    pop: 1000  // 纯属虚构
  }
]

convert2geojson(data, {
  dataType: 'point',
  adminField: 'name',
  searchArea: '420000'  // 在湖北省范围内匹配
})
/* => {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {
        adname: '武汉市',
        adcode: '420100',
        name: '武汉市',
        gdp: 1000,
        pop: 3000
      },
      geometry: {
        type: 'Point',
        coordinates: [114.298, 30.584]
      }
    },
    {
      type: 'Feature',
      properties: {
        adname: '黄冈市',
        adcode: '421100',
        name: '黄冈市',
        gdp: 800,
        pop: 1000
      },
      geometry: {
        type: 'Point',
        coordinates: [114.879, 30.447]
      }
    }
  ]
}
*/