VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "mapServerClass"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'Save JPG App
'Private Declare Function DIWriteJpg Lib "DIjpg.dll" (ByVal DestPath As String, ByVal quality As Long, ByVal progressive As Long) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" _
  (lpvDest As Any, _
   lpvSource As Any, _
   ByVal nofbyte As Long)

Private Declare Function sdllinit Lib "taiwan.dll" _
  (ByVal s1 As String, ByVal s2 As String) As Long
Private Declare Function sdllgetbmp Lib "taiwan.dll" _
  (ByRef b As Any) As Long
Private Declare Function sdllgetimgfile Lib "taiwan.dll" _
  (ByVal s As String) As Long
  
Private Declare Function sdllisinit Lib "taiwan.dll" _
  () As Long

Private Sub Class_Initialize()
  If -1 = sdllisinit() Then
    sdllinit App.Path + "\twmap\", App.Path + "\tmp\"
    'mapServerForm.show
  End If
End Sub
Private Sub Class_Terminate()
  '
End Sub

Public Function myend() As Long
  Unload mapServerForm
  End
  myend = 0
End Function

Public Function show() As Long
  mapServerForm.show
  show = 0
End Function


Public Function test(a As Long, b As Long) As Long
  testk = testk + 1
  test = a + b + testk
End Function


Public Function draw2(xc As Long, yc As Long, mp As Double, b() As Byte) As Long
  mapServerForm.Label1.Caption = "busy"
  mapServerForm.Label1.Refresh
  k = mydraw(xc, yc, mp)
  k = sdllgetbmp(b(0))
  mapServerForm.Label1.Caption = ""
  mapServerForm.Label4.Caption = Format(Date, "yy_mm_dd") + " " + Format(Time, "hh:mm:ss")
  draw2 = k
End Function
Public Function draw3(xc As Long, yc As Long, mp As Double) As Variant
  mapServerForm.Label1.Caption = "busy"
  mapServerForm.Label1.Refresh
  k = mydraw(xc, yc, mp)
  
  
  Dim b() As Byte
  ReDim b(500000) As Byte
  k = sdllgetbmp(b(0))
  ReDim Preserve b(1078 + k - 1) As Byte
  draw3 = b()
  
  
  mapServerForm.Label1.Caption = ""
  mapServerForm.Label4.Caption = Format(Date, "yy_mm_dd") + " " + Format(Time, "hh:mm:ss")
End Function

Public Function draw(xc As Long, yc As Long, mp As Double, ID As String, MapW As Integer, MapH As Integer) As String
On Error GoTo diserror
'For Gif Convert
    Dim sourcebmp As String
    Dim targetgif As String
    Dim interlaced As Boolean
    Dim errorstring As String
    Dim Cvrmp As Double
  mapServerForm.P.Height = MapH
  mapServerForm.P.Width = MapW
  mapServerForm.Label1.Caption = "busy"
  mapServerForm.Label1.Refresh
  k = mydraw(xc, yc, mp)  '繪入地圖
'轉換成Jpg File
  SavePicture mapServerForm.P.Image, App.Path & "\tmp\" & ID & ".bmp"
'  MyJpgName = App.Path & "\tmp\" & ID & ".jpg"
'  If DIWriteJpg(MyJpgName, 90, True) = 1 Then
'    Kill "C:\" & ID & ".bmp"
'    draw = ID & ".jpg"
'  Else
'    draw = "err.jpg"
'    Kill "C:\" & ID & ".bmp"
'  End If
'轉換成Gif File
    Extension = Trim(Str(Minute(Time))) + Trim(Str(Second(Time)))
    MyGifName = App.Path & "\tmp\" & ID & Extension & ".gif"
    sourcebmp = App.Path & "\tmp\" & ID & ".bmp"   ' the path to source bmp file
    interlaced = False            ' do not produce interlaced GIF
    mapServerForm.BMP2GIF1.BMP2GIF sourcebmp, MyGifName, interlaced
    If mapServerForm.BMP2GIF1.IsError Then      ' in case of error on converting
      'errorstring = BMP2GIF1.errorstring
       Kill App.Path & "\tmp\" & ID & ".bmp"
       draw = "err.gif"
    Else
       Kill App.Path & "\tmp\" & ID & ".bmp"
       draw = ID & Extension & ".gif"
    End If

'轉換成BMP File
'  Dim s As String * 500
'  sdllgetimgfile s
'
'  ss = ""
'  For i = 1 To Len(s)
'    s1 = Mid(s, i, 1)
'    If Asc(s1) = 0 Then Exit For
'    ss = ss + s1
'  Next i
'  mapServerForm.Label1.Caption = ""
'  mapServerForm.Label4.Caption = Format(Date, "yy_mm_dd") + " " + Format(Time, "hh:mm:ss")
'  draw = Mid(ss, Len(App.Path + "\tmp\") + 1)
Exit Function
diserror:
  draw = "err.gif"
End Function

