Select to view content in your preferred language

need help with set pop up window for Dynamic map service layer

4433
20
08-26-2013 12:29 PM
JinZhang
Occasional Contributor
Hello,

I am very new to ArcGIS in general, any help is appreciated!

I have a dynamic map service that has only one layer that shows the asset related work order. This layer is a spatial view created by joining a feature class table(a gis asset table) to a non spatial database table(work order) on a matching field ASSET_NAME. I want to set up the the pop up window so when user click on the map, the work order associated to the clicked asset will pop up.

I have searched this forum and found the following thread:

http://forums.arcgis.com/threads/36210-popup-widget-for-ArcGISDynamicMapServiceLayer?highlight=dynam...


This example works with our other dynamic map services that do not have layers from spatial views. But for the dynamic map service that has spatial view as the query layer, i can't seem to get it to work:

Here is my code:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title></title>
    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/dojo/dijit/themes/tundra/tundra.css">
    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/esri/dijit/css/Popup.css">
    <style>
      html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
      #map{ margin: 0; padding: 0; }
    </style>
    <script>
        var dojoConfig = { parseOnLoad: true };
            </script>
    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.7"></script>
    <script type="GIS_WAM_TEST\jsapi_vsdoc10_v36.js"></script>
    <script>
        dojo.require("dijit.layout.BorderContainer");
        dojo.require("dijit.layout.ContentPane");
        dojo.require("esri.map");
        dojo.require("esri.tasks.query");
        dojo.require("esri.dijit.Popup");
      

        var map;
        function init() {
            var dynSvc = new esri.layers.ArcGISDynamicMapServiceLayer("http://10.1.22.31/arcgis/rest/services/test/stormwater_wo_rd/MapServer", { "opacity": 0.5 });
            dynSvc.hasAttributionData = true;
            var ext = new esri.geometry.Extent({ "xmin": 2125148.0132503808, "ymin": 596823.7652553022, "xmax": 2258287.4035612047, "ymax": 675346.1662348956, "spatialReference": { "wkid": 3734} });
            var popup = new esri.dijit.Popup(null, dojo.create("div"));

            map = new esri.Map("map", {
                "extent": ext,
                "infoWindow": popup
            });
            map.addLayer(dynSvc);

            dojo.connect(map, 'onClick', queryCounties);

            dojo.connect(map, 'onLoad', function () {
                dojo.connect(dijit.byId('map'), 'resize', map, map.resize);
            });
        }

        function queryCounties(e) {
            // build an extent around the click point
            var pad = map.extent.getWidth() / map.width * 3;
            var queryGeom = new esri.geometry.Extent(e.mapPoint.x - pad, e.mapPoint.y - pad, e.mapPoint.x + pad, e.mapPoint.y + pad, map.spatialReference);
            var q = new esri.tasks.Query();

            q.outSpatialReference = { "wkid": 3734 };
       
            q.returnGeometry = false;
            q.outFields = ["ASSET_NAME,ASSET_TYPE"];
            q.geometry = queryGeom;
           
           

            var popupTemplate = new esri.dijit.PopupTemplate({
                title: "{NAME}",
                fieldInfos: [
            { fieldName: "ASSET_NAME", visible: true, label: "ASSET_NAME: " },
            { fieldName: "ASSET_TYPE", visible: true, label: "ASSET_TYPE: " }
          ]
            });

            var qt = new esri.tasks.QueryTask("http://10.1.22.31/arcgis/rest/services/test/stormwater_wo_rd/MapServer/0");
            var def = qt.execute(q);
            def.addCallback(function (result) {
                return dojo.map(result.features, function (f) {
                    f.setInfoTemplate(popupTemplate);
                    return f;
                });
            });

            // use the deferred returned from the query task to set
            // the popup features
            map.infoWindow.setFeatures([def]);
            // show the popup
            map.infoWindow.show(e.screenPoint, map.getInfoWindowAnchor(e.screenPoint));
        }
        dojo.ready(init);
    </script>
  </head>
 
  <body class="tundra">
    <div data-dojo-type="dijit.layout.BorderContainer"
         data-dojo-props="design:'headline',gutters:false"
         style="width: 100%; height: 100%; margin: 0;">
      <div id="map"
           data-dojo-type="dijit.layout.ContentPane"
           data-dojo-props="region:'center'">
      </div>
    </div>
  </body>
</html>


i am able to see query result from rest point of the map service,for example

NAME: Blodgett Creek
Polyline:
[2145918.8909744024, 610092.0131329745] , [2145906.221844673, 610108.106422767] , [2145891.728881374, 610117.7147980779] more...


However, when I run my code, it seems there is no feature returns and the pop up window just say"no information available". here is what I get from Chrome's network window:

dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"displayFieldName":"NAME","fieldAliases":{"ASSET_NAME":"ASSET_NAME","ASSET_TYPE":"ASSET_TYPE"},"fields":[{"name":"ASSET_NAME","type":"esriFieldTypeString","alias":"ASSET_NAME","length":15},{"name":"ASSET_TYPE","type":"esriFieldTypeString","alias":"ASSET_TYPE","length":25}],"features":[]});
0 Kudos
20 Replies
JasonZou
Frequent Contributor
No feature returned is because you set returnGeometry = false.

Change:
q.returnGeometry = false;
q.outFields = ["ASSET_NAME,ASSET_TYPE"];


To:
q.returnGeometry = true;
q.outFields = ["ASSET_NAME","ASSET_TYPE"];
0 Kudos
JinZhang
Occasional Contributor
Thank you Jason,

I changed "returnGeometry = false" to "returnGeometry = true", however, the pop up window still shows "no information available" and the preview window in Chrome' network window shows the following without returning any feature:

dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"displayFieldName":"NAME","fieldAliases":{"ASSET_NAME":"ASSET_NAME","ASSET_TYPE":"ASSET_TYPE"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":102722,"latestWkid":3734},"fields":[{"name":"ASSET_NAME","type":"esriFieldTypeString","alias":"ASSET_NAME","length":15},{"name":"ASSET_TYPE","type":"esriFieldTypeString","alias":"ASSET_TYPE","length":25}],"features":[]});
0 Kudos
JasonZou
Frequent Contributor
dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"displayFieldName":"NAME","fieldAliases":{"ASSET_NAME":"ASSET_NAME","ASSET_TYPE":"ASSET_TYPE"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":102722,"latestWkid":3734},"fields":[{"name":"ASSET_NAME","type":"esriFieldTypeString","alias":"ASSET_NAME","length":15},{"name":"ASSET_TYPE","type":"esriFieldTypeString","alias":"ASSET_TYPE","length":25}],"features":[]});

The above is just the result of the feature layer REST endpoint, not the query result.

In addition to the change of returnGeometry, you also need to change outFields as shown in my previous post. What's the value of result returned from qt after making all these changes?

If qt returns nothing, then in Chrome Developer Tools, under Network tab, look for the query request starting with query?f=json.... Copy the whole request URL, and paste to the browser address. If you still get nothing, then something wrong with the request. Post the whole request URL if you like.
0 Kudos
JinZhang
Occasional Contributor
Thank you Jason,

I did change the outField to  q.outFields = ["ASSET_NAME","ASSET_TYPE"]; However, still no result returned.

I copied pasted the query request url from Chrome' network window under query request. No value returned, here is what it shows on screen:

{"displayFieldName":"NAME","fieldAliases":{"ASSET_NAME":"ASSET_NAME","ASSET_TYPE":"ASSET_TYPE"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":102722,"latestWkid":3734},"fields":[{"name":"ASSET_NAME","type":"esriFieldTypeString","alias":"ASSET_NAME","length":15},{"name":"ASSET_TYPE","type":"esriFieldTypeString","alias":"ASSET_TYPE","length":25}],"features":[]}


Here is the entire query request url:
http://10.1.22.31/arcgis/rest/services/test/vw_regional_drainage/MapServer/0/query?f=json&where=&ret...

I know something is wrong with the query request, but have no idea how to fix it.

Thank you,
0 Kudos
JasonZou
Frequent Contributor
Are you sure the extent fed in the request will intersect with some features? What is the feature type of the query layer? Increase the pad value to some big value for test, like 10000, and see if something returns.
0 Kudos
JinZhang
Occasional Contributor
The feature type is polyline.   I reset pad = 1000000; and still nothing returns.
0 Kudos
JasonZou
Frequent Contributor
I think I find the cause.

Change:
q.outSpatialReference = { "wkid": 3734 };


To:
q.outSpatialReference = new esri.SpatialReference({ "wkid": 3734 });
0 Kudos
JinZhang
Occasional Contributor
Jason, Thank you for look into this. I changed

q.outSpatialReference = { "wkid": 3734 };

to

q.outSpatialReference = new esri.SpatialReference({ "wkid": 3734 });

This time, when I run the code and click on the polyline, the pop up shows" searching..." for a couple seconds and then still display "no information available". This the same result I got by copy and paste the request URL in the browser:

{"displayFieldName":"NAME","fieldAliases":{"ASSET_NAME":"ASSET_NAME","ASSET_TYPE":"ASSET_TYPE"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":102722,"latestWkid":3734},"fields":[{"name":"ASSET_NAME","type":"esriFieldTypeString","alias":"ASSET_NAME","length":15},{"name":"ASSET_TYPE","type":"esriFieldTypeString","alias":"ASSET_TYPE","length":25}],"features":[]}

I am wondering if pop up does not work for a dynamic map service layer that is created by a spatial view in general? The code works fine if the dynamic map service layer is a feature layer coming from a feature class. For test purpose, I created two dynamic map services A and B, A has a feature layer (created from a feature class regionalDrainage), B has a layer coming from a spatial view(created by just select * from feature class regionalDrainage). The code works on A, the pop up shows up with the proper contents, but the code does work display any pop up with B.
0 Kudos
JasonZou
Frequent Contributor
You said in your first post that you can run the query from the rest endpoint. How did you do that? If you can get result back from the rest endpoint, the query should work then. JSAPI is built upon REST API. I don't think the issue is related to the popup. Popup is just a data viewer. The issue is whether you can query the feature layer and get something back.

Run a query against the REST endpoint directly with the following url, and see if it returns anything.
http://10.1.22.31/arcgis/rest/services/test/stormwater_wo_rd/MapServer/0/query?where=1%3D1&spatialRel=esriSpatialRelIntersects&outFields=*&returnGeometry=true&f=pjson
0 Kudos