Skip to content

Commit

Permalink
lab3
Browse files Browse the repository at this point in the history
  • Loading branch information
zhamic7 committed Jul 17, 2024
1 parent 896dbc8 commit a42537c
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 198 deletions.
78 changes: 78 additions & 0 deletions week3/gallery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html>

<head>
<title>AA191A GeoJSONs and Loops Lab</title>

<meta charset="utf-8" />
<link rel="shortcut icon" href="#">
<link rel="stylesheet" href="styles/gallery.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap" rel="stylesheet">
</head>

<body>

<header>
<h1>GALLERY! ^_<</h1>
<a href="index.html">go back</a>
</header>

<main>

<!-- hint: majority of your lab assignment can go here -->
<div class="col1">
<button onclick="openPopup(1)" class="placeholder-img"></button>
<button onclick="openPopup(2)" class="placeholder-img"></button>
</div>

<div class="col2">
<button onclick="openPopup(3)" class="placeholder-img"></button>
<button onclick="openPopup(4)" class="placeholder-img"></button>
</div>
</main>

<div id="popup">
<div id="content">
<button class="closeButton" onclick="closePopup()">X</button>
</div>
</div>

<div id="footer">
<p>COPYRIGHT 2024</p>
</div>

</body>

<script>
function createImage(img_id) {
const newImage = document.createElement("img");
newImage.id = "display-img";
newImage.src = "images/image.jpg";
newImage.setAttribute("alt", "Placeholder image " + img_id);
document.getElementById("content").appendChild(newImage);

}

function openPopup(img_id) {
let hash = "#image_" + img_id;
window.location = hash;
document.getElementById("popup").style.visibility = "visible";
createImage(img_id);
}

function closePopup() {
document.getElementById("popup").style.visibility = "hidden";
window.location = "";
document.getElementById("display-img").remove();
}

if (window.location.hash) {
let image_id = window.location.hash;
image_id = image_id.charAt(image_id.length - 1);
openPopup(image_id);
}
</script>

</html>
Binary file added week3/images/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
6 changes: 2 additions & 4 deletions week3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
<html>

<head>
<title>AA191A Functional Events Lab</title>
<title>AA191A GeoJSONs and Loops Lab</title>

<meta charset="utf-8" />
<link rel="shortcut icon" href="#">
<link rel="stylesheet" href="styles/style.css">
<link rel="stylesheet" href="styles/index.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap" rel="stylesheet">


<!-- MapLibreGL's css-->
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl/dist/maplibre-gl.css" />

Expand All @@ -26,7 +25,6 @@ <h1>ABOUT ME! ^_< ☆</h1>
</header>

<main>

<!-- hint: majority of your lab assignment can go here -->
<div class="col1">
<!-- Portfolio content goes here -->
Expand Down
83 changes: 36 additions & 47 deletions week3/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,66 +32,55 @@ function createCustomIcon (caption, latlng) {
.setHTML(caption));
}

function Place(place_name, place_district, place_city, place_desc, lat, lon) {
function Place(index, place_name, place_district, place_city, place_desc, lat, lon) {
let image_url = "gallery.html#image_" + index;
this.caption = `<div class="mapPopup">
<div class="popupTitle">
<h2 style="font-size:16px;">${place_name}, ${place_district}, ${place_city}</h2>
</div>
<p style="font-size:15px;">${place_desc}</p>
<a style="font-size: 13px;" href="${image_url}"}>View Image >></a>
<p style="margin-top: 7px; font-size: 15px;">${place_desc}</p>
</div>`;
this.coords = [lon, lat];
createButtons(place_city, lat, lon, 9);
}

const places = [
new Place(
'Zhujiajiao',
'Qingpu District',
'Shanghai',
'Super pretty water town with lots of historic architecture and yummy food.',
31.113630863554462,
121.05345698483865
),
new Place(
'Leifeng Pagoda',
'Xihu District',
'Hangzhou',
'Originally a Buddhist tower that has been rebuilt over the years. \
I sadly didn\'t have time to go see the view from the topmost level.',
30.231512056688324,
120.149705725118
),
new Place(
'Classical Gardens of Suzhou',
'Gusu District',
'Suzhou',
'Collection of gardens. The lotus ponds were really pretty!',
31.372395575344928,
120.62852505160254
),
new Place(
'Nanjing Fuzimiao',
'Qinhuai District',
'Nanjing',
'A Confucius Temple where the imperial exam was held. \
There\'s a museum on the same street with a cheatsheet from the Qing Dynasty \
on display. As expected, the handwriting is tiny, haha.',
32.02184144417682,
118.79184414016119
),
]
function processData (data) {
let places = [];
for (let i = 0; i < data.features.length; i++) {
let tmp = data.features[i];
places.push(new Place(i + 1,
tmp.properties.name,
tmp.properties.district,
tmp.properties.city,
tmp.properties.desc,
tmp.geometry.coordinates[1],
tmp.geometry.coordinates[0]
));
}
places.forEach(place => createCustomIcon(place.caption, place.coords).addTo(map) );
}

let initZoom = {
"lat": 31.204359154022054,
"lon": 120.10623118282591,
"zoom": 7
}

// Create map and add markers
const map = new maplibregl.Map({
container: 'map', // container ID
style: 'https://api.maptiler.com/maps/dataviz/style.json?key=aRyJfnj25CKYN2noi9Wt', // Your style URL
center: [120.10623118282591, 31.204359154022054], // Starting position [lng, lat]
zoom: 7 // Starting zoom level
center: [initZoom.lon, initZoom.lat], // Starting position [lng, lat]
zoom: initZoom.zoom // Starting zoom level
});
createButtons("Default View", 31.204359154022054, 120.10623118282591, 7);
createButtons("Default View", initZoom.lat, initZoom.lon, initZoom.zoom);

let markers = [];
for (let i = 0; i < places.length; i++) {
markers.push(createCustomIcon(places[i].caption, places[i].coords));
}
markers.forEach((marker) => marker.addTo(map)); // Ensure the order is longitude, latitude
map.on("load", function() {
fetch("map.geojson") // fetch data
.then(data => { return data.json(); }) // check data
.then(data => { processData(data); }) // process data
.catch(function(error) {
console.log("An error occurred: ", error);
});
});
69 changes: 69 additions & 0 deletions week3/map.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Zhujiajiao",
"district": "Qingpu District",
"city": "Shanghai",
"desc": "Super pretty water town with lots of historic architecture and yummy food."
},
"geometry": {
"coordinates": [
121.05079163809194,
31.113422651979562
],
"type": "Point"
}
},
{
"type": "Feature",
"properties": {
"name": "Leifeng Pagoda",
"district": "Xihu District",
"city": "Hangzhou",
"desc": "Originally a Buddhist tower that has been rebuilt over the years. I sadly didn't have time to go see the view from the topmost level."
},
"geometry": {
"coordinates": [
120.14494204232636,
30.233352123539035
],
"type": "Point"
}
},
{
"type": "Feature",
"properties": {
"name": "Humble Administrator's Garden",
"district": "Gusu District",
"city": "Suzhou",
"desc": "A part of the Classical Gardens of Suzhou. The lotus ponds were really pretty!"
},
"geometry": {
"coordinates": [
120.62533357835912,
31.325210071401756
],
"type": "Point"
}
},
{
"type": "Feature",
"properties": {
"name": "Nanjing Fuzimiao",
"district": "Qinhuai District",
"city": "Nanjing",
"desc": "A Confucius Temple where the imperial exam was held. There's a museum on the same street with a cheatsheet from the Qing Dynasty on display. As expected, the handwriting is tiny, haha."
},
"geometry": {
"coordinates": [
118.78434984973381,
32.02188820240707
],
"type": "Point"
}
}
]
}
88 changes: 88 additions & 0 deletions week3/styles/gallery.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
@import "style.css";

/* Defines the page layout using a grid */
main {
grid-area: main;
display: grid;
grid-template-areas: "col1 col2";
grid-template-columns: 1fr 1fr;
}

/* Assigns each major section to a part of the grid */
.col1 {
grid-area: col1;
display: flex;
flex-direction: column;
align-items: flex-end;
padding-right:10px;
}

.col2 {
grid-area: col2;
display: flex;
flex-direction: column;
padding-left:10px;
}

.placeholder-img {
width: 75%;
height: 100%;
background: url("../images/image.jpg");
background-size: cover;
background-position: center;

border: none;
margin:10px;
}

#popup {
visibility: hidden;
position:fixed;
padding:0;
margin:0;

top:0;
left:0;

width: 100%;
height: 100%;
background:rgba(0, 0, 0, 0.8);
}

.closeButton {
margin-right: 0;
width: 20px;
margin: 5px;
background-color: white;
border: solid;
border-width: 2px;

font-weight:bold;
}
.closeButton:hover {
color: #0088ff;
border-color:#0088ff;
}

#content {
width:75%;
height:75%;
background-color: white;
position: absolute;
top: 0;
left: 0;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);

display: flex;
flex-direction: column;
align-items: flex-end;
}

#display-img {
height: 100%;
width: auto;
margin-bottom: 2.5%;
align-self: center;
}
Loading

0 comments on commit a42537c

Please sign in to comment.