You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importmapboxglfrom'mapbox-gl';constinitMapboxShow=()=>{constfitMapToMarkers=(map,markers)=>{ ... };// create a function to make a directions requestfunctiondrawRoute(start,end){// make directions request using cycling profilevarurl=`https://api.mapbox.com/directions/v5/mapbox/driving/${start[0]},${start[1]};${end[0]},${end[1]}?steps=true&geometries=geojson&access_token=${mapboxgl.accessToken}`;// make an XHR request https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestvarreq=newXMLHttpRequest();req.responseType='json';req.open('GET',url,true);req.onload=function(){vardata=req.response.routes[0];console.log(data.duration)// display itinerary durationvarduration=parseInt(data.duration/60);vardistance=parseInt(data.distance/1000);// draw routevarroute=data.geometry.coordinates;vargeojson={"type": "Feature","properties": {},"geometry": {"type": "LineString","coordinates": route}};map.addLayer({"id": "route","type": "line","source": {"type": "geojson","data": {"type": "Feature","properties": {},"geometry": {"type": "LineString","coordinates": geojson}}},"layout": {"line-join": "round","line-cap": "round"},"paint": {"line-color": "#3887be","line-width": 5,"line-opacity": 0.75}});map.getSource('route').setData(geojson);};req.send();};constmapElement=document.getElementById('map_show');constmarkers=JSON.parse(mapElement.dataset.markers);conststart=[markers[0].lng,markers[0].lat];constend=[markers[1].lng,markers[1].lat];mapboxgl.accessToken=mapElement.dataset.mapboxApiKey;varmap=newmapboxgl.Map({container: 'map_show',// container idstyle: 'mapbox://styles/mapbox/streets-v11',//stylesheet locationcenter: start,// starting positionzoom: 12,// starting zoom});/// Markersmarkers.forEach((marker)=>{constelement=document.createElement('div');element.className='marker';element.style.backgroundImage=`url('${marker.image_url}')`;element.style.backgroundSize='contain';element.style.width='40px';element.style.height='40px';constpopup=newmapboxgl.Popup().setHTML(marker.infoWindow);newmapboxgl.Marker(element).setLngLat([marker.lng,marker.lat]).setPopup(popup).addTo(map);});fitMapToMarkers(map,markers);// draw routemap.on('load',function(){drawRoute(start,end);});};export{initMapboxShow};
Dropzone delete picture
importDropzonefrom"dropzone";import"dropzone/dist/dropzone.css";Dropzone.autoDiscover=false;functioninitDropzones(){constcsrfToken=document.querySelector('meta[name="csrf-token"]').getAttribute('content');constforms=document.querySelectorAll('.dropzone');forms.forEach((form)=>{constselector="#"+form.id;constphotosURL=form.dataset.stepPhotosUrl;newDropzone(selector,{paramName: "picture",addRemoveLinks: true,init: function(){constthisDropzone=this;// Load the existing photos$.getJSON(photosURL).done(function(photos){photos.forEach((photo)=>{// 1. Call the default addedfile event handler// 2. And optionally show the thumbnail of the file:// 3. Make sure that there is no progress bar, etc...thisDropzone.emit("addedfile",photo);thisDropzone.emit("thumbnail",photo,photo.picture_url);thisDropzone.emit("complete",photo);});});this.on("removedfile",function(file){constdeletionUrl=file.deletion_url;fetch(deletionUrl,{method: "DELETE",headers: {"Accept": "application/json","Content-Type": "application/json",'X-CSRF-Token': csrfToken},credentials: 'same-origin'});});}});});}export{initDropzones};