Vue component to display a choropleth map given a certain GeoJSON and another datasource to show information from. Using Vue2Leaflet
Register ChoroplethMap as a component
import ChoroplethMap from 'vue-choropleth'
Vue.component(ChoroplethMap)
Make sure the leaflet.css is included, either via a HTML link tag or in your vue component style
@import "~leaflet/dist/leaflet.css";
On the template:
<ChoroplethMap
:geojson="geojson"
:data="pyDepartmentsData"
titleKey="department_name"
geojsonIdKey="dpto"
idKey="department_id"
:value="value"
:extraValues="extraValues"
referenceTitle="Girls school enrolment"
dataTitle="Department"
dataPlaceholder="Hover over a department"
:center="center"
:colorScale="colorScale"
mapStyle="height: 500px;"
:zoom="6"
:mapOptions="mapOptions">
</ChoroplethMap>
- geojson: The GeoJSON object to use
- data: Data object with the information to show on the map
- titleKey: Property of the data object to show when you hover over a certain region of your map (e.g. state_name)
- geojsonIdKey: Property under the properties array of the GeoJSON that serves as identifier of each region of the map.
- idKey: Property of the data object that matches the geojsonIdKey value.
- value: JS object with two properties, key: that maps to the data property that contains the value domain set (e.g. amount) and metric: that maps to the data property that describes the unit that you're working on (e.g.
"% of students"
) - extraValues: Array of value objects that show additional information of a certain region of the map.
- referenceTitle: Short description to show as reference of the information described by the map (e.g.
"Population density"
) - dataTitle: Description about what each item of the map is (e.g.
"State"
) - dataPlaceholder: Placeholder text to show when no element is currently selected
- center: Geographic coordinates of the map initial center (e.g.
[-23.752961, -57.854357]
) - colorScale: Array of hex color codes to fill each region of the map with. At the minimum you need to specify two colors, the one to use with the lowest values and another one to use with the highest values. (e.g.
["e7d090", "de7062"]
) - mapStyle: CSS style of the map.
- zoom: With how much zoom to init the map.
- mapOptions: Additional leaflet Map options. (e.g.
{attributionControl: false}
)
$ npm install vue-choropleth --save
$ yarn add vue-choropleth
Example available here.
# Once you have cloned this repo, install dependencies
$ npm install
# build for development and production with minification
$ npm run build
# Run demo at localhost:8080
$ npm link
$ cd examples
$ npm link vue-choropleth
$ npm install
# serve with hot reload at localhost:8080
$ npm run dev
Go to http://localhost:8080/ to see the demo
NOTE: If you make changes to the library you should run 'npm run build' again in the root folder. The dev server should detect modification and reload the demo
Guillermo Peralta Scura
Thanks to the works of Mickaël Bouchaud with Vue2Leaflet