Exemple #1
0
    def writeOL(cls, iface, feedback, layers, groups, popup, visible, json,
                clustered, getFeatureInfo, settings, folder):
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        mapSettings = iface.mapCanvas().mapSettings()
        controlCount = 0
        stamp = datetime.now().strftime("%Y_%m_%d-%H_%M_%S_%f")
        folder = os.path.join(folder, 'qgis2web_' + unicode(stamp))
        restrictToExtent = settings["Scale/Zoom"]["Restrict to extent"]
        matchCRS = settings["Appearance"]["Match project CRS"]
        precision = settings["Data export"]["Precision"]
        optimize = settings["Data export"]["Minify GeoJSON files"]
        debugLibs = settings["Data export"]["Use debug libraries"]
        extent = settings["Scale/Zoom"]["Extent"]
        mapbounds = bounds(iface, extent == "Canvas extent", layers, matchCRS)
        fullextent = bounds(iface, False, layers, matchCRS)
        geolocateUser = settings["Appearance"]["Geolocate user"]
        maxZoom = int(settings["Scale/Zoom"]["Max zoom level"])
        minZoom = int(settings["Scale/Zoom"]["Min zoom level"])
        popupsOnHover = settings["Appearance"]["Show popups on hover"]
        highlightFeatures = settings["Appearance"]["Highlight on hover"]
        geocode = settings["Appearance"]["Add address search"]
        measureTool = settings["Appearance"]["Measure tool"]
        addLayersList = settings["Appearance"]["Add layers list"]
        htmlTemplate = settings["Appearance"]["Template"]
        layerSearch = unicode(settings["Appearance"]["Layer search"])
        searchLayer = settings["Appearance"]["Search layer"]
        mapLibLocn = settings["Data export"]["Mapping library location"]

        writeFiles(folder, restrictToExtent, feedback, debugLibs)
        exportLayers(iface, layers, folder, precision, optimize, popup, json,
                     restrictToExtent, extent, feedback, matchCRS)
        mapUnitsLayers = exportStyles(layers, folder, clustered)
        mapUnitLayers = getMapUnitLayers(mapUnitsLayers)
        osmb = writeLayersAndGroups(layers, groups, visible, folder, popup,
                                    settings, json, matchCRS, clustered,
                                    getFeatureInfo, iface, restrictToExtent,
                                    extent, mapbounds,
                                    mapSettings.destinationCrs().authid())
        (jsAddress, cssAddress, layerSearch,
         controlCount) = writeHTMLstart(settings, controlCount, osmb,
                                        mapLibLocn, layerSearch, searchLayer,
                                        feedback, debugLibs)
        (geojsonVars, wfsVars,
         styleVars) = writeScriptIncludes(layers, json, matchCRS)
        popupLayers = "popupLayers = [%s];" % ",".join(
            ['1' for field in popup])
        project = QgsProject.instance()
        controls = getControls(project, measureTool, geolocateUser)
        layersList = getLayersList(addLayersList)
        pageTitle = project.title()
        backgroundColor = getBackground(mapSettings)
        (geolocateCode, controlCount) = geolocateStyle(geolocateUser,
                                                       controlCount)
        backgroundColor += geolocateCode
        mapextent = "extent: %s," % mapbounds if restrictToExtent else ""
        onHover = unicode(popupsOnHover).lower()
        highlight = unicode(highlightFeatures).lower()
        highlightFill = mapSettings.selectionColor().name()
        (proj, proj4, view) = getCRSView(mapextent, fullextent, maxZoom,
                                         minZoom, matchCRS, mapSettings)
        (measureControl, measuring, measure, measureUnit, measureStyle,
         controlCount) = getMeasure(measureTool, controlCount)
        geolocateHead = geolocationHead(geolocateUser)
        geolocate = geolocation(geolocateUser)
        geocodingLinks = geocodeLinks(geocode)
        geocodingJS = geocodeJS(geocode)
        geocodingScript = geocodeScript(geocode)
        m2px = getM2px(mapUnitsLayers)
        (extracss, controlCount) = getCSS(geocode, geolocateUser, controlCount)
        ol3layerswitcher = getLayerSwitcher()
        ol3popup = getPopup()
        ol3qgis2webjs = getJS(osmb)
        ol3layers = getLayers()
        mapSize = iface.mapCanvas().size()
        exp_js = getExpJS()
        grid = getGrid(project)
        values = {
            "@PAGETITLE@": pageTitle,
            "@CSSADDRESS@": cssAddress,
            "@EXTRACSS@": extracss,
            "@JSADDRESS@": jsAddress,
            "@MAP_WIDTH@": unicode(mapSize.width()) + "px",
            "@MAP_HEIGHT@": unicode(mapSize.height()) + "px",
            "@OL3_STYLEVARS@": styleVars,
            "@OL3_BACKGROUNDCOLOR@": backgroundColor,
            "@OL3_POPUP@": ol3popup,
            "@OL3_GEOJSONVARS@": geojsonVars,
            "@OL3_WFSVARS@": wfsVars,
            "@OL3_PROJ4@": proj4,
            "@OL3_PROJDEF@": proj,
            "@OL3_GEOCODINGLINKS@": geocodingLinks,
            "@OL3_GEOCODINGJS@": geocodingJS,
            "@QGIS2WEBJS@": ol3qgis2webjs,
            "@OL3_LAYERSWITCHER@": ol3layerswitcher,
            "@OL3_LAYERS@": ol3layers,
            "@OL3_MEASURESTYLE@": measureStyle,
            "@EXP_JS@": exp_js,
            "@LEAFLET_ADDRESSCSS@": "",
            "@LEAFLET_MEASURECSS@": "",
            "@LEAFLET_EXTRAJS@": "",
            "@LEAFLET_ADDRESSJS@": "",
            "@LEAFLET_MEASUREJS@": "",
            "@LEAFLET_CRSJS@": "",
            "@LEAFLET_LAYERSEARCHCSS@": "",
            "@LEAFLET_LAYERSEARCHJS@": "",
            "@LEAFLET_CLUSTERCSS@": "",
            "@LEAFLET_CLUSTERJS@": ""
        }
        with open(os.path.join(folder, "index.html"), "w") as f:
            htmlTemplate = htmlTemplate
            if htmlTemplate == "":
                htmlTemplate = "basic"
            templateOutput = replaceInTemplate(htmlTemplate + ".html", values)
            templateOutput = re.sub('\n[\s_]+\n', '\n', templateOutput)
            f.write(templateOutput)
        values = {
            "@GEOLOCATEHEAD@": geolocateHead,
            "@BOUNDS@": mapbounds,
            "@CONTROLS@": ",".join(controls),
            "@LAYERSLIST@": layersList,
            "@POPUPLAYERS@": popupLayers,
            "@VIEW@": view,
            "@LAYERSEARCH@": layerSearch,
            "@ONHOVER@": onHover,
            "@DOHIGHLIGHT@": highlight,
            "@HIGHLIGHTFILL@": highlightFill,
            "@GEOLOCATE@": geolocate,
            "@GEOCODINGSCRIPT@": geocodingScript,
            "@MEASURECONTROL@": measureControl,
            "@MEASURING@": measuring,
            "@MEASURE@": measure,
            "@MEASUREUNIT@": measureUnit,
            "@GRID@": grid,
            "@M2PX@": m2px,
            "@MAPUNITLAYERS@": mapUnitLayers
        }
        with open(os.path.join(folder, "resources", "qgis2web.js"), "w") as f:
            out = replaceInScript("qgis2web.js", values)
            f.write(out)
        QApplication.restoreOverrideCursor()
        return os.path.join(folder, "index.html")
Exemple #2
0
    def writeOL(cls, iface, feedback, layers, groups, popup, visible,
                json, clustered, getFeatureInfo, settings, folder):
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        mapSettings = iface.mapCanvas().mapSettings()
        controlCount = 0
        stamp = datetime.now().strftime("%Y_%m_%d-%H_%M_%S_%f")
        folder = os.path.join(folder, 'qgis2web_' + unicode(stamp))
        restrictToExtent = settings["Scale/Zoom"]["Restrict to extent"]
        matchCRS = settings["Appearance"]["Match project CRS"]
        precision = settings["Data export"]["Precision"]
        optimize = settings["Data export"]["Minify GeoJSON files"]
        debugLibs = settings["Data export"]["Use debug libraries"]
        extent = settings["Scale/Zoom"]["Extent"]
        mapbounds = bounds(iface, extent == "Canvas extent", layers, matchCRS)
        fullextent = bounds(iface, False, layers, matchCRS)
        geolocateUser = settings["Appearance"]["Geolocate user"]
        maxZoom = int(settings["Scale/Zoom"]["Max zoom level"])
        minZoom = int(settings["Scale/Zoom"]["Min zoom level"])
        popupsOnHover = settings["Appearance"]["Show popups on hover"]
        highlightFeatures = settings["Appearance"]["Highlight on hover"]
        geocode = settings["Appearance"]["Add address search"]
        measureTool = settings["Appearance"]["Measure tool"]
        addLayersList = settings["Appearance"]["Add layers list"]
        htmlTemplate = settings["Appearance"]["Template"]
        layerSearch = unicode(settings["Appearance"]["Layer search"])
        searchLayer = settings["Appearance"]["Search layer"]
        mapLibLocn = settings["Data export"]["Mapping library location"]

        writeFiles(folder, restrictToExtent, feedback, debugLibs)
        exportLayers(iface, layers, folder, precision, optimize,
                     popup, json, restrictToExtent, extent, feedback, matchCRS)
        mapUnitsLayers = exportStyles(layers, folder, clustered)
        mapUnitLayers = getMapUnitLayers(mapUnitsLayers)
        osmb = writeLayersAndGroups(layers, groups, visible, folder, popup,
                                    settings, json, matchCRS, clustered,
                                    getFeatureInfo, iface, restrictToExtent,
                                    extent, mapbounds,
                                    mapSettings.destinationCrs().authid())
        (jsAddress, cssAddress, layerSearch,
         controlCount) = writeHTMLstart(settings, controlCount, osmb,
                                        mapLibLocn, layerSearch, searchLayer,
                                        feedback, debugLibs)
        (geojsonVars, wfsVars, styleVars) = writeScriptIncludes(layers,
                                                                json, matchCRS)
        popupLayers = "popupLayers = [%s];" % ",".join(
            ['1' for field in popup])
        project = QgsProject.instance()
        controls = getControls(project, measureTool, geolocateUser)
        layersList = getLayersList(addLayersList)
        pageTitle = project.title()
        backgroundColor = getBackground(mapSettings)
        (geolocateCode, controlCount) = geolocateStyle(geolocateUser,
                                                       controlCount)
        backgroundColor += geolocateCode
        mapextent = "extent: %s," % mapbounds if restrictToExtent else ""
        onHover = unicode(popupsOnHover).lower()
        highlight = unicode(highlightFeatures).lower()
        highlightFill = mapSettings.selectionColor().name()
        (proj, proj4, view) = getCRSView(mapextent, fullextent, maxZoom,
                                         minZoom, matchCRS, mapSettings)
        (measureControl, measuring, measure, measureUnit, measureStyle,
         controlCount) = getMeasure(measureTool, controlCount)
        geolocateHead = geolocationHead(geolocateUser)
        geolocate = geolocation(geolocateUser)
        geocodingLinks = geocodeLinks(geocode)
        geocodingJS = geocodeJS(geocode)
        geocodingScript = geocodeScript(geocode)
        m2px = getM2px(mapUnitsLayers)
        (extracss, controlCount) = getCSS(geocode, geolocateUser, controlCount)
        ol3layerswitcher = getLayerSwitcher()
        ol3popup = getPopup()
        ol3qgis2webjs = getJS(osmb)
        ol3layers = getLayers()
        mapSize = iface.mapCanvas().size()
        exp_js = getExpJS()
        grid = getGrid(project)
        values = {"@PAGETITLE@": pageTitle,
                  "@CSSADDRESS@": cssAddress,
                  "@EXTRACSS@": extracss,
                  "@JSADDRESS@": jsAddress,
                  "@MAP_WIDTH@": unicode(mapSize.width()) + "px",
                  "@MAP_HEIGHT@": unicode(mapSize.height()) + "px",
                  "@OL3_STYLEVARS@": styleVars,
                  "@OL3_BACKGROUNDCOLOR@": backgroundColor,
                  "@OL3_POPUP@": ol3popup,
                  "@OL3_GEOJSONVARS@": geojsonVars,
                  "@OL3_WFSVARS@": wfsVars,
                  "@OL3_PROJ4@": proj4,
                  "@OL3_PROJDEF@": proj,
                  "@OL3_GEOCODINGLINKS@": geocodingLinks,
                  "@OL3_GEOCODINGJS@": geocodingJS,
                  "@QGIS2WEBJS@": ol3qgis2webjs,
                  "@OL3_LAYERSWITCHER@": ol3layerswitcher,
                  "@OL3_LAYERS@": ol3layers,
                  "@OL3_MEASURESTYLE@": measureStyle,
                  "@EXP_JS@": exp_js,
                  "@LEAFLET_ADDRESSCSS@": "",
                  "@LEAFLET_MEASURECSS@": "",
                  "@LEAFLET_EXTRAJS@": "",
                  "@LEAFLET_ADDRESSJS@": "",
                  "@LEAFLET_MEASUREJS@": "",
                  "@LEAFLET_CRSJS@": "",
                  "@LEAFLET_LAYERSEARCHCSS@": "",
                  "@LEAFLET_LAYERSEARCHJS@": "",
                  "@LEAFLET_CLUSTERCSS@": "",
                  "@LEAFLET_CLUSTERJS@": ""}
        with open(os.path.join(folder, "index.html"), "w") as f:
            htmlTemplate = htmlTemplate
            if htmlTemplate == "":
                htmlTemplate = "full-screen"
            templateOutput = replaceInTemplate(
                htmlTemplate + ".html", values)
            templateOutput = re.sub(r'\n[\s_]+\n', '\n', templateOutput)
            f.write(templateOutput)
        values = {"@GEOLOCATEHEAD@": geolocateHead,
                  "@BOUNDS@": mapbounds,
                  "@CONTROLS@": ",".join(controls),
                  "@LAYERSLIST@": layersList,
                  "@POPUPLAYERS@": popupLayers,
                  "@VIEW@": view,
                  "@LAYERSEARCH@": layerSearch,
                  "@ONHOVER@": onHover,
                  "@DOHIGHLIGHT@": highlight,
                  "@HIGHLIGHTFILL@": highlightFill,
                  "@GEOLOCATE@": geolocate,
                  "@GEOCODINGSCRIPT@": geocodingScript,
                  "@MEASURECONTROL@": measureControl,
                  "@MEASURING@": measuring,
                  "@MEASURE@": measure,
                  "@MEASUREUNIT@": measureUnit,
                  "@GRID@": grid,
                  "@M2PX@": m2px,
                  "@MAPUNITLAYERS@": mapUnitLayers}
        with open(os.path.join(folder, "resources", "qgis2web.js"),
                  "w") as f:
            out = replaceInScript("qgis2web.js", values)
            f.write(out)
        QApplication.restoreOverrideCursor()
        return os.path.join(folder, "index.html")