示例#1
0
 def write(self, appdef, folder, app, progress):
     layers = appdef["Layers"]
     collapsed = str(self._parameters["Collapsed"]).lower()
     overviewLayers = ",".join(["lyr_%s" % safeName(layer.layer.name())
                     for layer in layers if layer.showInOverview])
     app.posttarget.append("map.addControl(new ol.control.OverviewMap({collapsed: %s, layers: [overviewMapBaseLayer, %s]}));"
                     % (collapsed, overviewLayers))
 def write(self, appdef, folder, app, progress):
     layerVar = ""
     layers = appdef["Layers"]
     for applayer in layers:
         layer = applayer.layer
         if layer.type() == layer.VectorLayer and applayer.method not in [
                 METHOD_WMS, METHOD_WMS_POSTGIS
         ]:
             layerVar = "lyr_" + safeName(layer.name())
             break
     self.addReactComponent(app, "FeatureTable")
     pointZoom = int(
         self._parameters["Zoom level when zooming to point feature"][0])
     theme = appdef["Settings"]["Theme"]
     if theme == "tabbed":
         idx = len(app.tabs) + 1
         app.tabs.append(
             '''React.createElement(Tab,{value:%i, label:"Attributes table"},
                                 React.createElement(FeatureTable, {ref:"table", layer:%s, pointZoom:%d,
                                 resizeTo:"tabs-panel", offset:[50, 60], map: map})
                             )''' % (idx, layerVar, pointZoom))
     else:
         app.tools.append(
             "React.createElement(RaisedButton, {label: 'Table', style: {margin: '10px 12px'}, onTouchTap: this._toggleTable})"
         )
         app.panels.append(
             ''' React.createElement("div", {id: 'table-panel', className: 'attributes-table'},
                                       React.createElement(FeatureTable, {offset: [20, 20], ref: 'table', resizeTo: 'table-panel', layer: %s, pointZoom:%d, map: map})
                                 )''' % (layerVar, pointZoom))
示例#3
0
    def write(self, appdef, folder, app, progress):
        refresh = []
        for lyr, interval in self._parameters["layers"].iteritems():
            layer = findProjectLayerByName(lyr)
            if layer.dataProvider().name().lower() == "wms":
                refresh.append('''window.setInterval(function(){
                                lyr_%s.getSource().updateParams({'dummy': Math.random()});
                                }, %s);''' % (safeName(lyr), interval))
            else:
                refresh.append('''window.setInterval(function(){
                                lyr_%s.getSource().clear();
                                }, %s);''' % (safeName(lyr), interval))

        if refresh:
            app.posttarget.append('''map.once("postcompose", function(){
                                        %s
                                });''' % "\n".join(refresh))
 def write(self, appdef, folder, app, progress):
     layerVar = ""
     layers = appdef["Layers"]
     for applayer in layers:
         layer = applayer.layer
         if layer.type() == layer.VectorLayer and applayer.method not in [METHOD_WMS, METHOD_WMS_POSTGIS]:
             layerVar = "lyr_" + safeName(layer.name())
             break
     self.addReactComponent(app, "FeatureTable")
     pointZoom = int(self._parameters["Zoom level when zooming to point feature"][0])
     theme = appdef["Settings"]["Theme"]
     if theme == "tabbed":
         idx = len(app.tabs) + 1
         app.tabs.append('''React.createElement(Tab,{value:%i, label:"Attributes table"},
                                 React.createElement(FeatureTable, {ref:"table", layer:%s, pointZoom:%d,
                                 resizeTo:"tabs-panel", offset:[50, 60], map: map})
                             )''' % (idx, layerVar, pointZoom))
     else:
         app.tools.append("React.createElement(RaisedButton, {label: 'Table', style: {margin: '10px 12px'}, onTouchTap: this._toggleTable})")
         app.panels.append(''' React.createElement("div", {id: 'table-panel', className: 'attributes-table'},
                                       React.createElement(FeatureTable, {offset: [20, 20], ref: 'table', resizeTo: 'table-panel', layer: %s, pointZoom:%d, map: map})
                                 )''' % (layerVar, pointZoom))
 def write(self, appdef, folder, app, progress):
     layerVar = ""
     layers = appdef["Layers"]
     for applayer in layers:
         layer = applayer.layer
         if layer.type() == layer.VectorLayer and applayer.method not in [METHOD_WMS, METHOD_WMS_POSTGIS]:
             layerVar = "lyr_" + safeName(layer.name())
             break
     self.addReactComponent(app, "FeatureTable")
     pointZoom = int(self._parameters["Zoom level when zooming to point feature"][0])
     theme = appdef["Settings"]["Theme"]
     if theme == "tabbed":
         idx = len(app.tabs) + 1
         app.tabs.append('''React.createElement(UI.Tab,{eventKey:%i, title:"Attributes table"},
                                 React.createElement(FeatureTable, {ref:"table", layer:%s, pointZoom:%d,
                                 resizeTo:"tabs-panel", offset:[50, 60], map: map})
                             )''' % (idx, layerVar, pointZoom))
     else:
         app.tools.append("{text: 'Table', icon: 'list-alt', onClick: this._toggleTable.bind(this)}")
         app.panels.append(''' React.createElement("div", {id: 'table-panel', className: 'attributes-table'},
                                       React.createElement(FeatureTable, {offset: [20, 20], ref: 'table', resizeTo: 'table-panel', layer: %s, pointZoom:%d, map: map})
                                 )''' % (layerVar, pointZoom))
    def writePrintFiles(self, appdef, folder, app, progress):
        progress.setText("Writing print layout files")
        progress.setProgress(0)
        printFolder = os.path.join(folder, "resources", "print")
        if not QDir(printFolder).exists():
            QDir().mkpath(printFolder)
        dpis = [72, 150, 300]
        layoutDefs = []
        def getBasicInfo(item):
            coords = {}
            pos = item.pos()
            coords["x"] = pos.x()
            coords["y"] = pos.y()
            rect = item.rect()
            coords["width"] = rect.width()
            coords["height"] = rect.height()
            coords["id"] = str(uuid.uuid4())
            return coords
        composers = iface.activeComposers()
        for i, composer in enumerate(composers):
            name = composer.composerWindow().windowTitle()
            layoutSafeName = safeName(name)
            layoutDef = {}
            composition = composer.composition()
            img = composition.printPageAsRaster(0)
            img = img.scaledToHeight(100, Qt.SmoothTransformation)
            img.save(os.path.join(printFolder, "%s_thumbnail.png" % layoutSafeName))
            layoutDef["width"] = composition.paperWidth()
            layoutDef["height"] = composition.paperHeight()
            elements = []
            layoutDef["thumbnail"] = "%s_thumbnail.png" % layoutSafeName
            layoutDef["name"] = name
            layoutDef["elements"] = elements
            for item in composition.items():
                element = None
                if isinstance(item, (QgsComposerLegend, QgsComposerShape, QgsComposerScaleBar, QgsComposerArrow)):
                    element = getBasicInfo(item)
                    for dpi in dpis:
                        dpmm = dpi / 25.4
                        s = QSize(item.rect().width() * dpmm, item.rect().height() * dpmm)
                        img = QImage(s, QImage.Format_ARGB32_Premultiplied)
                        img.fill(Qt.transparent)
                        painter = QPainter(img)
                        painter.scale(dpmm, dpmm)
                        item.paint(painter, None, None)
                        painter.end()
                        img.save(os.path.join(printFolder, "%s_%s_%s.png" %
                                (layoutSafeName, element["id"], str(dpi))))
                elif isinstance(item, QgsComposerLabel):
                    element = getBasicInfo(item)
                    element["name"] = item.text()
                    element["size"] = item.font().pointSize()
                    element["font"] = item.font().rawName()
                elif isinstance(item, QgsComposerMap):
                    element = getBasicInfo(item)
                    grid = item.grid()
                    if grid is not None:
                        element["grid"] = {}
                        element["grid"]["intervalX"] = grid.intervalX()
                        element["grid"]["intervalY"] = grid.intervalY()
                        element["grid"]["crs"] = grid.crs().authid()
                        element["grid"]["annotationEnabled"] = grid.annotationEnabled()
                elif isinstance(item, QgsComposerPicture):
                    filename = os.path.basename(item.picturePath())
                    if os.path.exists(filename):
                        element = getBasicInfo(item)
                        shutil.copy(item.pictureFile(), os.path.join(printFolder, filename))
                        element["file"] = filename
                if element is not None:
                    element["type"] = item.__class__.__name__[11:].lower()
                    elements.append(element)

            layoutDefs.append(layoutDef)
            progress.setProgress(int((i+1)*100.0/len(composers)))

        app.variables.append("var printLayouts = %s;" % json.dumps(layoutDefs))
示例#7
0
    def writePrintFiles(self, appdef, folder, app, progress):
        progress.setText("Writing print layout files")
        progress.setProgress(0)
        printFolder = os.path.join(folder, "resources", "print")
        if not QDir(printFolder).exists():
            QDir().mkpath(printFolder)
        dpis = [72, 150, 300]
        layoutDefs = []
        def getBasicInfo(item):
            coords = {}
            pos = item.pos()
            coords["x"] = pos.x()
            coords["y"] = pos.y()
            rect = item.rect()
            coords["width"] = rect.width()
            coords["height"] = rect.height()
            coords["id"] = str(uuid.uuid4())
            return coords
        composers = iface.activeComposers()
        for i, composer in enumerate(composers):
            name = composer.composerWindow().windowTitle()
            layoutSafeName = safeName(name)
            layoutDef = {}
            composition = composer.composition()
            img = composition.printPageAsRaster(0)
            img = img.scaledToHeight(100, Qt.SmoothTransformation)
            img.save(os.path.join(printFolder, "%s_thumbnail.png" % layoutSafeName))
            layoutDef["width"] = composition.paperWidth()
            layoutDef["height"] = composition.paperHeight()
            elements = []
            layoutDef["thumbnail"] = "%s_thumbnail.png" % layoutSafeName
            layoutDef["name"] = name
            layoutDef["elements"] = elements
            for item in composition.items():
                element = None
                if isinstance(item, (QgsComposerLegend, QgsComposerShape, QgsComposerScaleBar, QgsComposerArrow)):
                    element = getBasicInfo(item)
                    for dpi in dpis:
                        dpmm = dpi / 25.4
                        s = QSize(item.rect().width() * dpmm, item.rect().height() * dpmm)
                        img = QImage(s, QImage.Format_ARGB32_Premultiplied)
                        img.fill(Qt.transparent)
                        painter = QPainter(img)
                        painter.scale(dpmm, dpmm)
                        item.paint(painter, None, None)
                        painter.end()
                        img.save(os.path.join(printFolder, "%s_%s_%s.png" %
                                (layoutSafeName, element["id"], str(dpi))))
                elif isinstance(item, QgsComposerLabel):
                    element = getBasicInfo(item)
                    element["name"] = item.text()
                    element["size"] = item.font().pointSize()
                    element["font"] = item.font().rawName()
                elif isinstance(item, QgsComposerMap):
                    element = getBasicInfo(item)
                    grid = item.grid()
                    if grid is not None:
                        element["grid"] = {}
                        element["grid"]["intervalX"] = grid.intervalX()
                        element["grid"]["intervalY"] = grid.intervalY()
                        element["grid"]["crs"] = grid.crs().authid()
                        element["grid"]["annotationEnabled"] = grid.annotationEnabled()
                elif isinstance(item, QgsComposerPicture):
                    filename = os.path.basename(item.picturePath())
                    if os.path.exists(filename):
                        element = getBasicInfo(item)
                        shutil.copy(item.pictureFile(), os.path.join(printFolder, filename))
                        element["file"] = filename
                if element is not None:
                    element["type"] = item.__class__.__name__[11:].lower()
                    elements.append(element)

            layoutDefs.append(layoutDef)
            progress.setProgress(int((i+1)*100.0/len(composers)))

        app.variables.append("var printLayouts = %s;" % json.dumps(layoutDefs))