diff --git a/README.md b/README.md index 29b8b1e..b1029c6 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ First, make sure to have all dependencies installed: - Import the database bridging functions: `import pt_map.gtfs, pt_map.bridge` - Load sample data to db: `pt_map.bridge.gtfs_to_db(pt_map.gtfs.GTFS("/path/to/folder"))` (This might take some time) -Run, study, improve, share. +Run, study, improve, share. ## Copying ### Code diff --git a/transport_accessibility/pt_map/static/pt_map/leaflet_drawing.js b/transport_accessibility/pt_map/static/pt_map/script/leaflet_drawing.js similarity index 100% rename from transport_accessibility/pt_map/static/pt_map/leaflet_drawing.js rename to transport_accessibility/pt_map/static/pt_map/script/leaflet_drawing.js diff --git a/transport_accessibility/pt_map/static/pt_map/script/map.js b/transport_accessibility/pt_map/static/pt_map/script/map.js new file mode 100644 index 0000000..1dfda37 --- /dev/null +++ b/transport_accessibility/pt_map/static/pt_map/script/map.js @@ -0,0 +1,101 @@ +/* + This file is part of transport-accessibility. + Copyright (C) 2024 Janek Kiljanski, Johannes Randerath + + transport-accessibility is free software: you can redistribute it and/or modify it under the terms of the + GNU General Public License as published by the Free Software Foundation, either version 3 + of the License, or (at your option) any later version. + + transport-accessibility is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with transport-accessibility. + If not, see . +*/ +// Initialize the map centered on Toruń, Poland +var map = L.map('map').setView([53.0138, 18.5984], 13); + +// Load OpenStreetMap tiles +L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { + maxZoom: 19, +}).addTo(map); + +// Holder for data imported from the server. +let imported_data = null; +let routesData = []; +let tripsData = []; +let stopsData = []; +let stopTimesData = []; +// Variable set to true if a new shape is being added. +let addingNewShape = false; +let currentlyAddedPolyline = null; +// Holder of currently inspected shape ID value +let currentShapeIDs = {}; +currentShapeIDs["routes"] = []; +currentShapeIDs["stops"] = []; +// Create empty dictionary for shapes to be displayed on the map. +let shapes = {}; +shapes["routes"] = {}; +shapes["stops"] = {}; +// Total number of newly defined Shapes +// In a mature version the indexing has to be changed. +let numNewShapes = 0; +// Current layer that can be saved or discarded +let currentLayer = null; + +// Setting up the drawing control + +// FeatureGroup to store layers created by drawing +var drawnItems = new L.FeatureGroup(); + map.addLayer(drawnItems); + + // Set up the drawing control + var drawControl = new L.Control.Draw({ + position: 'topright', // Adds the drawing control on the right + edit: { + featureGroup: drawnItems + }, + draw: false + }); + +// Polyline drawer that will be used for drawing on the map +let polylineDrawer = new L.Draw.Polyline(map, drawControl.options.polyline); + +document.getElementById('fileInput').addEventListener('change', handleFileSelect, false); + +// Add the map click event listener +map.on('click', onMapClick); + +// Function to write "Hello World!" to the console when the map is clicked +function onMapClick(event) { + // Check if the click event is not on a shape + if (!event.originalEvent.target.closest('.leaflet-interactive')) { + cancelShapeEdit(); + } +} + +function importGTFS() { + // Import stops + shapes["stops"] = JSON.parse('{{ stops|safe }}'); + for (const id in shapes["stops"]) { + //console.log("id: ", id); + let stop_lat = shapes["stops"][id]["stop_lat"]; + let stop_lon = shapes["stops"][id]["stop_lon"]; + if (stop_lat == undefined || stop_lon == undefined) { + continue; + } + else { + //console.log("stop_lat: ", stop_lat); + //console.log("stop_lon: ", stop_lon); + //console.log(shapes["stops"][stop["stop_id"]]); + addClickablePoint([stop_lat, stop_lon], id); + } + } + + routes = JSON.parse('{{ routes|safe }}'); + console.log("routes: ", routes); + timetable = JSON.parse('{{ timetable|safe }}'); + console.log("timetable: ", timetable); + +} diff --git a/transport_accessibility/pt_map/static/pt_map/osrm_drawing.js b/transport_accessibility/pt_map/static/pt_map/script/osrm_drawing.js similarity index 100% rename from transport_accessibility/pt_map/static/pt_map/osrm_drawing.js rename to transport_accessibility/pt_map/static/pt_map/script/osrm_drawing.js diff --git a/transport_accessibility/pt_map/static/pt_map/parsing_files.js b/transport_accessibility/pt_map/static/pt_map/script/parsing_files.js similarity index 100% rename from transport_accessibility/pt_map/static/pt_map/parsing_files.js rename to transport_accessibility/pt_map/static/pt_map/script/parsing_files.js diff --git a/transport_accessibility/pt_map/static/pt_map/shapes_on_map.js b/transport_accessibility/pt_map/static/pt_map/script/shapes_on_map.js similarity index 100% rename from transport_accessibility/pt_map/static/pt_map/shapes_on_map.js rename to transport_accessibility/pt_map/static/pt_map/script/shapes_on_map.js diff --git a/transport_accessibility/pt_map/static/pt_map/sidebar.js b/transport_accessibility/pt_map/static/pt_map/script/sidebar.js similarity index 100% rename from transport_accessibility/pt_map/static/pt_map/sidebar.js rename to transport_accessibility/pt_map/static/pt_map/script/sidebar.js diff --git a/transport_accessibility/pt_map/templates/testing.html b/transport_accessibility/pt_map/static/pt_map/style/style.css similarity index 58% rename from transport_accessibility/pt_map/templates/testing.html rename to transport_accessibility/pt_map/static/pt_map/style/style.css index 580d1f2..033f40f 100644 --- a/transport_accessibility/pt_map/templates/testing.html +++ b/transport_accessibility/pt_map/static/pt_map/style/style.css @@ -1,5 +1,4 @@ - - +*/ - - - -{% for x in fruits %} -

{{ x }}

-{% endfor %} - -

In views.py you can see what the fruits variable looks like.

- - - +body, html { + height: 100%; + margin: 0; +} +#map { + height: 100%; + width: 100%; +} +.sidebar { + height: 100%; + position: fixed; + top: 0; + left: 0; + width: 250px; + background-color: #f8f9fa; + border-right: 1px solid #dee2e6; + padding-top: 20px; +} +.content { + margin-left: 250px; + height: 100%; +} +.modal-body { + max-height: 60vh; + overflow-y: auto; +} +.route-list { + max-height: 400px; + overflow-y: scroll; +} +div.copying { + position: absolute; + bottom: 0em; + padding-left: .5em; + padding-right: .5em; +} +div.copying > p { + margin: 0; +} diff --git a/transport_accessibility/pt_map/templates/base.html b/transport_accessibility/pt_map/templates/base.html index f7bf204..423e02e 100644 --- a/transport_accessibility/pt_map/templates/base.html +++ b/transport_accessibility/pt_map/templates/base.html @@ -27,41 +27,30 @@ - + {% block content %}{% endblock %} + diff --git a/transport_accessibility/pt_map/templates/map.html b/transport_accessibility/pt_map/templates/map.html index d93160a..6409337 100644 --- a/transport_accessibility/pt_map/templates/map.html +++ b/transport_accessibility/pt_map/templates/map.html @@ -42,6 +42,11 @@ +
+

© 2024 Janek Kiljanski & Johannes Randerath.

+

This is free software. License: AGPL.

+

Download source code.

+
@@ -82,96 +87,9 @@ --> - - - + + + + - {% endblock %}