GithubHelp home page GithubHelp logo

a-mukubayashi / japanese-prefectures Goto Github PK

View Code? Open in Web Editor NEW

This project forked from geolonia/japanese-prefectures

0.0 0.0 0.0 212 KB

SVG map of Japan

Home Page: https://geolonia.github.io/japanese-prefectures/

japanese-prefectures's Introduction

SVG Map of Japan

ウェブサイトの検索インターフェース等で使用することを想定した、SVG フォーマットの日本地図です。都道府県別のリンクを作るなどのユースケースを想定しています。

https://geolonia.github.io/japanese-prefectures/demo/

仕様

  • 都道府県ごとにグループ化してあり、都道府県名、八地方区分名を class 属性の値としてセットしてありますので、CSS で都道府県や地方別に色分けすることができます。
  • data-code という属性をもっており、都道府県コードが格納されています。(大阪府の例: data-code="27")
  • 誠に申し訳ございませんが、縦横比の都合上、小笠原諸島等の一部の離島は省略してあります。
  • 2種類の SVG ファイルがありますので、好みで使い分けてください。
    • map-full.svg - フルサイズの地図です。
    • map-mobile.svg - モバイルデバイス用にアレンジした地図です。

使い方 (例)

JavaScript

JavaScript で以下のように読み込んでください。

const map = "./map-full.svg" // Or "./map-mobile.svg"
const container = document.querySelector( '#map' )

const res = await fetch( map )

if ( res.ok ) {
  const svg = await res.text()
  container.innerHTML = svg
  const prefs = document.querySelectorAll( '.geolonia-svg-map .prefecture' )

  prefs.forEach( ( pref ) => {
    // マウスオーバーで色を変える
    pref.addEventListener( 'mouseover', ( event ) => {
      event.currentTarget.style.fill = "#ff0000"
    } )

    // マウスが離れたら色をもとに戻す
    pref.addEventListener( 'mouseleave', ( event ) => {
      event.currentTarget.style.fill = ""
    } )

    // マウスクリック時のイベント
    pref.addEventListener( 'click', ( event ) => {
      location.href = `https://example.com/${event.currentTarget.dataset.code}` // 例(大阪): https://example.com/27
    } )
  } )
}

CSS

以下は CSS の記述例です。

.geolonia-svg-map
{
  width: 100%;
}

.geolonia-svg-map .prefecture
{
  fill: #f7f7f7;
  stroke: #666666;
  cursor: pointer;
}

.geolonia-svg-map .boundary-line
{
  stroke: #999999;
}

ライセンス

この SVG データは、Wikipedia の 日本地図.svg をベースにしており、ライセンスは GFDL とします。

japanese-prefectures's People

Contributors

miya0001 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.