From 6eb951bedcc04ef52e39c4ed144799c80a8050f7 Mon Sep 17 00:00:00 2001 From: Xianxiang Li Date: Wed, 19 May 2021 14:14:33 +0800 Subject: [PATCH] update styler to only modify LineString --- lib/cartopy/mpl/geoaxes.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/cartopy/mpl/geoaxes.py b/lib/cartopy/mpl/geoaxes.py index b10bc0019..187bdb412 100644 --- a/lib/cartopy/mpl/geoaxes.py +++ b/lib/cartopy/mpl/geoaxes.py @@ -753,20 +753,25 @@ def add_geometries(self, geoms, crs, **kwargs): """ styler = kwargs.pop('styler', None) - has_LineString = False - try: - for g in iter(tuple(geoms)): - if isinstance(g, sgeom.LineString): - has_LineString = True - break - except TypeError: - if isinstance(geoms, sgeom.LineString): - has_LineString = True - - if has_LineString: - kwargs['facecolor'] = 'none' - if 'edgecolor' not in kwargs or kwargs['edgecolor'] == 'face': - kwargs['edgecolor'] = mpl.rcParams['patch.edgecolor'] + + if (not callable(styler)) and ('facecolor' not in kwargs): + styler_kw = styler + + def styler(geom): + styler_g = styler_kw if styler_kw else dict() + styler_g = styler_g.copy() + + if isinstance(geom, sgeom.LineString): + styler_g['facecolor'] = 'none' + if ('edgecolor' not in kwargs) or ( + kwargs['edgecolor'] == 'face'): + styler_g['edgecolor'] = mpl.rcParams['patch.edgecolor'] + else: + styler_g['edgecolor'] = kwargs['edgecolor'] + return styler_g + else: + return styler_kw + feature = cartopy.feature.ShapelyFeature(geoms, crs, **kwargs) return self.add_feature(feature, styler=styler)