diff --git a/app/assets/javascripts/tailwind/maps.js b/app/assets/javascripts/tailwind/maps.js index fc11d3362..2e518ae7a 100644 --- a/app/assets/javascripts/tailwind/maps.js +++ b/app/assets/javascripts/tailwind/maps.js @@ -1,50 +1,58 @@ //= require maps/pano_utils -async function initialisePano2(elem) { +async function initialisePano2(elem, params) { const { StreetViewPanorama } = await google.maps.importLibrary("streetView"); const { Marker } = await google.maps.importLibrary("marker") - var lat = Number(elem.dataset.lat); - var lng = Number(elem.dataset.lng); - var address = elem.dataset.address; - // Can't yet figure out how to make the POV point at the marker - var pointToLookAt = new google.maps.LatLng(lat, lng); + var pointToLookAt = new google.maps.LatLng(params.lat, params.lng); var myPano = new StreetViewPanorama(elem, - {position: pointToLookAt, navigationControl: false, addressControl: false, zoom: 0, scrollwheel: false, fullscreenControl: false, linksControl: false}); + { + position: pointToLookAt, + navigationControl: false, + addressControl: false, + zoom: 0, + scrollwheel: false, + fullscreenControl: false, + linksControl: false + }); google.maps.event.addListener(myPano, 'position_changed', function() { // Orient the camera to face the position we're interested in var angle = computeAngle(pointToLookAt, myPano.getPosition()); myPano.setPov({heading:angle, pitch:0, zoom:1}); }); - var panoMarker = new Marker({position: pointToLookAt, title: address}); + var panoMarker = new Marker({position: pointToLookAt, title: params.address}); panoMarker.setMap(myPano); } -async function initialiseBasicMapWithMarker2(map_div) { +async function initialiseBasicMapWithMarker2(map_div, params) { const { Map } = await google.maps.importLibrary("maps"); const { Marker } = await google.maps.importLibrary("marker"); - var center = { lat: Number(map_div.dataset.lat), lng: Number(map_div.dataset.lng) }; - var address = map_div.dataset.address; - var zoom = Number(map_div.dataset.zoom); - + var center = { lat: params.lat, lng: params.lng }; var map = new Map( map_div, - { zoom: zoom, center: center, fullscreenControl: false, streetViewControl: false, draggable: false, backgroundColor: "#d1e6d9" } + { + zoom: params.zoom, + center: center, + fullscreenControl: false, + streetViewControl: false, + draggable: false, + backgroundColor: "#d1e6d9" + } ); - new Marker({ position: center, map: map, title: address }); + new Marker({ + position: center, + map: map, + title: params.address + }); return map; } -async function initialiseAlertMap2(map_div) { - var lat = Number(map_div.dataset.lat); - var lng = Number(map_div.dataset.lng); - var radius_meters = Number(map_div.dataset.radiusMeters); - - var map = await initialiseBasicMapWithMarker2(map_div); - return drawCircleOnMap2(map, lat, lng, radius_meters); +async function initialiseAlertMap2(map_div, params) { + var map = await initialiseBasicMapWithMarker2(map_div, params); + return drawCircleOnMap2(map, params.lat, params.lng, params.radius_meters); } async function drawCircleOnMap2(map, centre_lat, centre_lng, radius_in_metres) { diff --git a/app/views/_tailwind/alerts_new/edit.html.erb b/app/views/_tailwind/alerts_new/edit.html.erb index 4bf13eccc..bc50a7aa5 100644 --- a/app/views/_tailwind/alerts_new/edit.html.erb +++ b/app/views/_tailwind/alerts_new/edit.html.erb @@ -12,7 +12,7 @@ <%= form_with model: [:profile, @alert], builder: FormBuilders::Tailwind, class: "mt-5" do |f| %> <%= f.label :radius_meters, "Alert distance" %>