-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlifestorymap.min.js
1 lines (1 loc) · 2.56 KB
/
lifestorymap.min.js
1
class LifeStoryMap{constructor(o,t,e){e||(e={}),e.zoomLevel||(e.zoomLevel=12),e.vOffset||(e.vOffset=.04),$("#"+o).css("width","100vw"),$("#"+o).css("height","100vh");var n=L.map(o,{zoomControl:!1});L.tileLayer("https://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}",{maxZoom:18,attribution:'see <a href="https://github.com/neinkob15/LifeStoryMap">LifeStoryMap™</a>',subdomains:["mt0","mt1","mt2","mt3"]}).addTo(n);var a=L.easyButton("fa-arrow-circle-left fa-lg",function(o,t){history.go(-1)}),i=L.easyBar([L.easyButton("fa-plus",function(o,t){t.setZoom(t.getZoom()+1)}),L.easyButton("fa-minus",function(o,t){t.setZoom(t.getZoom()-1)})]);a.addTo(n),i.addTo(n);var l=new L.Icon({iconUrl:"https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png",shadowUrl:"https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",iconSize:[25,41],iconAnchor:[12,41],popupAnchor:[1,-34],shadowSize:[41,41]});$.getJSON(t,function(o){var t=[];for(let e of o.milestones){var a=L.marker(e.location,{icon:l}).addTo(n);a.content=e,t.push(a)}e.linesBetween&&L.geodesic([o.milestones.map(o=>new L.LatLng(o.location[0],o.location[1]))],e.lineOptions).addTo(n);n.setView([t[0].getLatLng().lat+e.vOffset,t[0].getLatLng().lng],e.zoomLevel),t[0].openPopup(),t.forEach(function(o,a){o.bindPopup(function(o,t,n,a,i,l){let s="<div class='popupTitle'>"+o+"</div>",p="";t&&(p="<div class='popupDate'>"+t+"</div>");let r="";n&&(r="<img src='"+n+"' class='popupImage' />");let c="<div class='popupDescription'>"+a+"</div>",g="";g=l?"<div style='height: 35px; margin-top: 10px;'><a class='link link"+i+"' style='color: black; float: right; font-size: 20px; display: inline-block; margin: 0 20px;'>Next Milestone</a></div>":e.loop?"<div style='height: 35px; margin-top: 10px;'><a class='link link"+i+"' style='color: black; float: right; font-size: 20px; display: inline-block; margin: 0 20px;'>Start over</a></div>":"<div style='height: 35px; margin-top: 10px;'><a class='link link"+i+"' style='color: black; float: right; font-size: 20px; display: inline-block; margin: 0 20px;'>Overview</a></div>";return s+p+r+c+g}(o.content.title,o.content.date,o.content.image,o.content.description,a,t[a+1]),{className:"myPopup",maxWidth:"500"}).addTo(n),$(document).on("click touchstart",".link"+a,function(){if(t[a].closePopup(),t[a+1])n.flyTo([t[a+1].getLatLng().lat+e.vOffset,t[a+1].getLatLng().lng],e.zoomLevel),t[a+1].openPopup();else{var o=new L.featureGroup(t);e.loop?(n.flyTo([t[0].getLatLng().lat+e.vOffset,t[0].getLatLng().lng],e.zoomLevel),t[0].openPopup()):n.flyToBounds(o.getBounds())}})}),t[0].openPopup()})}}