How to add a Google Maps styled layer in Qgis 2

I have been struggling for days to make a very simple and light base-map of the UK showing town circle markers, town names sized according to their population, a couple of country borders and nothing more than a plain white background for lands above sea-level.

After using numerous data sources (Natural Earth, Ordnance Survey, Open Gazetteers, Open Street Map vectors, OSM-GB WMS layers - none of which worked well) I finally came across an acceptable solution...

...which is to make a Google Maps Styled and to tweak Qgis Openlayers Plugin in order to load such a customised layer.

Firstly, make your styled Google Map. You can find mine on Snazzymaps. It is very easy to make your own, just have a go on the Styled Maps Wizard.

Once you have finished your customisations, export the style Javascript Array and place it as the value of the stylez variable in this Html.

<html xmlns="">
    <title>OpenLayers Google Streets Layer</title>
    <link rel="stylesheet" href="qgis.css" type="text/css">
    <link rel="stylesheet" href="google.css" type="text/css">
    <script src=";sensor=false"></script>
    <script src="OpenLayers.js"></script>
    <script src="OlOverviewMarker.js"></script>
    <script type="text/javascript">
        var map;
        var loadEnd;
        var oloMarker; // OpenLayer Overview Marker
        function init() {
            map = new OpenLayers.Map('map', {
                theme: null,
                controls: [],
                units: "m",
                maxResolution: 156543.0339,
                maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34)

            var stylez = [ { featureType: "all", elementType: "all", stylers: [ { visibility: "simplified" } ] } ];
            var styledMapType = new google.maps.StyledMapType(stylez, styledMapOptions);           
            var gmap = new OpenLayers.Layer.Google(
                "Google Custom",
                { type: 'styled' }
            gmap.mapObject.mapTypes.set('styled', styledMapType);

            loadEnd = false;
  'movestart', map, function() {
                loadEnd = false;
            google.maps.event.addListener(gmap.mapObject, "tilesloaded", function() {
                // wait for tiles to fade in completely
                setTimeout(function() {
                  loadEnd = true;

            map.setCenter(new OpenLayers.LonLat(0, 0), 2);
            oloMarker = new OlOverviewMarker(map, getPathUpper(document.URL) + '/x.png');
  <body onload="init()">
    <div id="map"></div>

Save this code as google_custom.html in this folder:

For the sophisticated users:

After that, enter folder C:\Users\youruser\.qgis2\python\plugins\openlayers_plugin\
and open with a text editor.

Go around line 124, where you find the #Layer comment and add this line to the layers section, just below the Google satellite entry:

    self.olLayerTypeRegistry.add( OlLayerType(self, 'Google Custom', 'google_icon.png', 'google_custom.html', True) )

Save and close the file and restart Qgis. A new Google custom item appears in the Openlayers plugin Menu.


1 comment:

  1. interesting, but it doesnt work on qgis 2.16.1

    cant find #Layer comment