-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Map resources and JavaScript map client
To display a map of the Japanese municipalities, two resources are needed: 1. The vector tile endpoint to stream the binary vector tiles. 2. A Mapbox Style endpoint to tell the map client how to render the vector data. The JavaScript client can now render this map with the style URL without further design configuration.
- Loading branch information
1 parent
4efa05d
commit f481ac1
Showing
13 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
class MapStylesController < ApplicationController; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
class MapsController < ApplicationController; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class TilesController < ApplicationController | ||
def show | ||
zoom, x, y = params.values_at(:zoom, :x, :y).map(&:to_i) | ||
|
||
respond_to do |format| | ||
format.mvt do | ||
send_data(Municipality.as_mvt_for(zoom:, x:, y:)) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import { apply } from "ol-mapbox-style" | ||
|
||
export default class extends Controller { | ||
static values = { url: String } | ||
|
||
connect() { | ||
apply(this.element, this.urlValue) | ||
.then((value) => { this.map = value }) | ||
} | ||
|
||
disconnect() { | ||
this.map.setTarget(null) | ||
this.map = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
json.version 8 | ||
|
||
json.center [130.399994, 33.583332] # Fukuoka | ||
|
||
json.zoom 12 | ||
|
||
json.sources do | ||
json.map do | ||
json.type 'vector' | ||
json.tiles [tile_url('{z}', '{x}', '{y}', format: :mvt)] | ||
end | ||
end | ||
|
||
json.layers do | ||
json.child! do | ||
json.id 'municipality-label' | ||
json.type 'symbol' | ||
json.source 'map' | ||
json.set! 'source-layer', 'default' | ||
json.layout do | ||
json.set! 'text-field', %w[get name] | ||
json.set! 'symbol-placement', 'line-center' | ||
end | ||
end | ||
|
||
json.child! do | ||
json.id 'municipality-outline' | ||
json.type 'line' | ||
json.source 'map' | ||
json.set! 'source-layer', 'default' | ||
json.paint do | ||
json.set! 'line-color', '#3EA5F5' | ||
json.set! 'line-width', 3 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<div class='map' data-controller="map" data-map-url-value="<%= map_style_url(format: :json) -%>"> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,8 @@ | |
pin '@hotwired/stimulus', to: 'stimulus.min.js', preload: true | ||
pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js', preload: true | ||
pin_all_from 'app/javascript/controllers', under: 'controllers' | ||
pin 'ol-mapbox-style', to: 'https://ga.jspm.io/npm:[email protected]/dist/index.js' | ||
pin 'ieee754', to: 'https://ga.jspm.io/npm:[email protected]/index.js' | ||
pin 'ol/', to: 'https://ga.jspm.io/npm:[email protected]/' | ||
pin 'pbf', to: 'https://ga.jspm.io/npm:[email protected]/index.js' | ||
pin 'rbush', to: 'https://ga.jspm.io/npm:[email protected]/rbush.min.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
Mime::Type.register 'application/vnd.mapbox-vector-tile', :mvt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.routes.draw do | ||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html | ||
get 'tiles/:zoom/:x/:y', to: 'tiles#show', as: :tile | ||
resource :map_style, only: :show | ||
|
||
# Defines the root path route ("/") | ||
# root "articles#index" | ||
root 'maps#show' | ||
end |