Code Monkey home page Code Monkey logo

sdg_leaflet's Introduction

SDG_Leaflet Choropleth Map - light and interactive

Now that you have followed the tutorial to make a Choropleth map using SDG data and QGIS here Now you want to make it interactive and this map online!
Here I will show you how to create a global SDG Choropleth Map using Leaflet. Here I explain how to clean your data in QGIS and then I build and modify code from this leaflet tutorial. See a live working version here

Steps

• Convert your shapefile to geojson
• Create a webmap using the Leaflet API
• Reference your geojson file on your webmap

Prepare your data in QGIS

Open your shapefile with the countries and joined data using QGIS.
Open the attribute table.
Please make sure you write down the goal, target, and indicator title year the data were collected and any other relevant info that you might want to include in the text on your website about the map.
The SDG value – if it is more than 2 decimal places, please convert the value to an integer.
To do this – when the attribute table is open and editable –click field calculator.
Toggle “Create New Field” and name it SDG
Then cut and paste this expression and replace SDG_Field with the name of the field with your SDG indicator in it.

To_int(“SDG_Field”)

Then click ok and the new field should generate.
Now we will export and Convert to GeoJSON.
Right-click and the layer Export Save Vector Layer As
Format change to GeoJSON
Name your file and make sure you see where it is being saved.
You only need to keep the attribute with the name of the country and the value – so only toggle the country name and the SDG value field you just created.
Then click okay

##Open the new GeoJSON file in a text editor On line one, before the open brackets Add the following text

var nationData=

Next, Finally File Save As and name it and save it with .js extension

Close this file.

Modify the HTML file

Next open the HTML file found here in your text editor. Find all the places I left UPDATE in the comments. These are the places you need to make changes to reference your documents. You can control f to find those places.
Good luck!

sdg_leaflet's People

Contributors

bricker0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.