Your goal is to add an additional layer that shows flight routes and display it on the map. This time we will incorporate our map into a Spring Boot project. We will store geographic data in our Postgresql database. Some starter code has been provided for you.
$ git checkout -b day5-solution
PostGIS is a spatial database extension for PostgreSQL object-relational database. PostGIS adds support for geographic objects in Postgresql. This includes features such as georgraphic data types, location functions, and location based querying.
If you don’t already have a PostGIS container installed checkout the Installation: Docker PostGIS.
Make sure the PostGIS container is the only container running that is listening on port 5432. You can check this with $ docker ps -a
Run $ psql -h 127.0.0.1 -U psq_user -d postgres
to access the PSQL CLI.
Then in the postgres termainl run this to create a new database:
postgres=# CREATE DATABASE airwaze;
Also create a database for your tests:
postgres=# CREATE DATABASE airwaze_test;
Now we want to install the geospatial extensions to Postgres for the airwaze
db.
From the PSQL CLI:
# CONNECT TO AIRWAZE DB
postgres=# \c airwaze;
# CREATE GEOSPATIAL EXTENSIONS
airwaze=# CREATE EXTENSION postgis;
airwaze=# CREATE EXTENSION postgis_topology;
airwaze=# CREATE EXTENSION fuzzystrmatch;
airwaze=# CREATE EXTENSION postgis_tiger_geocoder;
Make sure that everything installed correctly by running this query
- Remember to do that for your test database airwaze_test
as well!:
airwaze=# SELECT POSTGIS_FULL_VERSION();
airwaze_user
and airwaze_test_user
airwaze_user
-> airwaze
and airwaze_test_user
-> airewaze_test
superuser
rights because we are going to be running a file with postgres
Notice in application.properties
and application-test.properties
that the db configurtion refers to token values like ${APP_DB_NAME}
and ${APP_DB_HOST}
.
This application uses Spring Boot and Spring Data. When the project boots up, if you have a src/main/resources/import.sql
file, it will automatically be executed against your database by hibernate.
import.sql
only runs if ddl-auto=create or create-drop
in application.properties
The import.sql
file in this project contains SQL statements that import CSV data into SQL tables. Please take a minute to review import.sql
and the two .csv
files.
import.sql
file in the airwaze projectWe are using a PostGIS docker container. Althought it is installed on our computer, docker is a virtualization/containerization tool, so our PostGIS container is unaware of any other files on our computer. We will need to COPY our CSV files to a location our PostGIS container can work with.
Luckily docker gives us an easy way to do this.
$ docker cp Airports.csv postgis:/tmp
$ docker cp routes.csv postgis:/tmp
The cp
command in docker stands for copy. We are copying the two CSV files into a directory called /tmp inside of our container.
import.sql
points to the copies of airports.csv
and routes.csv
in your containercsv
files to see what data is being imported for routes and airportsbootRun
gradle task to build and run the web applicationimport.sql
file and populate the related tableshttp://localhost:8080
in your browser. You should see a map with Mexico on it that includes a map layer for airports as red circles.Open a psql
prompt connected to airwaze
database and then run these commands one at a time:
airwaze=# select count(*) from route;
airwaze=# select count(*) from airport;
airwaze=# \d
airwaze=# \d airport
airwaze=# \d route
/
is important.Understand provided tests and get them to pass
Hint
To pass these tests you will need to create a new Repository, and a new Controller. Read the tests to figure out how to get them to pass.
When the map is clicked, list all airports that are at that pixel
map.forEachFeatureAtPixel(event.pixel, function(feature,layer)
in resources/static/js/scripts.js
Create a route endpoint that returns routes for a certain srcId
http://localhost:8080/route/?srcId=12
When an airport feature is clicked on the map, show the routes for that airport
http://localhost:8080/route/?srcId=X
, where X will be the airportId
from the featureWrite integration tests for ``RouteController`` use ``AirportControllerTests`` as a guide
document.findElementById
(Your list of airports can be organized and styled differently)