AnsweredAssumed Answered

javascript map periodically fails to load

Question asked by ssdema on Jul 30, 2014
Latest reply on Jul 30, 2014 by ssdema

I am using asp.net along with JavaScript to develop a webpage that will display a map,

 

Basically, I am loading an image service and a map service, selecting a feature and zooming to that feature.  The code works about 90% of the time. When it does fail, it will load the map service and zoom to the proper extent, but it DOES NOT load the image service or select a feature.

 

It appears the instigator either the query or the or the feature selection - if I remove the call to doMaps(), the code never fails.

Does anyone have any experience in this area?

 

I have attached two images as examples.  This is the code I am using:          

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head >

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <title></title>

    <script src="http://js.arcgis.com/3.7/" type="text/javascript"></script>

   <script>

       var MN, ParcelMap, sfs, queryTask;

       var featurelayer;

        require(["esri/map","dojo/on","dojo/parser","esri/layers/ArcGISDynamicMapServiceLayer","esri/layers/ArcGISImageServiceLayer","esri/renderers/SimpleRenderer","dojo/_base/connect","dojo/dom","dojo/query","esri/graphic","esri/layers/FeatureLayer","dojo/domReady!"],

        function (Map, on, parser, ArcGISDynamicMapServiceLayer, ArcGISImageServiceLayer, SimpleRenderer, connect, dom, query, Graphic, FeatureLayer) {

                 

            parser.parse();

          

            queryTask = new esri.tasks.QueryTask("http://MapServer/2");

            MN = "5"

            //define maps

            ParcelMap = new esri.Map("ParcelMap");

 

            var layer1 = new esri.layers.ArcGISImageServiceLayer("http://ImageServer");

            ParcelMap.addLayer(layer1);

            var layer2 = new esri.layers.ArcGISDynamicMapServiceLayer("http:///MapServer");

            ParcelMap.addLayer(layer2);

 

            ParcelMap.on("load", doMaps());

          

            function doMaps() {

                sfs = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 2));

                //create selection layer

                featureLayer = new esri.layers.FeatureLayer("http://MapServer/2", {

                    mode: esri.layers.FeatureLayer.MODE_SELECTION

                })

                featureLayer.setSelectionSymbol(sfs);

 

                //add selection layer to map

                ParcelMap.addLayers([featureLayer]);

                //set up query

                query = new esri.tasks.Query();

                query.returnGeometry = true;

                query.where = "MAP_NO = '" + MN + "'";

 

                //select parcel

                featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {

                    if (features.length == 0) {

                        alert("No Parcel Found");

                    }

                    else {

                        //zoom to the selected feature

                        parcelExtent = features[0].geometry.getExtent().expand(1.5);

                        ParcelMap.setExtent(parcelExtent);

                   }

                });

            }

        });

    </script>

  </head>

<body class="tundra">

    <form id="form1" runat="server">

        <div id="ParcelMap" style="width:400px; height:400px;runat="server"></div>

    </form>

</body>

</html>

Attachments

Outcomes