Unsolved Problem with QML Map tiles updating
-
Hi everyone. I have a solution to load on disk selected map area and than use it as cached map. I want to make tiles visible after downloading. I decided to call window with proposal to reload Map. Programm also supports choosing of Map providers, so Map is created dynamically(using Loader) each time when plugin changed or propose to reload submitted. The problem is that if plugin wasn't changed to reload plugin parameters I need to create Map object twice, with empty plugin name and current provider. Look at reloadMap() method. If there some method exists to solve it less askew?
Item {
id: item// Just to use shorter names of dynamic components property alias customMap: customMapLoader.item property alias cacheMapArea: cacheMapAreaLoader.item property alias cacheWindow: cacheWindowLoader.item property alias mapUpdaterDialog: mapUpdaterDialogLoader.item property var controlsHeight: 20 property bool cachingFinished: !cacheManager.isDownloading function cache() { if (cacheMapArea.firstPoint !== undefined && cacheMapArea.lastPoint !== undefined) { cacheManager.setZoomRange(cacheWindow.zoomFrom, cacheWindow.zoomTo) cacheManager.setCacheCoordinates(cacheMapArea.firstPoint, cacheMapArea.lastPoint) cacheManager.cacheMap() } } visible: true //choose plugins ComboBox { id: plugins function reloadMap() { if (currentText === mapPlugin.name) { // setting empty plugin just to reload tiles reading if provider wasn't changed customMapLoader.source = "" customMapLoader.source = "CustomMap.qml" mapPlugin.name = "" customMap.plugin = mapPlugin } customMapLoader.source = "" customMapLoader.source = "CustomMap.qml" mapPlugin.name = currentText customMap.plugin = mapPlugin } model: ["osm", "esri"] width: item.width / 2 height: controlsHeight onCurrentTextChanged: { reloadMap() } Plugin { // offline cache implemented only for osm id: mapPlugin onNameChanged: { cacheButton.enabled = true cacheManager.setProvider(name); } // OSM parameters: PluginParameter { name: 'osm.mapping.cache.directory' value: cacheManager.appCachePath + "osm/" } PluginParameter { name: 'osm.mapping.cache.disk.cost_strategy' value: "unitary" } PluginParameter { name: 'osm.mapping.cache.disk.size' value: 10000000 // ~ 60 GB } } } Button { id: cacheButton parent: item text: qsTr("Cache area") width: item.width / 4 height: controlsHeight x: plugins.x + plugins.width y: 0 onClicked: { cacheWindowLoader.source = "" cacheWindowLoader.source = "CacheWindow.qml" cacheMapAreaLoader.source = "" // delete previous area cacheMapAreaLoader.source = "CacheMapArea.qml" // create new area cacheWindow.applyClicked.connect(cache) cacheWindow.stopClicked.connect(cacheManager.stopCaching) cacheWindow.resetClicked.connect(cacheMapArea.resetSelection) } } ProgressBar { property int progress: cacheManager.total != 0 ? cacheManager.downloaded / cacheManager.total * 100 : 0 width: item.width / 4 height: controlsHeight x: cacheButton.width + cacheButton.x minimumValue: 0 maximumValue: 100 value: cacheManager.isDownloading === true ? progress : 0 Label { x: (parent.width - width) / 2; y: (parent.height - height) / 2; text: cacheManager.status } } Loader { id: customMapLoader parent: item anchors { fill: parent; topMargin: controlsHeight } } Loader { // to open window id: cacheWindowLoader function deleteObject() { source = "" } // to create connection parent: item anchors { fill: parent; topMargin: plugins.height } onLoaded: { customMap.mapDestroyed.connect(deleteObject) } } Loader { id: cacheMapAreaLoader function deleteObject() { source = "" } // to create connection parent: item anchors { fill: parent; topMargin: 20 } onLoaded: { cacheMapArea.parent = customMap customMap.mapDestroyed.connect(deleteObject) } } Loader { id: mapUpdaterDialogLoader function deleteObject() { source = "" } // to create connection parent: item anchors { fill: parent; topMargin: 20 } onLoaded: { customMap.mapDestroyed.connect(deleteObject) } } onCachingFinishedChanged: { if (cachingFinished === true && cacheManager.downloaded > 0) { mapUpdaterDialogLoader.source = "" mapUpdaterDialogLoader.source = "MapUpdaterDialog.qml" mapUpdaterDialog.yes.connect(plugins.reloadMap) mapUpdaterDialog.no.connect(mapUpdaterDialogLoader.deleteObject) } }
}