Skip to content

Commit

Permalink
v3.4.3 change map backgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
answerquest committed Jul 18, 2019
1 parent bc012d7 commit 9b27dfe
Show file tree
Hide file tree
Showing 13 changed files with 855 additions and 55 deletions.
25 changes: 23 additions & 2 deletions GTFSManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import numpy as np
import io # used in hyd csv import
import requests, platform # used to log user stats
requests.packages.urllib3.disable_warnings() # suppress warning messages like "InsecureRequestWarning: Unverified HTTPS request is being made." from https://stackoverflow.com/a/44850849/4355695

# setting constants
root = os.path.dirname(__file__) # needed for tornado
Expand All @@ -43,6 +44,8 @@
configFile = 'config.json'
thisURL = ''

# paths were you must not tread.. see "MyStaticFileHandler" class in apy.py
forbiddenPaths = ['/pw/']
debugMode = False # using this flag at various places to do or not do things based on whether we're in development or production

requiredFeeds = ['agency.txt','calendar.txt','stops.txt','routes.txt','trips.txt','stop_times.txt']
Expand All @@ -69,7 +72,23 @@

logmessage('Loaded dependencies, starting static GTFS Manager program.')

'''
#################################
# Tornado classes : One class = one API call / request

# 22.4.19 Making a custom class/function to control how the user's browser loads normal URLs
# from https://stackoverflow.com/a/55762431/4355695 : restrict direct browser access to .py files and stuff
class MyStaticFileHandler(tornado.web.StaticFileHandler):
def validate_absolute_path(self, root, absolute_path):
if absolute_path.endswith('.py') or any([ (x in absolute_path) for x in forbiddenPaths]):
# raise tornado.web.HTTPError(403) # this is the usual thing: raise 403 Forbidden error. But instead..
return os.path.join(root,'lib','errorpage.txt')

if absolute_path.endswith('favicon.ico'):
return os.path.join(root,'lib','favicon.ico')

return super().validate_absolute_path(root, absolute_path) # you may pass

comment= '''
# Tornado API functions template:
class APIHandler(tornado.web.RequestHandler):
def get(self):
Expand Down Expand Up @@ -1398,7 +1417,9 @@ def make_app():
(r"/API/tableReadSave", tableReadSave),
(r"/API/tableColumn", tableColumn),
#(r"/API/idList", idList),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": root, "default_filename": "index.html"})
# (r"/(.*)", tornado.web.StaticFileHandler, {"path": root, "default_filename": "index.html"})
(r"/(.*)", MyStaticFileHandler, {"path": root, "default_filename": "index.html"})

])

# for catching Ctrl+C and exiting gracefully. From https://nattster.wordpress.com/2013/06/05/catch-kill-signal-in-python/
Expand Down
2 changes: 1 addition & 1 deletion GTFSserverfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ def logUse(action='launch'):
cvar['3'] = ['version', platform.release() ]
payload['_cvar'] = json.dumps(cvar)
try:
r = requests.get('http://nikhilvj.co.in/tracking/piwik.php', params=payload, verify=False, timeout=1)
r = requests.get('https://nikhilvj.co.in/tracking/piwik.php', params=payload, verify=False, timeout=1)
except requests.exceptions.RequestException as e:
# print('exception',e)
pass
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

A browser-based user interface for creating, editing, exporting of static GTFS (General Transit Feed Specification Reference) feeds for a public transit authority.

**Release Status** : V 3.4.2 (live branch may be some commits ahead)
**Release Status** : V 3.4.3 (live branch may be some commits ahead)
Download from [Releases page](https://github.com/WRI-Cities/static-GTFS-manager/releases/).
- Windows binary is available in the repo itself, just double-click GTFSManager.exe to start the program.
- Mac, Ubuntu users can run by first installing docker, then double-clicking two scripts. See [Running with Docker on any OS](https://github.com/WRI-Cities/static-GTFS-manager/wiki/Running-with-Docker-on-any-OS)
Expand All @@ -20,10 +20,12 @@ The GTFS data pre-loaded in the program is of Kochi Metro, Kerala, India which o

See the [KMRL open data portal](https://kochimetro.org/open-data/) and some news articles: [1](http://www.newindianexpress.com/cities/kochi/2018/mar/17/kochi-metro-adopts-open-data-system-to-improve-access-to-its-services-1788342.html), [2](http://indianexpress.com/article/india/kochi-metro-throws-open-transit-data-to-public-on-the-lines-of-london-new-york-5100381/), [3](http://www.thehindu.com/news/cities/Kochi/open-data-to-improve-commuter-experience/article23275844.ece), [4](http://www.thehindu.com/news/cities/Kochi/kmrl-moves-a-step-ahead-to-open-up-transit-data/article23247617.ece).

This program adheres to the static GTFS (General Transit Feed Specification Reference) open transit data specs as published by Google Transit here: <https://developers.google.com/transit/gtfs/reference/>
It also implements a [GTFS extension for translations](https://developers.google.com/transit/gtfs/reference/gtfs-extensions#translations) of stops and routes names to facilitate multilingual use of the data.
This program adheres strictly to the static GTFS (General Transit Feed Specification Reference) open transit data specs as published by Google Transit here: <https://developers.google.com/transit/gtfs/reference/>

Lead programmer up till November 2018: [Nikhil VJ](https://answerquest.github.io) from Pune, India.
Note: We have created a second complimentary application **[Payanam](https://github.com/WRI-Cities/payanam)** to address needs where a) the system is simple and routes don't have variations; b) properly mapped stops data is not available to begin with.
**[Payanam](https://github.com/WRI-Cities/payanam)** can take you from nothing up to a basic GTFS, and after that you can use this application to edit it. So check it out!

Lead programmer as of July 2019: [Nikhil VJ](https://nikhilvj.co.in) from Pune, India.

See this and many more GTFS related resources listed on **[Awesome Transit](https://github.com/CUTR-at-USF/awesome-transit#gtfs-tools)**, a one-stop community listing for all things GTFS.

Expand Down
10 changes: 9 additions & 1 deletion js/deleteID.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ function populateLists() {
$('#stop2Delete').html(content);
$('#stop2Delete').chosen({search_contains:true, allow_single_deselect:true, width:300, placeholder_text_single:'Pick a Stop'});
$('#stop2Delete').trigger('chosen:updated'); // if the function is called again, then update it
$("#stop2Delete").off("change"); // 10.5.19 fix for multiple triggers
$('#stop2Delete').on('change', function(evt,params) {
if(!params) return;
let stop_id = params.selected;
Expand All @@ -436,6 +437,7 @@ function populateLists() {
$('#route2Delete').html(content);
$('#route2Delete').chosen({search_contains:true, allow_single_deselect:true, width:300, placeholder_text_single:'Pick a Route' });
$('#route2Delete').trigger('chosen:updated');
$("#route2Delete").off("change"); // 10.5.19 fix for multiple triggers
$('#route2Delete').on('change', function(evt,params) {
if(!params) return;
let route = params.selected;
Expand All @@ -455,6 +457,7 @@ function populateLists() {
$('#trip2Delete').html(content);
$('#trip2Delete').chosen({search_contains:true, allow_single_deselect:true, width:300, placeholder_text_single:'Pick a Trip'});
$('#trip2Delete').trigger('chosen:updated');
$("#trip2Delete").off("change"); // 10.5.19 fix for multiple triggers
$('#trip2Delete').on('change', function(evt,params) {
if(!params) return;
let trip = params.selected;
Expand All @@ -473,6 +476,7 @@ function populateLists() {
$('#shape2Delete').html(content);
$('#shape2Delete').chosen({search_contains:true, allow_single_deselect:true, width:300, placeholder_text_single:'Pick a Shape'});
$('#shape2Delete').trigger('chosen:updated');
$("#shape2Delete").off("change"); // 10.5.19 fix for multiple triggers
$('#shape2Delete').on('change', function(evt,params) {
if(!params) return;
let shape = params.selected;
Expand All @@ -491,6 +495,7 @@ function populateLists() {
$('#service2Delete').html(content);
$('#service2Delete').chosen({search_contains:true, allow_single_deselect:true, width:300, placeholder_text_single:'Pick a Calendar Service'});
$('#service2Delete').trigger('chosen:updated');
$("#service2Delete").off("change"); // 10.5.19 fix for multiple triggers
$('#service2Delete').on('change', function(evt,params) {
if(!params) return;
let service = params.selected;
Expand All @@ -510,6 +515,7 @@ function populateLists() {
$('#zone2Delete').html(content);
$('#zone2Delete').chosen({search_contains:true, allow_single_deselect:true, width:300, placeholder_text_single:'Pick a Fare Zone'});
$('#zone2Delete').trigger('chosen:updated');
$("#zone2Delete").off("change"); // 10.5.19 fix for multiple triggers
$('#zone2Delete').on('change', function(evt,params) {
if(!params) return;
let zone = params.selected;
Expand All @@ -529,6 +535,7 @@ function populateLists() {
$('#fareID2Delete').html(content);
$('#fareID2Delete').chosen({search_contains:true, allow_single_deselect:true, width:300, placeholder_text_single:'Pick a Fare ID'});
$('#fareID2Delete').trigger('chosen:updated');
$("#fareID2Delete").off("change"); // 10.5.19 fix for multiple triggers
$('#fareID2Delete').on('change', function(evt,params) {
if(!params) return;
let fare = params.selected;
Expand All @@ -548,6 +555,7 @@ function populateLists() {
$('#agency2Delete').html(content);
$('#agency2Delete').chosen({search_contains:true, allow_single_deselect:true, width:300, placeholder_text_single:'Pick an Agency ID'});
$('#agency2Delete').trigger('chosen:updated');
$("#agency2Delete").off("change"); // 10.5.19 fix for multiple triggers
$('#agency2Delete').on('change', function(evt,params) {
if(!params) return;
let agency = params.selected;
Expand Down Expand Up @@ -846,4 +854,4 @@ function getPythonTranslations() {
};
xhr.send();
}
*/
*/
6 changes: 3 additions & 3 deletions js/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getPythonPastCommits() {
var data = JSON.parse(xhr.responseText);
var content = '<ol>';
for (i in data.commits) {
content += '<li>' + data.commits[i] + ' : <a href="GTFS/' + data.commits[i] + '/gtfs.zip">Download gtfs.zip</a></li>';
content += '<li>' + data.commits[i] + ' : <a href="export/' + data.commits[i] + '/gtfs.zip">Download gtfs.zip</a></li>';
}
content += '</ol>';

Expand All @@ -77,7 +77,7 @@ function getPythonPastCommits() {

function exportGTFS() {
// lowercase and zap everything that is not a-z, 0-9, - or _ from https://stackoverflow.com/a/4460306/4355695
var commit = $("#commitName").val().toLowerCase().replace(/[^a-z0-9-_]/g, "");
var commit = $("#commitName").val().toLowerCase().replace(/[^a-z0-9-_.]/g, "");

$("#commitName").val(commit); // showing the corrected name to user.

Expand Down Expand Up @@ -181,4 +181,4 @@ function gtfsBlankSlate() {
$("#gtfsBlankSlateStatus").html('<span class="alert alert-danger">' + jqXHR.responseText + '</span>');
}
});
}
}
16 changes: 5 additions & 11 deletions js/sequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,11 @@ $("#sequence-1-table").tabulator({

// #################################
/* Initiate map */
var osmLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
var MBAttrib = '&copy; ' + osmLink + ' Contributors & <a href="https://www.mapbox.com/about/maps/">Mapbox</a>';
var mapboxUrl = 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png';
var scenicUrl = 'https://api.mapbox.com/styles/v1/nikhilsheth/cj8rdd7wu45nl2sps9teusbbr/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibmlraGlsc2hldGgiLCJhIjoiQTREVlJuOCJ9.YpMpVVbkxOFZW-bEq1_LIw' ;
var carto1 = L.tileLayer.provider('CartoDB.Positron');
var carto2 = L.tileLayer.provider('CartoDB.Positron');

var MBdark = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.jme9hi44', attribution: MBAttrib });
var scenic0 = L.tileLayer(scenicUrl, { attribution: MBAttrib });
var scenic1 = L.tileLayer(scenicUrl, { attribution: MBAttrib });

var mapOptions0 = { 'center': [0,0], 'zoom': 2, 'layers': scenic0, scrollWheelZoom: false };
var mapOptions1 = { 'center': [0,0], 'zoom': 2, 'layers': scenic1, scrollWheelZoom: false };
var mapOptions0 = { 'center': [0,0], 'zoom': 2, 'layers': carto1, scrollWheelZoom: true };
var mapOptions1 = { 'center': [0,0], 'zoom': 2, 'layers': carto2, scrollWheelZoom: true };
//var mapOptionsClone = jQuery.extend(true, {}, mapOptions);

var map = [];
Expand Down Expand Up @@ -937,4 +931,4 @@ function saveRoutes() {
xhr.send(JSON.stringify(data)); // this is where POST differs from GET : we can send a payload instead of just url arguments.
}
*/
*/
54 changes: 22 additions & 32 deletions js/stops.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,11 @@ $("#stops-table").tabulator({

// #################################
/* 3. Initiate map */
var osmLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
var MBAttrib = '&copy; ' + osmLink + ' Contributors & <a href="https://www.mapbox.com/about/maps/">Mapbox</a>';
var mapboxUrl = 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png';
var scenicUrl = 'https://api.mapbox.com/styles/v1/nikhilsheth/cj8rdd7wu45nl2sps9teusbbr/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibmlraGlsc2hldGgiLCJhIjoiQTREVlJuOCJ9.YpMpVVbkxOFZW-bEq1_LIw' ;

var MBstreets = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mlpl2d', attribution: MBAttrib, maxZoom: 20}),
MBsatlabel = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mmaa87', attribution: MBAttrib, maxZoom: 20}),
MBsat = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mni8e7', attribution: MBAttrib, maxZoom: 20}),
MBlight = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mmobne', attribution: MBAttrib, maxZoom: 20}),
MBdark = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.jme9hi44', attribution: MBAttrib, maxZoom: 20}),
OsmIndia = L.tileLayer(mapboxUrl, {id: 'openstreetmap.1b68f018', attribution: MBAttrib, maxZoom: 20}),
GithubLight = L.tileLayer('https://{s}.tiles.mapbox.com/v3/github.map-xgq2svrz/{z}/{x}/{y}.png', {attribution: MBAttrib, maxZoom: 20}),
scenic = L.tileLayer(scenicUrl, {attribution: MBAttrib, maxZoom: 20}) ;
var cartoLight = L.tileLayer.provider('CartoDB.Positron');
var cartoDark = L.tileLayer.provider('CartoDB.DarkMatter');
var esriSat = L.tileLayer.provider('Esri.WorldImagery');
var OSM = L.tileLayer.provider('OpenStreetMap.Mapnik');

var gStreets = L.tileLayer('https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
Expand All @@ -141,12 +133,19 @@ var gSat = L.tileLayer('https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{
subdomains:['mt0','mt1','mt2','mt3']
});

const startLocation = [10.030259357021862, 76.31446838378908];
var baseLayers = {
"CartoDB Positron" : cartoLight,
"CartoDB DarkMatter" : cartoDark,
"ESRI Sat" : esriSat,
"OpenStreetMap" : OSM,
"gStreets": gStreets,
"gHybrid": gHybrid
};

var map = new L.Map('map', {
center: [0,0],
zoom: 2,
layers: [MBlight],
layers: [cartoLight],
scrollWheelZoom: true
});

Expand All @@ -163,17 +162,7 @@ var stopsLayer = new L.geoJson(null)
})
.on('click',markerOnClick);

var baseLayers = {
"Scenic" : scenic,
"OpenStreetMap.IN": OsmIndia,
"Streets": MBstreets,
"Satellite": MBsatlabel ,
"Light": MBlight,
"Dark" : MBdark,
"gStreets": gStreets,
"gHybrid": gHybrid,
"gSat": gSat
};


var overlays = {
'stops': stopsLayer,
Expand Down Expand Up @@ -205,7 +194,7 @@ var dragmarkerOptions = {
};
var clickedflag = 0;

var dragmarker = L.circleMarker(startLocation, dragmarkerOptions);
var dragmarker = L.circleMarker(null, dragmarkerOptions);
/* we're not dragging anymore!
dragmarker.on('dragend', function(e) {
updateLatLng();
Expand Down Expand Up @@ -474,9 +463,9 @@ function updateLatLng(latlong, revflag) {
dragmarker.setLatLng([lat, lng]);
map.panTo([lat, lng]);
} else {
lat = Math.round(( dragmarker.getLatLng().lat + 0.0000001) * 10000) / 10000;
lat = Math.round(( dragmarker.getLatLng().lat + 0.0000001) * 100000) / 100000;
// Rounding, from https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary. The +0.000.. is to trip forward a number hinging on x.9999999...
lng = Math.round(( dragmarker.getLatLng().lng + 0.0000001) * 10000) / 10000;
lng = Math.round(( dragmarker.getLatLng().lng + 0.0000001) * 100000) / 100000;
document.getElementById('newlatlng').value = lat + ',' + lng;
//document.getElementById('longitude').value = marker.getLatLng().lng;
//map.panTo(dragmarker.getLatLng());
Expand Down Expand Up @@ -618,11 +607,12 @@ function databank() {
console.log(databankCounter,'locations found in databank.');

// removing all and adding consecutively so stops are always on top
map.removeLayer(stopsLayer);
// map.removeLayer(stopsLayer);
if(! map.hasLayer(databankLayer)) databankLayer.addTo(map);
map.addLayer(stopsLayer);
// map.addLayer(stopsLayer);
stopsLayer.bringToFront();

map.flyToBounds(databankLayer.getBounds(), {padding:[10,10], maxZoom:14});
}
});
}
}
1 change: 1 addition & 0 deletions lib/errorpage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
YOU SHALL NOT PASS !!
Binary file added lib/favicon.ico
Binary file not shown.
Loading

0 comments on commit 9b27dfe

Please sign in to comment.