//
// 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