Skip to content

Commit

Permalink
Rename settings to options
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Sep 2, 2024
1 parent ba4373b commit 4579225
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 40 deletions.
4 changes: 2 additions & 2 deletions _experimental/maplibre_express_circle.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from maplibre import express as mx
from maplibre.__future__ import datasets
from maplibre.config import settings
from maplibre.config import options

settings.fallback_color = "steelblue"
options.fallback_color = "steelblue"

data = datasets.DataSets.earthquakes.url
# data = "/home/stefan/tmp/vancouver-blocks.json"
Expand Down
4 changes: 2 additions & 2 deletions _experimental/maplibre_express_fill.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from maplibre import express as mx
from maplibre.__future__ import datasets
from maplibre.config import settings
from maplibre.config import options

settings.fallback_color = "steelblue"
options.fallback_color = "steelblue"

data = datasets.DataSets.vancouver_blocks.url
# data = "/home/stefan/tmp/vancouver-blocks.json"
Expand Down
2 changes: 1 addition & 1 deletion examples/maplibre_express_circle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from maplibre import express as mx
from maplibre.config import settings
from maplibre.config import options
from maplibre.expressions import interpolate

data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"
Expand Down
10 changes: 5 additions & 5 deletions examples/maplibre_express_fill.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from maplibre import express as mx
from maplibre.config import settings
from maplibre.config import options
from maplibre.expressions import interpolate

settings.fallback_color = "#ffffff"
settings.fill_outline_color = "yellow"
settings.fill_opacity = 1
settings.cmap = "YlOrRd"
options.fallback_color = "#ffffff"
options.fill_outline_color = "yellow"
options.fill_opacity = 1
options.cmap = "YlOrRd"

# data = "https://docs.maptiler.com/sdk-js/assets/Mean_age_of_women_at_first_marriage_in_2019.geojson"
# data = "https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_urban_areas.geojson"
Expand Down
10 changes: 5 additions & 5 deletions examples/maplibre_express_fill_extrusion.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from maplibre import express as mx
from maplibre.config import settings
from maplibre.config import options
from maplibre.expressions import get_column, interpolate

settings.fallback_color = "#ffffff"
settings.fill_extrusion_color = "yellow"
settings.fill_extrusion_opacity = 0.5
settings.cmap = "YlOrRd"
options.fallback_color = "#ffffff"
options.fill_extrusion_color = "yellow"
options.fill_extrusion_opacity = 0.5
options.cmap = "YlOrRd"

# data = "https://docs.maptiler.com/sdk-js/assets/Mean_age_of_women_at_first_marriage_in_2019.geojson"
data = "https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_urban_areas.geojson"
Expand Down
6 changes: 3 additions & 3 deletions examples/maplibre_express_line.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from maplibre import express as mx
from maplibre.config import settings
from maplibre.config import options
from maplibre.expressions import interpolate

settings.line_width = 2
settings.line_color = "green"
options.line_width = 2
options.line_color = "green"

# data = "https://docs.maptiler.com/sdk-js/assets/Mean_age_of_women_at_first_marriage_in_2019.geojson"
# data = "https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_urban_areas.geojson"
Expand Down
4 changes: 2 additions & 2 deletions maplibre/basemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from enum import Enum

from .config import settings
from .config import options
from .layer import Layer, LayerType

MAPLIBRE_DEMO_TILES = "https://demotiles.maplibre.org/style.json"
Expand Down Expand Up @@ -82,7 +82,7 @@ class MapTiler(Enum):


def construct_maptiler_basemap_url(style_name: str | MapTiler = "aquarelle") -> str:
maptiler_api_key = settings.maptiler_api_key
maptiler_api_key = options.maptiler_api_key
if isinstance(style_name, MapTiler):
style_name = MapTiler(style_name).value

Expand Down
4 changes: 2 additions & 2 deletions maplibre/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import BaseModel


class Settings(BaseModel):
class Options(BaseModel):
cmap: Optional[str] = "viridis"
fallback_color: Optional[str] = "#000000"

Expand Down Expand Up @@ -63,4 +63,4 @@ def set_maptiler_api_key(self, api_key: str) -> None:
os.environ[self.maptiler_api_key_env_var] = api_key


settings = Settings()
options = Options()
33 changes: 19 additions & 14 deletions maplibre/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
from typing_extensions import Self

from maplibre.colors import color_brewer
from maplibre.config import settings
from maplibre.config import options
from maplibre.controls import NavigationControl
from maplibre.expressions import (GeometryType, color_match_expr,
color_quantile_step_expr, color_step_expr,
geometry_type_filter, interpolate)
from maplibre.expressions import (
GeometryType,
color_match_expr,
color_quantile_step_expr,
color_step_expr,
geometry_type_filter,
interpolate,
)
from maplibre.layer import Layer, LayerType
from maplibre.map import Map, MapOptions
from maplibre.sources import GeoJSONSource, SimpleFeatures
Expand Down Expand Up @@ -45,7 +50,7 @@ def model_post_init(self, __context) -> None:

if self.paint is None:
layer_type = LayerType(self.type).value
self.paint = {f"{layer_type}-color": settings.fallback_color}
self.paint = {f"{layer_type}-color": options.fallback_color}

def _set_paint_property(self, prop, value):
layer_type = LayerType(self.type).value
Expand All @@ -59,7 +64,7 @@ def opacity(self, value: float) -> Self:
self._set_paint_property("opacity", value)
return self

def color_category(self, column: str, cmap: str = settings.cmap) -> Self:
def color_category(self, column: str, cmap: str = options.cmap) -> Self:
expr = color_match_expr(column, categories=self.sf.data[column], cmap=cmap)
self._set_paint_property("color", expr)
return self
Expand All @@ -68,7 +73,7 @@ def color_quantile(
self,
column: str,
probs: list = [0.1, 0.25, 0.5, 0.75],
cmap: str = settings.cmap,
cmap: str = options.cmap,
) -> Self:
expr = color_quantile_step_expr(
column, probs, values=self.sf.data[column], cmap=cmap
Expand All @@ -77,7 +82,7 @@ def color_quantile(
return self

def color_bin(
self, column: str, stops: list = None, n: int = None, cmap=settings.cmap
self, column: str, stops: list = None, n: int = None, cmap=options.cmap
) -> Self:
if stops is None and n is None:
pass
Expand Down Expand Up @@ -119,7 +124,7 @@ def _create_prop_key(layer_type: str, prop: str) -> str:

def fill(data: gpd.GeoDataFrame | str, **kwargs) -> SimpleLayer:
if "paint" not in kwargs:
kwargs["paint"] = settings.paint_props[LayerType.FILL.value]
kwargs["paint"] = options.paint_props[LayerType.FILL.value]

return SimpleLayer(
type=LayerType.FILL,
Expand All @@ -130,7 +135,7 @@ def fill(data: gpd.GeoDataFrame | str, **kwargs) -> SimpleLayer:

def circle(data: gpd.GeoDataFrame | str, **kwargs) -> SimpleLayer:
if "paint" not in kwargs:
kwargs["paint"] = settings.paint_props[LayerType.CIRCLE.value]
kwargs["paint"] = options.paint_props[LayerType.CIRCLE.value]

return SimpleLayer(
type=LayerType.CIRCLE,
Expand All @@ -141,7 +146,7 @@ def circle(data: gpd.GeoDataFrame | str, **kwargs) -> SimpleLayer:

def line(data: gpd.GeoDataFrame | str, **kwargs) -> SimpleLayer:
if "paint" not in kwargs:
kwargs["paint"] = settings.paint_props[LayerType.LINE.value]
kwargs["paint"] = options.paint_props[LayerType.LINE.value]

return SimpleLayer(
type=LayerType.LINE,
Expand All @@ -157,7 +162,7 @@ def fill_extrusion(
**kwargs,
) -> SimpleLayer:
if "paint" not in kwargs:
kwargs["paint"] = settings.paint_props[
kwargs["paint"] = options.paint_props[
LayerType.FILL_EXTRUSION.value.replace("-", "_")
]

Expand All @@ -175,7 +180,7 @@ def fill_line_circle(source_id: str, colors: list = None) -> list:
if colors is not None:
assert len(colors) == 3
else:
colors = color_brewer(settings.cmap, 3)
colors = color_brewer(options.cmap, 3)

fill_color, line_color, circle_color = colors

Expand All @@ -184,7 +189,7 @@ def fill_line_circle(source_id: str, colors: list = None) -> list:
source=source_id,
filter=geometry_type_filter(GeometryType.POLYGON),
).set_paint_props(
fill_color=fill_color, fill_outline_color=settings.fill_outline_color
fill_color=fill_color, fill_outline_color=options.fill_outline_color
)

line_layer = Layer(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_express.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import maplibre.express as mx
from maplibre.config import settings
from maplibre.config import options
from maplibre.layer import Layer
from maplibre.sources import SimpleFeatures

Expand All @@ -21,7 +21,7 @@ def test_circle():

def test_fill():
# Prepare
settings.fill_outline_color = None
options.fill_outline_color = None
data_url = "https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_admin_1_states_provinces.geojson"

# Act
Expand Down
4 changes: 2 additions & 2 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os

from maplibre.config import settings
from maplibre.config import options


def test_maptiler_api_key():
# Prepare
os.environ["MAPTILER_API_KEY"] = "test"

# Act
maptiler_api_key = settings.maptiler_api_key
maptiler_api_key = options.maptiler_api_key

# Assert
assert maptiler_api_key == "test"

0 comments on commit 4579225

Please sign in to comment.