Select to view content in your preferred language

QML ArcGISDynamicMapServiceLayer timeInterval

3334
2
Jump to solution
04-14-2016 04:08 PM
BenSaunders1
Regular Contributor

I am trying to set a time interval on a dynamic map service to only see a certain time slice of the data without success (I do not want to impose the time interval on the map). Here's some sample code:

import QtQuick 2.3
import QtQuick.Controls 1.2
import ArcGIS.Runtime 10.26

ApplicationWindow {
    id: appWindow
    width: 800
    height: 600
    title: "Time Interval"

    Map {
        id: mainMap
        anchors.fill: parent
        hidingNoDataTiles: false
        wrapAroundEnabled: true
        focus: true

        ArcGISTiledMapServiceLayer {
            url: "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
        }

        ArcGISDynamicMapServiceLayer {
            url: "http://tmservices1.esri.com/arcgis/rest/services/LiveFeeds/Earthquakes/MapServer"
            timeInterval: myTimeExtent

            Component.onCompleted: {
                console.log("timeInterval is undefined:", timeInterval == undefined);
            }
        }

        onStatusChanged: {
            if (status === Enums.MapStatusReady)
                mainMap.zoomTo(usExtent);
        }
    }

    Envelope {
        id: usExtent
        xMax: -15000000
        yMax: 2000000
        xMin: -7000000
        yMin: 8000000
        spatialReference: SpatialReference {
            wkid: 102100
        }
    }

    TimeExtent {
        id: myTimeExtent
        startDate: new Date(2016, 2, 26, 0, 0, 0, 0)
        endDate: new Date(2016, 2, 27, 0, 0, 0, 0)
    }
}

Not only does it not set a timeInterval, the timeInterval is still undefined after the onCompleted (timeInterval == undefined resolves to true).

Any help or insight would be greatly appreciated!

Ben

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Hmm, it seems like it is having issues assigning it declaratively. Try setting it in JavaScript, and see if it works. I believe I have it working with the following code:

import QtQuick 2.3
import QtQuick.Controls 1.2
import ArcGIS.Runtime 10.26


ApplicationWindow {
    id: appWindow
    width: 800
    height: 600
    title: "Time Interval"


    Map {
        id: mainMap
        anchors.fill: parent
        wrapAroundEnabled: true


        ArcGISTiledMapServiceLayer {
            url: "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
        }


        ArcGISDynamicMapServiceLayer {
            id: timeAwareDynamicLayer
            url: "http://tmservices1.esri.com/arcgis/rest/services/LiveFeeds/Earthquakes/MapServer"


            onTimeIntervalChanged: {
                console.log("time interval changed")
            }


            onStatusChanged: {
                if (status === Enums.LayerStatusInitialized) {
                    // assign a new timeInterval
                    timeAwareDynamicLayer.timeInterval = myTimeExtent;
                }
            }
        }
    }




    TimeExtent {
        id: myTimeExtent
        startDate: new Date(2016, 2, 27)
        endDate: new Date(2016, 2, 28)
    }
}
















As a side note, I recommend using the layer status (statusChanged signal) instead of Component.onCompleted for something like this. With checking layer status, you can make sure it is initialized, whereas Component.onCompleted is built into all QML types, and will just tell you if it is default constructed basically. In this case, we want to wait until we actually know it is initialized, meaning it has gone out to the service, obtained all of the layer info, been added to the map, etc. Component.onCompleted would likely fire before all of that stuff has happened.

-Luke

View solution in original post

0 Kudos
2 Replies
LucasDanzinger
Esri Frequent Contributor

Hmm, it seems like it is having issues assigning it declaratively. Try setting it in JavaScript, and see if it works. I believe I have it working with the following code:

import QtQuick 2.3
import QtQuick.Controls 1.2
import ArcGIS.Runtime 10.26


ApplicationWindow {
    id: appWindow
    width: 800
    height: 600
    title: "Time Interval"


    Map {
        id: mainMap
        anchors.fill: parent
        wrapAroundEnabled: true


        ArcGISTiledMapServiceLayer {
            url: "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
        }


        ArcGISDynamicMapServiceLayer {
            id: timeAwareDynamicLayer
            url: "http://tmservices1.esri.com/arcgis/rest/services/LiveFeeds/Earthquakes/MapServer"


            onTimeIntervalChanged: {
                console.log("time interval changed")
            }


            onStatusChanged: {
                if (status === Enums.LayerStatusInitialized) {
                    // assign a new timeInterval
                    timeAwareDynamicLayer.timeInterval = myTimeExtent;
                }
            }
        }
    }




    TimeExtent {
        id: myTimeExtent
        startDate: new Date(2016, 2, 27)
        endDate: new Date(2016, 2, 28)
    }
}
















As a side note, I recommend using the layer status (statusChanged signal) instead of Component.onCompleted for something like this. With checking layer status, you can make sure it is initialized, whereas Component.onCompleted is built into all QML types, and will just tell you if it is default constructed basically. In this case, we want to wait until we actually know it is initialized, meaning it has gone out to the service, obtained all of the layer info, been added to the map, etc. Component.onCompleted would likely fire before all of that stuff has happened.

-Luke

0 Kudos
BenSaunders1
Regular Contributor

Yup, that does the trick. And thanks for the tip on the layer status - that makes good sense!

Thanks!

Ben

0 Kudos