[GIS] How to load html file with leaflet map using PyQGIS

htmlleafletpyqgisqgis

I have a simple HTML file with Leaflet map layers. I want to load these layers in QGIS Map Canvas with the ability to choose one of the layers.

How can I load this HTML and show one of map layers with using python (QGIS plugin)?

This is an example of my HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Leaflet Map Template</title>`
    <link rel="stylesheet" 
          href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />      
</head>
<body>
    <style>
        body { padding: 0; margin: 0; }
        html, body, #map { height: 100%; width: 100%; }
    </style>
    <div id="map"></div>      
    <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script> 
    <script>
        var map = L.map('map', {
            center: [46.239052, 31.638786],
            zoom: 13
        })
        L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',
           {
            attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);
    </script>
</body>
</html>

Best Answer

The Leaflet html file is not a GIS layer and cannot be added to QGIS via pyQGIS. The html does reference various kinds of GIS layers, e.g. geojson, wfs, wms which may be loaded to QGIS via pyQGIS. There are many examples of this on this site and on the web how to add these layers to QGIS via pyQGIS.

Load a GeoJSON layer with QGIS's Python module

http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html