You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Mapbox access token should really be stored in the Django settings
331
-
file, so we left a TODO note to handle that as a future step.
332
+
file, so we left a "TODO" note to handle that as a future step.
332
333
333
334
Now we can try our webpage again. Refresh `localhost:8000` in your
334
335
web browser.
335
336
336
-
<imgsrc="/img/180519-django-maps/map-time-with-map.png"width="100%"class="shot rnd outl"alt="Screenshot of the Mapbox map showing up in our Django front end.">
337
+
<imgsrc="/img/180519-django-maps/map-time-with-map.jpg"width="100%"class="shot rnd outl"alt="Screenshot of the Mapbox map showing up in our Django front end.">
337
338
338
339
Sweet, we've got a live, interactive map! It's kind of weird thought how it
339
340
is zoomed out to view the entire world. Time to customize the map using
@@ -344,6 +345,96 @@ a few JavaScript parameters.
344
345
We can modify the map by changing parameters for the style, zoom level,
345
346
location and many other attributes.
346
347
348
+
We'll start by changing the location that the initial map centers in
349
+
on as well as the zoom level.
350
+
351
+
Re-open `djmaps/maps/templates/default.html` and modify the first
352
+
highlighted lines so it ends with a commas and add the two new
353
+
highlighted lines shown below.
354
+
355
+
```
356
+
<!DOCTYPE html>
357
+
<html>
358
+
<head>
359
+
<title>Interactive maps for Django web apps</title>
The first number, -77.03, for the `center` array is the longitude
380
+
and the second number, 38.91, is the latitude. Zoom level 9 is much
381
+
closer to the city than the default which was the entire world at
382
+
level 0. All of the customization values are listed in the
383
+
[Mapbox GL JS API documentation](https://www.mapbox.com/mapbox-gl-js/api/).
384
+
385
+
Now refresh the page at `localhost:8000` to reload our map.
386
+
387
+
<imgsrc="/img/180519-django-maps/map-updated-style-1.jpg"width="100%"class="shot rnd outl"alt="Updated map centered and zoomed in on Washington, D.C.">
388
+
389
+
Awesome, now we are zoomed in on Washington, D.C. and can still move
390
+
around to see more of the map. Let's make a couple other changes to
391
+
our map before wrapping up.
392
+
393
+
Again back in `djmaps/maps/templates/default.html` change the highlighted
394
+
line for the `style` key to the `mapbox://styles/mapbox/satellite-streets-v10`
395
+
value. That will change the look from an abstract map style to satellite
396
+
image data. Update `zoom: 9` so that it has a comma at the end of the line
397
+
and add `bearing: 180` as the last key-value pair in the configuration.
398
+
399
+
400
+
```
401
+
<!DOCTYPE html>
402
+
<html>
403
+
<head>
404
+
<title>Interactive maps for Django web apps</title>
<imgsrc="/img/180519-django-maps/map-updated-style-2.jpg"width="100%"class="shot rnd outl"alt="Updated map with satellite imagery and street map overlay.">
428
+
429
+
The map now provides a satellite view with streets overlay but it is
430
+
also... "upside down"! At least the map is upside down compared to how
431
+
most maps are drawn, due to the `bearing: 180` value, which modified
432
+
this map's rotation.
433
+
434
+
Not bad for a few lines of JavaScript in our Django application.
435
+
Remember to check the
436
+
[Mapbox GL JS API documentation](https://www.mapbox.com/mapbox-gl-js/api/)
437
+
for the exhaustive list of parameters that you can adjust.
0 commit comments