Map and MapView autocast

415
3
Jump to solution
06-22-2021 03:01 PM
Shimoorook
New Contributor

On the documentation it's written that the Map class is autocasted for MapView class.

However, when Map module isn't imported in the beginning of the code with "esri/map", it doesn't seem to work. Am I misunderstanding how autocast works or is this a bug?

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II

Is there a particular way you're trying to create the map that doesn't work? I tried this basic example and the map works.

 

require(["esri/views/MapView"], (MapView) => {
  const view = new MapView({
    container: "viewDiv",
    map: {
      basemap: "topo-vector"
    },
    zoom: 4,
    center: [15, 65]
  });
});

View solution in original post

0 Kudos
3 Replies
ReneRubalcava
Frequent Contributor II

Is there a particular way you're trying to create the map that doesn't work? I tried this basic example and the map works.

 

require(["esri/views/MapView"], (MapView) => {
  const view = new MapView({
    container: "viewDiv",
    map: {
      basemap: "topo-vector"
    },
    zoom: 4,
    center: [15, 65]
  });
});
0 Kudos
Shimoorook
New Contributor

Oh my bad..
My code was like below

require(["esri/view/MapView"], (MapView) => {

  cost view = new MapView({

    container: "viewDiv",

    map: new Map({

      basemap: "topo-vector"

    },

    zoom: 4, 

    center: [15, 65]

  });

});

 

so when it's autocasted, there's no need to crate a new instance of the class and just provide the object with correct properties? 

0 Kudos
ReneRubalcava
Frequent Contributor II

That is correct. In some cases you need to provide a "type", like for renderers, symbols, geometry, etc. Those cases should be in the doc .

0 Kudos