In the first two hours of the One Hour AI Map challenge I created a very basic Meet in the Middle interactive map. If you want a recap (or missed the first two posts) then check out:
One Hour AI Map Challenge - Part One
One Hour AI Map Challenge - Part Two
In the third hour of the One Hour AI Map Challenge I want Bard to add custom numbered markers (1, 2 & 3 ) to the map. I also want to add a 'share' button to the map which will post a message ('Let's meet here') to Twitter with a link to the midpoint location on Google Maps.
Prompt No.1:
How do I add a custom marker to a marker with the variable name 'markerA' in Leaflet.js
To which Bard responded with:
const myIcon = L.icon({iconUrl: 'https://your-website.com/marker.png',shadowUrl: 'https://your-website.com/marker-shadow.png',iconSize: [32, 32], // size of the icon imageshadowSize: [48, 32], // size of the shadow imageiconAnchor: [16, 32], // point of the icon which will correspond to the marker's locationshadowAnchor: [16, 24] // point of the shadow that will be positioned below the icon});const markerA = L.marker([lat, lng], {icon: myIcon}).addTo(map);
I then downloaded three numbered markers from the Map Icons Collection and uploaded them to the same server as the Meet in the Middle map. I used Bard's suggested code to create three marker variables (aIcon, bIcon & cIcon) and added the correct marker to the markerA, markerB and markerC variables.
Our map now has numbered markers.
Next I want to add a 'share' button after the midpoint marker is added to the map, so that users can share their meeting location with friends.
Prompt No.2:
after this javascript statement use innerhtml to add a button with an id of 'share' to an element called 'instructions' -
var midpointMarker = L.marker([midLat, midLng]).addTo(map); midpointMarker.bindPopup("I'm the midpoint!");
var midpointMarker = L.marker([midLat, midLng], {draggable: true}).addTo(map);midpointMarker.bindPopup("I'm the midpoint!");// Add the button using innerHTMLdocument.getElementById('instructions').innerHTML += '<button id="share">Share</button>';
This will add a 'share' button next to our 'Calculate Midpoint' marker. We actually want the 'share' button to replace the 'Calculate Midpoint' button so I omitted the '+' symbol from the line -
document.getElementById('instructions').innerHTML += '<button id="share">Share</button>';
Prompt No.3:
Add an event listener to the 'share' button which will call a function called' shareToTwitter'
document.getElementById('share').addEventListener('click', shareToTwitter);
Prompt No.4:
Prompt No.4 failed miserably
function shareToTwitter() {var twtLink = "https://twitter.com/intent/tweet?text=Let's%20meet%20here:%20" +encodeURIComponent("https://www.google.com/maps/@" + midLat + "," + midLng + ",15z");}// Add the button using innerHTMLdocument.getElementById("instructions").innerHTML = '<button id="share">Share</button>';document.getElementById("share").addEventListener("click", shareToTwitter);
In summary the third hour of the One How AI Map Challenge was a little disappointing. I had to break the rule that all the JavaScript for the map was produced by Bard. Never mind, the adventure will continue.
In the fourth hour we could ask Bard to make our buttons a little more attractive. We also still need an option to create a midpoint between 2 or 3 (or more) points. We also need to change the Google Maps link to a link back to the meeting point on the Meet in the Middle map.
No comments:
Post a Comment