// // Copyright (c) 2021 Clementine Computing LLC. // // 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. // // 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. // // You should have received a copy of the GNU Affero General Public License // along with RideLogic. If not, see . // var MAX_ICON = 128; var g_info = { "geojson" : {}, "route" : {}, "route_path": {}, "active_route" : [], "ol_route_layer" : {}, "json_gtfs": {} }; var Feature = ol.Feature; var Map = ol.Map; var Overlay = ol.Overlay; var Point = ol.geom.Point; var TileJSON = ol.source.TileJSON; var VectorSource = ol.source.Vector; var View = ol.View; var Icon = ol.style.Icon; var Style = ol.style.Style; var TileLayer = ol.layer.Tile; 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]; //var defaultLonLat = [ -76.1805, 42.6012 ]; var defaultLonLat = [ -76.2705, 42.5512 ]; var defaultWebMerc = fromLonLat(defaultLonLat); function _rnd(a,b) { a = ((typeof a == "undefined") ? 1.0 : a); if (typeof b === "undefined") { return Math.random()*a; } return Math.random()*(b-a) + a; } function example_change_pos() { let w = 1/16.0; let lonlat = [ defaultLonLat[0] + _rnd(-w,w), defaultLonLat[1] + _rnd(-w,w)]; let merc = fromLonLat(lonlat); _icon[0].feature.getGeometry().setCoordinates(merc); busLayer.getSource().changed(); } function example_change_opacity(p) { p = ((typeof p === "undefined") ? 0.0 : p); _icon[0].style.getImage().setOpacity(p); busLayer.getSource().changed(); } // icon can't change image src dynamically, // so have to replace. // See https://stackoverflow.com/questions/57341190/how-can-i-change-icon-source-dynamically // function example_change_image() { let _nuimg = new Icon({ anchor: [0.5, 46], anchorXUnits: 'fraction', anchorYUnits: 'pixels', src: 'data/bus_gw_90.png', }); _icon[0].style.setImage(_nuimg); busLayer.getSource().changed(); } //--- var vectorSource = new VectorSource(); var g_icon = []; for (let ii=0; ii 7) { iheading = 0; } let bearing_str = "_stat" if (p.speed != 0) { bearing_str = "_" + bearingIdxLookup[iheading]; } let _nuimg = new Icon({ //scale: [1.5, 1.5], anchor: [0.5, 46], anchorXUnits: 'fraction', anchorYUnits: 'pixels', //src: 'data/bus_gw' + route_str + "_" + bearingIdxLookup[iheading] + '.png', src: 'data/bus_gw' + route_str + bearing_str + '.png', }); g_icon[ii].style.setImage(_nuimg); if (g_info.active_route.length == 0) { g_icon[ii].style.getImage().setOpacity(0.8); } else { let is_active = false; for (let _aridx=0; _aridx < g_info.active_route.length; _aridx++) { if ( g_info.active_route[_aridx] == route_id) { is_active = true; } } if (is_active) { g_icon[ii].style.getImage().setOpacity(0.8); } else { g_icon[ii].style.getImage().setOpacity(0.0); } } } for (let ii=json_gtfs.entityList.length; ii { let _a = parseInt(a), _b = parseInt(b); if (ab) { return 1; } return 0; }); for (let i=0; i<_route_list.length; i++) { let _rln = _route_list[i]; let _a = document.createElement("a"); _a.classList.add("list-group-item"); _a.classList.add("list-gorup-item-action"); _a.classList.add("list-gorup-item-light"); _a.classList.add("p-3"); _a.innerText = _route_long_name[_rln]; _a.onclick = (function(_r) { return function() { if ( g_info.active_route == _r) { ui_clear_routes(); update_buses(g_info.json_gtfs); } else { ui_show_single_route(_r); update_buses(g_info.json_gtfs); } } })(_route_list[i]); ele.appendChild(_a); } toggle_sidebar(g_side_toggle); } //--- // resize map // function resize_map() { let h = $(window).height(); let m = document.getElementById("map"); m.style.height = (h-10) + "px"; g_map.updateSize(); } function init() { setInterval(fetch_gtfs_vehicle_position, 1000); setTimeout( function() { fetch_geojson("geojson/test_route.geojson"); }, 100); $(window).on('resize', resize_map); } $(document).ready(function() { init(); resize_map(); toggle_sidebar(g_side_toggle); });