jonnybarnes.uk/public/assets/js/newnote.js

3 lines
6.2 KiB
JavaScript
Raw Normal View History

2016-10-03 14:48:44 +01:00
function getLocation(){navigator.geolocation.getCurrentPosition(function(e){addPlacesMap(e.coords.latitude,e.coords.longitude,e.coords.accuracy)})}function addPlacesMap(e,t,a){fetch("/places/near/"+e+"/"+t+"?u="+a,{credentials:"same-origin",method:"get"}).then(function(e){return e.json()}).then(function(a){if(1==a.error&&(alertify.reset(),alertify.error(a.error_description)),a.length>0){var n,r=[];for(n=0;n<a.length;++n){var o=parseLocation(a[n].location),l=a[n].name,c=a[n].slug;r.push([l,c,o[0],o[1]])}addMap(e,t,r)}else addMap(e,t)}).catch(function(e){console.error(e)})}function addMap(e,t,a){2==arguments.length&&(a=null);var n=button.parentNode,r=document.createElement("div");r.setAttribute("id","map"),n.appendChild(r),L.mapbox.accessToken="pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w";var o=L.mapbox.map("map","jonnybarnes.gnoihnim").setView([e,t],15).addLayer(L.mapbox.tileLayer("jonnybarnes.gnoihnim",{detectRetina:!0})),l=L.marker([e,t],{draggable:!0}).addTo(o);l.on("dragend",function(){var e=document.querySelector("#place-latitude");null!==e&&(e.value=getLatitudeFromMapboxMarker(l.getLatLng()));var t=document.querySelector("#place-longitude");null!==t&&(t.value=getLongitudeFromMapboxMarker(l.getLatLng()))});var c=document.createElement("select");c.setAttribute("name","location");var i=document.createElement("option");i.setAttribute("selected","selected"),i.setAttribute("value","no-location");var d=document.createTextNode("Select no location");i.appendChild(d),c.appendChild(i),n.insertBefore(c,r),null!==a&&(a.forEach(function(e){var t=document.createElement("option");t.setAttribute("value",e[1]);var a=document.createTextNode(e[0]);t.appendChild(a),t.dataset.latitude=e[2],t.dataset.longitude=e[3],c.appendChild(t);var n=L.marker([e[2],e[3]],{icon:L.mapbox.marker.icon({"marker-size":"large","marker-symbol":"building","marker-color":"#fa0"})}).addTo(o),r="Name: "+e[0];n.bindPopup(r,{closeButton:!0}),n.on("click",function(){o.panTo([e[2],e[3]]),selectPlace(e[1])})}),c.addEventListener("change",function(){if("no-location"!==c.value){var e=c[c.selectedIndex].dataset.latitude,t=c[c.selectedIndex].dataset.longitude;o.panTo([e,t])}}));var u=document.createElement("button");u.setAttribute("type","button"),u.setAttribute("id","create-new-place"),u.appendChild(document.createTextNode("Create New Place?")),u.addEventListener("click",function(){var e=document.createElement("label");e.setAttribute("for","place-name"),e.classList.add("place-label"),e.appendChild(document.createTextNode("Place Name:"));var t=document.createElement("input");t.setAttribute("placeholder","Name"),t.setAttribute("name","place-name"),t.setAttribute("id","place-name"),t.setAttribute("type","text");var a=document.createElement("label");a.setAttribute("for","place-description"),a.classList.add("place-label"),a.appendChild(document.createTextNode("Place Description:"));var r=document.createElement("input");r.setAttribute("placeholder","Description"),r.setAttribute("name","place-description"),r.setAttribute("id","place-description"),r.setAttribute("type","text");var i=document.createElement("label");i.setAttribute("for","place-latitude"),i.classList.add("place-label"),i.appendChild(document.createTextNode("Place Latitude:"));var d=document.createElement("input");d.setAttribute("name","place-latitude"),d.setAttribute("id","place-latitude"),d.setAttribute("type","text"),d.value=getLatitudeFromMapboxMarker(l.getLatLng());var u=document.createElement("label");u.setAttribute("for","place-longitude"),u.classList.add("place-label"),u.appendChild(document.createTextNode("Place Longitude:"));var p=document.createElement("input");p.setAttribute("name","place-longitude"),p.setAttribute("id","place-longitude"),p.setAttribute("type","text"),p.value=getLongitudeFromMapboxMarker(l.getLatLng());var m=document.createElement("button");m.setAttribute("id","place-submit"),m.setAttribute("value","Submit New Place"),m.setAttribute("name","place-submit"),m.setAttribute("type","button"),m.appendChild(document.createTextNode("Submit New Place")),n.appendChild(e
2016-09-26 13:19:52 +01:00
//# sourceMappingURL=maps/newnote.js.map