Skip to content

Commit

Permalink
new client side
Browse files Browse the repository at this point in the history
  • Loading branch information
shliamin committed Jun 17, 2024
1 parent ce61b06 commit 3f1ba60
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<div id="map"></div>

<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="script.js"></script>
<script src="scripts.js"></script>
</body>
</html>
30 changes: 25 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@ async function findMuseums() {
var radius = document.getElementById('radius').value;

// Convert address to latitude and longitude
var geoResponse = await axios.get(`https://nominatim.openstreetmap.org/search?format=json&q=${address}`);
if (geoResponse.data.length > 0) {
var lat = geoResponse.data[0].lat;
var lon = geoResponse.data[0].lon;
var geoResponse = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${address}`);
var geoData = await geoResponse.json();

if (geoData.length > 0) {
var lat = geoData[0].lat;
var lon = geoData[0].lon;

// Center the map on the provided location
map.setView([lat, lon], 13);

// Fetch museums from your API
var apiResponse = await axios.get(`https://geocodingapi-7cc21820406a.herokuapp.com/museums?lat=${lat}&lon=${lon}&
var apiResponse = await fetch(`https://geocodingapi-7cc21820406a.herokuapp.com/museums?lat=${lat}&lon=${lon}&radius=${radius}`);
var museums = await apiResponse.json();

// Clear existing markers
map.eachLayer(function (layer) {
if (!!layer.toGeoJSON) {
map.removeLayer(layer);
}
});

// Add markers for each museum
museums.forEach(function (museum) {
var marker = L.marker([museum.lat, museum.lon]).addTo(map);
marker.bindPopup(`<b>${museum.name}</b><br>${museum.email ? 'Email: ' + museum.email + '<br>' : ''}${museum.phone ? 'Phone: ' + museum.phone + '<br>' : ''}${museum.website ? '<a href="' + museum.website + '" target="_blank">Website</a>' : ''}`);
});
} else {
alert('Address not found');
}
}
2 changes: 2 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ body {
margin: 0;
padding: 0;
}

#map {
height: 500px;
width: 100%;
}

.form-container {
margin: 20px;
}

0 comments on commit 3f1ba60

Please sign in to comment.