Base Map
<BaseMap>
<Areas data={la_zip_sales} geoId=ZCTA5CE10 areaCol=zip_code value=sales valueFmt=usd/>
<Points data={la_locations} lat=lat long=long color=#179917/>
</BaseMap>
Overview
The BaseMap component provides a flexible and extensible way to create maps with multiple layers. This component serves as the foundation for AreaMap, PointMap, and BubbleMap.
Within BaseMap, you can add layers using the following components:
<Areas/>
<Points/>
<Bubbles/>
Examples
See the pages for Area Map, Point Map, and Bubble Map for examples specific to those layers. The same options can be applied to the layer components within BaseMap.
Adding Multiple Layers
<BaseMap>
<Areas
data={la_zip_sales}
areaCol=zip_code
geoJsonUrl="path/to/your/geoJSON"
geoId=ZCTA5CE10
value=sales
valueFmt=usd
/>
<Bubbles
data={la_locations}
lat=lat
long=long
size=sales
sizeFmt=usd
value=sales
valueFmt=usd
pointName=point_name
colorPalette={['yellow','orange','red','darkred']}
opacity=0.5
/>
</BaseMap>
Custom Basemap
You can add a different basemap by passing in a basemap URL. You can find examples here: https://leaflet-extras.github.io/leaflet-providers/preview/
<BaseMap basemap={`https://tile.openstreetmap.org/{z}/{x}/{y}.png`}>
<Points
data={la_locations}
lat=lat
long=long
value=sales
valueFmt=usd
pointName=point_name
color=violet
borderColor=black
borderWidth=2
/>
</BaseMap>
Custom Tooltip
tooltipType=hover
<BaseMap>
<Areas
data={la_zip_sales}
areaCol=zip_code
geoJsonUrl='https://evd-geojson.b-cdn.net/ca_california_zip_codes_geo_1.min.json'
geoId=ZCTA5CE10
value=sales
valueFmt=usd
height=250
tooltip={[
{id: 'zip_code', fmt: 'id', showColumnName: false, valueClass: 'text-xl font-semibold'},
{id: 'sales', fmt: 'eur', fieldClass: 'text-[grey]', valueClass: 'text-[green]'},
{id: 'zip_code', showColumnName: false, contentType: 'link', linkLabel: 'Click here', valueClass: 'font-bold mt-1'}
]}
/>
</BaseMap>
With clickable link and tooltipType=click
<BaseMap>
<Areas
data={la_zip_sales}
areaCol=zip_code
geoJsonUrl='https://evd-geojson.b-cdn.net/ca_california_zip_codes_geo_1.min.json'
geoId=ZCTA5CE10
value=sales
valueFmt=usd
height=250
tooltipType=click
tooltip={[
{id: 'zip_code', fmt: 'id', showColumnName: false, valueClass: 'text-xl font-semibold'},
{id: 'sales', fmt: 'eur', fieldClass: 'text-[grey]', valueClass: 'text-[green]'},
{id: 'link_col', showColumnName: false, contentType: 'link', linkLabel: 'Click here', valueClass: 'font-bold mt-1'}
]}
/>
</BaseMap>
Map Resources
Below are a selection of publically available GeoJSON files that may be useful for mapping. These are from the Natural Earth Data project, and hosted by GeoJSON.xyz.
Country, State, and City Locations
Base Map Options
- Options:
- URL
- Options:
- text
- Options:
- latitude coordinate
- Options:
- longitude coordinate
- Options:
- number (1 to 18)
- Options:
- pixel value
- Default:
- 300
Layer Options
Areas
Use the <Areas/>
component to add an area layer
- Options:
- query name
Path to source geoJSON data from - can be a URL (see Map Resources) or a file in your project.
If the file is in your project, store it in a static
folder in the root of your project, and reference it as geoJsonUrl="/your_file.geojson"
- Options:
- URL
- Options:
- column name
- Options:
- geoJSON property name
- Options:
- column name
- Options:
- format string
Points
Use the <Points/>
component to add an area layer
- Options:
- query name
- Options:
- column name
- Options:
- column name
- Options:
- column name
- Options:
- format string
- Options:
- column name
Bubbles
Use the <Bubbles/>
component to add an area layer
- Options:
- query name
- Options:
- column name
- Options:
- column name
- Options:
- column name
- Options:
- format string
- Options:
- number
- Default:
- 20
- Options:
- column name
- Options:
- format string
- Options:
- column name
Common Layer Options
Color Scale
- Options:
- array of colors
- Options:
- number
- Default:
- min of value column
- Options:
- number
- Default:
- max of value column
Interactivity
- Options:
- URL
- Options:
- string
Styling
- Options:
- CSS color value
- Options:
- pixel value
- Options:
- CSS color value
- Options:
- number between 0 and 1
Selected State
- Options:
- CSS color value
- Options:
- pixel value
- Options:
- CSS color value
- Options:
- number between 0 and 1
Tooltips
- Options:
- CSS class
- Options:
- array of objects
tooltip
example:
tooltip={[
{id: 'zip_code', fmt: 'id', showColumnName: false, valueClass: 'text-xl font-semibold'},
{id: 'sales', fmt: 'eur', fieldClass: 'text-[grey]', valueClass: 'text-[green]'},
{id: 'zip_code', showColumnName: false, contentType: 'link', linkLabel: 'Click here', valueClass: 'font-bold mt-1'}
]}
All options available in tooltip
:
id
: column IDtitle
: custom string to use as title of fieldfmt
: format to use for valueshowColumnName
: whether to show the column name. Iffalse
, only the value will be showncontentType
: currently can only be "link"linkLabel
: text to show for a link when contentType="link"formatColumnTitle
: whether to automatically uppercase the first letter of the title. Only applies whentitle
not passed explicitlyvalueClass
: custom Tailwind classes to style the valuesfieldClass
: custom Tailwind classes to style the column names