Select to view content in your preferred language

Qml - load a tif map and use it offline, without any online base map?

5284
11
Jump to solution
09-03-2017 04:50 AM
AnatBen_Israel
Emerging Contributor

Hi, I have a tif (and tfw) map that I want to be able to use offline (QML).

I have managed to load the tif as a raster layer on top of an online map, but I want to avoid it.

I I try to remove the BasemapImagery {}, the raster doesn't load...

In addition, how do I load the tfw file?

This is my code:

ApplicationWindow {
      id: appWindow
      width: 850
      height: 650
      title: "MapsProj"

     

      Rectangle {
           id: rootRectangle
           clip: true
           width: 800
           height: 600

           property real scaleFactor: System.displayScaleFactor
           property var rasterLayer: null
           property string rasterFilePath: "file:///C:/Projects/Sample/Maps/map1.tif"

           MapView {
                id: mapView
                anchors.fill: parent

                Map {
                    id: map

                    BasemapImagery {}

                    RasterLayer {
                           Raster {
                                 path: ""
                     }

                    onLoadStatusChanged: {
                           if (loadStatus !== Enums.LoadStatusLoaded)
                                    return;

                            mapView.setViewpointCenterAndScale(fullExtent.center, 80000);
                     }
               }

         }

     }

     Rectangle {
          visible: addButton.visible
           anchors.centerIn: addButton
           radius: 8 * rootRectangle.scaleFactor
           height: addButton.height + (16 * rootRectangle.scaleFactor)
           width: addButton.width + (16 * rootRectangle.scaleFactor)
           color: "lightgrey"
           border.color: "darkgrey"
           border.width: 2 * rootRectangle.scaleFactor
           opacity: 0.75
     }

     Button {
           id: addButton
           anchors {
                   bottom: parent.bottom
                   horizontalCenter: parent.horizontalCenter
                   margins: 32 * rootRectangle.scaleFactor
             }

           text: "Add Raster"
           onClicked: {
                 rootRectangle.createAndAddRasterLayer(rootRectangle.rasterFilePath)

            }
      }

      function createAndAddRasterLayer(rasterUrl) {
          var newRaster = ArcGISRuntimeEnvironment.createObject("Raster", {path: rasterUrl});
          rasterLayer = ArcGISRuntimeEnvironment.createObject("RasterLayer", {raster: newRaster});

          rasterLayer.loadStatusChanged.connect(zoomToRaster);

          map.operationalLayers.clear();
          map.operationalLayers.append(rasterLayer);
     }

     function zoomToRaster(){
        if (rasterLayer === null)
              return;

        if (rasterLayer.loadStatus !== Enums.LoadStatusLoaded)
              return;

         mapView.setViewpointCenterAndScale(rasterLayer.fullExtent.center, 80000);
     }
  }
}

0 Kudos
11 Replies
LukeSmallwood
Esri Contributor

That doesn't sound expected - would you be able to post your code and I'll see if I can reproduce?

0 Kudos
AnatBen_Israel
Emerging Contributor

I figured it out. I've created a MouseArea to report mouse coordinate and it blocked the panning.

If I disable the MouseArea the panning works again.

Thanks again for everything!!

0 Kudos