Skip to content

Commit 5d8ea22

Browse files
Enhancements for OpenRailway Map:
- added web browser tab Open Rails icon (favicon) - changed locomotive icon, now three icons: steam, electric, diesel - added locomotive direction arrow - added three OpenRailway layers to choose from: maximum speed, guage and electrification. Choice stored in registry and used the next opening of the map. - added three layers with Open Rails data: track, named and rest. Choice also stored. Don't know if these layers are usefull, anyway they can be switched on and off again. Names of the layers are not translateble, is that a problem? Would be hard to implement. For some routes the track layer takes too much performance from the web browser because of tracks size (for instance the MECoast line). But it gives you an idea of the layout of the track in the real world. On the Ruebelandbahn for the "RLB Schneepflug Fahrbar" the locomotive arrow on the map is in the wrong direction (180 degrees). I can't find out why. Not seen this for any other locomotive.
1 parent db5764c commit 5d8ea22

File tree

14 files changed

+732
-47
lines changed

14 files changed

+732
-47
lines changed

Source/ORTS.Common/InfoApiMap.cs

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// COPYRIGHT 2013 by the Open Rails project.
2+
//
3+
// This file is part of Open Rails.
4+
//
5+
// Open Rails is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Open Rails is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using System.Collections.Generic;
19+
using Microsoft.Xna.Framework;
20+
using ORTS.Common;
21+
22+
namespace Orts.Common
23+
{
24+
public class OverlayLayer
25+
{
26+
public string name;
27+
public bool show;
28+
}
29+
30+
public enum TypeOfPointOnApiMap {
31+
track,
32+
named,
33+
rest
34+
}
35+
36+
public class PointOnApiMap
37+
{
38+
public LatLon latLon;
39+
public string color;
40+
public TypeOfPointOnApiMap typeOfPointOnApiMap;
41+
public string name;
42+
}
43+
44+
public class LineOnApiMap
45+
{
46+
public LatLon latLonFrom;
47+
public LatLon latLonTo;
48+
}
49+
50+
public class InfoApiMap
51+
{
52+
public string typeOfLocomotive;
53+
public string baseLayer;
54+
public OverlayLayer[] overlayLayer;
55+
56+
public LinkedList<PointOnApiMap> pointOnApiMapList;
57+
public LinkedList<LineOnApiMap> lineOnApiMapList;
58+
59+
public float latMin;
60+
public float latMax;
61+
public float lonMin;
62+
public float lonMax;
63+
64+
public const string RegistrySection = "ApiMap";
65+
public const string RegistryKeyBaselayer = "baseLayer";
66+
public const string RegistrySectionLayers = "ApiMap\\Layers";
67+
68+
public InfoApiMap(string powerSupplyName, string settingsFilePath, string registryKey)
69+
{
70+
initTypeOfLocomotive(powerSupplyName);
71+
initLayers(settingsFilePath, registryKey);
72+
73+
pointOnApiMapList = new LinkedList<PointOnApiMap>();
74+
lineOnApiMapList = new LinkedList<LineOnApiMap>();
75+
76+
latMax = -999999f;
77+
latMin = +999999f;
78+
lonMax = -999999f;
79+
lonMin = +999999f;
80+
}
81+
82+
private void initTypeOfLocomotive(string powerSupplyName)
83+
{
84+
string powerSupplyNameToLower = powerSupplyName.ToLower();
85+
if (powerSupplyNameToLower.Contains("steam"))
86+
{
87+
typeOfLocomotive = "steam";
88+
}
89+
else
90+
{
91+
if (powerSupplyNameToLower.Contains("diesel"))
92+
{
93+
typeOfLocomotive = "diesel";
94+
}
95+
else
96+
{
97+
typeOfLocomotive = "electric";
98+
}
99+
}
100+
}
101+
102+
private void initLayers(string settingsFilePath, string registryKey)
103+
{
104+
var store = SettingsStore.GetSettingStore(settingsFilePath, registryKey, RegistrySection);
105+
baseLayer = (string)store.GetUserValue(RegistryKeyBaselayer, typeof(string));
106+
107+
overlayLayer = null;
108+
store = SettingsStore.GetSettingStore(settingsFilePath, registryKey, RegistrySectionLayers);
109+
string[] names = store.GetUserNames();
110+
if (names.Length > 0)
111+
{
112+
overlayLayer = new OverlayLayer[names.Length];
113+
114+
int index = 0;
115+
foreach (string name in names)
116+
{
117+
overlayLayer[index] = new OverlayLayer
118+
{
119+
name = name,
120+
show = (bool)store.GetUserValue(name, typeof(bool))
121+
};
122+
index++;
123+
}
124+
}
125+
}
126+
127+
public static void storeLayerSetting(
128+
string settingsFilePath, string registryKey,
129+
string layerAction, string layerName)
130+
{
131+
if (layerAction == "baseLayerChange")
132+
{
133+
var store = SettingsStore.GetSettingStore(settingsFilePath, registryKey, InfoApiMap.RegistrySection);
134+
store.SetUserValue(InfoApiMap.RegistryKeyBaselayer, layerName);
135+
}
136+
else
137+
{
138+
var store = SettingsStore.GetSettingStore(settingsFilePath, registryKey, InfoApiMap.RegistrySectionLayers);
139+
if (layerAction == "overlayAdd")
140+
{
141+
store.SetUserValue(layerName, (bool)true);
142+
}
143+
if (layerAction == "overlayRemove")
144+
{
145+
store.SetUserValue(layerName, (bool)false);
146+
}
147+
}
148+
}
149+
150+
public static LatLon convertToLatLon(int TileX, int TileZ, float X, float Y, float Z)
151+
{
152+
double latitude = 1f;
153+
double longitude = 1f;
154+
155+
WorldLocation mstsLocation = new WorldLocation(TileX, TileZ, X, Y, Z);
156+
new WorldLatLon().ConvertWTC(TileX, TileZ, mstsLocation.Location, ref latitude, ref longitude);
157+
LatLon latLon = new LatLon(MathHelper.ToDegrees((float)latitude), MathHelper.ToDegrees((float)longitude));
158+
159+
return latLon;
160+
}
161+
162+
public void addToPointOnApiMap(
163+
int TileX, int TileZ, float X, float Y, float Z,
164+
string color, TypeOfPointOnApiMap typeOfPointOnApiMap, string name)
165+
{
166+
LatLon latLon = InfoApiMap.convertToLatLon(TileX, TileZ, X, Y, Z);
167+
168+
addToPointOnApiMap(latLon,
169+
color, typeOfPointOnApiMap, name);
170+
}
171+
172+
public void addToPointOnApiMap(
173+
LatLon latLon,
174+
string color, TypeOfPointOnApiMap typeOfPointOnApiMap, string name)
175+
{
176+
PointOnApiMap pointOnApiMap = new PointOnApiMap
177+
{
178+
latLon = latLon,
179+
color = color,
180+
typeOfPointOnApiMap = typeOfPointOnApiMap,
181+
name = name
182+
};
183+
184+
if (pointOnApiMap.typeOfPointOnApiMap == TypeOfPointOnApiMap.named)
185+
{
186+
// named last is the list so that they get displayed on top
187+
pointOnApiMapList.AddLast(pointOnApiMap);
188+
}
189+
else
190+
{
191+
pointOnApiMapList.AddFirst(pointOnApiMap);
192+
}
193+
194+
if (pointOnApiMap.latLon.Lat > latMax)
195+
{
196+
latMax = pointOnApiMap.latLon.Lat;
197+
}
198+
if (pointOnApiMap.latLon.Lat < latMin)
199+
{
200+
latMin = pointOnApiMap.latLon.Lat;
201+
}
202+
if (pointOnApiMap.latLon.Lon > lonMax)
203+
{
204+
lonMax = pointOnApiMap.latLon.Lon;
205+
}
206+
if (pointOnApiMap.latLon.Lon < lonMin)
207+
{
208+
lonMin = pointOnApiMap.latLon.Lon;
209+
}
210+
}
211+
212+
public void addToLineOnApiMap(LatLon latLonFrom, LatLon latLongTo)
213+
{
214+
LineOnApiMap lineOnApiMap = new LineOnApiMap
215+
{
216+
latLonFrom = latLonFrom,
217+
latLonTo = latLongTo
218+
};
219+
lineOnApiMapList.AddLast(lineOnApiMap);
220+
}
221+
}
222+
}

Source/Orts.Simulation/Common/WorldLatLon.cs renamed to Source/ORTS.Common/WorldLatLon.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
namespace Orts.Common
3636
{
3737
public class WorldLatLon
38-
{
38+
{
3939
int earthRadius = 6370997; // Average radius of the earth, meters
4040
double Epsilon = 0.0000000001; // Error factor (arbitrary)
4141
double[] Lon_Center = new double[12];
@@ -159,7 +159,7 @@ private int Goode_Inverse(double GX, double GY, ref double Latitude, ref double
159159
switch (region)
160160
{
161161
case 1:
162-
case 3:
162+
case 3:
163163
case 4:
164164
case 5:
165165
case 8:
@@ -289,20 +289,33 @@ static double Adjust_Lon(double value)
289289
}
290290

291291
/// <summary>
292-
/// Class to store the latitude and longitude values of a point on the map
292+
/// Class to store the latitude and longitude of a position on the webpage map
293293
/// </summary>
294294
public class LatLon
295295
{
296-
private readonly float _lat;
297-
private readonly float _lon;
296+
public float Lat { get; }
297+
public float Lon { get; }
298298

299299
public LatLon(float lat, float lon)
300300
{
301-
this._lat = lat;
302-
this._lon = lon;
301+
Lat = lat;
302+
Lon = lon;
303303
}
304+
}
305+
306+
/// <summary>
307+
/// Class to store the latitude, longitude and direction of a locomotive on the webpage map
308+
/// </summary>
309+
public class LatLonDirection
310+
{
311+
public LatLon LatLon { get; }
312+
public float directionDeg { get; }
304313

305-
public float Lat => _lat;
306-
public float Lon => _lon;
314+
public LatLonDirection(LatLon latLon, float directionDeg)
315+
{
316+
LatLon = latLon;
317+
this.directionDeg = directionDeg;
318+
}
307319
}
308320
}
321+

0 commit comments

Comments
 (0)