def initTemplateList(self): cbox = self.ui.comboBox_Template cbox.clear() templateDir = QDir(tools.templateDir()) for i, entry in enumerate(templateDir.entryList(["*.html", "*.htm"])): cbox.addItem(entry) config = tools.getTemplateConfig(entry) # get template type templateType = config.get("type", "plain") cbox.setItemData(i, templateType, Qt.UserRole) # set tool tip text desc = config.get("description", "") if desc: cbox.setItemData(i, desc, Qt.ToolTipRole) # select the template of the settings templatePath = self._settings.get("Template") # if no template setting, select the last used template if not templatePath: templatePath = QSettings().value("/Qgis2threejs/lastTemplate", def_vals.template, type=unicode) if templatePath: index = cbox.findText(templatePath) if index != -1: cbox.setCurrentIndex(index) return index return -1
def initTemplateList(self): cbox = self.ui.comboBox_Template cbox.clear() templateDir = QDir(tools.templateDir()) for i, entry in enumerate(templateDir.entryList(["*.html", "*.htm"])): cbox.addItem(entry) config = tools.getTemplateConfig(templateDir.filePath(entry)) # get template type templateType = config.get("type", "plain") cbox.setItemData(i, templateType, Qt.UserRole) # set tool tip text desc = config.get("description", "") if desc: cbox.setItemData(i, desc, Qt.ToolTipRole) # select the last used template templateName = QSettings().value("/Qgis2threejs/lastTemplate", "", type=unicode) if templateName: index = cbox.findText(templateName) if index != -1: cbox.setCurrentIndex(index) return index return -1
def __init__(self, settings, canvas, pluginManager, localBrowsingMode=True): self.data = settings self.timestamp = datetime.datetime.today().strftime("%Y%m%d%H%M%S") # output html file path htmlfilename = settings.get("OutputFilename") if not htmlfilename: htmlfilename = tools.temporaryOutputDir() + "/%s.html" % self.timestamp self.htmlfilename = htmlfilename self.path_root = os.path.splitext(htmlfilename)[0] self.htmlfiletitle = os.path.basename(self.path_root) self.title = self.htmlfiletitle # load configuration of the template self.templateName = settings.get("Template", "") templatePath = os.path.join(tools.templateDir(), self.templateName) self.templateConfig = tools.getTemplateConfig(templatePath) # MapTo3D object world = settings.get(ObjectTreeItem.ITEM_WORLD, {}) baseSize = world.get("lineEdit_BaseSize", def_vals.baseSize) verticalExaggeration = world.get("lineEdit_zFactor", def_vals.zExaggeration) verticalShift = world.get("lineEdit_zShift", def_vals.zShift) self.mapTo3d = MapTo3D(canvas, float(baseSize), float(verticalExaggeration), float(verticalShift)) self.coordsInWGS84 = world.get("radioButton_WGS84", False) self.canvas = canvas self.mapSettings = canvas.mapSettings() if apiChanged23 else canvas.mapRenderer() self.baseExtent = RotatedRect.fromMapSettings(self.mapSettings) self.pluginManager = pluginManager self.localBrowsingMode = localBrowsingMode self.crs = self.mapSettings.destinationCrs() wgs84 = QgsCoordinateReferenceSystem(4326) transform = QgsCoordinateTransform(self.crs, wgs84) self.wgs84Center = transform.transform(self.baseExtent.center()) controls = settings.get(ObjectTreeItem.ITEM_CONTROLS, {}) self.controls = controls.get("comboBox_Controls") if not self.controls: self.controls = QSettings().value("/Qgis2threejs/lastControls", "OrbitControls.js", type=unicode) self.demProvider = None self.quadtree = None if self.templateConfig.get("type") == "sphere": self.exportMode = ExportSettings.SPHERE return demProperties = settings.get(ObjectTreeItem.ITEM_DEM, {}) self.demProvider = self.demProviderByLayerId(demProperties["comboBox_DEMLayer"]) if demProperties.get("radioButton_Simple", False): self.exportMode = ExportSettings.PLAIN_SIMPLE else: self.exportMode = ExportSettings.PLAIN_MULTI_RES self.quadtree = createQuadTree(self.baseExtent, demProperties)
def templateConfig(self): if self._templateConfig: return self._templateConfig if not self.templatePath: self.setTemplatePath(def_vals.template) self._templateConfig = tools.getTemplateConfig(self.templatePath) return self._templateConfig
def exportToThreeJS(htmlfilename, context, progress=None): mapTo3d = context.mapTo3d canvas = context.canvas extent = canvas.extent() if progress is None: progress = dummyProgress temp_dir = QDir.tempPath() #TODO: do in JSWriter? timestamp = datetime.datetime.today().strftime("%Y%m%d%H%M%S") if htmlfilename == "": htmlfilename = tools.temporaryOutputDir() + "/%s.html" % timestamp out_dir, filename = os.path.split(htmlfilename) if not QDir(out_dir).exists(): QDir().mkpath(out_dir) # create JavaScript writer object writer = JSWriter(htmlfilename, context) writer.timestamp = timestamp # read configuration of the template templatePath = os.path.join(tools.templateDir(), context.templateName) templateConfig = tools.getTemplateConfig(templatePath) templateType = templateConfig.get("type", "plain") if templateType == "sphere": writer.openFile(False) # render texture for sphere and write it progress(5, "rendering texture...") writeSphereTexture(writer) else: # plain type demProperties = context.properties[ObjectTreeItem.ITEM_DEM] isSimpleMode = demProperties.get("radioButton_Simple", False) writer.openFile(not isSimpleMode) writer.writeWorldInfo() progress(5, "writing DEM...") # write primary DEM if isSimpleMode: writeSimpleDEM(writer, demProperties, progress) else: writeMultiResDEM(writer, demProperties, progress) writer.prepareNext() # write additional DEM(s) primaryDEMLayerId = demProperties["comboBox_DEMLayer"] for layerId, properties in context.properties[ObjectTreeItem.ITEM_OPTDEM].iteritems(): if layerId != primaryDEMLayerId and properties.get("visible", False): writeSimpleDEM(writer, properties) progress(50, "writing vector data...") # write vector data writeVectors(writer) progress(80, "") # copy three.js files tools.copyThreejsFiles(out_dir, context.controls) # copy additional library files tools.copyLibraries(out_dir, templateConfig) # generate html file with codecs.open(templatePath, "r", "UTF-8") as f: html = f.read() filetitle = os.path.splitext(filename)[0] with codecs.open(htmlfilename, "w", "UTF-8") as f: f.write(html.replace("${title}", filetitle).replace("${controls}", '<script src="./threejs/%s"></script>' % context.controls).replace("${options}", writer.options()).replace("${scripts}", writer.scripts())) return htmlfilename