1

I have a data set of points. Each point has latitude, longitude, date and description sent from the server

I already have a graphic layer which is used for represening the points in a static way with some popups like this

          ...
          var graphic = new esri.Graphic(point, symbol);

          graphic.setInfoTemplate(new esri.InfoTemplate("", "Number: " + data.number));

          gLayer.add(graphic);
          ...

But Now I need to add a time-aware layer (a feature layer I believe) that allows me to show the data according to datetime information using a time slider, like here [oil Filed][1]. The only difference, I need to use the data sent from the server as json and I need to add popups to each point

I believe I need to add a featureLayer (MODE_SNAPSHOT) with a featureCollection as params that contains the data sent from server but I coulnd't figgure out how to do this (I'm a newbie in ArcGis, several hours only).

To be exact I'm not sure how to create that feature collection with latitude/longitude for each point and the most important thing: how to connect it with corresponding time information

I.e. I have sets of

{lat: xxx, long: yyy, datetime: yyyy-mm-dd, description: sometext }

sent from the server

Now I need to figure out how to pass the data to a featureLayer so it can be shown on a map with a time slider [1]: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/time_slider_layerDef.html "oil Field"

2

You can create the feature layer from JSON like this:

    {
       "layerDefinition": {
       "geometryType": "esriGeometryPoint",
       "objectIdField": "ObjectID",
       "drawingInfo": {
       "renderer": {
        "type": "simple",
        "label": "",
        "description": "",
        "symbol": {
            "color": [
                205,
                212,
                144
            ],
            "size": 8,
            "angle": 0,
            "xoffset": 0,
            "yoffset": 0,
            "type": "esriSMS",
            "style": "esriSLSSolid",
            "outline": {
                "color": [
                    205,
                    212,
                    144
                ],
                "width": 0,
                "type": "esriSLS",
                "style": "esriSLSolid"
            }
        }
    }
},
"fields": [
    {
        "name": "ObjectID",
        "alias": "ObjectID",
        "type": "esriFieldTypeOID"
    }, ...some more fields...
 ]
 },
"featureSet": {
"features": []
}

To create the feature layer, you'll need to pass the JSON to a feature collection first. Here's some sample code:

    var spatialReference = new esri.SpatialReference({ wkid: 102100 });
    var featureCollection = JSON.parse(msg.d);
    var featureLayer = new esri.layers.FeatureLayer(featureCollection, {
           id: 'HourlyDataLayer',
           mode: esri.layers.FeatureLayer.MODE_SNAPSHOT
    });
    map.addLayers([featureLayer]);

You'll then have to loop through the features to add them to an array and add that to the feature layer. I've found that passing the features with the rest of the JSON for the feature collection doesn't work. Note that applyEdits() won't add your features to the layer unless you've already done map.addLayers([featureLayer]) first.

   var pointFeatures = [];
   for (var i = 0; i < features.length; i++) {
       var feature = features[i];
       var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 8,
    new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
    new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
       var geometry = new esri.geometry.Point(feature.longitude, feature.latitude, spatialReference);
       var graphic = new esri.Graphic(geometry, symbol);
       graphic.setInfoTemplate(infoTemplate);
       graphic.setAttributes(attr);
       pointFeatures.push(graphic);
   }

   featureLayer.applyEdits(pointFeatures, null, null);

The infoTemplate in that code will give you a popup for each point, you create a custom info template like this:

    var infoTemplate = new esri.InfoTemplate();

    infoTemplate.setTitle("Time Point");
    infoTemplate.setContent("<b>Attribute display: ${attribute field name}</b><br/>"

    + "<b>Another attribute: </b>${another field name}<br/>"

    + "<b>One more attribute: ${field name}</b>");

Where "attribute field name" is in the attributes defined for your points and "Attribute display" is what you want it titled in the popup.

The only problem is, I don't know how to make the layer work with the time slider, I haven't been able to.

EDIT: The more I try to do this for my own project, the more I become convinced it can't be done. There doesn't seem to be any way to make a roll-your-own feature layer time aware. You could accomplish something similar by handling the time-extent-change event of the timeSlider to customize display of your features, and I've seen a colleague do that in the Flex API, but I don't think it will be very responsive if you're dealing with a lot of features and a lot of time stops, like I am. If anyone ever solves this, I'd love to know I'm wrong!

  • re: There doesn't seem to be any way to make a roll-your-own feature layer time aware - you may have hit a limitation of feature layers created from a feature collection. developers.arcgis.com/javascript/3/jsapi/… says: "Does not support queries that need to be performed on the server", which may apply to time-awareness – Stephen Lead Jun 23 '16 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.