From 8cfdb486fc06f467c61c59c869c7faa9a975f56f Mon Sep 17 00:00:00 2001 From: Erik Reed Date: Mon, 16 May 2022 12:25:45 -0700 Subject: [PATCH] Lazily instantiate geocoder --- cesiumpy/extension/geocode.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cesiumpy/extension/geocode.py b/cesiumpy/extension/geocode.py index f6b2bfa..60b7311 100644 --- a/cesiumpy/extension/geocode.py +++ b/cesiumpy/extension/geocode.py @@ -8,8 +8,15 @@ import cesiumpy.util.common as com -# ToDo: want different geocoders? -_GEOCODER = GoogleV3() +_GEOCODER = None + + +def _get_geocoder(): + global _GEOCODER + if _GEOCODER is None: + # ToDo: want different geocoders? + _GEOCODER = GoogleV3() + return _GEOCODER def _maybe_geocode(x, height=None): @@ -18,7 +25,7 @@ def _maybe_geocode(x, height=None): height can be used to create base data for Cartesian3 """ if isinstance(x, six.string_types): - loc = _GEOCODER.geocode(x) + loc = _get_geocoder().geocode(x) if loc is not None: if height is None: # return x, y order