Skip to content

Commit

Permalink
plotlyjs v2.16: Add bounds to mapbox subplots (plotly/plotly.js#6339)
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Feb 10, 2023
1 parent f3c053b commit 046e3c4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Plotly.NET/Layout/ObjectAbstractions/Map/Mapbox.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Mapbox() =
/// <param name="Domain">Sets the domain of the Mapbox subplot</param>
/// <param name="AccessToken">Sets the mapbox access token to be used for this mapbox map. Alternatively, the mapbox access token can be set in the configuration options under `mapboxAccessToken`. Note that accessToken are only required when `style` (e.g with values : basic, streets, outdoors, light, dark, satellite, satellite-streets ) and/or a layout layer references the Mapbox server.</param>
/// <param name="Style">Defines the map layers that are rendered by default below the trace layers defined in `data`, which are themselves by default rendered below the layers defined in `layout.mapbox.layers`. These layers can be defined either explicitly as a Mapbox Style object which can contain multiple layer definitions that load data from any public or private Tile Map Service (TMS or XYZ) or Web Map Service (WMS) or implicitly by using one of the built-in style objects which use WMSes which do not require any access tokens, or by using a default Mapbox style or custom Mapbox style URL, both of which require a Mapbox access token Note that Mapbox access token can be set in the `accesstoken` attribute or in the `mapboxAccessToken` config option. Mapbox Style objects are of the form described in the Mapbox GL JS documentation available at https://docs.mapbox.com/mapbox-gl-js/style-spec The built-in plotly.js styles objects are: carto-darkmatter, carto-positron, open-street-map, stamen-terrain, stamen-toner, stamen-watercolor, white-bg The built-in Mapbox styles are: basic, streets, outdoors, light, dark, satellite, satellite-streets Mapbox style URLs are of the form: mapbox://mapbox.mapbox/name/version</param>
/// <param name="Bounds">Sets the bounds of the map</param>
/// <param name="Center">Sets the (lon,lat) coordinates of the center of the map view</param>
/// <param name="Zoom">Sets the zoom level of the map (mapbox.zoom).</param>
/// <param name="Bearing">Sets the bearing angle of the map in degrees counter-clockwise from North (mapbox.bearing).</param>
Expand All @@ -26,6 +27,7 @@ type Mapbox() =
[<Optional; DefaultParameterValue(null)>] ?Domain: Domain,
[<Optional; DefaultParameterValue(null)>] ?AccessToken: string,
[<Optional; DefaultParameterValue(null)>] ?Style: StyleParam.MapboxStyle,
[<Optional; DefaultParameterValue(null)>] ?Bounds: MapboxBounds,
[<Optional; DefaultParameterValue(null)>] ?Center: (float * float),
[<Optional; DefaultParameterValue(null)>] ?Zoom: float,
[<Optional; DefaultParameterValue(null)>] ?Bearing: float,
Expand All @@ -37,6 +39,7 @@ type Mapbox() =
?Domain = Domain,
?AccessToken = AccessToken,
?Style = Style,
?Bounds = Bounds,
?Center = Center,
?Zoom = Zoom,
?Bearing = Bearing,
Expand All @@ -48,6 +51,7 @@ type Mapbox() =
/// <param name="Domain">Sets the domain of the Mapbox subplot</param>
/// <param name="AccessToken">Sets the mapbox access token to be used for this mapbox map. Alternatively, the mapbox access token can be set in the configuration options under `mapboxAccessToken`. Note that accessToken are only required when `style` (e.g with values : basic, streets, outdoors, light, dark, satellite, satellite-streets ) and/or a layout layer references the Mapbox server.</param>
/// <param name="Style">Defines the map layers that are rendered by default below the trace layers defined in `data`, which are themselves by default rendered below the layers defined in `layout.mapbox.layers`. These layers can be defined either explicitly as a Mapbox Style object which can contain multiple layer definitions that load data from any public or private Tile Map Service (TMS or XYZ) or Web Map Service (WMS) or implicitly by using one of the built-in style objects which use WMSes which do not require any access tokens, or by using a default Mapbox style or custom Mapbox style URL, both of which require a Mapbox access token Note that Mapbox access token can be set in the `accesstoken` attribute or in the `mapboxAccessToken` config option. Mapbox Style objects are of the form described in the Mapbox GL JS documentation available at https://docs.mapbox.com/mapbox-gl-js/style-spec The built-in plotly.js styles objects are: carto-darkmatter, carto-positron, open-street-map, stamen-terrain, stamen-toner, stamen-watercolor, white-bg The built-in Mapbox styles are: basic, streets, outdoors, light, dark, satellite, satellite-streets Mapbox style URLs are of the form: mapbox://mapbox.mapbox/name/version</param>
/// <param name="Bounds">Sets the bounds of the map</param>
/// <param name="Center">Sets the (lon,lat) coordinates of the center of the map view</param>
/// <param name="Zoom">Sets the zoom level of the map (mapbox.zoom).</param>
/// <param name="Bearing">Sets the bearing angle of the map in degrees counter-clockwise from North (mapbox.bearing).</param>
Expand All @@ -58,6 +62,7 @@ type Mapbox() =
[<Optional; DefaultParameterValue(null)>] ?Domain: Domain,
[<Optional; DefaultParameterValue(null)>] ?AccessToken: string,
[<Optional; DefaultParameterValue(null)>] ?Style: StyleParam.MapboxStyle,
[<Optional; DefaultParameterValue(null)>] ?Bounds: MapboxBounds,
[<Optional; DefaultParameterValue(null)>] ?Center: (float * float),
[<Optional; DefaultParameterValue(null)>] ?Zoom: float,
[<Optional; DefaultParameterValue(null)>] ?Bearing: float,
Expand All @@ -69,7 +74,7 @@ type Mapbox() =
Domain |> DynObj.setValueOpt mapBox "domain"
AccessToken |> DynObj.setValueOpt mapBox "accesstoken"
Style |> DynObj.setValueOptBy mapBox "style" StyleParam.MapboxStyle.convert

Bounds |> DynObj.setValueOpt mapBox "bounds"
Center
|> Option.map (fun (lon, lat) ->
let t = DynamicObj()
Expand Down
56 changes: 56 additions & 0 deletions src/Plotly.NET/Layout/ObjectAbstractions/Map/MapboxBounds.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Plotly.NET.LayoutObjects

open Plotly.NET
open DynamicObj
open System
open System.Runtime.InteropServices

/// <summary></summary>
type MapboxBounds() =

inherit DynamicObj()

/// <summary>
/// Returns a new MapboxBounds object with the given styles
/// </summary>
/// <param name="East">Sets the maximum longitude of the map (in degrees East) if `west`, `south` and `north` are declared.</param>
/// <param name="North">Sets the maximum latitude of the map (in degrees North) if `east`, `west` and `south` are declared.</param>
/// <param name="South">Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared.</param>
/// <param name="West">Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared.</param>
static member init
(
[<Optional; DefaultParameterValue(null)>] ?East: float,
[<Optional; DefaultParameterValue(null)>] ?North: float,
[<Optional; DefaultParameterValue(null)>] ?South: float,
[<Optional; DefaultParameterValue(null)>] ?West: float
) =
MapboxBounds()
|> MapboxBounds.style (
?East = East,
?North = North,
?South = South,
?West = West
)

/// <summary>
/// Returns a function that applies the given styles to a MapoxBounds object.
/// </summary>
/// <param name="East">Sets the maximum longitude of the map (in degrees East) if `west`, `south` and `north` are declared.</param>
/// <param name="North">Sets the maximum latitude of the map (in degrees North) if `east`, `west` and `south` are declared.</param>
/// <param name="South">Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared.</param>
/// <param name="West">Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared.</param>
static member style
(
[<Optional; DefaultParameterValue(null)>] ?East: float,
[<Optional; DefaultParameterValue(null)>] ?North: float,
[<Optional; DefaultParameterValue(null)>] ?South: float,
[<Optional; DefaultParameterValue(null)>] ?West: float
) =
(fun (mapboxBounds: MapboxBounds) ->

East |> DynObj.setValueOpt mapboxBounds "east"
North |> DynObj.setValueOpt mapboxBounds "north"
South |> DynObj.setValueOpt mapboxBounds "south"
West |> DynObj.setValueOpt mapboxBounds "west"

mapboxBounds)
1 change: 1 addition & 0 deletions src/Plotly.NET/Plotly.NET.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="Layout\ObjectAbstractions\Map\MapboxLayerSymbol.fs" />
<Compile Include="Layout\ObjectAbstractions\Map\MapboxLayer.fs" />
<Compile Include="Layout\ObjectAbstractions\Map\MapboxCluster.fs" />
<Compile Include="Layout\ObjectAbstractions\Map\MapboxBounds.fs" />
<Compile Include="Layout\ObjectAbstractions\Map\Mapbox.fs" />
<Compile Include="Layout\ObjectAbstractions\Ternary\Ternary.fs" />
<Compile Include="Layout\ObjectAbstractions\3D\Camera.fs" />
Expand Down

0 comments on commit 046e3c4

Please sign in to comment.