AnsweredAssumed Answered

Setting Map Extent Based on Layer Extent

Question asked by LeviCecil on Jan 4, 2018
Latest reply on Jan 11, 2018 by LeviCecil

I want to set my map's extent to the extent of a feature layer. This layer will be updated regularly and the extent will be different every time. I'm following this example, and substituted my layer. It's not showing up, and the extent is far to the north of my feature. I'm getting this error in the console: Map: Geometry (wkid: 3395) cannot be converted to spatial reference of the map (wkid: 102100). I've tried setting the spatial reference of the map and the layer, to no avail. 

 

<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"> 
  <title>Resource Loader Test</title> 
 
  <link rel="stylesheet" href="http://js.arcgis.com/3.23/dijit/themes/claro/claro.css"> 
  <link rel="stylesheet" href="http://js.arcgis.com/3.23/esri/css/esri.css"> 
 
  <script src="http://js.arcgis.com/3.23/"></script> 
  <script> 
    require([ 
      "esri/map", 
      "esri/layers/FeatureLayer",           
      "esri/geometry/Extent", 
      "esri/SpatialReference", 
      "dojo/on", 
      "dojo/domReady!" 
    ], 
 
      function (Map, FeatureLayer, Extent, SpatialReference, on) { 
      
       var typhoonOutlineURL = "http://<ourserver>/arcgis/rest/services/typhoon_outlines/MapServer/0";
      
        var myLyr = new FeatureLayer(typhoonOutlineURL, { 
          mode: FeatureLayer.MODE_ONDEMAND, 
          
        }); 
 
        myLyr.on('load', initMap); 
          
          
 
        function initMap() { 
          var mapMain = new Map("mapDiv", { 
            basemap: "dark-gray", 
            extent: myLyr.fullExtent, 
            zoom: 3
          
          }); 
 
          mapMain.addLayer(myLyr); 
 
           
        } 
 
      }); 
  </script> 
 
</head> 
 
<body class="claro"> 
  <div id="mapDiv" style="width:900px; height:600px;"></div> 
  <div id="mapInfo"></div> 
</body> 
 
</html> 

Outcomes