Browse Source

starting to add route toggle menu

abram 4 years ago
parent
commit
d4a33095c8
2 changed files with 175 additions and 59 deletions
  1. 73 36
      html/index.html
  2. 102 23
      html/js/RideLogicAVLS.js

+ 73 - 36
html/index.html

@@ -1,46 +1,83 @@
 <!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8" />
+        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
+        <meta name="description" content="" />
+        <meta name="author" content="" />
+        <title>RideLogic AVLS</title>
 
-<!--
+        <script src="js/jquery.js"></script>
+        <script>
+        </script>
 
-	Copyright (c) 2021 Clementine Computing LLC.
+        <link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
+        <link href="css/styles.css" rel="stylesheet" />
 
-	This file is part of RideLogic.
 
-	RideLogic is free software: you can redistribute it and/or modify
-	it under the terms of the GNU Affero General Public License as published by
-	the Free Software Foundation, either version 3 of the License, or
-	(at your option) any later version.
+  <link rel="stylesheet" href="css/ol.css" type="text/css">
+  <script src="js/ol.js"></script>
+  <style>
+    .map {
+      width: 100%;
+      height:500px;
+      /* height:100%; */
+    }   
+    .custom-zoom{
+        top: .5em;
+        right: .5em;
+    }
+    .custom-button {
+      margin-left: .5em;
+      margin-top: .5em;
+  background-color: #bbb; /* Green */
+  border: none;
+  color: black;
+  padding: 15px 32px;
+  text-align: center;
+  opacity: 0.75;
+  /* text-decoration: none; */
+  /* display: inline-block; */
+  font-size: 16px;
+    }
+    </style>
 
-	RideLogic 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 Affero General Public License for more details.
+    </head>
 
-	You should have received a copy of the GNU Affero General Public License
-	along with RideLogic.  If not, see <https://www.gnu.org/licenses/>.
+    <body>
+        <div class="d-flex" id="wrapper">
+            <!-- Sidebar-->
+            <div class="border-end bg-white" id="sidebar-wrapper">
+                <div class="sidebar-heading border-bottom bg-light">RideLogic AVLS</div>
+                <div class="list-group list-group-flush">
+                    <a class="list-group-item list-group-item-action list-group-item-light p-3" href="#!">route0</a>
+                    <a class="list-group-item list-group-item-action list-group-item-light p-3" href="#!">route1</a>
+                    <a class="list-group-item list-group-item-action list-group-item-light p-3" href="#!">route2</a>
+                    <a class="list-group-item list-group-item-action list-group-item-light p-3" href="#!">route3</a>
+                    <a class="list-group-item list-group-item-action list-group-item-light p-3" href="#!">route4</a>
+                    <a class="list-group-item list-group-item-action list-group-item-light p-3" href="#!">route5</a>
+                </div>
+            </div>
 
--->
+            <!-- Page content wrapper-->
+            <div id="page-content-wrapper">
 
-<html lang="en">
-  <head>
-    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
-    <meta content="utf-8" http-equiv="encoding">
-
-    <title>RideLogic AVLS</title>
-    <link rel="stylesheet" href="css/ol.css" type="text/css">
-    <script src="js/jquery.js"></script>
-    <script src="js/ol.js"></script>
-    <style>
-      .map {
-        width: 100%;
-        height:500px;
-        /* height:100%; */
-      }
-    </style>
-  </head>
-  <body>
-    <div id="map" class="map"><div id="popup"></div></div>
-    <script src="js/pb2jsonlib.js"></script>
-    <script src="js/RideLogicAVLS.js"></script>
-  </body>
+                <div class="container-fluid">
+
+                  <!-- <button class="btn" id="sidebarToggle" style='display:float;'>Toggle Menu</button> -->
+
+                    <div id="map" class="map">
+                      <div id="popup"></div>
+                    </div>
+
+
+                </div>
+            </div>
+        </div>
+        <!-- Bootstrap core JS-->
+        <script src="js/bootstrap.bundle.min.js"></script>
+        <!-- <script src="js/scripts.js"></script> -->
+        <script src="js/pb2jsonlib.js"></script>
+        <script src="js/RideLogicAVLS.js"></script>
+    </body>
 </html>

+ 102 - 23
html/js/RideLogicAVLS.js

@@ -32,6 +32,8 @@ var VectorLayer = ol.layer.Vector;
 var OSM = ol.source.OSM;
 var fromLonLat =  ol.proj.fromLonLat;
 
+var Control = ol.control.Control;
+
 var LineString = ol.geom.LineString;
 
 //var defaultLonLat = [ -76.5019, 42.4440];
@@ -51,7 +53,7 @@ function _rnd(a,b) {
 
 function example_change_pos() {
 
-  var w = 1/16.0;
+  let w = 1/16.0;
 
   let lonlat = [
     defaultLonLat[0] + _rnd(-w,w),
@@ -74,7 +76,7 @@ function example_change_opacity(p) {
 // See https://stackoverflow.com/questions/57341190/how-can-i-change-icon-source-dynamically
 //
 function example_change_image() {
-  var _nuimg = new Icon({
+  let _nuimg = new Icon({
       anchor: [0.5, 46],
       anchorXUnits: 'fraction',
       anchorYUnits: 'pixels',
@@ -89,20 +91,20 @@ function example_change_image() {
 //var vectorSource = new VectorSource({ features: [iconFeature], });
 var vectorSource = new VectorSource();
 var _icon = [];
-for (var ii=0; ii<2; ii++) {
+for (let ii=0; ii<2; ii++) {
 
-  var w = 1/32.0;
+  let w = 1/32.0;
   let lonlat = [
     defaultLonLat[0] + _rnd(-w,w),
     defaultLonLat[1] + _rnd(-w,w)];
   let merc = fromLonLat(lonlat);
 
-  var iconFeature = new Feature({
+  let iconFeature = new Feature({
     geometry: new Point([merc[0], merc[1]]),
     name: 'bus'
   });
 
-  var iconStyle = new Style({
+  let iconStyle = new Style({
     image: new Icon({
       anchor: [0.5, 46],
       anchorXUnits: 'fraction',
@@ -136,16 +138,63 @@ const rasterLayer = new TileLayer({
 
 //--
 
+
+//-------------------
+//-------------------
+//-------------------
+
+
 const g_map = new Map({
   //layers: [rasterLayer, vectorLayer, routeLayer],
   layers: [rasterLayer, busLayer ],
   target: document.getElementById('map'),
+
+  controls:[],
   view: new View({
     center: defaultWebMerc,
     zoom: 11,
   }),
 });
 
+class CustomToggle extends Control {
+  constructor(opt) {
+    opt = opt || {};
+    let ele = document.createElement("button");
+    ele.id = 'ui_route_toggle';
+    ele.innerHTML = "Route";
+
+    // class="btn" id="sidebarToggle" style='display:float;'
+    ele.classList.add("custom-button");
+
+    super({
+      element: ele,
+      target: opt.target
+    });
+
+    ele.addEventListener('click', this.fire.bind(this), false);
+  }
+
+  fire() {
+    document.body.classList.toggle('sb-sidenav-toggled');
+    localStorage.setItem('sb|sidebar-toggle', document.body.classList.contains('sb-sidenav-toggled'));
+
+    // hacky, but functional
+    //
+    setTimeout(_resize, 250);
+
+  }
+}
+g_map.addControl(new  CustomToggle({ className: 'custom-zoom' }));
+
+//-------------------
+//-------------------
+//-------------------
+
+
+g_map.addControl(new ol.control.Zoom({
+  className: 'custom-zoom'
+}));
+
 const element = document.getElementById('popup');
 
 const popup = new Overlay({
@@ -159,7 +208,7 @@ g_map.addOverlay(popup);
 //
 g_map.on('click', function (evt) {
 
-  // note working (wip)
+  // not working (wip)
   //
   /*
   const feature = map.forEachFeatureAtPixel(evt.pixel, function (feature) {
@@ -199,7 +248,7 @@ setInterval( function() {
 
 function update_buses(json_gtfs) {
 
-  var bearingIdxLookup = [ "0", "45", "90", "135", "180", "225", "270", "315" ];
+  let bearingIdxLookup = [ "0", "45", "90", "135", "180", "225", "270", "315" ];
 
   for (let ii=0; ii<json_gtfs.entityList.length; ii++) {
     let id = json_gtfs.entityList[ii].id;
@@ -221,7 +270,7 @@ function update_buses(json_gtfs) {
     let iheading = Math.floor( (parseInt( bearing ) + 23) / 45 );
     if (iheading > 7) { iheading = 0; }
 
-    var _nuimg = new Icon({
+    let _nuimg = new Icon({
         anchor: [0.5, 46],
         anchorXUnits: 'fraction',
         anchorYUnits: 'pixels',
@@ -239,8 +288,8 @@ function update_buses(json_gtfs) {
 function fetch_gtfs_vehicle_position() {
   let xhr = new XMLHttpRequest();
   xhr.onload = function() {
-    var ab = xhr.response;
-    var json_pb  = pb2json.pb2json(ab);
+    let ab = xhr.response;
+    let json_pb  = pb2json.pb2json(ab);
     //console.log(">>>", json_pb);
 
     update_buses(json_pb)
@@ -255,20 +304,20 @@ function fetch_gtfs_vehicle_position() {
 
 function update_route_layer(geojson) {
   if (!geojson) { return; }
-  var route_points = geojson.features[0].geometry.coordinates;
-  var merc_points = [];
+  let route_points = geojson.features[0].geometry.coordinates;
+  let merc_points = [];
   for (let ii=0; ii<route_points.length; ii++) {
     merc_points.push(ol.proj.transform(route_points[ii], 'EPSG:4326', 'EPSG:3857'));
   }
 
-  var routeLine = new ol.Feature({
+  let routeLine = new ol.Feature({
     geometry: new ol.geom.LineString(merc_points)
   });
 
-  var routeLineVector = new ol.source.Vector({});
+  let routeLineVector = new ol.source.Vector({});
   routeLineVector.addFeature(routeLine);
 
-  var routeLayer = new VectorLayer({
+  let routeLayer = new VectorLayer({
     source: routeLineVector,
     style: new ol.style.Style({
       fill: new ol.style.Fill({ color: 'rgb(0,0,255,0.25)', weight: 4, opacity: 0.5 }),
@@ -292,19 +341,19 @@ function update_stop_layer(geojson) {
     merc_points.push(ol.proj.transform(pnt, 'EPSG:4326', 'EPSG:3857'));
   }
 
-  var stopVectorSource = new VectorSource();
+  let stopVectorSource = new VectorSource();
 
-  for (var ii=0; ii<merc_points.length; ii++) {
+  for (let ii=0; ii<merc_points.length; ii++) {
     let _stop = stop_points[ii].stop;
 
     let _stop_name = _stop.stop_name;
 
-    var iconFeature = new Feature({
+    let iconFeature = new Feature({
       geometry: new Point([merc_points[ii][0], merc_points[ii][1]]),
       name: _stop_name
     });
 
-    var iconStyle = new Style({
+    let iconStyle = new Style({
       image: new Icon({
         anchor: [0.5, 46],
         anchorXUnits: 'fraction',
@@ -319,7 +368,7 @@ function update_stop_layer(geojson) {
 
   }
 
-  var stopLayer = new VectorLayer({
+  let stopLayer = new VectorLayer({
     source: stopVectorSource,
     zIndex: 0
   });
@@ -330,7 +379,7 @@ function update_stop_layer(geojson) {
 function fetch_geojson(url) {
   let xhr = new XMLHttpRequest();
   xhr.onload = function() {
-    var geojson = xhr.response;
+    let geojson = xhr.response;
     update_route_layer(geojson);
     update_stop_layer(geojson);
   };
@@ -341,9 +390,11 @@ function fetch_geojson(url) {
 
 }
 
-//--
+//---
+
 
 function _resize() {
+
   let h = $(window).height();
   let m = document.getElementById("map");
   m.style.height = (h-10) + "px";
@@ -357,7 +408,35 @@ function init() {
   $(window).on('resize', _resize);
 }
 
+window.addEventListener('DOMContentLoaded', event => {
+
+    // Toggle the side navigation
+    const sidebarToggle = document.body.querySelector('#sidebarToggle');
+    if (sidebarToggle) {
+      // Uncomment Below to persist sidebar toggle between refreshes
+      // if (localStorage.getItem('sb|sidebar-toggle') === 'true') {
+      //     document.body.classList.toggle('sb-sidenav-toggled');
+      // }
+      sidebarToggle.addEventListener('click', event => {
+        event.preventDefault();
+        document.body.classList.toggle('sb-sidenav-toggled');
+        localStorage.setItem('sb|sidebar-toggle', document.body.classList.contains('sb-sidenav-toggled'));
+
+
+        // hacky, but functional
+        //
+        setTimeout(_resize, 250);
+      });
+
+
+    }
+  //init();
+  //_resize();
+
+});
+
 $(document).ready(function() {
   init();
   _resize();
 });
+