Modules/UniversalDashboard.Map/Scripts/map.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function New-UDMap {
    param(
        [Parameter()]
        [string]$Id = (New-Guid).ToString(),
        [Parameter()]
        [float]$Longitude,
        [Parameter()]
        [float]$Latitude,
        [Parameter()]
        [int]$Zoom,
        [Parameter()]
        [string]$Height = '500px',
        [Parameter()]
        [string]$Width = '100%',
        [Parameter(Mandatory)]
        [object]$Endpoint,
        [ValidateSet("topright", "topleft", "bottomright", "bottomleft")]
        [string]$ZoomControlPosition = "topright",
        [ValidateSet("topright", "topleft", "bottomright", "bottomleft", "hide")]
        [string]$ScaleControlPosition = "bottomleft",
        [Parameter()]
        [Switch]$Animate,
        [Parameter()]
        [int]$MaxZoom = 18
    )

    End {

        if ($Endpoint -is [scriptblock]) {
            $Endpoint = New-UDEndpoint -Endpoint $Endpoint -Id $Id
        }
        elseif ($Endpoint -isnot [UniversalDashboard.Models.Endpoint]) {
            throw "Endpoint must be a script block or UDEndpoint"
        }

        @{
            assetId = $AssetId 
            isPlugin = $true 
            type = "ud-map"
            id = $Id

            longitude = $Longitude
            latitude = $Latitude
            zoom = $Zoom
            height = $Height
            width = $Width
            zoomControlPosition = $ZoomControlPosition
            animate = $Animate.IsPresent
            scaleControlPosition = $ScaleControlPosition
            maxZoom = $MaxZoom
        }
    }
}