def writeVectorLayer(layer, safeLayerName, usedFields, highlight, popupsOnHover, popup, outputProjectFileName, wfsLayers, cluster, visible, json, legends, new_src, canvas, zIndex): zIndex = zIndex + 600 markerFolder = os.path.join(outputProjectFileName, "markers") (new_pop, labeltext, popFuncs) = labelsAndPopups(layer, safeLayerName, highlight, popupsOnHover, popup) renderer = layer.rendererV2() layer_transp = 1 - (float(layer.layerTransparency()) / 100) style = "" if is25d(layer, canvas): shadows = "" renderer = layer.rendererV2() renderContext = QgsRenderContext.fromMapSettings(canvas.mapSettings()) fields = layer.pendingFields() renderer.startRender(renderContext, fields) for feat in layer.getFeatures(): if isinstance(renderer, QgsCategorizedSymbolRendererV2): classAttribute = renderer.classAttribute() attrValue = feat.attribute(classAttribute) catIndex = renderer.categoryIndexForValue(attrValue) categories = renderer.categories() symbol = categories[catIndex].symbol() elif isinstance(renderer, QgsGraduatedSymbolRendererV2): classAttribute = renderer.classAttribute() attrValue = feat.attribute(classAttribute) ranges = renderer.ranges() for range in ranges: if (attrValue >= range.lowerValue() and attrValue <= range.upperValue()): symbol = range.symbol().clone() else: symbol = renderer.symbolForFeature2(feat, renderContext) symbolLayer = symbol.symbolLayer(0) if not symbolLayer.paintEffect().effectList()[0].enabled(): shadows = "'2015-07-15 10:00:00'" renderer.stopRender(renderContext) new_obj = """ var osmb = new OSMBuildings(map).date(new Date({shadows})); osmb.set(json_{sln});""".format(shadows=shadows, sln=safeLayerName) # else: # layer_style = getLayerStyle(layer, safeLayerName) elif isinstance(renderer, QgsHeatmapRenderer): (new_obj, legends, wfsLayers) = heatmapLayer(layer, safeLayerName, renderer, legends, wfsLayers) elif (isinstance(renderer, QgsSingleSymbolRendererV2) or isinstance(renderer, QgsRuleBasedRendererV2)): (style, markerType) = getLayerStyle(layer, safeLayerName, markerFolder) (new_obj, legends, wfsLayers) = singleLayer(renderer, outputProjectFileName, safeLayerName, wfsLayers, layer, labeltext, cluster, json, usedFields, legends, markerType) elif isinstance(renderer, QgsCategorizedSymbolRendererV2): (style, markerType) = getLayerStyle(layer, safeLayerName, markerFolder) (new_obj, legends, wfsLayers) = categorizedLayer(layer, renderer, safeLayerName, outputProjectFileName, usedFields, legends, labeltext, cluster, json, wfsLayers, markerType) elif isinstance(renderer, QgsGraduatedSymbolRendererV2): (style, markerType) = getLayerStyle(layer, safeLayerName, markerFolder) (new_obj, legends, wfsLayers) = graduatedLayer(layer, safeLayerName, renderer, outputProjectFileName, labeltext, cluster, json, usedFields, legends, wfsLayers, markerType) blend = BLEND_MODES[layer.blendMode()] new_obj = """{style} map.createPane('pane_{sln}'); map.getPane('pane_{sln}').style.zIndex = {zIndex}; map.getPane('pane_{sln}').style['mix-blend-mode'] = '{blend}'; {new_obj}""".format( style=style, sln=safeLayerName, zIndex=zIndex, blend=blend, new_obj=new_obj) if usedFields != 0: new_src += new_pop.decode("utf-8") new_src += """ """ + new_obj if is25d(layer, canvas): pass else: new_src += """ bounds_group.addLayer(layer_""" + safeLayerName + """);""" if visible: if cluster is False: new_src += """ feature_group.addLayer(layer_""" + safeLayerName + """);""" else: new_src += """ cluster_""" + safeLayerName + """.addTo(map);""" return new_src, legends, wfsLayers
def writeVectorLayer(layer, safeLayerName, usedFields, highlight, popupsOnHover, popup, outputProjectFileName, wfsLayers, cluster, visible, json, legends, new_src, canvas, zIndex, restrictToExtent, extent): zIndex = zIndex + 600 markerFolder = os.path.join(outputProjectFileName, "markers") (new_pop, labeltext, popFuncs) = labelsAndPopups(layer, safeLayerName, highlight, popupsOnHover, popup, outputProjectFileName) renderer = layer.rendererV2() layer_transp = 1 - (float(layer.layerTransparency()) / 100) style = "" if is25d(layer, canvas, restrictToExtent, extent): shadows = "" renderer = layer.rendererV2() renderContext = QgsRenderContext.fromMapSettings(canvas.mapSettings()) fields = layer.pendingFields() renderer.startRender(renderContext, fields) for feat in layer.getFeatures(): if isinstance(renderer, QgsCategorizedSymbolRendererV2): classAttribute = renderer.classAttribute() attrValue = feat.attribute(classAttribute) catIndex = renderer.categoryIndexForValue(attrValue) categories = renderer.categories() symbol = categories[catIndex].symbol() elif isinstance(renderer, QgsGraduatedSymbolRendererV2): classAttribute = renderer.classAttribute() attrValue = feat.attribute(classAttribute) ranges = renderer.ranges() for range in ranges: if (attrValue >= range.lowerValue() and attrValue <= range.upperValue()): symbol = range.symbol().clone() else: symbol = renderer.symbolForFeature2(feat, renderContext) symbolLayer = symbol.symbolLayer(0) if not symbolLayer.paintEffect().effectList()[0].enabled(): shadows = "'2015-07-15 10:00:00'" renderer.stopRender(renderContext) new_obj = """ var osmb = new OSMBuildings(map).date(new Date({shadows})); osmb.set(json_{sln});""".format(shadows=shadows, sln=safeLayerName) elif isinstance(renderer, QgsHeatmapRenderer): (new_obj, legends, wfsLayers) = heatmapLayer(layer, safeLayerName, renderer, legends, wfsLayers) elif isinstance(renderer, QgsSingleSymbolRendererV2): (style, markerType) = getLayerStyle(layer, safeLayerName, markerFolder, outputProjectFileName) (new_obj, legends, wfsLayers) = singleLayer(renderer, outputProjectFileName, safeLayerName, wfsLayers, layer, labeltext, cluster, json, usedFields, legends, markerType) elif isinstance(renderer, QgsCategorizedSymbolRendererV2): (style, markerType) = getLayerStyle(layer, safeLayerName, markerFolder, outputProjectFileName) (new_obj, legends, wfsLayers) = categorizedLayer(layer, renderer, safeLayerName, outputProjectFileName, usedFields, legends, labeltext, cluster, json, wfsLayers, markerType) elif isinstance(renderer, QgsGraduatedSymbolRendererV2): (style, markerType) = getLayerStyle(layer, safeLayerName, markerFolder, outputProjectFileName) (new_obj, legends, wfsLayers) = graduatedLayer(layer, safeLayerName, renderer, outputProjectFileName, labeltext, cluster, json, usedFields, legends, wfsLayers, markerType) elif isinstance(renderer, QgsRuleBasedRendererV2): (style, markerType) = getLayerStyle(layer, safeLayerName, markerFolder, outputProjectFileName) (new_obj, legends, wfsLayers) = ruleBasedLayer(layer, renderer, safeLayerName, outputProjectFileName, usedFields, legends, labeltext, cluster, json, wfsLayers, markerType) blend = BLEND_MODES[layer.blendMode()] new_obj = u"""{style} map.createPane('pane_{sln}'); map.getPane('pane_{sln}').style.zIndex = {zIndex}; map.getPane('pane_{sln}').style['mix-blend-mode'] = '{blend}'; {new_obj}""".format( style=style, sln=safeLayerName, zIndex=zIndex, blend=blend, new_obj=new_obj) if usedFields != 0: new_src += new_pop.decode("utf-8") new_src += """ """ + new_obj if is25d(layer, canvas, restrictToExtent, extent): pass else: new_src += """ bounds_group.addLayer(layer_""" + safeLayerName + """);""" if visible: if cluster is False: new_src += """ map.addLayer(layer_""" + safeLayerName + """);""" else: new_src += """ cluster_""" + safeLayerName + """.addTo(map);""" return new_src, legends, wfsLayers