'#Reference {A3B5C45B-F842-44fc-A5E5-50CED69BA86E}#2.0#0#C:\Program Files\Mindjet\MindManager 6\Mm5WebExport.dll#Mm5webexport 2.0 Type Library
'#Uses "GlobalUtilities.mmbas"
Option Explicit

Sub Main

    Dim addin As Mm5WebExportAddIn
    Dim webex As WebExport
    Dim aPage As Mm5WebExportLib.Page

    Set addin = WebExportHelper.WebExportAddIn
    Set webex = addin.ActiveWebExport

    Dim oneMapMarkerGroupsCollection As MapMarkerGroups
    Dim oneMapMarkerGroup As MapMarkerGroup

    Dim mapMarkerGroupTemplateString As String
    Dim mapMarkerGroupString As String
    Dim mapMarkerString As String
    Dim bodyString As String

    On Error GoTo ReportError
    
    webex.Trace("Entering ToolsLg.mmbas",2)

    ' Collection of map markers group
    Set oneMapMarkerGroupsCollection = webex.Document.MapMarkerGroups

    For Each oneMapMarkerGroup In oneMapMarkerGroupsCollection

        Select Case oneMapMarkerGroup.Type

            Case mmMapMarkerGroupTypeFillColor
                ' Don't process text colors
            Case mmMapMarkerGroupTypeTextColor
                ' Don't process fill colors
            Case Else
                ' Process everything else
                webex.SetParameter("CustomParameter.LegendGroupName", VerifyText(webex,oneMapMarkerGroup.Name))

                ' Process template and store result
                mapMarkerGroupTemplateString = webex.ReadFile("ToolsLgGroupItem.htm")
                mapMarkerGroupString = mapMarkerGroupTemplateString

                ProcessString webex, mapMarkerGroupString

                ' Now process the map marker items inside the map marker group
                mapMarkerString = ProcessMapMarkerItems (oneMapMarkerGroup, webex)

                If mapMarkerString = "" Then
                    ' Don't export group, no markers in group used
                Else
                    bodyString = bodyString + mapMarkerGroupString + mapMarkerString
                End If

        End Select

    Next

    ' If no map markers are used in any groups, show message saying "no legend items" or similar
    If bodyString = "" Then
       bodyString = webex.GetParameter ("Strings.Hidden.MapMarkerGroupNoItems")
    End If
      
   ' Write out the result
    webex.PushString (bodyString)
 
    webex.Trace("Exiting ToolsLg.mmbas",2)

    Exit Sub
 
ReportError:
    ProcessError(webex)
    Exit Sub
 
End Sub


Function ProcessMapMarkerItems (ByVal oneMapMarkerGroup As MapMarkerGroup, ByRef webex As WebExport)

    Dim oneMapMarkerIcon As MapMarkerIcon
    Dim oneMapMarker As MapMarker
    Dim oneIcon As Icon

    Dim localTemplate As String
    Dim localItemString As String
    Dim localBodyString As String
    Dim ImagePath As String

    For Each oneMapMarker In oneMapMarkerGroup

        Select Case oneMapMarker.Type
        
            ' all cases with icons
            Case mmMapMarkerGroupTypePriority, _
                 mmMapMarkerGroupTypePercentageComplete, _
                 mmMapMarkerGroupTypeSingleIcon, _
                 mmMapMarkerGroupTypeIcon
				    
                Set oneMapMarkerIcon = oneMapMarker.Icon

                If webex.VariantSets(weVariantSetIcons).Find(oneMapMarkerIcon.Name,False) > 0 Then
                    ImagePath = RelativeMapMarkerPath(webex, oneMapMarkerIcon.Name)
                    webex.SetParameter("CustomParameter.LegendItemImage", webex.PathToUrl(ImagePath))
                    webex.SetParameter("CustomParameter.LegendItemLabel", VerifyText(webex, oneMapMarker.Label))

                    localTemplate = webex.ReadFile("ToolsLgItemImg.htm")
                    localItemString = localTemplate

                    ProcessString webex, localItemString
                    localBodyString = localBodyString + localItemString
                Else
                    localBodyString = localBodyString
                End If

        End Select

    Next

    ProcessMapMarkerItems = localBodyString

End Function
