Skip to content

Commit f05efbc

Browse files
committed
Stimulize-it
1 parent edbb8a6 commit f05efbc

File tree

5 files changed

+30
-45
lines changed

5 files changed

+30
-45
lines changed

app/controllers/record_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def view
1616
# Manipulation of returned record would go here...
1717

1818
@record = response&.data&.to_h&.dig('recordId')
19-
@rectangle = bounding_box_to_coords(@record)
2019
end
2120

2221
private
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// app/javascript/controllers/map_controller.js
2+
import { Controller } from "@hotwired/stimulus"
3+
// import L from 'leaflet'
4+
export default class extends Controller {
5+
static values = {
6+
coords: Array,
7+
id: String
8+
}
9+
connect() {
10+
// Map logic goes here
11+
// console.log(this.identifier)
12+
// console.log(this.coordsValue)
13+
// console.log(this.idValue)
14+
15+
var map = L.map(this.idValue);
16+
17+
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
18+
maxZoom: 19,
19+
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
20+
}).addTo(map);
21+
22+
// create an orange rectangle
23+
L.rectangle(this.coordsValue, {color: "#ff7800", weight: 1}).addTo(map);
24+
25+
// // zoom the map to the rectangle bounds
26+
map.fitBounds(this.coordsValue);
27+
}
28+
}

app/views/record/_record_geo.html.erb

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,7 @@
6464
<% if geospatial_coordinates?(@record['locations']) %>
6565
<h3 class="section-title">Geospatial coordinates</h3>
6666

67-
<div id="map" style="height: 180px"></div>
68-
<script>
69-
var map = L.map('map');
70-
71-
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
72-
maxZoom: 19,
73-
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
74-
}).addTo(map);
75-
76-
// define rectangle geographical bounds
77-
// -71.158693, -71.064796, 42.395972, 42.351993
78-
// var bounds = [[42.395972, -71.158693],[42.351993, -71.064796]];
79-
80-
console.log('#<%= @rectangle %>');
81-
var bounds = <%= @rectangle %>;
82-
83-
// create an orange rectangle
84-
L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);
85-
86-
// zoom the map to the rectangle bounds
87-
map.fitBounds(bounds);
88-
</script>
89-
67+
<div id="map" style="height: 180px" data-controller="map" data-map-coords-value=<%= bounding_box_to_coords(@record).to_json %> data-map-id-value="map"></div>
9068
<p>
9169
<ul>
9270
<% parse_nested_field(@record['locations']).each do |location| %>

app/views/search/_result_geo.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<!-- We only care about geospatial locations for this, as place names are also subjects. -->
2626
<% if geospatial_coordinates?(result_geo['locations']) %>
2727

28-
<%= render partial: 'shared/map', locals: { result_geo_counter: result_geo_counter, result_geo: result_geo} %>
28+
<div id=<%= "map_#{result_geo_counter}" %> style="height: 180px" data-controller="map" data-map-coords-value=<%= bounding_box_to_coords(result_geo).to_json %> data-map-id-value=<%= "map_#{result_geo_counter}" %>></div>
2929

3030
<p>
3131
<ul>

app/views/shared/_map.html.erb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1 @@
1-
<div id=<%= "map_#{result_geo_counter}" %> style="height: 180px"></div>
21

3-
<script>
4-
var <%= "map_#{result_geo_counter}" %> = L.map('<%= "map_#{result_geo_counter}" %>');
5-
6-
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
7-
maxZoom: 19,
8-
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
9-
}).addTo(<%= "map_#{result_geo_counter}" %>);
10-
11-
// define rectangle geographical bounds
12-
var bounds = <%= bounding_box_to_coords(result_geo) %>;
13-
14-
// console.log(bounds);
15-
16-
// create an orange rectangle
17-
L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(<%= "map_#{result_geo_counter}" %>);
18-
19-
// zoom the map to the rectangle bounds
20-
<%= "map_#{result_geo_counter}" %>.fitBounds(bounds);
21-
</script>

0 commit comments

Comments
 (0)