Пример #1
0
    def create_html(self, filename=None):
        """Create a circle visual from a geojson data source"""
        if isinstance(self.style, str):
            style = "'{}'".format(self.style)
        else:
            style = self.style
        options = dict(
            gl_js_version=GL_JS_VERSION,
            accessToken=self.access_token,
            div_id=self.div_id,
            style=style,
            center=list(self.center),
            zoom=self.zoom,
            geojson_data=json.dumps(self.data, ensure_ascii=False),
            belowLayer=self.below_layer,
            opacity=self.opacity,
            minzoom=self.min_zoom,
            maxzoom=self.max_zoom,
            pitch=self.pitch,
            bearing=self.bearing,
            boxZoomOn=json.dumps(self.box_zoom_on),
            doubleClickZoomOn=json.dumps(self.double_click_zoom_on),
            scrollZoomOn=json.dumps(self.scroll_zoom_on),
            touchZoomOn=json.dumps(self.touch_zoom_on),
            showLegend=self.legend,
            legendLayout=self.legend_layout,
            legendStyle=self.legend_style,  # reserve name for custom CSS?
            legendGradient=json.dumps(self.legend_gradient),
            legendFill=self.legend_fill,
            legendHeaderFill=self.legend_header_fill,
            legendTextColor=self.legend_text_color,
            legendNumericPrecision=json.dumps(
                self.legend_text_numeric_precision),
            legendTitleHaloColor=self.legend_title_halo_color,
            legendKeyShape=self.legend_key_shape,
            legendKeyBordersOn=json.dumps(self.legend_key_borders_on))

        if self.label_property is None:
            options.update(labelProperty=None)
        else:
            options.update(labelProperty='{' + self.label_property + '}')

        self.add_unique_template_variables(options)

        if filename:
            html = templates.format(self.template, **options)
            with codecs.open(filename, "w", "utf-8-sig") as f:
                f.write(html)
            return None
        else:
            return templates.format(self.template, **options)
Пример #2
0
    def create_html(self):
        """Create a circle visual from a geojson data source"""
        if isinstance(self.style, str):
            style = "'{}'".format(self.style)
        else:
            style = self.style
        options = dict(gl_js_version=GL_JS_VERSION,
                       accessToken=self.access_token,
                       div_id=self.div_id,
                       style=style,
                       center=list(self.center),
                       zoom=self.zoom,
                       geojson_data=json.dumps(self.data, ensure_ascii=False),
                       belowLayer=self.below_layer,
                       opacity=self.opacity,
                       minzoom=self.min_zoom,
                       maxzoom=self.max_zoom)

        if self.label_property is None:
            options.update(labelProperty=None)
        else:
            options.update(labelProperty='{' + self.label_property + '}')

        self.add_unique_template_variables(options)

        return templates.format(self.template, **options)
Пример #3
0
    def create_html(self):
        """Create a circle visual from a geojson data source"""
        options = dict(gl_js_version=GL_JS_VERSION,
                       accessToken=self.access_token,
                       div_id=self.div_id,
                       styleUrl=self.style_url,
                       center=list(self.center),
                       zoom=self.zoom,
                       geojson_data=json.dumps(self.data, ensure_ascii=False),
                       colorStops=self.color_stops,
                       radiusStops=self.radius_stops,
                       weightProperty=self.weight_property,
                       weightStops=self.weight_stops)

        return templates.format('heatmap', **options)
Пример #4
0
    def create_html(self):
        """Create a circle visual from a geojson data source"""
        options = dict(gl_js_version=GL_JS_VERSION,
                       accessToken=self.access_token,
                       div_id=self.div_id,
                       styleUrl=self.style_url,
                       center=list(self.center),
                       zoom=self.zoom,
                       geojson_data=json.dumps(self.data, ensure_ascii=False),
                       colorProperty=self.color_property,
                       colorStops=self.color_stops)

        if self.label_property is None:
            options.update(labelProperty=None)
        else:
            options.update(labelProperty='{' + self.label_property + '}')

        return templates.format('circle', **options)
Пример #5
0
    def create_html(self):
        """Create a circle visual from a geojson data source"""
        options = dict(gl_js_version=GL_JS_VERSION,
                       accessToken=self.access_token,
                       div_id=self.div_id,
                       styleUrl=self.style_url,
                       center=list(self.center),
                       zoom=self.zoom,
                       geojson_data=json.dumps(self.data, ensure_ascii=False),
                       colorStops=self.color_stops,
                       baseColor=self.color_stops[0][1],
                       radiusStops=self.radius_stops,
                       clusterRadius=self.clusterRadius,
                       clusterMaxZoom=self.clusterMaxZoom,
                       opacity=self.opacity,
                       belowLayer=self.below_layer)

        return templates.format('clustered_circle', **options)
Пример #6
0
    def create_html(self):
        """Create a circle visual from a geojson data source"""
        options = dict(gl_js_version=GL_JS_VERSION,
                       accessToken=self.access_token,
                       div_id=self.div_id,
                       styleUrl=self.style_url,
                       center=list(self.center),
                       zoom=self.zoom,
                       geojson_data=self.data,
                       colorProperty=self.color_property,
                       colorStops=self.color_stops,
                       colorType=self.color_type,
                       radiusProperty=self.radius_property,
                       radiusStops=self.radius_stops,
                       opacity=self.opacity)

        if self.label_property is None:
            options.update(labelProperty=None)
        else:
            options.update(labelProperty='{' + self.label_property + '}')

        return templates.format('graduated_circle', **options)
Пример #7
0
    def create_html(self, filename=None):
        """Create a circle visual from a geojson data source"""

        if isinstance(self.style, str):
            style = "'{}'".format(self.style)
        else:
            style = self.style

        options = dict(
            gl_js_version=GL_JS_VERSION,
            accessToken=self.access_token,
            div_id=self.div_id,
            style=style,
            center=list(self.center),
            zoom=self.zoom,
            geojson_data=json.dumps(self.data, ensure_ascii=False),
            belowLayer=self.below_layer,
            opacity=self.opacity,
            minzoom=self.min_zoom,
            maxzoom=self.max_zoom,
            pitch=self.pitch,
            bearing=self.bearing,
            boxZoomOn=json.dumps(self.box_zoom_on),
            doubleClickZoomOn=json.dumps(self.double_click_zoom_on),
            scrollZoomOn=json.dumps(self.scroll_zoom_on),
            touchZoomOn=json.dumps(self.touch_zoom_on),
            popupOpensOnHover=self.popup_open_action == 'hover',
            includeSnapshotLinks=self.add_snapshot_links,
            preserveDrawingBuffer=json.dumps(self.add_snapshot_links),
            showScale=self.scale,
            scaleUnits=self.scale_unit_system,
            scaleBorderColor=self.scale_border_color,
            scalePosition=self.scale_position,
            scaleFillColor=self.scale_background_color,
            scaleTextColor=self.scale_text_color,
        )

        if self.legend:

            if all([
                    self.legend, self.legend_gradient,
                    self.legend_function == 'radius'
            ]):
                raise LegendError(' '.join([
                    'Gradient legend format not compatible with a variable radius legend.',
                    'Please either change `legend_gradient` to False or `legend_function` to "color".'
                ]))

            options.update(
                showLegend=self.legend,
                legendLayout=self.legend_layout,
                legendFunction=self.legend_function,
                legendStyle=self.legend_style,  # reserve for custom CSS
                legendGradient=json.dumps(self.legend_gradient),
                legendFill=self.legend_fill,
                legendHeaderFill=self.legend_header_fill,
                legendTextColor=self.legend_text_color,
                legendNumericPrecision=json.dumps(
                    self.legend_text_numeric_precision),
                legendTitleHaloColor=self.legend_title_halo_color,
                legendKeyShape=self.legend_key_shape,
                legendKeyBordersOn=json.dumps(self.legend_key_borders_on))

        if self.vector_source:
            options.update(vectorUrl=self.vector_url,
                           vectorLayer=self.vector_layer_name,
                           vectorJoinDataProperty=self.vector_join_property,
                           joinData=json.dumps(False),
                           dataJoinProperty=self.data_join_property,
                           enableDataJoin=not self.disable_data_join)
            data = geojson_to_dict_list(self.data)
            if bool(data):
                options.update(joinData=json.dumps(data, ensure_ascii=False))

        if self.label_property is None:
            options.update(labelProperty=None)
        else:
            options.update(labelProperty='{' + self.label_property + '}')

        options.update(labelColor=self.label_color,
                       labelSize=self.label_size,
                       labelHaloColor=self.label_halo_color,
                       labelHaloWidth=self.label_halo_width)

        self.add_unique_template_variables(options)

        if filename:
            html = templates.format(self.template, **options)
            with codecs.open(filename, "w", "utf-8-sig") as f:
                f.write(html)
            return None
        else:
            return templates.format(self.template, **options)