jonnybarnes.uk/public/assets/js/maps.js

2 lines
No EOL
5 KiB
JavaScript
Vendored

!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t,r){"use strict";function n(e){var t=/POINT\((.*)\)/.exec(e),r=t[1].split(" ")[0];return{latitude:t[1].split(" ")[1],longitude:r}}r.d(t,"a",function(){return c}),mapboxgl.accessToken="pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiY2l2cDhjYW04MDAwcjJ0cG1uZnhqcm82ayJ9.qA2zeVA-nsoMh9IFrd5KQw";function i(e){return e.split("-").map(function(e){var t=function(e){return function(e){if(Array.isArray(e))return e}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}(e),r=t[0],n=t.slice(1);return r.toUpperCase()+n.join("").toLowerCase()}).join(" ")}function a(e){var t=e._container.parentNode.querySelector(".u-url").getAttribute("href");return t.substr(t.lastIndexOf("/")+1)}var l=function(e,t,r){var n=3<arguments.length&&void 0!==arguments[3]&&arguments[3],o=document.createElement("div"),l=document.createElement("input"),u=r+a(e);l.setAttribute("id",u),l.setAttribute("type","radio"),l.setAttribute("name","map"+a(e)),l.setAttribute("value",r),1==n&&l.setAttribute("checked","checked"),l.addEventListener("click",function(){var t=e.getSource("points");e.setStyle("mapbox://styles/mapbox/"+r+"-v9"),e.on("style.load",function(){e.addLayer({id:"points",type:"symbol",source:{type:"geojson",data:t._data},layout:{"icon-image":"{icon}-15","text-field":"{title}","text-offset":[0,1]}})})});var c=document.createElement("label");c.setAttribute("for",r+a(e)),c.appendChild(document.createTextNode(i(r))),o.appendChild(l),o.appendChild(c),t.appendChild(o)},u=function(e){var t=document.createElement("fieldset"),r=document.createElement("legend"),n=document.createTextNode("Map Style");return r.appendChild(n),t.appendChild(r),t.classList.add("map-menu"),l(e,t,"streets",!0),l(e,t,"satellite-streets"),t};function c(e){var t,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,i=e.dataset.latitude,a=e.dataset.longitude,l=e.dataset.name,c=e.dataset.marker;if(""==c&&(c="circle"),t=null==l?{type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"Point",coordinates:[a,i]},properties:{title:"Current Location",icon:"circle-stroked",uri:"current-location"}}]}:{type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"Point",coordinates:[a,i]},properties:{title:l,icon:c}}]},null!=o){var d=!0,s=!1,p=void 0;try{for(var f,y=o[Symbol.iterator]();!(d=(f=y.next()).done);d=!0){var m=f.value,v=n(m.location).longitude,b=n(m.location).latitude;t.features.push({type:"Feature",geometry:{type:"Point",coordinates:[v,b]},properties:{title:m.name,icon:"circle",uri:m.slug}})}}catch(e){s=!0,p=e}finally{try{d||null==y.return||y.return()}finally{if(s)throw p}}}null!=r&&(a=r.coords.longitude,i=r.coords.latitude);var g=new mapboxgl.Map({container:e,style:"mapbox://styles/mapbox/streets-v9",center:[a,i],zoom:15});if(null==r&&g.scrollZoom.disable(),g.addControl(new mapboxgl.NavigationControl),e.appendChild(u(g)),g.on("load",function(){g.addLayer({id:"points",type:"symbol",source:{type:"geojson",data:t},layout:{"icon-image":"{icon}-15","text-field":"{title}","text-offset":[0,1]}})}),null!=r&&g.on("click",function(e){var t,r=g.queryRenderedFeatures(e.point,{layer:["points"]});r.length&&(g.flyTo({center:r[0].geometry.coordinates}),t=r[0].properties.uri,document.querySelector("select")&&("current-location"==t?document.querySelector('select [id="option-coords"]').selected=!0:document.querySelector('select [value="'+t+'"]').selected=!0))}),t.features&&1<t.features.length){var h=new mapboxgl.LngLatBounds,x=!0,j=!1,S=void 0;try{for(var A,C=t.features[Symbol.iterator]();!(x=(A=C.next()).done);x=!0){var w=A.value;h.extend(w.geometry.coordinates)}}catch(e){j=!0,S=e}finally{try{x||null==C.return||C.return()}finally{if(j)throw S}}g.fitBounds(h,{padding:65})}return g}},,,,function(e,t,r){"use strict";r.r(t);var n=r(0),o=document.querySelectorAll(".map"),i=!0,a=!1,l=void 0;try{for(var u,c=o[Symbol.iterator]();!(i=(u=c.next()).done);i=!0){var d=u.value;Object(n.a)(d)}}catch(e){a=!0,l=e}finally{try{i||null==c.return||c.return()}finally{if(a)throw l}}}]);
//# sourceMappingURL=maps.js.map