docstr: Construct a MapViz object
  
  :param data: GeoJSON Feature Collection
  :param vector_url: optional property to define vector data source
  :param vector_layer_name: property to define target layer of vector source
  :param vector_join_property: property to aid in determining color for styling vector layer
  :param data_join_property: property to join json data to vector features
  :param disable_data_join: property to switch off default data-join technique using vector layer and JSON join-data; 
                            also determines if a layer filter based on joined data is applied to features in vector layer
  :param access_token: Mapbox GL JS access token.
  :param center: map center point
  :param style: url to mapbox style or stylesheet as a Python dictionary in JSON format
  :param label_property: property to use for marker label
  :param label_size: size of label text
  :param label_color: color of label text
  :param label_halo_color: color of label text halo
  :param label_halo_width: width of label text halo
  :param div_id: The HTML div id of the map container in the viz
  :param width: The CSS width of the HTML div id in % or pixels.
  :param height: The CSS height of the HTML map div in % or pixels.
  :param zoom: starting zoom level for map
  :param opacity: opacity of map data layer
  :param pitch: starting pitch (in degrees) for map
  :param bearing: starting bearing (in degrees) for map
  :param box_zoom_on: boolean indicating if map can be zoomed to a region by dragging a bounding box
  :param double_click_zoom_on: boolean indicating if map can be zoomed with double-click
  :param scroll_zoom_on: boolean indicating if map can be zoomed with the scroll wheel
  :param touch_zoom_on: boolean indicating if map can be zoomed with two-finger touch gestures
  :param legend: boolean for whether to show legend on map
  :param legend_layout: determines if horizontal or vertical legend used
  :param legend_function: controls whether legend is color or radius-based
  :param legend_style: reserved for future custom CSS loader
  :param legend_gradient: boolean to determine if legend keys are discrete or gradient
  :param legend_fill: string background color for legend, default is white
  :param legend_header_fill: string background color for legend header (in vertical layout), default is #eee
  :param legend_text_color: string color for legend text default is #6e6e6e
  :param legend_text_numeric_precision: decimal precision for numeric legend values
  :param legend_title_halo_color: color of legend title text halo
  :param legend_key_shape: shape of the legend item keys, default varies by viz type; one of square, contiguous_bar, rounded-square, circle, line
  :param legend_key_borders_on: boolean for whether to show/hide legend key borders
  :param scale: add map control showing current scale of map
  :param scale_unit_system: choose units for scale display (metric, nautical or imperial)
  :param scale_position: location of the scale annotation
  :param scale_border_color: border color of the scale annotation
  :param scale_background_color: fill color of the scale annotation
  :param scale_text_color: text color the scale annotation
  :param popup_open_action: controls behavior of opening and closing feature popups; one of 'hover' or 'click'
  :param add_snapshot_links: boolean switch for adding buttons to download screen captures of map or legend
docstr_tok: ["Construct","a","MapViz","object",":","param","data",":","GeoJSON","Feature","Collection",":","param","vector_url",":","optional","property","to","define","vector","data","source",":","param","vector_layer_name",":","property","to","define","target","layer","of","vector","source",":","param","vector_join_property",":","property","to","aid","in","determining","color","for","styling","vector","layer",":","param","data_join_property",":","property","to","join","json","data","to","vector","features",":","param","disable_data_join",":","property","to","switch","off","default","data-join","technique","using","vector","layer","and","JSON","join-data",";","also","determines","if","a","layer","filter","based","on","joined","data","is","applied","to","features","in","vector","layer",":","param","access_token",":","Mapbox","GL","JS","access","token",".",":","param","center",":","map","center","point",":","param","style",":","url","to","mapbox","style","or","stylesheet","as","a","Python","dictionary","in","JSON","format",":","param","label_property",":","property","to","use","for","marker","label",":","param","label_size",":","size","of","label","text",":","param","label_color",":","color","of","label","text",":","param","label_halo_color",":","color","of","label","text","halo",":","param","label_halo_width",":","width","of","label","text","halo",":","param","div_id",":","The","HTML","div","id","of","the","map","container","in","the","viz",":","param","width",":","The","CSS","width","of","the","HTML","div","id","in","%","or","pixels",".",":","param","height",":","The","CSS","height","of","the","HTML","map","div","in","%","or","pixels",".",":","param","zoom",":","starting","zoom","level","for","map",":","param","opacity",":","opacity","of","map","data","layer",":","param","pitch",":","starting","pitch","(","in","degrees",")","for","map",":","param","bearing",":","starting","bearing","(","in","degrees",")","for","map",":","param","box_zoom_on",":","boolean","indicating","if","map","can","be","zoomed","to","a","region","by","dragging","a","bounding","box",":","param","double_click_zoom_on",":","boolean","indicating","if","map","can","be","zoomed","with","double-click",":","param","scroll_zoom_on",":","boolean","indicating","if","map","can","be","zoomed","with","the","scroll","wheel",":","param","touch_zoom_on",":","boolean","indicating","if","map","can","be","zoomed","with","two-finger","touch","gestures",":","param","legend",":","boolean","for","whether","to","show","legend","on","map",":","param","legend_layout",":","determines","if","horizontal","or","vertical","legend","used",":","param","legend_function",":","controls","whether","legend","is","color","or","radius-based",":","param","legend_style",":","reserved","for","future","custom","CSS","loader",":","param","legend_gradient",":","boolean","to","determine","if","legend","keys","are","discrete","or","gradient",":","param","legend_fill",":","string","background","color","for","legend",",","default","is","white",":","param","legend_header_fill",":","string","background","color","for","legend","header","(","in","vertical","layout",")",",","default","is","#","eee",":","param","legend_text_color",":","string","color","for","legend","text","default","is","#","6e6e6e",":","param","legend_text_numeric_precision",":","decimal","precision","for","numeric","legend","values",":","param","legend_title_halo_color",":","color","of","legend","title","text","halo",":","param","legend_key_shape",":","shape","of","the","legend","item","keys",",","default","varies","by","viz","type",";","one","of","square",",","contiguous_bar",",","rounded-square",",","circle",",","line",":","param","legend_key_borders_on",":","boolean","for","whether","to","show\/hide","legend","key","borders",":","param","scale",":","add","map","control","showing","current","scale","of","map",":","param","scale_unit_system",":","choose","units","for","scale","display","(","metric",",","nautical","or","imperial",")",":","param","scale_position",":","location","of","the","scale","annotation",":","param","scale_border_color",":","border","color","of","the","scale","annotation",":","param","scale_background_color",":","fill","color","of","the","scale","annotation",":","param","scale_text_color",":","text","color","the","scale","annotation",":","param","popup_open_action",":","controls","behavior","of","opening","and","closing","feature","popups",";","one","of","'hover","'","or","'click'",":","param","add_snapshot_links",":","boolean","switch","for","adding","buttons","to","download","screen","captures","of","map","or","legend"]
code: def __init__(
      self,
      data,
      vector_url=None,
      vector_layer_name=None,
      vector_join_property=None,
      data_join_property=None,
      disable_data_join=False,
      access_token=None,
      center=(0, 0),
      below_layer="",
      opacity=1,
      div_id="map",
      height="500px",
      style="mapbox://styles/mapbox/light-v10?optimize=true",
      label_property=None,
      label_size=8,
      label_color="#131516",
      label_halo_color="white",
      label_halo_width=1,
      width="100%",
      zoom=0,
      min_zoom=0,
      max_zoom=24,
      pitch=0,
      bearing=0,
      box_zoom_on=True,
      double_click_zoom_on=True,
      scroll_zoom_on=True,
      touch_zoom_on=True,
      legend=True,
      legend_layout="vertical",
      legend_function="color",
      legend_gradient=False,
      legend_style="",
      legend_fill="white",
      legend_header_fill="white",
      legend_text_color="#6e6e6e",
      legend_text_numeric_precision=None,
      legend_title_halo_color="white",
      legend_key_shape="square",
      legend_key_borders_on=True,
      scale=False,
      scale_unit_system="metric",
      scale_position="bottom-left",
      scale_border_color="#6e6e6e",
      scale_background_color="white",
      scale_text_color="#131516",
      popup_open_action="hover",
      add_snapshot_links=False,
  ):
      """Construct a MapViz object
  
      :param data: GeoJSON Feature Collection
      :param vector_url: optional property to define vector data source
      :param vector_layer_name: property to define target layer of vector source
      :param vector_join_property: property to aid in determining color for styling vector layer
      :param data_join_property: property to join json data to vector features
      :param disable_data_join: property to switch off default data-join technique using vector layer and JSON join-data;
                                also determines if a layer filter based on joined data is applied to features in vector layer
      :param access_token: Mapbox GL JS access token.
      :param center: map center point
      :param style: url to mapbox style or stylesheet as a Python dictionary in JSON format
      :param label_property: property to use for marker label
      :param label_size: size of label text
      :param label_color: color of label text
      :param label_halo_color: color of label text halo
      :param label_halo_width: width of label text halo
      :param div_id: The HTML div id of the map container in the viz
      :param width: The CSS width of the HTML div id in % or pixels.
      :param height: The CSS height of the HTML map div in % or pixels.
      :param zoom: starting zoom level for map
      :param opacity: opacity of map data layer
      :param pitch: starting pitch (in degrees) for map
      :param bearing: starting bearing (in degrees) for map
      :param box_zoom_on: boolean indicating if map can be zoomed to a region by dragging a bounding box
      :param double_click_zoom_on: boolean indicating if map can be zoomed with double-click
      :param scroll_zoom_on: boolean indicating if map can be zoomed with the scroll wheel
      :param touch_zoom_on: boolean indicating if map can be zoomed with two-finger touch gestures
      :param legend: boolean for whether to show legend on map
      :param legend_layout: determines if horizontal or vertical legend used
      :param legend_function: controls whether legend is color or radius-based
      :param legend_style: reserved for future custom CSS loader
      :param legend_gradient: boolean to determine if legend keys are discrete or gradient
      :param legend_fill: string background color for legend, default is white
      :param legend_header_fill: string background color for legend header (in vertical layout), default is #eee
      :param legend_text_color: string color for legend text default is #6e6e6e
      :param legend_text_numeric_precision: decimal precision for numeric legend values
      :param legend_title_halo_color: color of legend title text halo
      :param legend_key_shape: shape of the legend item keys, default varies by viz type; one of square, contiguous_bar, rounded-square, circle, line
      :param legend_key_borders_on: boolean for whether to show/hide legend key borders
      :param scale: add map control showing current scale of map
      :param scale_unit_system: choose units for scale display (metric, nautical or imperial)
      :param scale_position: location of the scale annotation
      :param scale_border_color: border color of the scale annotation
      :param scale_background_color: fill color of the scale annotation
      :param scale_text_color: text color the scale annotation
      :param popup_open_action: controls behavior of opening and closing feature popups; one of 'hover' or 'click'
      :param add_snapshot_links: boolean switch for adding buttons to download screen captures of map or legend
  
      """
      if access_token is None:
          access_token = os.environ.get("MAPBOX_ACCESS_TOKEN", "")
      if access_token.startswith("sk"):
          raise TokenError(
              "Mapbox access token must be public (pk), not secret (sk). "
              "Please sign up at https://www.mapbox.com/signup/ to get a public token. "
              "If you already have an account, you can retreive your token at https://www.mapbox.com/account/."
          )
      self.access_token = access_token
  
      self.data = data
  
      self.vector_url = vector_url
      self.vector_layer_name = vector_layer_name
      self.vector_join_property = vector_join_property
      self.data_join_property = data_join_property
      self.disable_data_join = disable_data_join
  
      self.template = "map"
      try:
          self.check_vector_template()
      except AttributeError:
          self.vector_source = False
  
      self.div_id = div_id
      self.width = width
      self.height = height
      self.style = style
      self.center = center
      self.zoom = zoom
      self.below_layer = below_layer
      self.opacity = opacity
      self.label_property = label_property
      self.label_color = label_color
      self.label_size = label_size
      self.label_halo_color = label_halo_color
      self.label_halo_width = label_halo_width
      self.min_zoom = min_zoom
      self.max_zoom = max_zoom
      self.pitch = pitch
      self.bearing = bearing
      self.box_zoom_on = box_zoom_on
      self.double_click_zoom_on = double_click_zoom_on
      self.scroll_zoom_on = scroll_zoom_on
      self.touch_zoom_on = touch_zoom_on
  
      # legend configuration
      self.legend = legend
      self.legend_layout = legend_layout
      self.legend_function = legend_function
      self.legend_style = legend_style
      self.legend_gradient = legend_gradient
      self.legend_fill = legend_fill
      self.legend_header_fill = legend_header_fill
      self.legend_text_color = legend_text_color
      self.legend_text_numeric_precision = legend_text_numeric_precision
      self.legend_title_halo_color = legend_title_halo_color
      self.legend_key_shape = legend_key_shape
      self.legend_key_borders_on = legend_key_borders_on
      self.popup_open_action = popup_open_action
      self.add_snapshot_links = add_snapshot_links
  
      # scale configuration
      self.scale = scale
      self.scale_unit_system = scale_unit_system
      self.scale_position = scale_position
      self.scale_border_color = scale_border_color
      self.scale_background_color = scale_background_color
      self.scale_text_color = scale_text_color
  
imports: import codecs
  import json
  import os
  from IPython.core.display import HTML, display
  import numpy
  import requests
  from mapboxgl.errors import TokenError, LegendError
  from mapboxgl.utils import color_map, numeric_map, img_encode, geojson_to_dict_list
  from mapboxgl import templates
label_desc: Use image node_id 1 to create a new MapViz object from inherited base classes: object with example: obj = MapViz(data, vector_url, vector_layer_name, vector_join_property, data_join_property, disable_data_join, access_token, center, below_layer, opacity, div_id, height, style, label_property, label_size, label_color, label_halo_color, label_halo_width, width, zoom, min_zoom, max_zoom, pitch, bearing, box_zoom_on, double_click_zoom_on, scroll_zoom_on, touch_zoom_on, legend, legend_layout, legend_function, legend_gradient, legend_style, legend_fill, legend_header_fill, legend_text_color, legend_text_numeric_precision, legend_title_halo_color, legend_key_shape, legend_key_borders_on, scale, scale_unit_system, scale_position, scale_border_color, scale_background_color, scale_text_color, popup_open_action, add_snapshot_links)