Show More
@@ -680,8 +680,45 b' lib_t1 = """$.getScript("%s", function () {' | |||||
680 | lib_t2 = """}); |
|
680 | lib_t2 = """}); | |
681 | """ |
|
681 | """ | |
682 |
|
682 | |||
683 |
class GeoJSON( |
|
683 | class GeoJSON(DisplayObject): | |
|
684 | """GeoJSON expects JSON-able dict | |||
684 |
|
|
685 | ||
|
686 | not an already-serialized JSON string. | |||
|
687 | ||||
|
688 | Scalar types (None, number, string) are not allowed, only dict containers. | |||
|
689 | """ | |||
|
690 | # wrap data in a property, which warns about passing already-serialized JSON | |||
|
691 | _data = None | |||
|
692 | ||||
|
693 | def __init__(self, data=None, url_template=None, layer_options=None, url=None, filename=None, metadata=None): | |||
|
694 | """Create a GeoJSON display object given raw data. | |||
|
695 | ||||
|
696 | Parameters | |||
|
697 | ---------- | |||
|
698 | data : dict or list | |||
|
699 | VegaLite data. Not an already-serialized JSON string. | |||
|
700 | Scalar types (None, number, string) are not allowed, only dict | |||
|
701 | or list containers. | |||
|
702 | url_template : string | |||
|
703 | Leaflet TileLayer URL template: http://leafletjs.com/reference.html#url-template | |||
|
704 | layer_options : dict | |||
|
705 | Leaflet TileLayer options: http://leafletjs.com/reference.html#tilelayer-options | |||
|
706 | url : unicode | |||
|
707 | A URL to download the data from. | |||
|
708 | filename : unicode | |||
|
709 | Path to a local file to load the data from. | |||
|
710 | metadata: dict | |||
|
711 | Specify extra metadata to attach to the json display object. | |||
|
712 | """ | |||
|
713 | self.url_template = url_template | |||
|
714 | self.layer_options = layer_options | |||
|
715 | self.metadata = metadata | |||
|
716 | super(GeoJSON, self).__init__(data=data, url=url, filename=filename) | |||
|
717 | ||||
|
718 | def _check_data(self): | |||
|
719 | if self.data is not None and not isinstance(self.data, dict): | |||
|
720 | raise TypeError("%s expects a JSONable dict, not %r" % (self.__class__.__name__, self.data)) | |||
|
721 | ||||
685 | @property |
|
722 | @property | |
686 | def data(self): |
|
723 | def data(self): | |
687 | return self._data |
|
724 | return self._data | |
@@ -693,11 +730,21 b' class GeoJSON(JSON):' | |||||
693 | self._data = data |
|
730 | self._data = data | |
694 |
|
731 | |||
695 | def _ipython_display_(self): |
|
732 | def _ipython_display_(self): | |
|
733 | md = {} | |||
|
734 | if self.url_template: | |||
|
735 | md['tileUrlTemplate'] = self.url_template | |||
|
736 | if self.layer_options: | |||
|
737 | md['tileLayerOptions'] = self.layer_options | |||
|
738 | if self.metadata: | |||
|
739 | md.update(self.metadata) | |||
696 | bundle = { |
|
740 | bundle = { | |
697 | 'application/geo+json': self.data, |
|
741 | 'application/geo+json': self.data, | |
698 | 'text/plain': '<jupyterlab_geojson.GeoJSON object>' |
|
742 | 'text/plain': '<jupyterlab_geojson.GeoJSON object>' | |
699 | } |
|
743 | } | |
700 | display(bundle, raw=True) |
|
744 | metadata = { | |
|
745 | 'application/geo+json': md | |||
|
746 | } | |||
|
747 | display(bundle, metadata=metadata, raw=True) | |||
701 |
|
748 | |||
702 | class Javascript(TextDisplayObject): |
|
749 | class Javascript(TextDisplayObject): | |
703 |
|
750 |
General Comments 0
You need to be logged in to leave comments.
Login now