-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
70 lines (69 loc) · 1.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://openlayers.org/en/v4.0.1/css/ol.css" type="text/css">
<style>
.map {
position: relative;
height: 500px;
width: 100%;
}
.starship {
position: absolute;
height: 400px;
width: 400px;
background: url("enterprise.png") no-repeat 0 0;
}
</style>
<script src="https://openlayers.org/en/v4.0.1/build/ol.js" type="text/javascript"></script>
<title>OpenLayers example</title>
</head>
<body>
<h2>Federation Map</h2>
<div id="map" class="map"></div>
<div id="enterprise" class="starship"></div>
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([-84.065299, 39.772954]),
zoom: 2
})
});
var starship = new ol.Overlay({
position: [-84.065299, 39.772954],
offset: [-200,-200],
element: document.getElementById('enterprise'),
});
map.addOverlay(starship);
map.on('click', function(event){
var coords = event.coordinate;
console.log(coords);
starship.setPosition(coords);
});
var ws = new WebSocket('ws://localhost:8080/');
ws.onopen = function() {
console.log("Connected");
};
ws.onclose = function() {
console.log("Disconnected");
};
ws.onmessage = function(event) {
var json_string = event.data;
console.log(json_string);
var obj = JSON.parse(json_string);
var latitude = parseInt(obj.latitude);
var longitude = parseInt(obj.longitude);
var coords = [longitude,latitude];
var newCoords = ol.proj.transform(coords, 'EPSG:4326', 'EPSG:3857');
console.log(newCoords);
starship.setPosition(newCoords);
};
</script>
</body>
</html>