コード例 #1
0
    def processAlgorithm(self, progress):
        """Here is where the processing itself takes place."""

        # The first thing to do is retrieve the values of the parameters
        # entered by the user
        inputFilename = self.getParameterValue(self.INPUT_LAYER)
        inputLayer = dataobjects.getObjectFromUri(inputFilename)
        inputVisible = self.getParameterValue("VISIBLE")

        inputParams = self.getInputs()

        inputMapFormat = self.getParameterValue("MAP_FORMAT")
        writer = self.getWriter(inputMapFormat)

        writer.params = defaultParams
        self.writerParams(writer, inputParams)
        writer.params["Appearance"][
            "Base layer"] = WRITER_REGISTRY.getBasemapsFromProject()
        writer.layers = [inputLayer]
        writer.groups = {}
        writer.popup = [False]
        writer.visible = [inputVisible]
        writer.json = [False]
        writer.cluster = [False]
        exporter = EXPORTER_REGISTRY.createFromProject()
        write_folder = exporter.exportDirectory()
        writer.write(iface, write_folder)
コード例 #2
0
 def exporterTypeChanged(self):
     new_exporter_name = self.exporter_combo.currentText()
     try:
         self.exporter = [
             e for e in EXPORTER_REGISTRY.getExporters()
             if e.name() == new_exporter_name][0]()
     except:
         pass
コード例 #3
0
ファイル: configparams.py プロジェクト: maellson/qgis2web
def getParams(configure_exporter_action=None):
    params = {
        "Appearance": {
            "Add layers list": ("None", "Collapsed", "Expanded"),
            "Match project CRS": False,
            "Add address search": False,
            "Layer search": ("None", "placeholder"),
            "Measure tool": ("None", "Metric", "Imperial"),
            "Show popups on hover": False,
            "Highlight on hover": False,
            "Geolocate user": False,
            "Template": getTemplates()
        },
        "Data export": {
            "Precision": ("maintain", "1", "2", "3", "4", "5", "6", "7", "8",
                          "9", "10", "11", "12", "13", "14", "15"),
            "Minify GeoJSON files":
            True,
            "Mapping library location": ("Local", "CDN"),
            "Use debug libraries":
            False
        },
        "Scale/Zoom": {
            "Extent": ("Canvas extent", "Fit to layers extent"),
            "Restrict to extent":
            False,
            "Max zoom level":
            ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
             "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23",
             "24", "25", "26", "27", "28"),
            "Min zoom level":
            ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
             "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23",
             "24", "25", "26", "27", "28"),
        }
    }

    if configure_exporter_action:
        params["Data export"]["Exporter"] = {
            'option': EXPORTER_REGISTRY.getOptions(),
            'action': configure_exporter_action
        }
    else:
        params["Data export"]["Exporter"] = EXPORTER_REGISTRY.getOptions()

    return params
コード例 #4
0
    def processAlgorithm(self, progress):
        """Here is where the processing itself takes place."""

        writer = WRITER_REGISTRY.createWriterFromProject()
        (writer.layers, writer.groups, writer.popup, writer.visible,
         writer.json, writer.cluster) = self.getLayersAndGroups()
        exporter = EXPORTER_REGISTRY.createFromProject()
        write_folder = exporter.exportDirectory()
        writer.write(iface, write_folder)
コード例 #5
0
    def processAlgorithm(self, progress):
        """Here is where the processing itself takes place."""

        # The first thing to do is retrieve the values of the parameters
        # entered by the user
        inputFilename = self.getParameterValue(self.INPUT_LAYER)
        inputLayer = dataobjects.getObjectFromUri(inputFilename)
        inputVisible = self.getParameterValue("VISIBLE")
        inputCluster = self.getParameterValue("CLUSTER")
        inputPopup = self.getParameterValue("POPUP")

        popupList = []
        fields = inputPopup.split(",")
        for field in fields:
            fieldList = []
            print field
            k, v = field.split(":")
            fieldList.append(k.strip())
            fieldList.append(v.strip())
            popupList.append(tuple(fieldList))

        inputParams = self.getInputs()

        inputMapFormat = self.getParameterValue("MAP_FORMAT")
        writer = self.getWriter(inputMapFormat)

        # Input layers vales are always a string with its location.
        # That string can be converted into a QGIS object (a
        # QgsVectorLayer in this case) using the
        # processing.getObjectFromUri() method.

        writer.params = defaultParams
        self.writerParams(writer, inputParams)
        writer.params["Appearance"][
            "Base layer"] = WRITER_REGISTRY.getBasemapsFromProject()
        writer.layers = [inputLayer]
        writer.groups = {}
        writer.popup = [OrderedDict(popupList)]
        writer.visible = [inputVisible]
        writer.json = [True]
        writer.cluster = [inputCluster]
        exporter = EXPORTER_REGISTRY.createFromProject()
        write_folder = exporter.exportDirectory()
        writer.write(iface, write_folder)
コード例 #6
0
    def test05_RegistrySaveReadFromProject(self):
        """ test saving and restoring current exporter in project"""
        e = FolderExporter()
        e.folder = '/my_folder'
        EXPORTER_REGISTRY.writeToProject(e)

        restored = EXPORTER_REGISTRY.createFromProject()
        self.assertEqual(type(restored), FolderExporter)
        self.assertEqual(restored.exportDirectory(), '/my_folder')

        # try with a non-folder exporter
        f = FtpExporter()
        EXPORTER_REGISTRY.writeToProject(f)
        restored = EXPORTER_REGISTRY.createFromProject()
        self.assertEqual(type(restored), FtpExporter)
コード例 #7
0
ファイル: maindialog.py プロジェクト: giohappy/qgis2web
    def __init__(self, iface):
        QDialog.__init__(self)
        self.setupUi(self)
        self.iface = iface

        self.previewUrl = None
        self.layer_search_combo = None
        self.exporter_combo = None

        stgs = QSettings()

        self.restoreGeometry(
            stgs.value("qgis2web/MainDialogGeometry",
                       QByteArray(),
                       type=QByteArray))

        if stgs.value("qgis2web/previewOnStartup", Qt.Checked) == Qt.Checked:
            self.previewOnStartup.setCheckState(Qt.Checked)
        else:
            self.previewOnStartup.setCheckState(Qt.Unchecked)
        self.paramsTreeOL.setSelectionMode(QAbstractItemView.SingleSelection)
        self.preview = None
        if webkit_available:
            widget = QWebView()
            self.preview = widget
            webview = self.preview.page()
            webview.setNetworkAccessManager(QgsNetworkAccessManager.instance())
            self.preview.settings().setAttribute(
                QWebSettings.DeveloperExtrasEnabled, True)
        else:
            widget = QTextBrowser()
            widget.setText(
                self.tr('Preview is not available since QtWebKit '
                        'dependency is missing on your system'))
        self.right_layout.insertWidget(0, widget)
        self.populateConfigParams(self)
        self.populate_layers_and_groups(self)
        self.populateLayerSearch()
        self.populateBasemaps()

        writer = WRITER_REGISTRY.createWriterFromProject()
        self.setStateToWriter(writer)

        self.exporter = EXPORTER_REGISTRY.createFromProject()
        self.exporter_combo.setCurrentIndex(
            self.exporter_combo.findText(self.exporter.name()))
        self.exporter_combo.currentIndexChanged.connect(
            self.exporterTypeChanged)

        self.toggleOptions()
        if webkit_available:
            if self.previewOnStartup.checkState() == Qt.Checked:
                self.previewMap()
            self.buttonPreview.clicked.connect(self.previewMap)
        else:
            self.buttonPreview.setDisabled(True)
        self.layersTree.model().dataChanged.connect(self.populateLayerSearch)
        self.ol3.clicked.connect(self.changeFormat)
        self.leaflet.clicked.connect(self.changeFormat)
        self.buttonExport.clicked.connect(self.saveMap)
        readme = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                              "README.md")
        helpText = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "helpFile.md")
        lines = open(readme, 'r').readlines()
        with open(helpText, 'w') as helpFile:
            for ct, line in enumerate(lines):
                if ct > 4:
                    helpFile.write(line)
            helpFile.close()
        self.helpField.setSource(QUrl.fromLocalFile(helpText))
        if webkit_available:
            self.devConsole = QWebInspector(self.verticalLayoutWidget_2)
            self.devConsole.setFixedHeight(0)
            self.devConsole.setObjectName("devConsole")
            self.devConsole.setPage(self.preview.page())
            self.right_layout.insertWidget(1, self.devConsole)
        self.filter = devToggleFilter()
        self.installEventFilter(self.filter)
        self.setModal(False)
コード例 #8
0
ファイル: maindialog.py プロジェクト: giohappy/qgis2web
 def saveParameters(self):
     """
     Saves current dialog state to project
     """
     WRITER_REGISTRY.saveWriterToProject(self.createWriter())
     EXPORTER_REGISTRY.writeToProject(self.exporter)
コード例 #9
0
 def test04_RegistryHasExporters(self):
     """test that exporter registry is populated with exporters"""
     self.assertTrue(FolderExporter in EXPORTER_REGISTRY.getExporters())