This workshop provides a foundation for getting started with creating, configuring, and hosting web maps with the QGIS plugin QGIS2Web and GitHub. It is not meant to give a comprehensive introduction to all applications used, such as QGIS, Leaflet, and Atom. Familiarity with editing html documents in a text editor and some foundational experience with geospatial data, GIS, and GitHub may be helpful if following along.
This workshop will not cover how to create the geospatial data or host images in web maps. However, some bonus sections at the bottom of this document contains basic information about image processing.
Using a free and open-source tool that gives access to source code ensures that you retain access and ownership of the code and data. Many content management system plugins, web map creation platforms (Esri, Carto), and/or freemium services may not allow you to fully retain ownership, often have data limits and restrictions, can use your map and data in any way per any license agreement, can make it difficult to extract the source code and data, may change pricing structures at any time, or delete your data without notice.
You can choose to host a Leaflet map on any platform, but this tutorial uses GitHub. GitHub is free and easy to use for sharing code, working on digital projects, and hosting html documents and images, which this tutorial makes use of.
This tutorial was made using Mac iOS Mojave v 10.14.5. The following software and accounts are used and are required before going further:
This tutorial uses git and GitHub mostly through the desktop and the online interface rather than the command line. All steps for creating new repositories, publishing, and pushing changes are possible in Terminal or a command line tool, too, and are recommended to use over the Desktop app. See the GitHub Cheat Sheet for the commands.
Go to github.com and login. Create a new account if needed.
Go the repository for this workshop: github.com/taylorhixson/WF
In the top right of the repository, click Fork.
Once the repository is forked, it will show up in your repositories. If needed click your profile avatar in the top right and choose Your repositories. If the repository was forked correctly, a repository called WF should appear.
In the WF repository, click Clone or download, and from that popup, choose Open in Desktop. Make sure the link shows your GitHub username NOT the workshop creator’s username. The below screenshot shows the creator’s because the screenshot was taken from her account.
If the browser prompts you, choose Open GitHub Desktop.
Click Create Branch.
Click Publish branch.
Once you publish something to the gh-pages branch, you can see it at the branch’s GitHub Pages site at YourGitHubAccount.github.io/gitRepositoryName/webapp.
Note: If downloading QGIS3 for the first time on a Mac, watch this video. It is not a one-click install on Mac.
Open QGIS. If you do not know where it is, search for it in Spotlight. The icon is a green Q.
Once open, use command + S, click the floppy disc icon in the top left of QGIS, OR click File>Save.
Navigate to the git repository for this project.
Name the QGIS project file.
Make sure the file type is .qgz.
While working in QGIS, periodically save the project. Saving the project makes sure layer styles and all other project properties, including qgis2web Leaflet properties, are saved when the project is closed or when it is shared with others.
Open QGIS.
Click Plugins from the top menu.
Click Manage and Install Plugins….
Make sure All is selected from the left side of the popup window, and in the search box, type qgis2web. Note: an internet connection is required to search for and install plugins this way.
Select the result qgis2web so that the information about the plugin appears on the right side of the window.
Below the plugin description, click Install plugin.
In the search results, make sure the box next to it is checked so that it appears.
Search for QuickMapServices, and click Install Plugin. Make sure the box next to it is checked, too. For future reference, open GIS Lab has a tutorial and more information about configuring QuickMapServices and accessing more basemap options than the default.
When both plugins are installed, close the plugins window. Not sure if they are installed? Click the Installed tab in the Plugins window.
From the top menu, click Web. Qgis2Web and QuickMapServices should both appear there. If not, quit QGIS and reopen the project. If it still does not appear, go back to the manage and install plugins window and check that these are listed in Installed Plugins. If the plugins are listed there, make sure the box to the left of the plugin is checked.
From the top menu, click Layer>Add Layer>Add Delimted Text data.
Click the three dots to the far right of File Name to navigate to the CSV used in this workshop.
Under Geometry Definitions make sure Point coordinates is selected.
Still in the Geometry Definition box, click the globe button to the far right of Geometry CRS.
In the Filter search bar type EPSG:4326
. The coordinate system, or CRS, used needs to correspond with the coordinates in the CSV. The coordinates are in the geographic coordinate system WGS 1984 format.
Once found, highlight it, and click OK.
All other system defaults or detected attributes should be OK, so click Add. Then, click Close as there are no other files to add from a delimited text source.
The points should appear in the main workspace, and the CSV should appear in the Layers panel.
Now, the data in the CSV needs to be reprojected to match the OpenStreetMap projection–a projected coordinate system.
Open the Processing Toolbox panel. Do this by clicking the gear icon, or from the top menu, View>Panels>Processing Toolbox.
Search for reproject, and double click Reproject layer under Vector general.
When the screen looks like the above image, click Run in the bottom right of the Reproject Layer window.
Close the Reproject Layer window when the Log tab shows the layer was reprojected successfully by displaying the message “Algorithm ‘Reproject Layer’ finished”
command + D
on the keyboard.In the Layers Panel double click the wf geojson layer to open the Layer Properties window. Click the Information tab to make sure next to CRS is EPSG:3857. If it is close the window.
Double check the project CRS by looking in the bottom right of QGIS. It should show EPSG:3857. If it does not click whatever EPSG code is there, and search for 3857 in the pop up, select it, and click OK.
Now that a spatial data file (GeoJSON) was created, there is no need for the latitude and longitude field. It is optional to either keep or delete these for aesthetic purposes.
Make sure QGIS is open and the reprojected geojson is in the Layers Panel.
Right click the layer in the Layers panel, and choose open attribute table.
To edit the attribute table, click the pencil icon in the top left of the attribute table or use Command + E (Mac).
To start deleting empty columns, click the Delete field icon, highlighted in the image below. This icon appears when editing mode is turned on. Note: Deleting a column is permanent. You may want to copy the geojson if this is your first time just in case.
In the window that appears, click the following columns to select the Latitude and Longitude columns in order to delete them.
Once all the necessary columns are highlighted, click OK.
If the correct columns were deleted, click the floppy disc icon in the top left to save edits, or press Ctrl + S
on the keyboard.
While in the attribute table, make any other content edits.
Click the pencil icon in the top left again when finished. Make sure to save edits.
You may wish to style the points or categorize the data on the map. This tutorial will not go in depth to discuss layer styling. If you have never styled or categorized vector data in QGIS before or need a refresher, QGIS Tutorials has a good Vector Styling tutorial.
Alternatively, you can also leave the default point marker and change it to a leaflet style, which is demonstrated in a later step.
Double click the points layer with the World’s Fair locations, shown here as wf.
In the Layer Properties window that appears, click the Symbology tab.
From the dropdown at the top of the screen choose Categorized.
Click the Column dropdown to choose a categorical feature to style the points. In this dataset, choose Type.
Near the bottom of the window, click Classify.
Highlight the line with the point that appears without any values.
At the bottom, click the minus sign.
Double click the points under Symbol to style them. Choose new colors or symbols.
Close the Layer Properties window when happy with the styles.
The point of using qgis2web instead of immediately starting with Leaflet is that qgis2web can output complex and correct javascript for pop-ups, legends, and other map options without needing to know the code. Then, it is very simple to go into qgis2web’s file outputs to make customizations and additions for basemaps, markers, more places, etc.
Make any other desired appearance changes. For example, and a layer search and/or address search to make the map more web accessible, measure tool, or have a custom map extent (how far someone can zoom in, out, and around). Click Update preview to see how any changes will look.
Click the Export tab.
Under Data export and to the right of Exporter, click the three dots at the end of the line to make sure the output goes to the git repository folder.
In the window that appears, navigate to the project’s git repository and choose Open.
In the Export to web map window in QGIS, click Export at the bottom of the window.
Navigate to the qgis2web folder in the git repository.
Rename the very long qgis2web folder name to webapp. This rename will be important for creating GitHub Pages at a later step. It is not necessary to use webapp specifically, but name it something short and memorable.
Open the folder, which is now named webapp in this tutorial, and double click the index.html file. The map will open in the default web browser. If for some reason the map is not appearing, right click the file and select Open with to open it with another web browser (e.g., Firefox instead of Chrome).
<head>
), delete line 6, or the line which begins meta name="viewport"...
.<head>
above the style tag <style>
. Leaflet is meant to create mobile and web responsive maps, but these will help even more.<!-- Mobile meta tags to go in head-->
<meta name="HandheldFriendly" content="True">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="MobileOptimized" content="320"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="cleartype" content="on">
<style>
) section of the head, paste the following code in line 25, or after the closed curly bracket. Note: the line could be different if you did not paste the code from the previous step exactly as shown, so just look for the line directly above the closed style tag </style>
. This code sets a minimum width and height for the map popups and adds scrolling capabilities. Change the min-width and min-height to meet your needs..leaflet-popup-content {
min-width: 200px;
min-height: 100px;
overflow-y: scroll;
}
(Optional) To remove the scroll bar from the map itself, paste overflow-y: scroll
within the #map class curly brackets.
(Optional) Use command + F to find marker
.
(Optional) Change L.circleMarker
to L.marker
to use the default Leaflet balloon markers instead of the one exported from QGIS. No need to delete any of the function style_wf_1_0
, Leaflet will now ignore it.
(Optional steps 10-14) Change the basemap to the Google Earth and Streets hybrid basemap. Note: It is possible to use Google Earth, Streets, or Hybrid from the start if QuickMapServices is configured with the open GIS Lab tutorial.
Use command + F to find var layer_OSMStandard_0
. This text may vary if you used a different basemap from the start.
Delete the lines of code that are as follows:
var layer_OSMStandard_0 = L.tileLayer('http://tile.openstreetmap.org/{z}/{x}/{y}.png', {
opacity: 1.0,
attribution: '<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap contributors, CC-BY-SA</a>',
});
layer_OSMStandard_0;
var googleHybrid = L.tileLayer('https://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',{
maxZoom: 20,
opacity: 1.0,
subdomains:['mt0','mt1','mt2','mt3']
});
googleHybrid;
layer_OSMStandard_0
and replace it with googleHybrid
(Optional) Edit the legend to reflect the changes made such as the new basemap name and to remove the old marker image.
Use command + F to find the line that begins with L.control.layers
.
Open GitHub Desktop.
The simplest way to embed the Leaflet map into a website is with an iframe. This may or may not be possible depending on the content management system being used. If you do not have a website, try creating a Jekyll blog that integrates with Github Pages. Note: This has not been tested by the tutorial author, but there is a good Jekyll tutorial.
As of May 2019, iframe html tags <iframe>
do not seem to be compatible with the most recent version of free, personal instances of WordPress. The best reason I could find was “due to security reasons.”
Iframe html tags (e.g., <iframe src=" ">
) may work with other content management systems and some older versions and instances of WordPress.
If you want to integrate the exported qgis2web map with a content management system that does not allow the iframe html tags or you do not currently have access to one there are a few ways to do it:
This option may work with some content management systems, self-hosted websites, or older versions of WordPress.
Create a new page or post in the content management system. This example uses WordPress.
Using the classic editor, choose Text instead of Visual.
Use the html iframe tag: <iframe src=" " width=" " height=" "></iframe>
Between the iframe src= quotation marks, paste the link to the GitHub Pages (gh-pages branch) for the project repository. It should look like https://YourGitHubAccount.github.io/repoName/webapp.
Between the width and height quotations, set the width and height of the map. For example, the final html might look like: <iframe src="https://taylorhixson.github.io/WF/webapp" width="100%" height="400"></iframe>
. For width=, the 100% indicates stretching to fill the page width. It is also possible to set the width to a static number such as width="800"
.
Click Preview to check out how it appears.
Maps are great! However, they may not be accessible to all users for reasons ranging from low-internet connectivity, incompatibility with a screenreader and/or keyboard-only navigation, vision impairment, and neurological differences.
Wherever the map is hosted, include a thorough text description. It is even possible to do add a text description within the index.html with basic html knowledge! Drafting the text descriptions in a spreadsheet from the start helps with the text description process because it makes it easy to directly copy text into the post editor. If the places were not listed in any particular order, make an effort to arrange the text descriptions in a way that will make narrative sense.
For example, if the map is of places, make an effort to provide a narrative or list that describes the places in the order they were visited. A thorough text description aims to give an equivalent experience to all users.
The images I downloaded from the database for this workshop came in PDF format. For web viewing a thumbnail within the map popups, I thought a .png file was more appropriate. To reformat images use the following commands. These instructions are for Mac. The commands may or may not be compatible with other operating systems.
Copy photos into a new folder in the git repository for this project. Make sure to COPY the images or have a backup of the original in case any errors occur.
Skip to step 4 if you already know how to open and navigate within Terminal. Open Terminal. If you are not sure where Terminal is, type Terminal into Mac’s spotlight.
cd
(change directory). For example, use a relative file path like: cd ~/git/WF/images
cd
(change directory) command through each subfolder to get to the images directory: cd git
cd WF
cd images
for i in *; do sips -s format png $i --out $i.png; done
The above will reformat all files in the directory, so if you have varied types in the folder such as PDFs and TIFFs that you want to turn into PNGs, this should still work.
Alternatively, reformat a single image using the following: sips -s format png 1873.pdf --out 1873.png
Note: replace the input and output file names and file types with your own.
These instructions are for Mac. The commands may or may not be compatible with other operating systems.
Copy photos into a new git repository folder titled images_small. Make sure to COPY the images or have a backup because these images will be resized.
(Optional) Rename the photos to something simpler or more systematic to make it easier to link them with the corresponding places in a later step.
Skip to step 4 if you already know how to open and navigate within Terminal. Open Terminal. If you are not sure where Terminal is, type Terminal into Mac’s spotlight.
cd
(change directory) to the git repository with the images. For example, use a relative file path like: cd git/WF/images
cd
(change directory) command through each subfolder to get to the images directory: cd git
cd WF
cd images
sips -Z 300 *.jpg
Format a column in html so that the photo will show up in the map popup. If you resized the image and want to link back to the original or larger format, create to columns: one with the image link to the large format one, and one with the html formatted image link to the resized image as shown how to format below.
Go to GitHub.com, and go to the project repository.
Click the images folder. This assumes there is a folder called images in the repository where images are saved.
Click on an individual image link in the folder.
Right click the image, and choose Copy Image Address.
Open the spreadsheet with the place names and descriptions from the List places… section.
Paste the image link into an empty column in the appropriate row where the image depicts the place listed and described. If using a new spreadsheet, place it A1.
In the first empty cell in the next empty column type =CONCATENATE
to activate the Concatenate formula.
Within the Concatenate formula parentheses () type: "<img src=+",A1,"+ alt=+",B1,"+>"
. In the formula the plus sign (+) acts as a placeholder for quotation marks needed in the html. Quotations may or may not work with the Concatenate formula in your spreadsheet software, but it definitely does not work in Google Sheets. Additionally, your columns (e.g., A1, B1) may be different depending on where links and alt text are placed.
Copy this formula down the column or into any cell that has an image and alt text.
Copy the column and paste as values in the next empty column. In Google Sheets, use command + shift + v to paste as values, or right click/control click the first empty cell and choose Paste Special>Paste Values Only.
Use find and replace to replace the +, or special character used, as a placeholder with a quotation mark.
Delete the column with the Concatenate formula, NOT the column with the final image link.
Now, there are a few options for how to integrate the image links:
<br>
in the concatenate formula. This will NOT show the line break immediately, but the break should appear in the final map.