////////////////////////////////////////////// // Code ////////////////////////////////////////////// var s = new Ships(); var lines = new Array(); var map, infoWindow, lineSymbol, lineSymbol2, osmOverlay; var ts = 0; var updateinterval = 10; // Update interval in seconds var idleTime = 3; // how many minutes must ship be incative to be considered incative //var colors = new Colors(["#a52a2a","#5f9ea0","#6495ed","#228b22","#daa520","#ffa07a","#663399","#008080","#9acd32","#6a5acd"], 0); var colors = new Colors(["#00ac59","#ff8e49","#fcdb00","#49dfff","#cacaca","#ff4bdb","#f4f8ab","#ff5c5c","#ff8cd8","#adae2a","#8b7fff","#ad2101","#007b7f","#e1831b"], 0); function initMap() { map = new google.maps.Map(document.getElementById('map'), { scaleControl: true, center: latlng = {lat: 43.342655458459, lng: 16.135852989155}, zoom: 9, mapTypeControlOptions: { mapTypeIds: ['roadmap', 'terrain', 'satellite', 'hybrid', 'OSM'] }, mapTypeId: 'OSM', }); map.mapTypes.set("OSM", new google.maps.ImageMapType({ getTileUrl: function(coord, zoom) { // "Wrap" x (logitude) at 180th meridian properly // NB: Don't touch coord.x because coord param is by reference, and changing its x property breakes something in Google's lib var tilesPerGlobe = 1 << zoom; var x = coord.x % tilesPerGlobe; if (x < 0) { x = tilesPerGlobe+x; } // Wrap y (latitude) in a like manner if you want to enable vertical infinite scroll return "http://tile.openstreetmap.org/" + zoom + "/" + x + "/" + coord.y + ".png"; }, tileSize: new google.maps.Size(256, 256), name: "OpenSeaMap", maxZoom: 18 })); var osmOverlay = new google.maps.ImageMapType({ getTileUrl: function(coord, zoom) { var tilesPerGlobe = 1 << zoom; var x = coord.x % tilesPerGlobe; if (x < 0) { x = tilesPerGlobe+x; } return "http://t1.openseamap.org/seamark/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; }, tileSize: new google.maps.Size(256, 256) }); map.overlayMapTypes.push(osmOverlay); map.addListener('maptypeid_changed', function() { setTimeout(function (){osmOverlay.setOpacity(map.getMapTypeId() !== 'OSM' ? 0 : 1)}, 300); }); lineSymbol = {path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW}; lineSymbol2 = {path: google.maps.SymbolPath.BACKWARD_CLOSED_ARROW}; //infoWindow = new google.maps.InfoWindow; //ship = new ShipObject(354, "Bilardos", map, 50.90, 14.50, 1.222, "2016-09-13 18:33:59", '#000000'); //ship.show(null); //ship.show(map); //s.addShip(ship); console.log("initmap called") setTimeout("loadData()", 100); setTimeout("loadLines()", 100); } function loadLines(){ console.log("loadlines called") $.ajax({ dataType: 'json', url: 'load_lines.php', type: "GET", }).done(function(data){ for(i in data){ if(i==0) { if(data[i].error == 1) return false; else continue; } //alert(data[i].name); drawLine(data[i].color, data[i].name, data[i].latstart, data[i].lngstart, data[i].latend, data[i].lngend); } }); } function loadData(){ console.log("loaddata called") $.ajax({ dataType: 'json', url: 'load_data.php', type: "GET", data: {timestamp:ts} }).done(function(data){ console.log(data); if(data[0].timestamp) ts = data[0].timestamp; if(data[0].error == 0) for(i in data){ if (i==0){ ts = data[0].timestamp; //$("#loading").hide(); continue; } if (s.exists(data[i].shipid)){ //console.log('exists'); //console.log(s.ships[data[i].shipid]) /*if(s.ships[data[i].shipid].name != data[i].shipname){ s.ships[data[i].shipid].name = data[i].shipname; $("#ship-"+data[i].shipid+" .shipname").html(data[i].shipname); s.ships[data[i].shipid].marker.labelContent = data[i].shipname; s.ships[data[i].shipid].marker.labelAnchor = new google.maps.Point(data[i].shipname.length*3.7, 60); s.ships[data[i].shipid].marker.label.draw(); }*/ s.ships[data[i].shipid].addPosition(data[i].lat, data[i].lng, data[i].speed, data[i].time, ts); $("#ship-"+data[i].shipid+" .shipdate").html(data[i].timeacquired); $("#ship-"+data[i].shipid+" .shipspeed").html(roundSpeed(data[i].speed)+" kn"); } else { c = colors.getColor(); ship = new ShipObject( data[i].shipid, data[i].shipname, map, data[i].lat, data[i].lng, data[i].speed, data[i].time, c, ts); $("#menu ul").append("
"+data[i].shipname+"
"+data[i].timeacquired+"
"+roundSpeed(data[i].speed) + " kn