Exercise 06 : Use Leaflet maps in React application
Introduction
This exercise teaches how to use Leaflet maps in a React application.
Golf courses
Your target is to create React application, which shows some of the Finnish Golf Courses in a Leaflet Maps. Use a following JSON file in your application https://ptm.fi/data/golf_courses.json. Save JSON file to your own project and use local server to watch it.
1 |
|
JSON file stucture is described below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Leaflet maps
You can use any map services found from the net, but one good - free one - is React leaflet. Go through the introdcution, Leaflet setup and installation.
A new project
Create a new React application project and use Leaflet map, which shows one marker (point it to JAMK/Dynamo building). Remember follow Leaflet setup and installation. Look and learn some example codes: Examples.
Note
If you have problems to show map tiles correctly:
- Remember use correct Leaflet CSS and JavaScript files in your
index.html
page. Link - Give width and height to your
App
1 2 3 4 |
|
Load JSON data and show markers with PopUp
Use Axios to load Golf JSON data to your application and show loaded golf courses in a map. Remember use localhost for data loading.
1 2 3 4 5 6 7 8 9 10 |
|
Loop throught the loaded markers data and create a markers collection with map
function. Use Popup
component inside a Marker
component to show some data from the selected course. Render generated marker collection inside a Map
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Test and run
Now your app should work. Click different markers to see golf course data.
Push exercise 06 / Maps to GitLab
Test your application in web browser, take screenshots and commit/push your project and screenshots back to JAMKIT/GitLab. Remember move your exercise/issue ticket from Doing to In Review in Issues Board and write your learning comments to issue comments.
Save screenshots to maps-app folder.