From 37615ef691e494e557ecfe73519516d114a96290 2017-02-07 18:14:39 From: Grant Nestor Date: 2017-02-07 18:14:39 Subject: [PATCH] Add GeoJSON display class --- diff --git a/IPython/core/display.py b/IPython/core/display.py index dd34e71..d1c3130 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -24,7 +24,7 @@ from IPython.testing.skipdoctest import skip_doctest __all__ = ['display', 'display_pretty', 'display_html', 'display_markdown', 'display_svg', 'display_png', 'display_jpeg', 'display_latex', 'display_json', 'display_javascript', 'display_pdf', 'DisplayObject', 'TextDisplayObject', -'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'JSON', 'Javascript', +'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'JSON', 'GeoJSON', 'Javascript', 'Image', 'clear_output', 'set_matplotlib_formats', 'set_matplotlib_close', 'publish_display_data', 'update_display', 'DisplayHandle'] @@ -680,6 +680,25 @@ lib_t1 = """$.getScript("%s", function () { lib_t2 = """}); """ +class GeoJSON(JSON): + + @property + def data(self): + return self._data + + @data.setter + def data(self, data): + if isinstance(data, str): + data = json.loads(data) + self._data = data + + def _ipython_display_(self): + bundle = { + 'application/geo+json': self.data, + 'text/plain': '' + } + display(bundle, raw=True) + class Javascript(TextDisplayObject): def __init__(self, data=None, url=None, filename=None, lib=None, css=None):