22W-UP206A

https://yohman.github.io/22W-UP206A/

View the Project on GitHub yohman/22W-UP206A

Week 10

Zoom link: https://ucla.zoom.us/j/92530704333

Final week!

Albert Kochaphum

Agenda

A javascript teaser

Open Sublime, and enter the following code. Then, save the file as index.html, and open it on a web browser (double clicking the file usually works).

<!DOCTYPE html>
<html>
<head>
	<title>My first map</title>
	<meta charset="utf-8" />

	<!-- styles -->
	<style type="text/css">
		html {height: 100%}
		body {height: 100%;margin: 0;}
		#map {height: 100%;}
	</style>

	<!-- leaflet stylesheet-->
	<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin=""/>

	<!-- leaflet js library -->
	<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>

</head>
<body>
	<!-- map container -->
	<div id="map"></div>

	<script>
		// initiate map
		var map = L.map('map').setView([34.0744413,-118.4391512], 18);

		// basemap
		var tiles = L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
			maxZoom: 18,
			attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, ' +
				'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
			id: 'mapbox/streets-v11',
			tileSize: 512,
			zoomOffset: -1
		}).addTo(map);

	</script>
</body>
</html>

Add a marker with a popup. Code hint:

var marker = L.marker([34.0744413,-118.4391512]).addTo(map).bindPopup('hello world!');

Add a circle with a 100m radius:

// add a circle
var circle = L.circle([34.0744413,-118.4391512], {
	color: 'red',
	fillColor: '#f03',
	fillOpacity: 0.2,
	radius: 100
}).addTo(map);