Skip to content

Commit

Permalink
0.2.0
Browse files Browse the repository at this point in the history
- basemaps in Leaflet #8
- extra basemaps from qgis2leaf #27
- UI icons fixed #21
- QGIS toolbar button added #12
- QGIS menu item renamed
  • Loading branch information
tomchadwin committed Apr 27, 2015
1 parent e4c5c34 commit 3193e7d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 37 deletions.
90 changes: 90 additions & 0 deletions basemaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
qgis2leaf @ Social Planing Council of the City of Ottawa
A QGIS plugin
QGIS to Leaflet creation programm
-------------------
begin : 2014-04-29
copyright : (C) 2013 by Riccardo Klinger
email : riccardo.klinger@geolicious.com
***************************************************************************/
/***************************************************************************
INSTRUCTION ON FILE USAGE:
***************************************************************************/
"""
# To add a line to the layer list you might use this dictionary python variable.
# its first element is the basemap service name which will be displayed in the GUI
# The second entry marked with "META" is the metadata for the leaflet. pleasy
# respect copyrights and licenses
# After you've added a basemap service, the plugin needs to be reinstalled.
#
"""
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""


def basemapAddresses():
dictionary = {
'OSM Standard':'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
'OSM Black & White':'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png',
'Stamen Toner':'http://a.tile.stamen.com/toner/{z}/{x}/{y}.png',
'OSM DE':'http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
'OSM HOT':'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
'OpenSeaMap':'http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png',
'Thunderforest Cycle':'http://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png',
'Thunderforest Transport':'http://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png',
'Thunderforest Landscape':'http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png',
'Thunderforest Outdoors':'http://{s}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png',
'OpenMapSurfer Roads':'http://openmapsurfer.uni-hd.de/tiles/roads/x={x}&y={y}&z={z}',
'OpenMapSurfer adminb':'http://openmapsurfer.uni-hd.de/tiles/adminb/x={x}&y={y}&z={z}',
'OpenMapSurfer roadsg':'http://openmapsurfer.uni-hd.de/tiles/roadsg/x={x}&y={y}&z={z}',
'MapQuestOpen OSM':'http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg',
'MapQuestOpen Aerial':'http://otile1.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg',
'Stamen Terrain':'http://a.tile.stamen.com/terrain/{z}/{x}/{y}.png',
'Stamen Watercolor':'http://a.tile.stamen.com/watercolor/{z}/{x}/{y}.png',
'OpenWeatherMap Clouds':'http://{s}.tile.openweathermap.org/map/clouds/{z}/{x}/{y}.png',
'OpenWeatherMap Precipitation':'http://{s}.tile.openweathermap.org/map/precipitation/{z}/{x}/{y}.png',
'OpenWeatherMap Rain':'http://{s}.tile.openweathermap.org/map/rain/{z}/{x}/{y}.png',
'OpenWeatherMap Pressure':'http://{s}.tile.openweathermap.org/map/pressure/{z}/{x}/{y}.png',
'OpenWeatherMap Wind':'http://{s}.tile.openweathermap.org/map/wind/{z}/{x}/{y}.png',
'OpenWeatherMap Temp':'http://{s}.tile.openweathermap.org/map/temp/{z}/{x}/{y}.png',
'OpenWeatherMap Snow':'http://{s}.tile.openweathermap.org/map/snow/{z}/{x}/{y}.png'
}
return dictionary

def basemapAttributions():
dictionary = {
'OSM Standard':'&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'OSM Black & White':'&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'Stamen Toner':'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'OSM DE':'&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'OSM HOT':'&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>',
'OpenSeaMap':'Map data: &copy; <a href="http://www.openseamap.org">OpenSeaMap</a> contributors',
'Thunderforest Cycle':'&copy; <a href="http://www.opencyclemap.org">OpenCycleMap</a>, &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'Thunderforest Transport':'&copy; <a href="http://www.opencyclemap.org">OpenCycleMap</a>, &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'Thunderforest Landscape':'&copy; <a href="http://www.opencyclemap.org">OpenCycleMap</a>, &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'Thunderforest Outdoors':'&copy; <a href="http://www.opencyclemap.org">OpenCycleMap</a>, &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'OpenMapSurfer Roads':'Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> &mdash; Map data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'OpenMapSurfer adminb':'Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> &mdash; Map data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'OpenMapSurfer roadsg':'Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> &mdash; Map data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'MapQuestOpen OSM':'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> &mdash; Map data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'MapQuestOpen Aerial':'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> &mdash; Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency',
'Stamen Terrain':'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'Stamen Watercolor':'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'OpenWeatherMap Clouds':'Map data &copy; <a href="http://openweathermap.org">OpenWeatherMap</a>',
'OpenWeatherMap Precipitation':'Map data &copy; <a href="http://openweathermap.org">OpenWeatherMap</a>',
'OpenWeatherMap Rain':'Map data &copy; <a href="http://openweathermap.org">OpenWeatherMap</a>',
'OpenWeatherMap Pressure':'Map data &copy; <a href="http://openweathermap.org">OpenWeatherMap</a>',
'OpenWeatherMap Wind':'Map data &copy; <a href="http://openweathermap.org">OpenWeatherMap</a>',
'OpenWeatherMap Temp':'Map data &copy; <a href="http://openweathermap.org">OpenWeatherMap</a>',
'OpenWeatherMap Snow':'Map data &copy; <a href="http://openweathermap.org">OpenWeatherMap</a>'
}
return dictionary
28 changes: 24 additions & 4 deletions configparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,30 @@ def getTemplates():
"Appearance":{
"Add layers list": True,
"Base layer": (
"OSM",
"MapQuest",
"Stamen watercolor",
"Stamen toner"
"OSM Standard",
"OSM Black & White",
"Stamen Toner",
"OSM DE",
"OSM HOT",
"OpenSeaMap",
"Thunderforest Cycle",
"Thunderforest Transport",
"Thunderforest Landscape",
"Thunderforest Outdoors",
"OpenMapSurfer Roads",
"OpenMapSurfer adminb",
"OpenMapSurfer roadsg",
"MapQuestOpen OSM",
"MapQuestOpen Aerial",
"Stamen Terrain",
"Stamen Watercolor",
"OpenWeatherMap Clouds",
"OpenWeatherMap Precipitation",
"OpenWeatherMap Rain",
"OpenWeatherMap Pressure",
"OpenWeatherMap Wind",
"OpenWeatherMap Temp",
"OpenWeatherMap Snow"
),
"Add scale bar": True,
"Show popups on hover": False,
Expand Down
42 changes: 15 additions & 27 deletions leafletWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
import fileinput
import webbrowser #to open the made map directly in your browser
import sys #to use another print command without annoying newline characters
from basemaps import basemapAddresses, basemapAttributions


basemapAddresses = basemapAddresses()
basemapAttributions = basemapAttributions()

def layerstyle_single(layer):
return color_code

def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress, width, height, full, layer_list, visible, opacity_raster, cluster_set, webpage_name, webmap_head,webmap_subhead, legend, locate, address, labels, labelhover, matchCRS, selected, json, params):
def writeLeaflet(outputProjectFileName, width, height, full, layer_list, visible, opacity_raster, cluster_set, webpage_name, webmap_head,webmap_subhead, legend, locate, address, labels, labelhover, matchCRS, selected, json, params):
# supply path to where is your qgis installed
#QgsApplication.setPrefixPath("/path/to/qgis/installation", True)

Expand Down Expand Up @@ -90,9 +92,11 @@ def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress
os.makedirs(miscStore)

extent = params["Scale/Zoom"]["Extent"]
print extent
minZoom = params["Scale/Zoom"]["Min zoom level"]
maxZoom = params["Scale/Zoom"]["Max zoom level"]
basemapName = params["Appearance"]["Base layer"]


#lets create a css file for own css:
with open(cssStore + 'own_style.css', 'w') as f_css:
text = """
Expand Down Expand Up @@ -254,7 +258,6 @@ def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress
processing.runalg("gdalogr:translate",prov_raster,100,True,"",0,"",extentRepNew,False,0,0,75,6,1,False,0,False,"",out_raster)
else:
print "Not JSON (" + i.providerType() + "): " + rawLayerName

#now determine the canvas bounding box
#####now with viewcontrol
if extent == "Canvas extent":
Expand Down Expand Up @@ -288,15 +291,13 @@ def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress
worldCopyJump: false, """
middle += """
zoomControl:true, maxZoom:""" + unicode(maxZoom) + """, minZoom:""" + unicode(minZoom) + """
}).fitBounds(""" + bounds + """);
var hash = new L.Hash(map);
var additional_attrib = 'created w. <a href="https://github.com/geolicious/qgis2leaf" target ="_blank">qgis2leaf</a> by <a href="http://www.geolicious.de" target ="_blank">Geolicious</a> & contributors<br>';"""
var additional_attrib = '<a href="https://github.com/tomchadwin/qgis2web" target ="_blank">qgis2web</a>';"""
if extent == 'Fit to layers extent':
middle = """
<script>
"""

if matchCRS == True and crsAuthId != 'EPSG:4326':
print '>> ' + crsProj4
middle += """
Expand All @@ -306,29 +307,22 @@ def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress
middle += """
var map = L.map('map', { zoomControl:true, maxZoom:19 });
var hash = new L.Hash(map); //add hashes to html address to easy share locations
var additional_attrib = 'created with <a href="https://github.com/geolicious/qgis2leaf" target ="_blank">qgis2leaf</a> by <a href="http://www.geolicious.de" target ="_blank">Geolicious</a> & contributors<br>';"""
var additional_attrib = '<a href="https://github.com/tomchadwin/qgis2web" target ="_blank">qgis2web</a>';"""
# we will start with the clustergroup
middle += """
var feature_group = new L.featureGroup([]);
var raster_group = new L.LayerGroup([]);"""
#here come the basemap (variants list thankfully provided by: "https://github.com/leaflet-extras/leaflet-providers") our geojsons will looped after that
#basemap name
if basemapName == 0 or matchCRS == True:
if basemapName == 0 or basemapName == "" or matchCRS == True:
basemapText = ""
else:
basemapText = ""
for l in range(0,len(basemapAddress)):
print basemapAddress[l]
basemapText += """
var basemap_""" + str(l) +""" = L.tileLayer('""" + basemapAddress[l] + """', {
attribution: additional_attrib + '""" + str(basemapMeta[l]) + """'
basemapText = """
var basemap = L.tileLayer('""" + basemapAddresses[basemapName] + """', {
attribution: additional_attrib + ' """ + basemapAttributions[basemapName] + """'
});"""
#attribution
# basemapText += """
#map.attributionControl.addAttribution(additional_attrib + '""" + basemapMeta + """');"""
if l == 0:
basemapText += """
basemap_""" + str(l)+""".addTo(map);"""
basemapText += """
basemap.addTo(map);"""
layerOrder = """
var layerOrder=new Array();
function restackLayers() {
Expand Down Expand Up @@ -441,7 +435,6 @@ def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress
var exp_""" + safeLayerName + """JSON = new L.geoJson(exp_""" + safeLayerName + """,{
onEachFeature: pop_""" + safeLayerName + "," + pointToLayer_str + """
}
});
layerOrder[layerOrder.length] = exp_"""+safeLayerName+"""JSON;"""
#add points to the cluster group
Expand Down Expand Up @@ -567,13 +560,11 @@ def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, doStyle""" + layerName + """(feature))"""+labeltext+"""
}
});
layerOrder[layerOrder.length] = exp_"""+safeLayerName+"""JSON;"""
#add points to the cluster group
if cluster_set[count] == True:


new_obj += """
var cluster_group"""+ safeLayerName + """JSON= new L.MarkerClusterGroup({showCoverageOnHover: false});
cluster_group"""+ safeLayerName + """JSON.addLayer(exp_""" + safeLayerName + """JSON);"""
Expand Down Expand Up @@ -711,7 +702,6 @@ def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, doStyle""" + safeLayerName + """(feature))"""+labeltext+"""
}
});
layerOrder[layerOrder.length] = exp_"""+safeLayerName+"""JSON;"""
#add points to the cluster group
Expand Down Expand Up @@ -1113,7 +1103,6 @@ def writeLeaflet(outputProjectFileName, basemapName, basemapMeta, basemapAddress
end += """
map.fitBounds(feature_group.getBounds());"""
else:

end += """
L.control.scale({options: {position: 'bottomleft',maxWidth: 100,metric: true,imperial: false,updateWhenIdle: false}}).addTo(map);"""
end += """
Expand Down Expand Up @@ -1159,7 +1148,6 @@ def buildNonPointJSON(categoryStr, safeLayerName):
var exp_""" + safeLayerName + """JSON = new L.geoJson(exp_""" + safeLayerName + """,{
onEachFeature: pop_""" + safeLayerName + """,
style: doStyle""" + safeLayerName + """
});
layerOrder[layerOrder.length] = exp_"""+safeLayerName+"""JSON;"""
return new_obj
Expand Down
2 changes: 1 addition & 1 deletion maindialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def saveLeaf(self):
if folder:
layers, groups, popup, visible, json, cluster = self.getLayersAndGroups()
params = self.getParameters()
writeLeaflet("index.html", "", "", "", 600, 400, "", layers, "show all", "", cluster, "", "", "", "", "", "", "", "", 0, 0, json, params)
writeLeaflet("index.html", 600, 400, "", layers, "show all", "", cluster, "", "", "", "", "", "", "", "", 0, 0, json, params)
reply = QMessageBox.question(self, "Leaflet map correctly exported",
"Do you want to open the resulting map in a web browser?",
QMessageBox.Yes | QMessageBox.No)
Expand Down
8 changes: 5 additions & 3 deletions metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name=qgis2web
qgisMinimumVersion=2.0
description=Creates web map from QGIS layers
version=0.1.0
version=0.2.0
author=Tom Chadwin
email=tom.chadwin@nnpa.org.uk

Expand All @@ -21,10 +21,12 @@ email=tom.chadwin@nnpa.org.uk
# Optional items:

# Uncomment the following line and add your changelog entries:
changelog= 2015/04/25 0.1.0 Extent, precision, min/maxZoom, clustering, JSON-encode, layer order in Leaflet export
changelog= 2015/04/27 0.2.0 Basemap in Leaflet export, additional basemaps from qgis2leaf, icons fixed, toolbar icon added, QGIS menu item renamed
2015/04/25 0.1.0 Extent, precision, min/maxZoom, clustering, JSON-encode, layer order in Leaflet export
2015/04/23 0.0.1 Initial release
# tags are comma separated with spaces allowed
tags=
tags=web, webmap, webmaps, Leaflet, OpenLayers, OL3, HTML, Javascript, CSS, export


homepage=https://github.com/tomchadwin/qgis2web
tracker=https://github.com/tomchadwin/qgis2web/issues
Expand Down
6 changes: 4 additions & 2 deletions qgis2web.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ def initGui(self):
u"Create web map", self.iface.mainWindow())
self.action.triggered.connect(self.run)

self.iface.addPluginToWebMenu(u"&Export web map", self.action)
self.iface.addPluginToWebMenu(u"&qgis2web", self.action)
self.iface.addToolBarIcon(self.action)

def unload(self):
self.iface.removePluginWebMenu(u"&Export web map", self.action)
self.iface.removePluginWebMenu(u"&qgis2web", self.action)
self.iface.removeToolBarIcon(self.action)

def run(self):
dlg = MainDialog()
Expand Down

0 comments on commit 3193e7d

Please sign in to comment.