Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Contributor
Posts: 28
Registered: ‎04-20-2016
Accepted Solution

Loop wfs service valuelist

Hi,

 

I´ve tried to get values from a wfs to fill it into a Toolbar label.

 

It will work so far but it is not a nice code. I use the $GP.services.add Function 3 times to get 3 Values.

I was not able to write it with a loop. Maybe someone can point me to the right direction how to loop trougth the values...

 

$GP.ready(function () {
    var TrStatMS = "xxx";
    var KMS = "xxx";
    var KNS = "xxx";
    $GP.services.add({
        url: "http://xxxx/WFS_002_SV_SummaryValues_2017/Service.svc/get",
        definitionName: "KNS"
    }, function (result1) {
        $GP.edit.getFeatureClassIds({
            mapServiceId: result1.mapServiceId
        }, function (result2) {
            $GP.edit.getAttributeList({
                mapServiceId: result1.mapServiceId,
                featureClassId: result2.featureClassIds[0]
            }, function (result3) {
                $GP.edit.getAttributeValues({
                    mapServiceId: result1.mapServiceId,
                    featureClassId: result2.featureClassIds[0],
                    attributeId: result3.attributeList[0].get_id()
                }, function (result4) {
                    var valueList = result4.values.map(function (x) {
                        return x.value;
                    });
                    $GP.ui.info($GP.utils.serialize(valueList));
                    KNS = valueList;
                }, function (result4) {
                    $GP.ui.info(result4.msg || result4.message);
                });
            }, function (result3) {
                $GP.ui.info(result3.msg || result3.message);
            });
        }, function (result2) {
            $GP.ui.info(result2.msg || result2.message);
        });
    }, function (result1) {
        $GP.ui.info(result1.msg || result1.message);
    });

$GP.services.add({ url: "http://xxxx/WFS_002_SV_SummaryValues_2017/Service.svc/get", definitionName: "KMS" }, function (result1) { $GP.edit.getFeatureClassIds({ mapServiceId: result1.mapServiceId }, function (result2) { $GP.edit.getAttributeList({ mapServiceId: result1.mapServiceId, featureClassId: result2.featureClassIds[0] }, function (result3) { $GP.edit.getAttributeValues({ mapServiceId: result1.mapServiceId, featureClassId: result2.featureClassIds[0], attributeId: result3.attributeList[1].get_id() }, function (result4) { var valueList = result4.values.map(function (x) { return x.value; }); $GP.ui.info($GP.utils.serialize(valueList)); KMS = valueList; }, function (result4) { $GP.ui.info(result4.msg || result4.message); }); }, function (result3) { $GP.ui.info(result3.msg || result3.message); }); }, function (result2) { $GP.ui.info(result2.msg || result2.message); }); }, function (result1) { $GP.ui.info(result1.msg || result1.message); });

$GP.services.add({ url: "http://xxxx/WFS_002_SV_SummaryValues_2017/Service.svc/get", definitionName: "TrStatMS" }, function (result1) { $GP.edit.getFeatureClassIds({ mapServiceId: result1.mapServiceId }, function (result2) { $GP.edit.getAttributeList({ mapServiceId: result1.mapServiceId, featureClassId: result2.featureClassIds[0] }, function (result3) { $GP.edit.getAttributeValues({ mapServiceId: result1.mapServiceId, featureClassId: result2.featureClassIds[0], attributeId: result3.attributeList[2].get_id() }, function (result4) { var valueList = result4.values.map(function (x) { return x.value; }); $GP.ui.info($GP.utils.serialize(valueList)); TrStatMS = valueList; }, function (result4) { $GP.ui.info(result4.msg || result4.message); }); }, function (result3) { $GP.ui.info(result3.msg || result3.message); }); }, function (result2) { $GP.ui.info(result2.msg || result2.message); }); }, function (result1) { $GP.ui.info(result1.msg || result1.message); }); /*Label erzeugen und anzeien*/ //var x = 5; var SumMS = "x"; var SumNS = "x"; function meineFunktion() { $GP.ready(function () { $GP.ui.toolbar.add({ xtype: 'label', forId: 'myFieldId', text: 'S MS / TrStMS: ' + +KMS + ' / ' + TrStatMS + " -", margins: '0 0 0 10', }); $GP.ui.toolbar.add({ xtype: 'label', forId: 'myFieldId2', text: "- " + 'SNS: ' + KNS, margins: '0 0 0 10', }); }); } setTimeout(meineFunktion, 8000); });
Highlighted
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: Loop wfs service valuelist

[ Edited ]

I'm getting a list with this code:

 

$GP.services.add({
   url : "http://cthse-gis/test_wfs_instance/service.svc/get",
   definitionName : "WFS"
}, function (result1) {
   $GP.edit.getFeatureClassIds({
      mapServiceId : result1.mapServiceId
   }, function (result2) {
      $GP.edit.getAttributeList({
         mapServiceId : result1.mapServiceId,
         featureClassId : result2.featureClassIds[1]
      }, function (result3) {
         $GP.edit.getAttributeValues({
            mapServiceId : result1.mapServiceId,
            featureClassId : result2.featureClassIds[1],
            attributeId : result3.attributeList[1].get_id(),
            start : 0,
            limit : 3000
         }, function (result4) {
            var valueList = result4.values.map(function (x) {
                  return x.value;
               });
            //$GP.ui.info($GP.utils.serialize(valueList));
            var yy = $GP.utils.serialize(valueList);
            var xx = yy.substring(1, yy.length - 2);
            var zz = xx.split(",");
            //$GP.ui.info("zz=" + zz[1]+","+ zz[2] + "," + zz[19]);
            aa = "<br><select id='owner1',name='owner1'>";
            var count = zz.length;
            count = count - 1;
            $GP.ui.info("# of owner choices: " + count);
            for (var i = 0; i < count; i++) {
               i
               bb = zz[i];
               bb = bb.substring(1, bb.length - 1);
               aa += "<OPTION VALUE=" + zz[i] + ">" + bb + "</OPTION>";
            }

            //$GP.ui.info(aa);
            document.getElementById('dialogboxhead').innerHTML = "Owner Name Query";
            document.getElementById('dialogboxbody').innerHTML = "Select an Owner Name";
            document.getElementById('dialogboxbody').innerHTML += aa;

         }, function (result4) {});
      }, function (result3) {});
   }, function (result2) {});
}, function (result1) {});