Private Sub GE_Update_Vessel() '************************************************************************************ 'This procedure updates the GE vessels 'The input parameters are: ' None 'Notes on this procedure: ' o For a procedure in greater C_wiz to update the GE vessels it: ' o Sets the GE_status_vessel_update flag to 1 ' o Waits for GE_interrogate_Timer to call this procedure ' o See the notes in GE_interrogate_Timer for the reasons why '************************************************************************************ 'Flag GE vessel update in progress GE_status_vessel_update = 2 '************************************************************************************ 'Build new vessel data kml file... '************************************************************************************ 'Open the new vessel data kml file for output File_xkm = FreeFile Open mydirectory + "C_wiz GE Vessels.newkml" For Output As #File_xkm 'Build kml file header Print #File_xkm, GE_kml_header1 Print #File_xkm, GE_kml_header2 Print #File_xkm, "<Document>" 'For each vessel supplying data... For id% = 1 To ... 'Some C_wiz co-existence code here, establishing... '... vessel current latitude vessel_lat# = ... '... vessel current longitude vessel_long# = ... 'Start description of vessel Print #File_xkm, " <Placemark>" Print #File_xkm, " <name>" + MAP_vessel_ID(id%) + "</name>" Print #File_xkm, " <visibility>1</visibility>" Print #File_xkm, " <Style>" 'If GE focalpoint icon not null... If GE_fpt_icon <> "" Then 'Set up description of vessel focalpoint icon Print #File_xkm, " <IconStyle>" Print #File_xkm, " <Icon>" Print #File_xkm, " <href>" + mydirectory + GE_fpt_icon + ".png</href>" Print #File_xkm, " <x>0</x>" Print #File_xkm, " <y>0</y>" Print #File_xkm, " <w>32</w>" Print #File_xkm, " <h>32</h>" Print #File_xkm, " </Icon>" Print #File_xkm, " </IconStyle>" End If 'Set up description of vessel track characteristics Print #File_xkm, " <LineStyle>" Print #File_xkm, " <color>" + GE_track_color_hex + "</color>" Print #File_xkm, " <width>" + Format$(MAP_track_width) + "</width>" Print #File_xkm, " </LineStyle>" Print #File_xkm, " </Style>" 'Set up description of vessel location Print #File_xkm, " <MultiGeometry>" Print #File_xkm, " <Point>" Print #File_xkm, " <coordinates>" Print #File_xkm, " " + Format$(vessel_long#) + "," + Format$(vessel_lat#) + ",0" Print #File_xkm, " </coordinates>" Print #File_xkm, " </Point>" 'Set up description of vessel track Print #File_xkm, " <LineString>" Print #File_xkm, " <coordinates>" 'For latitude/longitude pairs of vessels data... For ... 'Some C_wiz co-existence code here, establishing... '... vessel track point latitude vessel_lat# = ... '... vessel track point longitude vessel_long# = ... 'Add to vessel track coordinates list Print #File_xkm, " " + Format$(vessel_long#) + "," + Format$(vessel_lat#) + ",0" Next 'End description of vessel track Print #File_xkm, " </coordinates>" Print #File_xkm, " </LineString>" 'End description of vessel Print #File_xkm, " </MultiGeometry>" Print #File_xkm, " </Placemark>" Next Print #File_xkm, "</Document>" Print #File_xkm, "</kml>" 'Close the new vessel data kml file Close #File_xkm '************************************************************************************ 'Replace old vessel data kml file with new vessel data kml file... '************************************************************************************ 'Make up to 10 attempts... For i% = 1 To 10 'Move new vessel data kml file to the file actually pointed to by the vessel 'link kml file - use this approach because the obvious simpler approach 'routinely made GE complain about "fetch errors" - when GE went to access 'the file every second sometimes it wasn't available - still does this 'but only very occasionally (e.g. when replaying with a Map Throttle of '100) rc& = MoveFileEx(mydirectory + "C_wiz GE Vessels.newkml", mydirectory + "C_wiz GE Vessels.kml", MOVEFILE_REPLACE_EXISTING) 'Quit loop if move successful If rc& <> 0 Then Exit For Next '************************************************************************************ 'Massage vessel link kml file... '************************************************************************************ 'If GE vessels network link has not been established... If Not GE_status_networklink Then 'Open vessel link kml file for output File_xkm = FreeFile Open mydirectory + "C_wiz GE Vessels Link.kml" For Output As #File_xkm 'Build kml file header Print #File_xkm, GE_kml_header1 Print #File_xkm, GE_kml_header2 Print #File_xkm, "<visiblity>1</visiblity>" Print #File_xkm, "<NetworkLink>" Print #File_xkm, " <name>C_wiz Vessels</name>" Print #File_xkm, " <Url>" Print #File_xkm, " <href>" + mydirectory + "C_wiz GE Vessels.kml</href>" Print #File_xkm, " <refreshMode>onInterval</refreshMode>" Print #File_xkm, " <refreshInterval>1</refreshInterval>" Print #File_xkm, " <viewRefreshMode>never</viewRefreshMode>" Print #File_xkm, " </Url>" Print #File_xkm, "</NetworkLink>" Print #File_xkm, "</kml>" 'Close vessel link kml file Close #File_xkm 'Send vessel link kml file to GE, saving return code as the flag 'indicating the GE vessels network link state GE_status_networklink = GE_Send_Kml("C_wiz GE Vessels Link") End If '************************************************************************************ 'Move GE view if appropriate... '************************************************************************************ 'If vessel locked to cursor and has been found... If ... 'Some C_wiz co-existence code here, establishing... '... current latitude of vessel locked to cursor vessel_lat# = ... '... current longitude of vessel locked to cursor vessel_long# = ... 'If view needs to be moved... If vessel_lat# <> GE_view_last_lat Or vessel_long# <> GE_view_last_long Then 'Set up error handler On Error GoTo BAD_GE 'Move the view to coincide with vessel latitude and longitude - this 'call is made to force the view to change at top speed ("teleport" 'in GE parlance - the 6 parameter) thus overriding any user speed 'settings - this avoids the poncey bounce that GE can indulge in when 'changing views which stuffs up the range/bearing/tilt monitoring 'done by GE_interrogate GE_interface_view.FocusPointLatitude = vessel_lat# GE_interface_view.FocusPointLongitude = vessel_long# GE_interface_view.range = GE_range GE_interface_view.Tilt = GE_tilt GE_interface_view.Azimuth = GE_bearing Call GE_interface.SetCamera(GE_interface_view, 6) 'Give GE a chance to digest it DoEvents 'Turn default error handling back on On Error GoTo 0 'Update latitude and longitude to which view was last moved GE_view_last_lat = vessel_lat# GE_view_last_long = vessel_long# End If End If 'If GE vessel update in progress then flag GE vessel update not required (it is 'possible for this flag to be flicked to "GE vessel update required" during the 'execution of this procedure, in which case don't change it) If GE_status_vessel_update = 2 Then GE_status_vessel_update = 0 'Update time at which GE vessels were last updated GE_vessel_update_time = GetTickCount 'Quit Exit Sub '************************************************************************************ 'This GOSUB handles a GE error... '************************************************************************************ BAD_GE: 'Turn default error handling back on On Error GoTo 0 'In the next split second a similar error should occur in GE_interrogate_Timer 'which can tidy up End Sub