Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created September 16, 2019 10:07
Show Gist options
  • Save adamdriscoll/8810602070c8a5b26f789ced3882d462 to your computer and use it in GitHub Desktop.
Save adamdriscoll/8810602070c8a5b26f789ced3882d462 to your computer and use it in GitHub Desktop.
Dynamically add markers to a map using geocoding
$Dashboard = New-UDDashboard -Title "PowerShell Conference Asia 2019" -Content {
New-UDMap -Id 'map' -Endpoint {
New-UDMapLayerControl -Id 'layercontrol' -Content {
New-UDMapBaseLayer -Name "Bing" -Content {
New-UDMapRasterLayer -Bing -ApiKey '11111111' -Type Road
} -Checked
New-UDMapOverlay -Name "Cluster" -Content {
New-UDMapMarkerClusterLayer -Id 'cluster-layer' -Markers @(
)
} -Checked
}
}
New-UDTextbox -Id 'txtAddress' -Label 'Address'
New-UDButton -Text "Add marker to cluster" -OnClick {
$Address = (Get-UDElement -Id 'txtAddress').Attributes['value']
$item = Invoke-RestMethod "https://geocoder.cit.api.here.com/6.2/geocode.json?searchtext=$Address&app_id=1111111&app_code=12213123121&gen=8"
$position = $item.response.view.result.location.displayposition
Add-UDElement -ParentId 'cluster-layer' -Content {
New-UDMapMarker -Latitude $position.latitude -Longitude $position.longitude
} -Broadcast
Show-UDToast -Message "Added marker for $Address" -Broadcast
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment