TypeError: dojo.promise is undefined

1481
1
02-25-2016 12:00 PM
Chang-HengYang
New Contributor III

I am trying to convert my web mapping application from legacy to AMD style. However, the error

message tells the "TypeError: dojo.promise is undefined". I have tried to see if the error could come from the object "tasks" and "params". However, I can not tell anything wrong. Could anyone show me the solution?

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
 <link rel="stylesheet" type="text/css" href="style1.css">
  <link rel="stylesheet" type="text/css" href="style3.css">
  <link rel="stylesheet" href="https://js.arcgis.com/3.11/dijit/themes/tundra/tundra.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.11/esri/css/esri.css">

  <title>NMED MAP AMD</title>
  
  <script language="javascript" src="/JScript/universal_jsAPI.js"></script>
    <style type="text/css">
      .zoominIcon { background-image:url('Icons/Mag_plus2.svg');width:32px; height:31.1px;position:relative; right: 4px;bottom: 3px;background-size: contain;}
   .zoomprev { background-image:url('Icons/Mag_minus2.svg'); width:32px; height:31.1px;position:relative; right: 4px;bottom: 3px;background-size: contain;}
      .handIcon { background-image:url('Icons/HAND3.svg'); width:31.1px; height:31.1px;position:relative; right: 4px;bottom: 3.2px;background-size: contain;}
      .pdfIcon { background-image:url('Icons/excel.png'); width:34px; height:36px;position:relative; left: -3px;top: 0px;}
   .QueryInfo { background-image:url('Icons/Query.png'); width:32px; height:37px;position:relative; left: -2px;top: 3px;}
   .FullExtent1{ background-image:url('Icons/globe_dark2.svg'); width:31px; height:31px;position:;position:relative; right: 4px;bottom: 2px;background-size: contain;}
      .dijitButtonNode{width:55%;text-align: center; height: 120%}
   .BibliographyIcon{ background-image:url('Icons/Book.svg'); type="image/svg+xml";width:75px; height:75px;position:absolute; left: -20px;top: -17px;background-size:contain;}
   .UpdateIcon{ background-image:url('Icons/question.svg'); width:34px; height:34px;position:absolute; left: 1px;top: 2px;background-size: contain;}
   .PrintIcon{ background-image:url('Icons/Printer_dark.svg'); width:31.1px; height:30.5px;position:absolute; left: 3px;top: 2.5px;background-size: contain;}
   .WebmapData { background-image:url('Icons/DatFolder.svg'); width:34px; height:34px;position:relative; left: -5px;top: -5px;background-size: contain;}
    </style>

  <script src="https://js.arcgis.com/3.11/"></script>


  <script>
  var visible = [];
  var legendLayers = {};
  var coalminelayer; 
  var NMBGMRIndexlayer;
  var id_connect, idParams;
    require([
    "dojo/Deferred",
    "dojo/_base/connect",
    "dojo/_base/array",
    "dojo/promise/all",
    "dojo/promise/Promise",
  "dijit/form/HorizontalSlider",
  "dijit/form/CheckBox",
  "dojo/dom", 
  "dijit/registry",
  "dojo",
  "dojo/on",
  "dojo/ready",
  "dojo/parser",
  "dojo/dom-construct",
      "esri/tasks/IdentifyParameters",
      "esri/tasks/IdentifyTask",
      "esri/tasks/GeometryService",
      "esri/Color", 
      "esri/dijit/Geocoder",
      "esri/dijit/Popup",
      "esri/dijit/PopupTemplate",
      "esri/InfoTemplate",
      "esri/layers/ArcGISDynamicMapServiceLayer",
      "esri/map",
      "esri/symbols/SimpleFillSymbol",
      "esri/symbols/SimpleLineSymbol", "dojo/domReady!",
   "dijit/layout/BorderContainer",
   "dijit/layout/ContentPane",
    ], function(
     Deferred,connect,array, all, Promise, HorizontalSlider, CheckBox, dom, registry, dojo, on, ready, parser, domConstruct, IdentifyParameters,IdentifyTask, GeometryService, Color ,Geocoder, Popup, PopupTemplate,
   InfoTemplate, ArcGISDynamicMapServiceLayer, Map, SimpleFillSymbol, SimpleLineSymbol,BorderContainer,ContentPane) 
    {
      ready(function(){
   parser.parse();
   esriConfig.defaults.io.proxyUrl = "http://maps.nmt.edu/DotNet/proxy.ashx";
      esriConfig.defaults.io.alwaysUseProxy = false; 


      
   idParams = new esri.tasks.IdentifyParameters();


   var popupOptions = {
    'markerSymbol': new esri.symbol.SimpleMarkerSymbol('circle', 22, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([0, 0, 0, 0.25])),
  'fillSymbol': new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, 
  new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.5])),
  'lineSymbol': new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2),
  'marginLeft': '20', 
  'marginTop': '20'
                       };


    //create a popup to replace the map's info window
    //you'll need to include this dijit in the function
    var popup = new esri.dijit.Popup(popupOptions,dojo.create("div"));  
    




      


        map = new Map("map", {
        basemap:"topo",
          center: [-106.9048, 34.0665],
          zoom: 9,
          allowKineticScrolling : false,
  showAttribution: false,
  wrapAround180: true,
  sliderStyle: "large",
  infoWindow:popup
                    });


        
        var coalmineon = false
        if(2==1){coalmineon=true;legDisplay('coalmineLeg');dijit.byId("coalmineChk").attr('checked',true)};
        coalminelayer = initDynLayer("http://129.138.12.30:6080/arcgis/rest/services/CoalMineSJB/CoalMinsNM/MapServer","coalminelayer",false,0.8);
    

        var NMBGMRIndexon=false
        if(2==1){NMBGMRIndexon=true;legDisplay('NMBGMRIndexon');dijit.byId("NMBGMRIndexChk").attr('checked',true)};
        NMBGMRIndexlayer = initDynLayer("http://129.138.12.30:6080/arcgis/rest/services/IndexMap/NMBGMR/MapServer","NMBGMRIndexlayer",false,0.8);
              
       
    map.addLayers([coalminelayer,NMBGMRIndexlayer]);
    dojo.connect(map, "onLoad", mapReady); 






    function mapReady(map) {  
            dojo.connect(map, "onClick", runIdentifies);  
        }  


        function initDynLayer(url,id,visibility,opac) {
     var layer = new ArcGISDynamicMapServiceLayer(url, {id:id, visible:visibility, opacity:opac});
      return layer;
  }


  function legDisplay(legID){
  if(dojo.byId(legID).style.display=='none'){
  dojo.byId(legID).style.display='block'
  }else{
  dojo.byId(legID).style.display='none'
  }
           } 



  // info window 111214  
    function runIdentifies(evt) {  
            identifyResults = [];  
            idPoint = evt.mapPoint;  
            var layers = dojo.map(map.layerIds, function (layerId) {  
                return map.getLayer(layerId);  
            });  
            layers = dojo.filter(layers, function (layer) {  
                if (layer.visibleLayers[0] !== -1) {  
                    return layer.getImageUrl && layer.visible  
                }  
            }); //Only dynamic layers have the getImageUrl function. Filter so you only query visible dynamic layers  
            var tasks = dojo.map(layers, function (layer) {  
                return  esri.tasks.IdentifyTask(layer.url);  
            }); //map each visible dynamic layer to a new identify task, using the layer url  
            var defTasks = dojo.map(tasks, function (task) {  
                return new dojo.Deferred();  
            }); //map each identify task to a new dojo.Deferred  
            var params = createIdentifyParams(layers, evt);  
  
            var promises = [];  
  
            for (i = 0; i < tasks.length; i++) {  
                promises.push(tasks.execute(params)); //Execute each task  
            }  
  
            var allPromises = new dojo.promise.all(promises);  
            allPromises.then(function (r) { showIdentifyResults(r, tasks); });  
        } 
   
     function showIdentifyResults(r, tasks) {  
            var results = [];  
            var taskUrls = [];  
            r = dojo.filter(r, function (result) {  
                return r[0];  
            });  
            for (i = 0; i < r.length; i++) {  
                results = results.concat(r);  
                for (j = 0; j < r.length; j++) {  
                    taskUrls = taskUrls.concat(tasks.url);  
                }  
            }  
            results = dojo.map(results, function (result, index) {  
                var feature = result.feature;  
                var layerName = result.layerName;  
                var serviceUrl = taskUrls[index]; 
   feature.attributes.layerName = result.layerName;  
   
     <!-- CoalMine Location 02172016-->
            
               var content_CoalMineLocation = 
                  "<b>CoalMine ID</b>: ${CoalMine_I}" +
                  "<br><b>Mine Name</b>: ${Mine_name}" +
                  "<br><b>Township</b>: ${Township}" +
                  "<br><b>Range</b>: ${Range}" +
                  "<br><b>Section</b>: ${Section}" +
                  "<br><b>Subsection</b>: ${Subsection}" +
                  "<br><b>Longitude</b>: ${Long_DD}" +
                  "<br><b>Latitude</b>: ${Lat_DD}" +
                  "<br><b>Location Notes</b>: ${LocationNo}"+
                  "<br><b >More Information</b>:<a target='_blank' href='http://127.0.0.1:5000/CoalMine/${CoalMine_I}' >Coal Mine Info</a>";
  if(result.layerName=="GISData.CoakMinesNM") {  
                var template = new esri.dijit.PopupTemplate('<b>Coal Mine Location</b>', content_CoalMineLocation);  }
                    
                 var contentNMBGMR="<b>Quad Name</b>: ${NAME}" +
  "<br><b>Map Title</b>: ${Map_Title}" +
  "<br><b>Authors</b>: ${Authors}" +
  "<br><b>Publication Year</b>: ${PubYear}" +
  "<br><b>Series</b>: ${Series}" +
  "<br><b>Series Number</b>: ${SeriesNo}" +
                "<br><b >Publication Status</b>:<a target='_blank' href='${Web_URL}' >Geologic Map Information</a>";
  if(result.layerName=="GISData.DBO.NMBGMR1") {  
                var template = new esri.dijit.PopupTemplate('<b>NMBGMR (pre-1993)</b>', contentNMBGMR);}   
                
                map.infoWindow.resize(400, 550);
                feature.setInfoTemplate(template);  
  
                var resultGeometry = feature.geometry;  
                var resultType = resultGeometry.type;  
                return feature;  
            });  
  
            if (results.length === 0) {  
                map.infoWindow.clearFeatures();  
            } else {  
                map.infoWindow.setFeatures(results);  
            }  
            map.infoWindow.show(idPoint);  
            return results;  
        }         
  function createIdentifyParams(layers, evt) {  
            var identifyParamsList = [];  
            identifyParamsList.length = 0;  
            dojo.forEach(layers, function (layer) {  
                var idParams = new esri.tasks.IdentifyParameters();  
                idParams.width = map.width;  
                idParams.height = map.height; 

                idParams.geometry = evt.mapPoint;  
                idParams.mapExtent = map.extent;  
                idParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;  
                id_connect = dojo.connect(map,"onClick",runIdentifies);
                var visLayers = layer.visibleLayers;  
                if (visLayers !== -1) {  
                    idParams.layerIds = layer.visibleLayers;  
                } else {  
                    idParams.layerIds = [];  
                }  

                idParams.tolerance = 3;  
                idParams.returnGeometry = true;  
                identifyParamsList.push(idParams);  
            });  
            return identifyParamsList;  
        }  
       
       });
    });


     


      
  </script>
</head>


<body class="tundra">
<!--[if IE 7]>
<style>
  html, body {
    margin: 0;
  </style>
<![endif]-->


<div id="mainWindow" 
0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

At first glance, the modules in your require are not matching the arguments in your function. They go out of whack at "dojo/domReady!". You have to move the BorderContainer and ContentPane modules before it.

Also, why are you including "dojo" as a module (between "registry" and "on")?

0 Kudos