-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
executable file
·180 lines (162 loc) · 6.23 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
<head>
<title>MarineTraffic and OpenSeaMap</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css" />
<link rel="stylesheet" href="http://www.jacklmoore.com/colorbox/example1/colorbox.css" />
<style type="text/css">
html, body,#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-popup-content { overflow: hidden; }
.leaflet-popup-content #infopic { float: right; }
.leaflet-popup-content #infotext { float: left; }
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<script src="http://rawgithub.com/shramov/leaflet-plugins/master/layer/Marker.Rotate.js"></script>
<script src="http://rawgithub.com/mlevans/leaflet-hash/master/leaflet-hash.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="http://www.jacklmoore.com/colorbox/jquery.colorbox.js"></script>
</head>
<body>
<div id="map"></div>
<script src="geojson.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
(function($){
$(function(){
var map = new L.Map('map').setView([48.5, -5], 9);
map.attributionControl.setPrefix('').addAttribution('Map data © <a href="http://www.marinetraffic.com">MarineTraffic</a>');
var hash = new L.Hash(map);
var obm = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Sources: GEBCO, NOAA, CHS, OSU, UNH, CSUMB, National Geographic, DeLorme, NAVTEQ, and Esri',
maxZoom: 13
}).addTo(map);
var positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>',
subdomains: 'abcd',
maxZoom: 19
});
openseamap = new L.TileLayer('http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png', {maxZoom: 19}).addTo(map);
var openweathermapAttribution = 'OpenWeatherMap',
clouds = new L.TileLayer('http://{s}.tile.openweathermap.org/map/clouds/{z}/{x}/{y}.png', {
maxZoom: 19,
opacity: 0.3,
attribution: openweathermapAttribution
}),
precip = new L.TileLayer('http://{s}.tile.openweathermap.org/map/precipitation/{z}/{x}/{y}.png', {
maxZoom: 19,
opacity: 0.3,
attribution: openweathermapAttribution
});
pressure = new L.TileLayer('http://{s}.tile.openweathermap.org/map/pressure/{z}/{x}/{y}.png', {
maxZoom: 19,
opacity: 0.3,
attribution: openweathermapAttribution
});
wind = new L.TileLayer('http://{s}.tile.openweathermap.org/map/wind/{z}/{x}/{y}.png', {
maxZoom: 19,
opacity: 0.3,
attribution: openweathermapAttribution
});
var rail = new L.geoJson(rail_ouessant,{
style: function (feature) {
return feature.properties.style;
}
});
var cams = new L.geoJson(webcams,{
onEachFeature: function (feature, layer) {
if (feature.properties && feature.properties.popupContent) {
layer.on('click',function(e){
$.colorbox({
href: feature.properties.popupContent,
iframe: true,
width:'80%',
height:'80%'
});
});
}
layer.setIcon(new L.Icon({
'iconUrl': 'cam.png',
'iconSize': new L.Point(32,37),
'iconAnchor': new L.Point(16,37),
'popupAnchor': new L.Point(1,-34)
}));
}
}).addTo(map);
var layersControl = new L.Control.Layers({
'Positron': positron,
'Ocean Base Map': obm
}, {
'OpenSeaMap': openseamap,
'Webcams': cams,
'Rail Ouessant': rail,
'Clouds': clouds,
'Precipitation': precip,
'Pressure': pressure,
'Wind': wind
}).addTo(map);
var boatIcon = new L.Icon({
iconUrl: 'marker.png',
shadowUrl: null,
iconSize: new L.Point(19, 26),
iconAnchor: new L.Point(9, 13)
});
var markerGroup = new L.LayerGroup();
var loadAis = function() {
$.getJSON("proxy.php",
{
url: "http://services.marinetraffic.com/api/exportvessels/cc503f48eb2c8e49549cc56de3c7059c4b042931/timespan:4/protocol:json",
mode: "native"
},
function(data) {
if (data) {
markerGroup.clearLayers(); // comment this line to see the traject of boat just for fun
$.each(data, function(i,item){
var lat = item[1];
var lng = item[2];
var marker = new L.Marker(new L.LatLng(lat,lng), {icon:boatIcon});
marker.options.course = item[4];
marker.setIconAngle(marker.options.course);
marker.options.mmsi = item[0];
marker.options.status = item[5];
marker.on('click', function(e) {
var popup = new L.Popup();
popup.setLatLng(e.target._latlng);
$.get("proxy.php",
{
url: "http://services.marinetraffic.com/api/exportvessel/00945bab8516d2db6d52a752c9c89232f6e0e7d0/timespan:2/msgtype:extended/protocol:json/mmsi:"+ e.target.options.mmsi,
mode: "native"
},
function(data) {
if (data.length > 0) {
var content = '';
content += '<strong><a href="http://www.marinetraffic.com/fr/ais/details/ships/' + data[0][0] + '/">' + data[0][6] + ' - ' + data[0][10] + '</a></strong>';
content += '<br /><strong>Longueur / Largeur</strong> : ' + data[0][16] + ' / ' + data[0][17];
content += '<br /><strong>Tirant d\'eau</strong> : ' + data[0][18];
content += '<br /><strong>Vitesse / Cap</strong> : ' + data[0][3]/10 + ' / ' + data[0][4];
content += '<br /><strong>Destination</strong> : ' + data[0][14];
popup.setContent(content);
map.openPopup(popup);
}
});
});
markerGroup.addLayer(marker);
});
map.addLayer(markerGroup);
}
})
.error(function() { alert("error loading data"); });
};
loadAis();
setInterval(loadAis, 125000); //125 seconds
});
})(jQuery);
//]]>
</script>
</body>
</html>