Skip to content

Commit f81a92c

Browse files
committed
Add MapBox related layout options and types
1 parent 41fe6e2 commit f81a92c

File tree

7 files changed

+368
-1
lines changed

7 files changed

+368
-1
lines changed

Diff for: src/Plotly.NET/ChartExtensions.fs

+11
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ module ChartExtensions =
400400
GenericChart.setLayout layout ch
401401
)
402402

403+
/// Sets a mapbox for the given chart (will only work with traces supporting mapboxes, e.g. choroplethmapbox, scattermapbox)
404+
[<CompiledName("WithMapBox")>]
405+
static member withMapBox(mapBox:MapBox,[<Optional;DefaultParameterValue(null)>] ?Id ) =
406+
(fun (ch:GenericChart) ->
407+
let layout =
408+
let id = defaultArg Id 1
409+
GenericChart.getLayout ch
410+
|> Layout.UpdateMapBoxById(id,mapBox)
411+
GenericChart.setLayout layout ch
412+
)
413+
403414
/// Sets the map style for the given chart (will only work with traces supporting geo, e.g. choropleth, scattergeo)
404415
///
405416
/// Parameters :

Diff for: src/Plotly.NET/Layout.fs

+19-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ type Layout() =
300300
layout
301301
)
302302

303-
// Updates the style of current axis with given AxisId
303+
// Updates the style of current geo map with given Id
304304
static member UpdateMapById
305305
(
306306
id : int,
@@ -317,6 +317,24 @@ type Layout() =
317317

318318
layout
319319
)
320+
321+
// Updates the style of current geo map with given Id
322+
static member UpdateMapBoxById
323+
(
324+
id : int,
325+
mapbox : MapBox
326+
) =
327+
(fun (layout:Layout) ->
328+
let key = if id < 2 then "mapbox" else sprintf "mapbox%i" id
329+
let mapbox' =
330+
match layout.TryGetTypedValue<MapBox>(key) with
331+
| Some a -> DynObj.combine (unbox a) mapbox
332+
| None -> mapbox :> DynamicObj
333+
334+
mapbox' |> DynObj.setValue layout key
335+
336+
layout
337+
)
320338

321339
static member setLegend(legend:Legend) =
322340
(fun (layout:Layout) ->

Diff for: src/Plotly.NET/MapBox.fs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
namespace Plotly.NET
2+
3+
/// <summary>Determines the style of the map shown in mapbox traces</summary>
4+
type MapBox() =
5+
6+
inherit DynamicObj ()
7+
8+
/// <summary>Initialize a MapBox object that determines the style of the map shown in geo mapbox</summary>
9+
10+
static member init
11+
(
12+
?Domain: Domain,
13+
?AccessToken: string,
14+
?Style: StyleParam.MapBoxStyle,
15+
?Center: (float*float),
16+
?Zoom: float,
17+
?Bearing: float,
18+
?Pitch: float,
19+
?Layers: seq<MapBoxLayer>
20+
) =
21+
MapBox()
22+
|> MapBox.style
23+
(
24+
?Domain = Domain,
25+
?AccessToken= AccessToken,
26+
?Style = Style,
27+
?Center = Center,
28+
?Zoom = Zoom,
29+
?Bearing = Bearing,
30+
?Pitch = Pitch,
31+
?Layers = Layers
32+
)
33+
34+
/// <summary>Create a function that applies the given style parameters to a MapBox object.</summary>
35+
36+
static member style
37+
(
38+
?Domain: Domain,
39+
?AccessToken: string,
40+
?Style: StyleParam.MapBoxStyle,
41+
?Center: (float*float),
42+
?Zoom: float,
43+
?Bearing: float,
44+
?Pitch: float,
45+
?Layers: seq<MapBoxLayer>
46+
47+
) =
48+
(fun (mapBox:MapBox) ->
49+
50+
Domain |> DynObj.setValueOpt mapBox "domain"
51+
AccessToken |> DynObj.setValueOpt mapBox "accesstoken"
52+
Style |> DynObj.setValueOptBy mapBox "style" StyleParam.MapBoxStyle.convert
53+
54+
Center
55+
|> Option.map (fun (lon,lat) ->
56+
let t = DynamicObj()
57+
t?lon <- lon
58+
t?lat <- lat
59+
t
60+
)
61+
|> DynObj.setValueOpt mapBox "center"
62+
63+
Zoom |> DynObj.setValueOpt mapBox "zoom"
64+
Bearing |> DynObj.setValueOpt mapBox "bearing"
65+
Pitch |> DynObj.setValueOpt mapBox "pitch"
66+
Layers |> DynObj.setValueOpt mapBox "layers"
67+
68+
mapBox
69+
)

Diff for: src/Plotly.NET/MapBoxLayer.fs

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
namespace Plotly.NET
2+
3+
open System
4+
5+
/// <summary></summary>
6+
type MapBoxLayer() =
7+
8+
inherit DynamicObj ()
9+
10+
/// <summary>Initialize a MapBoxLayer object</summary>
11+
12+
static member init
13+
(
14+
?Visible: bool,
15+
?SourceType: StyleParam.MapBoxLayerSourceType,
16+
?Source: #IConvertible,
17+
?SourceLayer: string,
18+
?SourceAttribution: string,
19+
?Type: StyleParam.MapBoxLayerType,
20+
?Coordinates:seq<#IConvertible*#IConvertible>,
21+
?Below: string,
22+
?Color: string,
23+
?Opacity: float,
24+
?MinZoom:float,
25+
?MaxZoom:float,
26+
?CircleRadius: float,
27+
?Line:Line,
28+
?FillOutlineColor:string,
29+
?Symbol:MapBoxLayerSymbol,
30+
?Name: string
31+
) =
32+
MapBoxLayer()
33+
|> MapBoxLayer.style
34+
(
35+
?Visible = Visible ,
36+
?SourceType = SourceType ,
37+
?Source = Source ,
38+
?SourceLayer = SourceLayer ,
39+
?SourceAttribution = SourceAttribution,
40+
?Type = Type ,
41+
?Coordinates = Coordinates ,
42+
?Below = Below ,
43+
?Color = Color ,
44+
?Opacity = Opacity ,
45+
?MinZoom = MinZoom ,
46+
?MaxZoom = MaxZoom ,
47+
?CircleRadius = CircleRadius ,
48+
?Line = Line ,
49+
?FillOutlineColor = FillOutlineColor ,
50+
?Symbol = Symbol ,
51+
?Name = Name
52+
)
53+
54+
/// <summary>Create a function that applies the given style parameters to a MapBoxLayer object.</summary>
55+
56+
static member style
57+
(
58+
?Visible: bool,
59+
?SourceType: StyleParam.MapBoxLayerSourceType,
60+
?Source: #IConvertible,
61+
?SourceLayer: string,
62+
?SourceAttribution: string,
63+
?Type: StyleParam.MapBoxLayerType,
64+
?Coordinates:seq<#IConvertible*#IConvertible>,
65+
?Below: string,
66+
?Color: string,
67+
?Opacity: float,
68+
?MinZoom:float,
69+
?MaxZoom:float,
70+
?CircleRadius: float,
71+
?Line:Line,
72+
?FillOutlineColor:string,
73+
?Symbol:MapBoxLayerSymbol,
74+
?Name: string
75+
76+
) =
77+
(fun (mapBoxLayer:MapBoxLayer) ->
78+
79+
Visible |> DynObj.setValueOpt mapBoxLayer "visible"
80+
SourceType |> DynObj.setValueOptBy mapBoxLayer "sourcetype" StyleParam.MapBoxLayerSourceType.convert
81+
Source |> DynObj.setValueOpt mapBoxLayer "source"
82+
SourceLayer |> DynObj.setValueOpt mapBoxLayer "sourcelayer"
83+
SourceAttribution|> DynObj.setValueOpt mapBoxLayer "sourceattribution"
84+
Type |> DynObj.setValueOptBy mapBoxLayer "type" StyleParam.MapBoxLayerType.convert
85+
Coordinates |> DynObj.setValueOpt mapBoxLayer "coordinates"
86+
Below |> DynObj.setValueOpt mapBoxLayer "below"
87+
Color |> DynObj.setValueOpt mapBoxLayer "color"
88+
Opacity |> DynObj.setValueOpt mapBoxLayer "opacity"
89+
MinZoom |> DynObj.setValueOpt mapBoxLayer "minzoom"
90+
MaxZoom |> DynObj.setValueOpt mapBoxLayer "maxzoom"
91+
92+
CircleRadius
93+
|> Option.map(fun r ->
94+
let circle = DynamicObj()
95+
circle?radius <- r
96+
circle
97+
)
98+
|> DynObj.setValueOpt mapBoxLayer "circle"
99+
100+
Line |> DynObj.setValueOpt mapBoxLayer "line"
101+
102+
FillOutlineColor
103+
|> Option.map(fun c ->
104+
let fill = DynamicObj()
105+
fill?outlinecolor <- c
106+
fill
107+
)
108+
|> DynObj.setValueOpt mapBoxLayer "fill"
109+
110+
Symbol |> DynObj.setValueOpt mapBoxLayer "symbol"
111+
Name |> DynObj.setValueOpt mapBoxLayer "name"
112+
113+
mapBoxLayer
114+
)

Diff for: src/Plotly.NET/MapBoxLayerSymbol.fs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace Plotly.NET
2+
3+
open System
4+
5+
/// <summary></summary>
6+
type MapBoxLayerSymbol() =
7+
8+
inherit DynamicObj ()
9+
10+
/// <summary>Initialize a MapBoxLayer object</summary>
11+
12+
static member init
13+
(
14+
?Icon: string,
15+
?IconSize:float,
16+
?Text: string,
17+
?Placement: StyleParam.MapBoxLayerSymbolPlacement,
18+
?TextFont: Font,
19+
?TextPosition: StyleParam.TextPosition
20+
) =
21+
MapBoxLayerSymbol()
22+
|> MapBoxLayerSymbol.style
23+
(
24+
?Icon = Icon ,
25+
?IconSize = IconSize ,
26+
?Text = Text ,
27+
?Placement = Placement ,
28+
?TextFont = TextFont ,
29+
?TextPosition = TextPosition
30+
)
31+
32+
/// <summary>Create a function that applies the given style parameters to a MapBoxLayer object.</summary>
33+
34+
static member style
35+
(
36+
?Icon: string,
37+
?IconSize:float,
38+
?Text: string,
39+
?Placement: StyleParam.MapBoxLayerSymbolPlacement,
40+
?TextFont: Font,
41+
?TextPosition: StyleParam.TextPosition
42+
43+
) =
44+
(fun (mapBoxLayerSymbol:MapBoxLayerSymbol) ->
45+
46+
Icon |> DynObj.setValueOpt mapBoxLayerSymbol "icon"
47+
IconSize |> DynObj.setValueOpt mapBoxLayerSymbol "iconsize"
48+
Text |> DynObj.setValueOpt mapBoxLayerSymbol "text"
49+
Placement |> DynObj.setValueOptBy mapBoxLayerSymbol "placement" StyleParam.MapBoxLayerSymbolPlacement.convert
50+
TextFont |> DynObj.setValueOpt mapBoxLayerSymbol "textfont"
51+
TextPosition|> DynObj.setValueOptBy mapBoxLayerSymbol "textposition" StyleParam.TextPosition.convert
52+
53+
54+
mapBoxLayerSymbol
55+
)

Diff for: src/Plotly.NET/Plotly.NET.fsproj

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
<Compile Include="Table.fs" />
6767
<Compile Include="GeoProjection.fs" />
6868
<Compile Include="Geo.fs" />
69+
<Compile Include="MapBoxLayerSymbol.fs" />
70+
<Compile Include="MapBoxLayer.fs" />
71+
<Compile Include="MapBox.fs" />
6972
<Compile Include="Trace.fs" />
7073
<Compile Include="Trace3d.fs" />
7174
<Compile Include="LayoutGrid.fs" />

0 commit comments

Comments
 (0)