1

I'm attempting to set the spatialReference property of the view to 102667. The console logs the error:

init.js:321 [esri.views.MapView] The view could not be initialized with the spatialReference 102667. Try specifying an extent or a center and scale

I'm using the sandbox environment as an example, because I'm not understanding why this wouldn't work. The data I am working with is all projected with this spatial reference, so I thought it would be prudent to set the View to match. The excerpt comes from here:

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=get-started-mapview

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Get started with MapView - Create a 2D map - 4.4</title>
  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <link rel="stylesheet" href="https://js.arcgis.com/4.4/esri/css/main.css">
  <script src="https://js.arcgis.com/4.4/"></script>

  <script>
    require([
      "esri/Map",
      "esri/views/MapView",
      "dojo/domReady!"
    ], function(Map, MapView) {

      var map = new Map({
        basemap: "streets"
      });

      var view = new MapView({
        container: "viewDiv",
        map: map,
        zoom: 4,
        center: [15, 65], // longitude, latitude
        spatialReference: {wkid: 102667}
      });

    });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>
</html>

1 Answer 1

1

When using an Esri basemap, the default spatial reference is Web Mercator Auxiliary Sphere, that is the reason the view could not be initialized with the spatialReference 102667.

You can try the following code:

<script>
require([
  "esri/Map",
  "esri/views/MapView",
  "esri/geometry/SpatialReference",
  "esri/geometry/Extent",
  "dojo/domReady!"
], function(Map, MapView, SpatialReference, Extent) {

  var map = new Map({
    basemap: "streets"
  });

  var view = new MapView({
    container: "viewDiv",
    map: map,
    zoom: 4,
    center: [15, 65]
  });

  // Set the extent on the view
  view.extent = new Extent({
    xmin: -9177882,
    ymin: 4246761,
    xmax: -9176720,
    ymax: 4247967,
    spatialReference: new SpatialReference({wkid:102667})
  });

});

But my suggestion is either to use a basemap with your current Spatial Reference System, or to proyect your layers on the fly to the Web Mercator Spatial Reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.