0
comment
on 8/4/2011 1:16 AM

The WebSharper Extensions for Bing Maps has been updated to reflect the last changes in the 7.0 API. Here is a list of additions:

  • A new "modules" API which allows you to create extension modules for Bing Maps. This also comes with the three following built-in modules.

    • Directions: This is a simplified API to access the Routes REST API. It provides a very convenient interface, with attractive features such as draggable waypoints which trigger a recalculation of the route, and clickable instructions which causes the map to zoom on the corresponding location.
    • We advise you to only use our previously existing interface to the Routes REST API if you want to use it without displaying a map.
      Traffic: This simple class allows you to display traffic information as a layer on the map.
    • VenueMaps: This API provides precise information about buildings surrounding an area, and draws their ground footprint on the map.
  • A new "strokeDashArray" property for polylines and polygons which allows you to use dashed lines. The WebSharper extension use an array of integers to represent the list of dash lengths more safely than the string used by the JavaScript API.

To demonstrate the simplicity of these new APIs, here is the code for a map allowing the user to search for a route between two locations.

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
open IntelliFactory.WebSharper.Bing
open IntelliFactory.WebSharper.Bing.Directions

[<JavaScript>]
let MapWithRouteRequest () =
    let origin = Input []
    let destination = Input []
    let button = Input [Attr.Type "button"; Attr.Value "Request route"]
    let answer = Div [Id "answer"]
    let mapContainer =
        Div []
        |>! OnAfterRender (fun el ->
            let opts = MapOptions(Credentials = "Your Bing maps developer key",
                                  Width = 600,
                                  Height = 500)
            let map = Map(el.Body, opts)
            map.SetMapType(MapTypeId.Road)
            let onDirsLoaded() =
                let dirman = DirectionsManager(map)
                let request (_:Element) (_:Events.MouseEvent) =
                    dirman.ResetDirections()
                    dirman.AddWaypoint
			<| Waypoint(WaypointOptions(Address = origin.Value))
                    dirman.AddWaypoint
			<| Waypoint(WaypointOptions(Address = destination.Value))
                    dirman.SetRenderOptions
			<| DirectionsRenderOptions(ItineraryContainer = answer.Body)
                    dirman.SetRequestOptions
			<| DirectionsRequestOptions(DistanceUnit = DistanceUnit.Kilometers)
                    dirman.CalculateDirections()
                button |>! OnClick request |> ignore
            Maps.LoadModule("Microsoft.Maps.Directions", LoadModuleArgs(onDirsLoaded))
        )
    Div [mapContainer
         Span[Text "From:"]; origin
         Span[Text "To:"]; destination
         button
         answer]

The updated extension for Bing Maps can be downloaded at this address.

.
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper