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

react-svg-zoom-map

v1.3.0

Published

A react map component can load TopoJson with county, town, village layer.

Downloads

51

Readme

react-svg-zoom-map

擁有三層放大功能的台灣地圖 React Component,地圖圖形資料使用 Topojson,並透過 D3 繪製

Live Demo

Installation

透過 NPM 安裝:

npm install react-svg-zoom-map --save

Development

開啟測試伺服器並執行 example

npm run watch

develop 建置

npm run dev

production 建置

npm run build

Usage

  import React, { useState } from 'react';
  import ReactSvgZoomMap from 'react-svg-zoom-map';

  const Example = () => {
    const [ area, setArea ] = useState(['', '', '']);

    return (
      <ReactSvgZoomMap 
        countyJsonSrc="https://cybermumu.github.io/react-svg-zoom-map/example/topojsons/taiwan-county.json"
        townJsonSrc="https://cybermumu.github.io/react-svg-zoom-map/example/topojsons/taiwan-town.json"
        villageJsonSrc="https://cybermumu.github.io/react-svg-zoom-map/example/topojsons/taiwan-village.json"
        county={ area[0] }
        town={ area[1] }
        village={ area[2] }
        onAreaClick={ (newArea, e) => setArea(newArea) }
        onPinClick={ console.log }
        pins={[
          {
            id: 1,
            title: '台北101',
            county: '臺北市',
            town: '信義區',
            village: '西村里',
            location: [ 25.034000, 121.564670 ]
          },
          {
            id: 2,
            title: '台灣最南點',
            county: '屏東縣',
            town: '恆春鎮',
            village: '鵝鑾里',
            location: [ 21.897750, 120.857921 ]
          },
          {
            id: 3,
            title: '貓鼻頭燈塔',
            county: '新北市',
            town: '瑞芳區',
            village: '鼻頭里',
            location: [ 25.129217, 121.923449 ]
          }
        ]}
      />
    )
  }

Props

county: string;

目前選取的縣市。

town: string;

目前選取的鄉鎮。

village: string;

目前選取的村里。

className?: string;

自訂此 Component 的 className。

countyJsonSrc: string;

導入外部的縣市界圖 TopoJson Source,此值為必填。

townJsonSrc: string;

導入外部的鄉鎮界圖 TopoJson Source,此值為必填。

villageJsonSrc: string;

導入外部的村里界圖 TopoJson Source,此值為必填。

pins?: array[{ title: string, county: string, town: string, village: string, location: [lat: number, long: number] }];

要 pin 上地圖的資訊,需帶點的縣市、鄉鎮、村里資訊,進入放大模式時,系統會篩選掉該區外的 pin。

範例資料如下:

{
  title: '台北101',
  county: '臺北市',
  town: '信義區',
  village: '西村里',
  location: [ 25.034000, 121.564670 ]
}

title 會帶入至 svg circle 內。此物件可以任意攜帶其他 property,此物件將會在 clickhover 的 callback 被完整傳回。

pinRadiusWithLayer?: array [ layer_0_reduis: number, layer_1_reduis: number, layer_2_reduis: number ];

每一層 pin 的半徑,預設為 [2, 0.3, 0.15]

zoomDuration?: number;

放大動畫的時間長度(毫秒),預設為 1000

zoomDelay?: number;

放大動畫的前置延遲(毫秒),預設為 100

Callback

onAreaClick?(selectAreaArray: array[countyName?: string, townName?: string, village?: string], event: MouseEvent )

selectAreaArray 格式為:[ 縣市名稱, 鄉鎮名稱, 村里名稱 ],若選取層級僅到縣市時,陣列長度為1,依此類推。

onAreaHover?(selectAreaArray: array[countyName?: string, townName?: string, village?: string], event: MouseEvent )

selectAreaArray 格式同上。

onPinClick?(selectPinObject: object, event: MouseEvent)

selectPinObject 格式與 Props 中帶入的 pins 單項物件相同。

onPinHover?(selectPinObject: object, event: MouseEvent)

selectPinObject 格式同上。

其他資訊

台灣行政區界圖資訊