Skip to content

Commit 66cce06

Browse files
authored
Merge pull request #2 from owikle/main
Add map popover functionality and show item transcripts by default
2 parents d9108f7 + 57c4fae commit 66cce06

File tree

5 files changed

+59
-15
lines changed

5 files changed

+59
-15
lines changed

_data/placename_main.csv

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
key,city,country,latitude,longitude,comment,annotation
2-
gallarate,Gallarate,Italia,45.6602,8.79348,,"En 1956, se creó el Centro per L'Automazione dell'Analisi Letteraria (CAAL), que luego de una etapa a mitad de camino entre las oficinas de IBM en Nueva York e Italia, en 1961 se trasladó definitivamente a una antigua fábrica textil en Gallarate, Milán. El acrónimo CAAL a veces también funcionaba como Centro Automazione Analisi Linguistica. En 1983 se renombró como CAEL (Computerizzazione delle Analisi Ermeneutiche e Lessicografiche)."
3-
,,,,,,
4-
,,,,,,
5-
,,,,,,
6-
,,,,,,
7-
,,,,,,
8-
2+
gallarate,Gallarate,Italia,45.6602,8.79348,,"En 1956, se creó el Centro per L'Automazione dell'Analisi Letteraria (CAAL), que luego de una etapa a mitad de camino entre las oficinas de IBM en Nueva York e Italia, en 1961 se trasladó definitivamente a una antigua fábrica textil en Gallarate, Milán. El acrónimo CAAL a veces también funcionaba como Centro Automazione Analisi Linguistica. En 1983 se renombró como CAEL (Computerizzazione delle Analisi Ermeneutiche e Lessicografiche)."

_includes/item/child/compound-item-download-buttons.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</div>
3434
</div>
3535
{% if page.object_transcript %}
36-
<div class="collapse mt-3" id="collapseTranscript">
36+
<div class="collapse show mt-3" id="collapseTranscript">
3737
<div class="card card-body text-start">
3838
{% assign transcript_type = page.object_transcript | slice: 0,1 %}
3939
{% if transcript_type == '/' %}

_includes/item/child/download-buttons.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</a>{% endif %}
2020
</div>
2121
{% if child.object_transcript %}
22-
<div class="collapse mt-3" id="collapseTranscript{{ child.objectid }}">
22+
<div class="collapse show mt-3" id="collapseTranscript{{ child.objectid }}">
2323
<div class="card card-body text-start">
2424
{% assign transcript_type = child.object_transcript | slice: 0,1 %}
2525
{% if transcript_type == '/' %}

_includes/item/download-buttons.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</a>{% endif %}
2121
</div>
2222
{% if page.object_transcript %}
23-
<div class="collapse mt-3" id="collapseTranscript">
23+
<div class="collapse show mt-3" id="collapseTranscript">
2424
<div class="card card-body text-start">
2525
{% assign transcript_type = page.object_transcript | slice: 0,1 %}
2626
{% if transcript_type == '/' %}
Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,77 @@
1+
<!-- load leaflet dependencies -->
2+
<link rel="stylesheet" href="{{ '/assets/lib/leaflet/leaflet.css' | relative_url }}">
3+
<link rel="stylesheet" href="{{ '/assets/lib/leaflet/leaflet.fullscreen.css' | relative_url }}">
4+
<script src="{{ '/assets/lib/leaflet/leaflet.js' | relative_url }}"></script>
5+
<script src="{{ '/assets/lib/leaflet/Leaflet.fullscreen.min.js' | relative_url }}"></script>
6+
<style>
7+
.custom-popover {
8+
max-width: none;
9+
width: 400px;
10+
}
11+
.custom-popover .popover-body {
12+
height: 100%;
13+
overflow: auto;
14+
}
15+
</style>
116
<script>
217
/* add annotation data from CSV */
318
var placedata = {
419
{%- for l in site.data.placename_main -%}
5-
{{ l.key | jsonify }} : { "city": {{ l.city | escape | jsonify }}, {% if l.annotation %}"annotation": {{ l.annotation | escape | jsonify }}{%- endif -%} }{% unless forloop.last %},{% endunless %}
20+
{{ l.key | jsonify }} : { "city": {{ l.city | escape | jsonify }}, {% if l.latitude %}"latitude": {{ l.latitude | escape | jsonify }}{%- endif -%}, {% if l.longitude %}"longitude": {{ l.longitude | escape | jsonify }}{%- endif -%}, {% if l.annotation %}"annotation": {{ l.annotation | escape | jsonify }}{%- endif -%} }{% unless forloop.last %},{% endunless %}
621
{%- endfor -%}
722
};
823

924
/* add popovers to each element */
1025
/* select elements with the class 'pop-annotation'*/
1126
var popAnnotations = document.querySelectorAll('.pop-annotation');
27+
1228
/* use data to create popover */
1329
popAnnotations.forEach(function(element) {
1430
var popId = element.getAttribute('id');
1531
var record = placedata[popId];
16-
if (record && record.city && record.annotation) {
32+
if (record && record.city && record.annotation && record.latitude && record.longitude) {
1733
var popoverOptions = {
1834
title: record.city,
19-
content: record.annotation,
35+
content: record.annotation + '<div id="map-' + popId + '"></div>',
2036
trigger: 'focus',
21-
html: true
37+
html: true,
38+
template: '<div class="popover custom-popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'
2239
};
40+
2341
/* initialize popover */
24-
new bootstrap.Popover(element, popoverOptions);
42+
var popover = new bootstrap.Popover(element, popoverOptions);
43+
44+
/* add event listener to initialize map after popover is shown */
45+
element.addEventListener('shown.bs.popover', function () {
46+
var mapContainerId = 'map-' + popId;
47+
var mapContainer = document.getElementById(mapContainerId);
48+
49+
/* set map container dimensions */
50+
mapContainer.style.height = '300px';
51+
mapContainer.style.width = '100%';
52+
53+
/* delay map initialization until popover content is fully rendered */
54+
setTimeout(function() {
55+
/* set up map */
56+
var mapCenter = [record.latitude, record.longitude];
57+
/* init map, set center and zoom */
58+
var map = L.map(mapContainerId, { zoomControl: false }).setView(mapCenter, 10);
59+
60+
/* define map layer */
61+
var Esri_WorldStreetMap = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
62+
attribution: 'Tiles &copy; Esri &mdash; Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012'
63+
});
64+
65+
/* load base map */
66+
Esri_WorldStreetMap.addTo(map);
67+
68+
/* add marker */
69+
L.marker(mapCenter).addTo(map)
70+
.bindPopup(record.city).openPopup();
71+
72+
/* delay 100 milliseconds to ensure map is rendered first */
73+
}, 100);
74+
});
2575
}
2676
});
2777
</script>

0 commit comments

Comments
 (0)