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

pdmaptw

v2.2.1

Published

Taiwan Map

Downloads

14

Readme

pdmaptw

台灣 ( "中華民國自由地區",含台、澎、金、馬 ) 縣市、鄉鎮、村里界圖。含前端繪圖函式 ( 基於 d3.js v4 )

Installation

npm install --save pdmaptw

Frontend Usage

pdmaptw depends on following libraries:

  • d3@^4.0.0
  • topojson@^2.0.0
  • d3-geo@^1.0.0
  • d3-geo-projection@^2.0.0

include dependencies:

<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script src="https://d3js.org/d3-color.v1.min.js"></script>
<script src="https://d3js.org/d3-interpolate.v1.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>

include main js file:

<script src="path/to/dist/index.js>"></script>

include corresponding map files:

<script src="path/to/dist/county.map.js>"></script>
<script src="path/to/dist/town.map.js>"></script>
<script src="path/to/dist/village.map.js>"></script>

Then, create map object:

var obj = new pdmaptw(opt);
obj.init().then(function() {
  obj.fit();
});

Constructor Options

  • root: container for this map
  • `type: 'county', 'town' or 'village'.

API

  • init(): map initialization, include data fetching / path elements creating. return promise.
  • fit(opt): fit map to the size of container. options:
    • box: bounding box {width, height} for fix size hinting

Events

  • hover: fired when user hovers on geographic paths. with parameters:
    • evt: event for mouseover.
    • data: not null if mouseover path element of map. usually a topojson object with properties member:
      • properties.name - name for this geographic block, like "高雄市左營區"

Class Methods

  • projection(): return a d3js GeoProjection for 台澎金馬地區, as compact as possible.
    • the returned function accepts parameters as an array with [lng, lat] format.
  • normalize(str) - name normalization, e.g., replace '臺' with '台'.

Building Map File

After npm install, Fetch data and build:

npm run build

Alternatively, execute the script manually:

./fetch
./node_modules/.bin/lsc convert.ls
./node_modules/.bin/lsc filter.ls
./build

What the above commands do:

  • fetch will download and unzip shp files from government website to download folder.
  • convert.ls will process all shp files and convert them to topojson.
    • tweak mw and w for twaking topojson size. be sure to test in major browsers before using. escpecially windows firefox since we encountered an abnormal path before.
  • filter.ls will generate separated county files.
  • build build the utility js twmap for frontend rendering.
  • tool/build.sh will process all shp files and convert them to geojson, topojson and sample svg.
    • for getting topojson, simply use convert.ls directly.

Demonstration

For a sample usage in frontend:

npm start

the script will start a simple server and open the demo page automatically.

meta.json structure

for keeping topojson metadata. lookup with cid/tid/vcode.

{ county: { "county-id": {c: "county-code", n: "county-name"}, ... }, town: { "town-id": {c: "town-code", n: "town-name"}, ... }, village: { "village-code": {n: "village-name"}, ... } }

properties in topojson is then converted to:

{ cid: "county-id", tid: "town-id", vcode: "village-code" }

each field exists only when applicable.

詳細產製流程

  • 取得 shp files.

    • 可以從政府開放資料平台取得. e.g.,
      • 縣市: https://data.gov.tw/dataset/7442
      • 鄉鎮: https://data.gov.tw/dataset/7441
      • 村里: https://data.gov.tw/dataset/7438
  • shp to geojson

    • 使用 npm module: shapefile
      • npm install shapefile
      • shp2json ( -o )
    • ( geojson 的格式說明? )
    • 轉出的geojson 仍需做投影, 而這可以先做, 就不用 runtime 做. 使用 d3-geo-projection
      • npm install d3-geo-projection
      • geoproject 'd3.geoConicEqualArea().parallels([34, 40.5]).rotate([120, 0]).fitSize([960, 960], d)'
        < \
      • geoConicEqualArea 適用於北美加州, 我們可以自已換投影法. 參考
        • https://github.com/d3/d3-geo-projection/blob/master/README.md
      • 可以用 geo2svg ( from d3-geo-projection ) 先輸出範本 svg ( 但大概會非常大 ):
        • geo2svg -w 960 -h 960 < >
    • Data Join: 利用 ndjson 將 geojson 分 features 切成很多行, 方便後續處理
      • npm install ndjson
      • 切開: ndjson-split 'd.features' < >
      • 轉換: ndjson-map 'd.id = d.properties.GEOID.slice(2), d' < >
      • 串接: ndjson-cat ...
      • join data: ndjson-join ...
      • 轉回 geojson: ndjson-reduce
    • 最佳化: 使用 topojson 格式.
      • npm install topojson
      • geo2topo -n tracts= >
      • toposimplify -p 1 -f < >
      • topoquantize 1e5 < >
    • 合併行政區塊: 使用 topomerge ( in topojson package )
      • topomerge -k 'd.id.slice(0,3)' counties=tracts < >
  • geojson to topojson

License

Source code: MIT