Choropleth Map component for Vue.js
Vue components to display a choropleth map given a certain GeoJSON and another datasource to show information from. Using Vue2Leaflet
For a complete example using a single-file component, check the code in the example.
For a complete example using script
tags check this codepen
Make sure you have Vue2Leaflet
installed and add the l-map
component along with the next vue-choropleth
components:
import {LMap} from 'vue2-leaflet';
import { InfoControl, ReferenceChart, ChoroplethLayer } from 'vue-choropleth'
// Register these components in the components
export default {
name: "app",
components: {
LMap,
'l-info-control': InfoControl,
'l-reference-chart': ReferenceChart,
'l-choropleth-layer': ChoroplethLayer
},
// .......your component code.........
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:
<l-map
:center="[-23.752961, -57.854357]"
:zoom="6"
style="height: 500px;"
:options="mapOptions">
<l-choropleth-layer
:data="pyDepartmentsData"
titleKey="department_name"
idKey="department_id"
:value="value"
:extraValues="extraValues"
geojsonIdKey="dpto"
:geojson="paraguayGeojson"
:colorScale="colorScale">
<template slot-scope="props">
<l-info-control
:item="props.currentItem"
:unit="props.unit"
title="Department"
placeholder="Hover over a department"/>
<l-reference-chart
title="Girls school enrolment"
:colorScale="colorScale"
:min="props.min"
:max="props.max"
position="topright"/>
</template>
</l-choropleth-layer>
</l-map>
l-choropleth-layer
Props"% of students"
)["e7d090", "de7062"]
)l-choropleth-layer
component pass the this information through its default slot:"e7d090"
). If a value is not specified fff
is used."e7d090"
). If a value is not specified 666
is used.2
).5
).As seen on the example, usually you’ll pass these values to the l-info-control
and l-reference-chart
components.
l-info-control
propsThis is the current item information view.
"State"
)"bottomleft"
)l-reference-chart
props"Population density"
)l-choropleth-layer
component"topright"
)$ 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/node-example
$ 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
You’ll also find an example using <script>
tags included under examples/browser-example
Guillermo Peralta Scura
Thanks to the works of Mickaël Bouchaud with Vue2Leaflet