Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #749 from sweiland-openrails/map_in_browser
OpenRailway Map
- Loading branch information
Showing
7 changed files
with
187 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Source/RunActivity/Viewer3D/WebServices/Web/Map/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<!DOCTYPE HTML> | ||
<!-- | ||
COPYRIGHT 2009, 2010, 2011, 2012, 2013, 2014 by the Open Rails project. | ||
This file is part of Open Rails. | ||
Open Rails is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Open Rails 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 General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Open Rails. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
<html lang="en"> | ||
<head> | ||
<title>OR: Map</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
|
||
<link rel="stylesheet" | ||
href="https://unpkg.com/leaflet@1.9.2/dist/leaflet.css" | ||
integrity="sha256-sA+zWATbFveLLNqWO2gtiw3HL/lh1giY/Inf1BJ0z14=" | ||
crossorigin=""> | ||
|
||
<script src="https://unpkg.com/jquery@3.6.0/dist/jquery.min.js" | ||
integrity="sha384-vtXRMe3mGCbOeY7l30aIg8H9p3GdeSe4IFlP6G8JMa7o7lXvnz3GFKzPxzJdPfGK" | ||
crossorigin="anonymous"></script> | ||
|
||
<script src="https://unpkg.com/leaflet@1.9.2/dist/leaflet.js" | ||
integrity="sha256-o9N1jGDZrf5tS+Ft4gbIK7mYMipq9lqpVJ91xHSyKhg=" | ||
crossorigin=""></script> | ||
|
||
<style type="text/css"> | ||
html, body { | ||
height: 99%; | ||
width: 99%; | ||
margin: 10px; | ||
padding: 0; | ||
} | ||
|
||
#map { | ||
height: 99%; | ||
min-height: 100%; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body onload="setInterval (ApiMap, 500)"> | ||
<div id="map"></div> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// COPYRIGHT 2009, 2010, 2011, 2012, 2013, 2014 by the Open Rails project. | ||
// | ||
// This file is part of Open Rails. | ||
// | ||
// Open Rails is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Open Rails 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 General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
const hr = new XMLHttpRequest; | ||
const httpCodeSuccess = 200; | ||
const xmlHttpRequestCodeDone = 4; | ||
|
||
var locomotiveMarker; | ||
var map; | ||
var latLonPrev = [0, 0]; | ||
|
||
function MapInit(latLon) { | ||
|
||
map = L.map('map').setView(latLon, 13); | ||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||
maxZoom: 19, | ||
attribution: 'Map data: © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | ||
}).addTo(map); | ||
|
||
L.tileLayer('https://{s}.tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png', { | ||
maxZoom: 19, | ||
attribution: ' | Map style: © <a href="https://www.OpenRailwayMap.org">OpenRailwayMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)' | ||
}).addTo(map); | ||
} | ||
|
||
function ApiMap() { | ||
|
||
hr.open("GET", "/API/MAP/", true); | ||
hr.send(); | ||
hr.onreadystatechange = function () { | ||
if (this.readyState == xmlHttpRequestCodeDone && this.status == httpCodeSuccess) { | ||
|
||
let latLonObj = JSON.parse(hr.responseText); | ||
|
||
if (latLonObj != null) { | ||
|
||
let latLon = [latLonObj.Lat, latLonObj.Lon]; | ||
|
||
if (typeof locomotiveMarker == 'undefined') { | ||
// init | ||
MapInit(latLon); | ||
locomotiveMarker = L.marker( | ||
latLon, | ||
{ icon: myIcon } | ||
).addTo(map); | ||
} else { | ||
if ((latLon[0] != latLonPrev[0]) || (latLon[1] != latLonPrev[1])) { | ||
// changed | ||
map.panTo(latLon); | ||
locomotiveMarker.setLatLng(latLon).update(); | ||
} | ||
} | ||
latLonPrev[0] = latLon[0]; | ||
latLonPrev[1] = latLon[1]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
var myIcon = L.icon({ | ||
iconUrl: 'locomotive.png', | ||
iconSize: [29, 24], | ||
iconAnchor: [9, 21], | ||
}) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters