From fdd2922964ab51d7354e341ab9efb8b9554ec29c Mon Sep 17 00:00:00 2001 From: Sandeep Pandey Date: Fri, 26 Jun 2020 18:17:20 +0200 Subject: [PATCH 01/11] added option to save map dir, config file dir, fixed browserless operation --- keplergl_cli/keplergl_cli.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/keplergl_cli/keplergl_cli.py b/keplergl_cli/keplergl_cli.py index 0fb7464..38285d5 100644 --- a/keplergl_cli/keplergl_cli.py +++ b/keplergl_cli/keplergl_cli.py @@ -40,7 +40,9 @@ def __init__( names=None, read_only=False, api_key=None, - style=None): + style=None, + config_file=None, + output_map=None): """Visualize data using kepler.gl Args: @@ -48,6 +50,9 @@ def __init__( either None, a List of data objects, or a single data object. If data is not None, then Visualize(data) will perform all steps, including rendering and opening a browser. + `config_file` provides the path of config file. + 'output_map` provides the location html file, if none then will + be dumped to temporaty files. """ super(Visualize, self).__init__() @@ -59,7 +64,11 @@ def __init__( msg += 'environment variable not set.\nMap may not display.' if self.MAPBOX_API_KEY is None: print(msg) - + self.config_file = config_file + if output_map is not None: + self.path = os.path.join(output_map, 'vis.html') + else: + self.path = os.path.join(tempfile.mkdtemp(), 'vis.html') config = self.config(style=style) self.map = KeplerGl(config=config) @@ -70,12 +79,11 @@ def __init__( def config(self, style=None): """Load kepler.gl config and insert Mapbox API Key""" - config_file = resource_filename( - 'keplergl_cli', 'keplergl_config.json') + # config_file = resource_filename('keplergl_cli', 'keplergl_config.json') # First load config file as string, replace {MAPBOX_API_KEY} with the # actual api key, then parse as JSON - with open(config_file) as f: + with open(self.config_file) as f: text = f.read() text = text.replace('{MAPBOX_API_KEY}', self.MAPBOX_API_KEY) @@ -141,11 +149,9 @@ def add_data(self, data, names=None): def render(self, open_browser=True, read_only=False): """Export kepler.gl map to HTML file and open in Chrome """ - # Generate path to a temporary file - path = os.path.join(tempfile.mkdtemp(), 'vis.html') - self.map.save_to_html(file_name=path, read_only=read_only) - + self.map.save_to_html(file_name=self.path, read_only=read_only) # Open saved HTML file in new tab in default browser - webbrowser.open_new_tab('file://' + path) + if open_browser: + webbrowser.open_new_tab('file://' + self.path) - return path + return self.path From b53707347948bf275b0363887f6d68a8676ab97b Mon Sep 17 00:00:00 2001 From: Sandeep Pandey Date: Wed, 8 Jul 2020 21:39:14 +0200 Subject: [PATCH 02/11] Readme for edited class --- README.md | 6 ++++-- keplergl_cli/keplergl_cli.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1e078ff..edd9811 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ More detail over the objects in your map: ```py from keplergl_cli import Visualize -vis = Visualize(api_key=MAPBOX_API_KEY) +vis = Visualize(api_key=MAPBOX_API_KEY, output_map = PATH_TO_SAVE_HTML_MAP, config_file = PATH_TO_JSON_CONFIG_FILE) vis.add_data(data=data, names='name of layer') vis.add_data(data=data2, names='name of layer') html_path = vis.render(open_browser=True, read_only=False) @@ -124,7 +124,7 @@ html_path = vis.render(open_browser=True, read_only=False) **Visualize** ```py -Visualize(data=None, names=None, read_only=False, api_key=None, style=None) +Visualize(data=None, names=None, read_only=False, api_key=None, style=None, config_file=None, output_map=None) ``` - `data` (either `None`, a single data object, or a list of data objects): @@ -170,6 +170,8 @@ Visualize(data=None, names=None, read_only=False, api_key=None, style=None) starts with `mapbox://`. Otherwise, a custom style using third-party map tiles should be a URL to a JSON file that conforms to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/). +- `config_file` (`string`): Path to custom JSON configuration file for kepler. +- `output_map` (`string`): If path is provided then map is saved to this path. **Visualize.add_data()** diff --git a/keplergl_cli/keplergl_cli.py b/keplergl_cli/keplergl_cli.py index 38285d5..ff75e0d 100644 --- a/keplergl_cli/keplergl_cli.py +++ b/keplergl_cli/keplergl_cli.py @@ -154,4 +154,4 @@ def render(self, open_browser=True, read_only=False): if open_browser: webbrowser.open_new_tab('file://' + self.path) - return self.path + return self.path \ No newline at end of file From e55d8e4f5970c272bb97298becf3d3f38ae28cce Mon Sep 17 00:00:00 2001 From: Sandeep Pandey Date: Thu, 16 Jul 2020 20:27:07 +0200 Subject: [PATCH 03/11] Fixed output map name --- keplergl_cli/keplergl_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keplergl_cli/keplergl_cli.py b/keplergl_cli/keplergl_cli.py index ff75e0d..de8edaf 100644 --- a/keplergl_cli/keplergl_cli.py +++ b/keplergl_cli/keplergl_cli.py @@ -66,7 +66,7 @@ def __init__( print(msg) self.config_file = config_file if output_map is not None: - self.path = os.path.join(output_map, 'vis.html') + self.path = output_map+'vis.html' else: self.path = os.path.join(tempfile.mkdtemp(), 'vis.html') config = self.config(style=style) From cf87092b58a0e2f9efac58bd57524c916a3f2b50 Mon Sep 17 00:00:00 2001 From: Sandeep Pandey Date: Mon, 28 Sep 2020 20:56:17 +0200 Subject: [PATCH 04/11] Fixed a bug for default config file --- keplergl_cli/keplergl_cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/keplergl_cli/keplergl_cli.py b/keplergl_cli/keplergl_cli.py index de8edaf..2f46702 100644 --- a/keplergl_cli/keplergl_cli.py +++ b/keplergl_cli/keplergl_cli.py @@ -64,7 +64,10 @@ def __init__( msg += 'environment variable not set.\nMap may not display.' if self.MAPBOX_API_KEY is None: print(msg) - self.config_file = config_file + if config_file is None: + self.config_file = resource_filename('keplergl_cli', 'keplergl_config.json') + else: + self.config_file = config_file if output_map is not None: self.path = output_map+'vis.html' else: From 873f7fb02fabc6c7fc4bd7b30babc0610fa83c31 Mon Sep 17 00:00:00 2001 From: ikespand <43318142+ikespand@users.noreply.github.com> Date: Sat, 31 Oct 2020 21:06:57 +0100 Subject: [PATCH 05/11] Updated readme to install this specific version --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index edd9811..17bf118 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,14 @@ to get an API key. **Package install**: +To install official version: ``` pip install keplergl_cli ``` - +To install this version, which has functionality to save map at custom locations and using custom config file: +``` +pip install git+https://github.com/ikespand/keplergl_cli +``` This package has dependencies on `geojson`, `shapely`, and `geopandas`. If you get errors when installing this package through pip, it may be easier to first install dependencies through Conda, then install this package. I.e.: From 94fa57ab0a523281c9ab65825095f5bc528fcc83 Mon Sep 17 00:00:00 2001 From: ikespand Date: Thu, 12 Nov 2020 20:50:07 +0100 Subject: [PATCH 06/11] Updated version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9d08620..c77b83e 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/kylebarron/keplergl_cli', - version='0.3.1', + version='0.3.2', zip_safe=False, ) From 2430f27b9c72835eec2a30a351b5e952324367f6 Mon Sep 17 00:00:00 2001 From: ikespand <43318142+ikespand@users.noreply.github.com> Date: Fri, 13 Nov 2020 22:27:35 +0100 Subject: [PATCH 07/11] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 27fbfa4..c657b74 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -keplergl>=0.1.2 +keplergl==0.2.0 geojson>=2.5.0 shapely>=1.6.4 geopandas>=0.6.0 From ac6b6e107bdea181fe553fdb3bfc4972ed281968 Mon Sep 17 00:00:00 2001 From: ikespand Date: Tue, 22 Dec 2020 17:07:15 +0100 Subject: [PATCH 08/11] Renamed the map output file name --- keplergl_cli/keplergl_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keplergl_cli/keplergl_cli.py b/keplergl_cli/keplergl_cli.py index 2f46702..d459bbe 100644 --- a/keplergl_cli/keplergl_cli.py +++ b/keplergl_cli/keplergl_cli.py @@ -69,9 +69,9 @@ def __init__( else: self.config_file = config_file if output_map is not None: - self.path = output_map+'vis.html' + self.path = output_map+'_vis.html' else: - self.path = os.path.join(tempfile.mkdtemp(), 'vis.html') + self.path = os.path.join(tempfile.mkdtemp(), 'defaultmap_vis.html') config = self.config(style=style) self.map = KeplerGl(config=config) From 2bf44df6bcfb41f8b3fee909fc29e12e7b10550e Mon Sep 17 00:00:00 2001 From: ikespand Date: Wed, 23 Dec 2020 12:46:05 +0100 Subject: [PATCH 09/11] Fixed the issue for map auto-centering by deleting the mapState in default config JSON --- keplergl_cli/keplergl_config.json | 9 --------- setup.py | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/keplergl_cli/keplergl_config.json b/keplergl_cli/keplergl_config.json index 987328d..21bb6c0 100644 --- a/keplergl_cli/keplergl_config.json +++ b/keplergl_cli/keplergl_config.json @@ -23,15 +23,6 @@ "speed": 1 } }, - "mapState": { - "bearing": 0, - "dragRotate": false, - "latitude": 37.75043, - "longitude": -122.34679, - "pitch": 0, - "zoom": 9, - "isSplit": false - }, "mapStyle": { "styleType": "streets", "topLayerGroups": {}, diff --git a/setup.py b/setup.py index c77b83e..255597e 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/kylebarron/keplergl_cli', - version='0.3.2', + version='0.3.3', zip_safe=False, ) From 8b8f9f2c2dca13098157e336e7bea73364141ea6 Mon Sep 17 00:00:00 2001 From: ikespand Date: Thu, 1 Sep 2022 22:28:42 +0200 Subject: [PATCH 10/11] Minor changes in documentation, rollback to original default config JSON and provide open_browser in init --- AUTHORS.rst | 2 +- README.md | 9 ++------- keplergl_cli/keplergl_cli.py | 10 ++++++---- keplergl_cli/keplergl_config.json | 11 ++++++++++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index a5bab2f..b213c31 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -10,4 +10,4 @@ Development Lead Contributors ------------ -None yet. Why not be the first? +* Sandeep Pandey diff --git a/README.md b/README.md index 17bf118..dadc506 100644 --- a/README.md +++ b/README.md @@ -38,19 +38,14 @@ Visualize(data) ## Install **Mapbox API key**: in order to display Mapbox-hosted maps, you need to provide -a Mapbox API key. Go to [Mapbox.com](https://account.mapbox.com/access-tokens) -to get an API key. +a Mapbox API key. Go to [Mapbox.com](https://account.mapbox.com/access-tokens) to get an API key. **Package install**: -To install official version: ``` pip install keplergl_cli ``` -To install this version, which has functionality to save map at custom locations and using custom config file: -``` -pip install git+https://github.com/ikespand/keplergl_cli -``` + This package has dependencies on `geojson`, `shapely`, and `geopandas`. If you get errors when installing this package through pip, it may be easier to first install dependencies through Conda, then install this package. I.e.: diff --git a/keplergl_cli/keplergl_cli.py b/keplergl_cli/keplergl_cli.py index b1f9564..f6c759f 100644 --- a/keplergl_cli/keplergl_cli.py +++ b/keplergl_cli/keplergl_cli.py @@ -42,7 +42,8 @@ def __init__( api_key=None, style=None, config_file=None, - output_map=None): + output_map=None, + open_browser=False): """Visualize data using kepler.gl Args: @@ -51,8 +52,9 @@ def __init__( data is not None, then Visualize(data) will perform all steps, including rendering and opening a browser. `config_file` provides the path of config file. - 'output_map` provides the location html file, if none then will + `output_map` provides the location html file, if none then will be dumped to temporaty files. + `open_browser` enables the browser opening if data is provided. """ super(Visualize, self).__init__() @@ -77,7 +79,7 @@ def __init__( if data is not None: self.add_data(data=data, names=names) - self.html_path = self.render(read_only=read_only) + self.html_path = self.render(read_only=read_only,open_browser=open_browser) def config(self, style=None): """Load kepler.gl config and insert Mapbox API Key""" @@ -154,7 +156,7 @@ def add_data(self, data, names=None): self.map.add_data(data=datum, name=name) def render(self, open_browser=True, read_only=False, center_map=True): - """Export kepler.gl map to HTML file and open in Chrome + """Export kepler.gl map to HTML file and open in defauly system browser """ self.map.save_to_html(file_name=self.path, read_only=read_only, center_map=center_map) # Open saved HTML file in new tab in default browser diff --git a/keplergl_cli/keplergl_config.json b/keplergl_cli/keplergl_config.json index 21bb6c0..9d9697d 100644 --- a/keplergl_cli/keplergl_config.json +++ b/keplergl_cli/keplergl_config.json @@ -23,6 +23,15 @@ "speed": 1 } }, + "mapState": { + "bearing": 0, + "dragRotate": false, + "latitude": 37.75043, + "longitude": -122.34679, + "pitch": 0, + "zoom": 9, + "isSplit": false + }, "mapStyle": { "styleType": "streets", "topLayerGroups": {}, @@ -95,4 +104,4 @@ "app": "kepler.gl", "created_at": "Tue Oct 29 2019 17:15:02 GMT+0100 (Central European Standard Time)" } -} +} \ No newline at end of file From 404bd13b1a2cfb116476a0313fe216915a74cb80 Mon Sep 17 00:00:00 2001 From: ikespand Date: Thu, 1 Sep 2022 22:36:43 +0200 Subject: [PATCH 11/11] =?UTF-8?q?Bump=20version:=200.3.3=20=E2=86=92=200.3?= =?UTF-8?q?.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ba4d9..2fef950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.3.4 (2022-09-01) + +- Arguments to save maps at user-defined location and use a custom configuration file +- Respect `open_browser=False` even during the class instantiation with data + ## 0.3.3 (2022-06-27) - Revert usage of `__geo_interface__` diff --git a/setup.py b/setup.py index 255597e..fd839b0 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/kylebarron/keplergl_cli', - version='0.3.3', + version='0.3.4', zip_safe=False, )