function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(18.000, -67.000), 9); map.addControl(new GMapTypeControl()); map.addControl(new GOverviewMapControl()); map.addControl(new GSmallMapControl()); map.addControl(new GScaleControl()); map.enableScrollWheelZoom(); GDownloadUrl("http://www.caricoos.org/app/smart_ais/data.php", function(data) { var xml = GXml.parse(data); var ships = xml.documentElement.getElementsByTagName("ship"); var m=0; for (var i = 0; i < ships.length; i++) { var shipTrailPoints = ships[i].getElementsByTagName("trail_point"); var trailVertices = new Array(); for (var j=0; j < shipTrailPoints.length; j++) trailVertices[j] = new GLatLng( parseFloat(shipTrailPoints[j].getAttribute("latitude")), parseFloat(shipTrailPoints[j].getAttribute("longitude")) ); var polyline = createTrail(trailVertices, "#ff0000", 5); map.addOverlay(polyline); //Add ship marker var last_index =shipTrailPoints.length -1; var lastShipComm = shipTrailPoints[0]; var shipData = new Array(); //shipData['mmsi'] = ships[i].getAttribute("mmsi"); shipData['rot'] = lastShipComm.getAttribute("rot"); shipData['cog'] = lastShipComm.getAttribute("cog"); shipData['sog'] = lastShipComm.getAttribute("sog"); shipData['lat'] = lastShipComm.getAttribute("latitude"); shipData['lon'] = lastShipComm.getAttribute("longitude"); shipData['eta'] = lastShipComm.getAttribute("eta"); //Static Vessel Data shipData['ship_name'] = ships[i].getAttribute("name"); shipData['ship_type'] = ships[i].getAttribute("ship_type"); //shipData['callsign'] = ships[i].getAttribute("callsign"); shipData['destination'] = lastShipComm.getAttribute("destination"); shipData['draught'] = ships[i].getAttribute("draught"); shipData['loa'] = ships[i].getAttribute("loa"); // shipData['last_communication'] = lastShipComm.getAttribute("created"); var shipMarker = createTrailMarker( new GLatLng( parseFloat(shipTrailPoints[0].getAttribute("latitude")), parseFloat(shipTrailPoints[0].getAttribute("longitude")) ), shipData); // var shipMarker = createTrailMarker( new GLatLng( parseFloat(shipTrailPoints[last_index].getAttribute("latitude")), // parseFloat(shipTrailPoints[last_index].getAttribute("longitude")) ), shipData); map.addOverlay(shipMarker); } }); //Now the FURA Map var mapFURA = new GMap2(document.getElementById("map_fura_canvas")); mapFURA.setCenter(new GLatLng(18.000, -67.000), 9); mapFURA.addControl(new GMapTypeControl()); mapFURA.addControl(new GOverviewMapControl()); mapFURA.addControl(new GSmallMapControl()); mapFURA.addControl(new GScaleControl()); mapFURA.enableScrollWheelZoom(); GDownloadUrl("http://www.caricoos.org/app/smart_ais/data_fura.php", function(data) { var xml = GXml.parse(data); var ships = xml.documentElement.getElementsByTagName("ship"); var m=0; for (var i = 0; i < ships.length; i++) { var shipTrailPoints = ships[i].getElementsByTagName("trail_point"); var trailVertices = new Array(); for (var j=0; j < shipTrailPoints.length; j++) trailVertices[j] = new GLatLng( parseFloat(shipTrailPoints[j].getAttribute("latitude")), parseFloat(shipTrailPoints[j].getAttribute("longitude")) ); var polyline = createTrail(trailVertices, "#ff0000", 5); mapFURA.addOverlay(polyline); //Add ship marker var last_index =shipTrailPoints.length -1; var lastShipComm = shipTrailPoints[0]; var shipData = new Array(); //shipData['mmsi'] = ships[i].getAttribute("mmsi"); shipData['rot'] = lastShipComm.getAttribute("rot"); shipData['cog'] = lastShipComm.getAttribute("cog"); shipData['sog'] = lastShipComm.getAttribute("sog"); shipData['lat'] = lastShipComm.getAttribute("latitude"); shipData['lon'] = lastShipComm.getAttribute("longitude"); shipData['eta'] = lastShipComm.getAttribute("eta"); //Static Vessel Data shipData['ship_name'] = ships[i].getAttribute("name"); shipData['ship_type'] = ships[i].getAttribute("ship_type"); //shipData['callsign'] = ships[i].getAttribute("callsign"); shipData['destination'] = lastShipComm.getAttribute("destination"); shipData['draught'] = ships[i].getAttribute("draught"); shipData['loa'] = ships[i].getAttribute("loa"); // shipData['last_communication'] = lastShipComm.getAttribute("created") + "(GMT)"; var shipMarker = createTrailMarker( new GLatLng( parseFloat(shipTrailPoints[0].getAttribute("latitude")), parseFloat(shipTrailPoints[0].getAttribute("longitude")) ), shipData); // var shipMarker = createTrailMarker( new GLatLng( parseFloat(shipTrailPoints[last_index].getAttribute("latitude")), // parseFloat(shipTrailPoints[last_index].getAttribute("longitude")) ), shipData); mapFURA.addOverlay(shipMarker); } }); } } function createTrail(verticesArray, color, size) { var poly = new GPolyline(verticesArray, color, size); return poly; } function createTrailMarker(point, shipData) { //Ship Marker var shipMarker = new GMarker(point, shipIcon); //Ship Icon var shipIcon = new GIcon(); var cog = parseFloat(shipData['cog']); //convert from geographical degrees to mathematical degrees and calculate the icon sub-i var icon_i = 37 - (Math.round( ((450-cog)%360) /10) + 1); if (icon_i >= 37) icon_i = 1; shipIcon.image = "http://www.caricoos.org/app/aislocator/icons/"+icon_i+".png"; shipIcon.iconSize = new GSize(32,32); shipIcon.iconAnchor = new GPoint(16,16); shipIcon.infoWindowAnchor = new GPoint(16,16); //Ship Marker var shipMarker = new GMarker(point, shipIcon); var html = ''; if (shipData['ship_name'] != null && shipData['ship_name'] != 'None') html += ''; //if (shipData['callsign'] != null && shipData['callsign'] != 'None') //html += ''; if (shipData['destination'] != null && shipData['destination'] != 'None') html += ''; if (shipData['eta'] != null && shipData['eta'] != 'None') html += ''; if (shipData['draught'] != null && shipData['draught'] != 'None') html += ''; //This data will always be present, no need to check //html += ''; html += '' html += ''; html += ''; //html += ''; html += ''; html += ''; html += ''; html += ''; html += '
Vessel Information
Ship Name:'+shipData['ship_name']+'
Callsign:'+shipData['callsign']+'
Destination:'+shipData['destination']+'
Estimated Time of Arrival:'+shipData['eta']+'
Draught:'+shipData['draught']+' m
MMSI:'+shipData['mmsi']+'
 
Course Over Ground:'+shipData['cog']+'
Speed Over Ground:'+shipData['sog']+' kts
Rate of Turn:'+shipData['rot']+'
Latitude:'+shipData['lat']+'
Longitude:'+shipData['lon']+'
LOA:'+shipData['loa']+'m
LAST COMMUNICATION:'+shipData['last_communication']+'
'; GEvent.addListener(shipMarker, 'click', function() { shipMarker.openInfoWindowHtml(html); }); return shipMarker; }