|
2 | 2 |
|
3 | 3 | > 日本語のREADMEはこちらです: [README.ja.md](README.ja.md) |
4 | 4 |
|
5 | | -Leafletjs x Geospatial Information Authority of Japan (GSIMAP) |
| 5 | +A lightweight JavaScript library for easily creating interactive maps using [Leaflet.js](https://leafletjs.com/) and map tiles from the [Geospatial Information Authority of Japan (GSI)](https://maps.gsi.go.jp/development/ichiran.html). |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
6 | 10 |
|
7 | 11 | ## Features |
8 | | -- Display maps using Leafletjs and GSIMAP |
9 | | -- Add icons and markers to the map |
10 | | -- Integrate with SPARQL API to display data on the map |
11 | 12 |
|
12 | | -## Requirements |
13 | | -None. Works in modern web browsers. |
| 13 | +- **Simple & Lightweight**: Quickly embed interactive maps with just a few lines of code. |
| 14 | +- **GSI Maps**: Utilizes beautiful and detailed map tiles from the Geospatial Information Authority of Japan. |
| 15 | +- **Easy Markers**: Add custom icons and pop-up markers with a single helper function. |
| 16 | +- **Open Data Ready**: Includes a helper (`sparql.js`) to fetch and display data from SPARQL endpoints. |
| 17 | +- **Modern JavaScript**: Also available as an ES Module (`egmap.mjs`). |
| 18 | + |
| 19 | +## Quick Start |
14 | 20 |
|
15 | | -## Usage |
16 | | -Include the required JavaScript and CSS files in your HTML: |
| 21 | +### 1. Add to your HTML |
| 22 | + |
| 23 | +First, create a `<div>` for your map. Then, include the CSS and JavaScript files for Leaflet and egmapjs. |
17 | 24 |
|
18 | 25 | ```html |
| 26 | +<!-- 1. Create a map container --> |
| 27 | +<div id="mapid" style="height: 400px;"></div> |
| 28 | + |
| 29 | +<!-- 2. Include Leaflet.js --> |
19 | 30 | <link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"/> |
20 | 31 | <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"></script> |
| 32 | + |
| 33 | +<!-- 3. Include egmapjs --> |
21 | 34 | <script src="https://code4fukui.github.io/egmapjs/egmap.js"></script> |
22 | 35 | ``` |
23 | 36 |
|
24 | | -Then, create a map in your JavaScript code: |
| 37 | +### 2. Initialize the Map |
| 38 | + |
| 39 | +Use JavaScript to initialize the map, set its view, and add markers. |
25 | 40 |
|
26 | 41 | ```javascript |
27 | | -var map = initMap('mapid'); |
| 42 | +// Initialize the map in the 'mapid' div |
| 43 | +const map = initMap('mapid'); |
| 44 | + |
| 45 | +// Set the view to Sabae Station with a zoom level of 16 |
28 | 46 | map.setZoom(16); |
29 | | -map.panTo([35.943560, 136.188917]); // Sabae Station |
30 | | -map.addIcon(35.944571, 136.186228, "Hana Dojo", "icon/hanadojo.png", 64); |
| 47 | +map.panTo([35.943560, 136.188917]); |
| 48 | + |
| 49 | +// Add a custom icon for "Hana道場" |
| 50 | +map.addIcon( |
| 51 | + 35.944571, // Latitude |
| 52 | + 136.186228, // Longitude |
| 53 | + "Hana道場", // Popup text |
| 54 | + "icon/hanadojo.png", // Icon image URL (optional) |
| 55 | + 64 // Icon width (optional) |
| 56 | +); |
31 | 57 | ``` |
32 | 58 |
|
33 | | -## Data / API |
34 | | -The project uses the GSIMAP (国土地理院地図) tile service provided by the Geospatial Information Authority of Japan. |
| 59 | +## Advanced Usage |
| 60 | + |
| 61 | +### Displaying Open Data via SPARQL |
| 62 | + |
| 63 | +You can easily plot open data on the map using the included `sparql.js` helper. |
| 64 | + |
| 65 | +1. Include the script in your HTML: |
| 66 | + ```html |
| 67 | + <script src="https://code4fukui.github.io/egmapjs/sparql.js"></script> |
| 68 | + ``` |
| 69 | + |
| 70 | +2. Write a SPARQL query and use `querySPARQL` to add the results to the map: |
| 71 | + ```javascript |
| 72 | + // SPARQL query to find public WiFi spots |
| 73 | + const query = ` |
| 74 | + PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
| 75 | + PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> |
| 76 | + SELECT ?name ?lat ?lng WHERE { |
| 77 | + ?uri a <http://purl.org/jrrk#PublicWIFI>; |
| 78 | + rdfs:label ?name; |
| 79 | + geo:lat ?lat; |
| 80 | + geo:long ?lng. |
| 81 | + } LIMIT 100`; |
| 82 | + |
| 83 | + querySPARQL(query, (data) => { |
| 84 | + const items = data.results.bindings; |
| 85 | + for (const item of items) { |
| 86 | + map.addIcon(item.lat.value, item.lng.value, item.name.value); |
| 87 | + } |
| 88 | + }); |
| 89 | + ``` |
| 90 | + |
| 91 | +### Using ES Modules |
| 92 | + |
| 93 | +For modern web development, you can use the ES Module version. |
| 94 | + |
| 95 | +```javascript |
| 96 | +import { initMap, L } from "https://code4fukui.github.io/egmapjs/egmap.mjs"; |
| 97 | + |
| 98 | +const map = initMap('mapid'); |
| 99 | +map.setView([35.94, 136.18], 15); |
| 100 | +map.addIcon(35.944, 136.186, "Hana道場"); |
| 101 | +``` |
| 102 | + |
| 103 | +## Demos & Tutorials |
| 104 | + |
| 105 | +Explore our comprehensive tutorials and live demos to see what's possible with egmapjs. |
| 106 | + |
| 107 | +- **[View All Tutorials](https://code4fukui.github.io/egmapjs/tutorial.html)**: Covers basic maps, SPARQL, GPS, routing, and more. |
| 108 | +- **Live Demos**: |
| 109 | + - [Kyoto Ishibumi Map](https://code4fukui.github.io/kyotoishibumi/) ([Source Code](https://github.com/code4fukui/kyotoishibumi/blob/main/index.html)) |
| 110 | + - [Maizuru High School Visit Map](https://code4fukui.github.io/egmapjs/samples/maizurukosen.html) |
| 111 | + |
| 112 | +## Data Source & Attribution |
| 113 | + |
| 114 | +This library uses map tiles from the **[Geospatial Information Authority of Japan (GSI)](https://maps.gsi.go.jp/development/ichiran.html)**. Please ensure proper attribution is maintained. |
| 115 | + |
| 116 | +## Related Resources |
| 117 | + |
| 118 | +- [Blog Post: 簡単で無料で活用できる地図API、leafletjs x 地理院地図](https://fukuno.jig.jp/2393) (in Japanese) |
35 | 119 |
|
36 | 120 | ## License |
37 | | -The project is released under the CC BY license. |
| 121 | + |
| 122 | +This project is licensed under the [Creative Commons Attribution 4.0 International License (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/). |
0 commit comments