Skip to content

Commit

Permalink
add geojson feature type support
Browse files Browse the repository at this point in the history
  • Loading branch information
doneill committed Aug 9, 2020
1 parent d64cae0 commit 6331c40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Preview map layer files in your web browser using [Sublime Text 3](https://www.s
## Supported Formats

- [GeoJSON](https://geojson.org/)

Currently support the following types:
- [Features](https://tools.ietf.org/html/rfc7946#section-3.2)
- [FeatureCollections](https://tools.ietf.org/html/rfc7946#section-3.3)

- [TopoJSON](https://github.com/topojson/topojson/wiki)

## Installation
Expand Down
17 changes: 11 additions & 6 deletions map_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,23 @@ def run(self, edit):
# check if json valid spatial type
if "type" in validateJson:
# check if valid GeoJSON
if validateJson["type"] == "FeatureCollection":
if validateJson["type"] == "FeatureCollection" or validateJson["type"] == "Feature":
type = "geojson"
html = wm.render(viewText, type)
else:
elif validateJson["type"] == "Topology":
type = "topojson"
html = wm.render(viewText, type)

# update output HTML file
tmp_fullpath = get_temp_preview_path(view)
save_utf8(tmp_fullpath, html)
try:
html
except NameError:
sublime.error_message("Could not convert file.\n\n Not valid GeoJSON or TopoJSON")
else:
# update output HTML file
tmp_fullpath = get_temp_preview_path(view)
save_utf8(tmp_fullpath, html)

webbrowser.open_new_tab("file:///" + tmp_fullpath)
webbrowser.open_new_tab("file:///" + tmp_fullpath)

else:
sublime.error_message("Could not convert file.\n\n Not valid spatial type")
Expand Down

0 comments on commit 6331c40

Please sign in to comment.