From 046e3c472447c720ec7896f2109895028dba471c Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Fri, 10 Feb 2023 07:33:28 +0100 Subject: [PATCH] plotlyjs v2.16: Add bounds to mapbox subplots (https://github.com/plotly/plotly.js/pull/6339) --- .../Layout/ObjectAbstractions/Map/Mapbox.fs | 7 ++- .../ObjectAbstractions/Map/MapboxBounds.fs | 56 +++++++++++++++++++ src/Plotly.NET/Plotly.NET.fsproj | 1 + 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/Plotly.NET/Layout/ObjectAbstractions/Map/MapboxBounds.fs diff --git a/src/Plotly.NET/Layout/ObjectAbstractions/Map/Mapbox.fs b/src/Plotly.NET/Layout/ObjectAbstractions/Map/Mapbox.fs index 594f4378a..70f7e9e19 100644 --- a/src/Plotly.NET/Layout/ObjectAbstractions/Map/Mapbox.fs +++ b/src/Plotly.NET/Layout/ObjectAbstractions/Map/Mapbox.fs @@ -16,6 +16,7 @@ type Mapbox() = /// Sets the domain of the Mapbox subplot /// 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. /// 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 + /// Sets the bounds of the map /// Sets the (lon,lat) coordinates of the center of the map view /// Sets the zoom level of the map (mapbox.zoom). /// Sets the bearing angle of the map in degrees counter-clockwise from North (mapbox.bearing). @@ -26,6 +27,7 @@ type Mapbox() = [] ?Domain: Domain, [] ?AccessToken: string, [] ?Style: StyleParam.MapboxStyle, + [] ?Bounds: MapboxBounds, [] ?Center: (float * float), [] ?Zoom: float, [] ?Bearing: float, @@ -37,6 +39,7 @@ type Mapbox() = ?Domain = Domain, ?AccessToken = AccessToken, ?Style = Style, + ?Bounds = Bounds, ?Center = Center, ?Zoom = Zoom, ?Bearing = Bearing, @@ -48,6 +51,7 @@ type Mapbox() = /// Sets the domain of the Mapbox subplot /// 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. /// 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 + /// Sets the bounds of the map /// Sets the (lon,lat) coordinates of the center of the map view /// Sets the zoom level of the map (mapbox.zoom). /// Sets the bearing angle of the map in degrees counter-clockwise from North (mapbox.bearing). @@ -58,6 +62,7 @@ type Mapbox() = [] ?Domain: Domain, [] ?AccessToken: string, [] ?Style: StyleParam.MapboxStyle, + [] ?Bounds: MapboxBounds, [] ?Center: (float * float), [] ?Zoom: float, [] ?Bearing: float, @@ -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() diff --git a/src/Plotly.NET/Layout/ObjectAbstractions/Map/MapboxBounds.fs b/src/Plotly.NET/Layout/ObjectAbstractions/Map/MapboxBounds.fs new file mode 100644 index 000000000..6d6c62b09 --- /dev/null +++ b/src/Plotly.NET/Layout/ObjectAbstractions/Map/MapboxBounds.fs @@ -0,0 +1,56 @@ +namespace Plotly.NET.LayoutObjects + +open Plotly.NET +open DynamicObj +open System +open System.Runtime.InteropServices + +/// +type MapboxBounds() = + + inherit DynamicObj() + + /// + /// Returns a new MapboxBounds object with the given styles + /// + /// Sets the maximum longitude of the map (in degrees East) if `west`, `south` and `north` are declared. + /// Sets the maximum latitude of the map (in degrees North) if `east`, `west` and `south` are declared. + /// Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared. + /// Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared. + static member init + ( + [] ?East: float, + [] ?North: float, + [] ?South: float, + [] ?West: float + ) = + MapboxBounds() + |> MapboxBounds.style ( + ?East = East, + ?North = North, + ?South = South, + ?West = West + ) + + /// + /// Returns a function that applies the given styles to a MapoxBounds object. + /// + /// Sets the maximum longitude of the map (in degrees East) if `west`, `south` and `north` are declared. + /// Sets the maximum latitude of the map (in degrees North) if `east`, `west` and `south` are declared. + /// Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared. + /// Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared. + static member style + ( + [] ?East: float, + [] ?North: float, + [] ?South: float, + [] ?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) diff --git a/src/Plotly.NET/Plotly.NET.fsproj b/src/Plotly.NET/Plotly.NET.fsproj index 552905fb0..9005e12b7 100644 --- a/src/Plotly.NET/Plotly.NET.fsproj +++ b/src/Plotly.NET/Plotly.NET.fsproj @@ -80,6 +80,7 @@ +