Skip to content

Commit

Permalink
add map config option
Browse files Browse the repository at this point in the history
  • Loading branch information
evanwill committed Dec 5, 2018
1 parent f2b90ea commit ae992ca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
5 changes: 5 additions & 0 deletions _data/map-config.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
field,display,search
date,Date,true
creator,Creator,true
subject,Subjects,true
location,Location,true
1 change: 0 additions & 1 deletion _data/metadata-config.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ identifier,Source Identifier
type,Type,DC.type
format,Format
rightsstatement,Rights
format-original, Original Format
26 changes: 16 additions & 10 deletions _includes/js/map-js.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
{%- assign items = site.data[site.data.theme.metadata] -%}
{%- assign fields = site.data.map-config -%}
<!-- load leaflet dependencies -->
<script src="{{ '/leaflet/leaflet.js' | prepend: site.digital-assets }}"></script>
<script src="{{ '/leaflet/fuse.min.js' | prepend: site.digital-assets }}"></script>
<script src="{{ '/leaflet/leaflet.fusesearch.js' | prepend: site.digital-assets }}"></script>

<!-- add collection map data -->
<script>
(function(){
/* add collection map data */
var geodata = { "type": "FeatureCollection", "features": [
{% for item in items %}{% if item.latitude and item.longitude %}
{ "type":"Feature", "geometry":{ "type":"Point", "coordinates":[{{ item.longitude | strip }},{{ item.latitude | strip }}] }, "properties":{ "title": {{ item.title | jsonify }}, "creator": {{ item.creator | jsonify }}, "date": {{ item.date | jsonify }}, "subjects": {{ item.subject | jsonify}}, "id": {{ item.cdm-id | jsonify }}, "obj": {{ item.object-id | jsonify }} } }{% unless forloop.last %}, {% endunless %}{% endif %}{% endfor %}
{ "type":"Feature", "geometry":{ "type":"Point", "coordinates":[{{ item.longitude | strip }},{{ item.latitude | strip }}] }, "properties":
{ "title": {{ item.title | jsonify }},
{% for f in fields %}"{{ f.field }}": {{ item[f.field] | jsonify }},{% endfor %} "cdm": {{ item.cdm-id | jsonify }}, "id": {{ item.object-id | jsonify }} } }{% unless forloop.last %}, {% endunless %}{% endif %}{% endfor %}
]};
</script>
<!-- int map and search -->
<script>
/* init and set zoom */
var map = L.map('map').setView([{{site.data.theme.latitude}},{{site.data.theme.longitude}}],{{ site.data.theme.zoom-level | default: 5 }});
/* init map and set zoom */
var map = L.map('map').setView([{{ site.data.theme.latitude | default: 46.727485 }},{{ site.data.theme.longitude | default: -117.014185 }}],{{ site.data.theme.zoom-level | default: 5 }});
/* load map layer */
/* var Esri_NatGeoWorldMap = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles &copy; Esri &mdash; National Geographic, Esri, DeLorme, NAVTEQ, UNEP-WCMC, USGS, NASA, ESA, METI, NRCAN, GEBCO, NOAA, iPC',
Expand All @@ -35,18 +37,22 @@
};
var searchCtrl = L.control.fuseSearch(options);
searchCtrl.addTo(map);
searchCtrl.indexFeatures(geodata.features, ['title', 'subjects', 'date', 'creator']);
searchCtrl.indexFeatures(geodata.features, {{ fields | where: 'search','true' | map: 'field' | unshift: 'title' | jsonify }});
/* add geojson marker and popup */
L.geoJson(geodata, {
pointToLayer: function(feature,latlng){
var marker = L.marker(latlng);
marker.bindPopup('<h3>' + feature.properties.title + '</h3><a target="_blank" class="btn btn-light" href="{% if site.data.theme.repo-link %}{{ site.data.theme.cdm-url }}/cdm/ref/collection/{{ site.data.theme.cdm-collection-id }}/id/'+feature.properties.id+'{% else %}{{ site.baseurl }}/items/'+feature.properties.id+'.html{% endif %}" ><img class="thumb" src="{{ site.data.theme.cdm-url }}/utils/getthumbnail/collection/{{ site.data.theme.cdm-collection-id }}/id/'+feature.properties.id+'" /></a><p>Date: ' + feature.properties.date + '<br>Subjects: ' + feature.properties.subjects + '</p><h4><a target="_blank" class="btn btn-light" href="{% if site.data.theme.repo-link %}{{ site.data.theme.cdm-url }}/cdm/ref/collection/{{ site.data.theme.cdm-collection-id }}/id/'+feature.properties.obj+'{% else %}{{ site.baseurl }}/items/'+feature.properties.obj+'.html{% endif %}" >View Item</a><h4>');
marker.bindPopup('<h3>' + feature.properties.title +
'</h3><p><a target="_blank" class="btn btn-light" href="{% if site.data.theme.repo-link %}{{ site.data.theme.cdm-url }}/cdm/ref/collection/{{ site.data.theme.cdm-collection-id }}/id/' + feature.properties.cdm + '{% else %}{{ site.baseurl }}/items/' + feature.properties.id + '.html{% endif %}" ><img class="mapthumb" src="{{ site.data.theme.cdm-url }}/utils/getthumbnail/collection/{{ site.data.theme.cdm-collection-id }}/id/' + feature.properties.cdm + '" /></a>' +
{% for f in fields %}{% if f.display %}
'<br><strong>{{ f.display }}:</strong> ' + feature.properties.{{ f.field }} + {% endif %}{% endfor %}
'<br><a target="_blank" class="btn btn-light" href="{% if site.data.theme.repo-link %}{{ site.data.theme.cdm-url }}/cdm/ref/collection/{{ site.data.theme.cdm-collection-id }}/id/' + feature.properties.cdm + '{% else %}{{ site.baseurl }}/items/' + feature.properties.id + '.html{% endif %}" >View Item</a></p>');
return marker;
},
onEachFeature: function (feature, layer) {
feature.layer = layer;
}
}).addTo(map);

})();
</script>
2 changes: 0 additions & 2 deletions _layouts/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

<style>
#map { height: 750px; z-index: 98; }
.leaflet-popup-content img { max-width: 100%;}
b { font-weight: bold; }
</style>
<link rel="stylesheet" href="{{ '/leaflet/leaflet.css' | prepend: site.digital-assets }}">
<link rel="stylesheet" href="{{ '/leaflet/leaflet.fusesearch.css' | prepend: site.digital-assets }}">
Expand Down

0 comments on commit ae992ca

Please sign in to comment.