Latest JS API v4 not working while older v3.17 works

2072
6
Jump to solution
07-08-2016 11:34 AM
KittyYiu
New Contributor II

Note: I'm a beginner to ArcGIS JavaScript API.

I want to check to see if anyone is also having the same problem.

Which I uploaded my codes here

< http://codepen.io/yiuklh/pen/vKZNoE >

And so I'm wondering if the latest ArcGIS JS API v4 is not compatible.

< https://developers.arcgis.com/javascript/latest/sample-code/get-started-mapview/index.html​ >

While the older < ArcGIS API for JavaScript 3.17  > works just fine.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Kitty,

  A lot has changed between the two versions you can not just use your old 3.x code in a 4.x app. Here is the changes to make to your js code:

//default World Map view
//since no initial map extent setup yet
var map;
require([
    "esri/Map",
    "esri/views/MapView"
  ],
  function(Map, MapView) {
    map = new Map({
      basemap: "topo"
    });
    var view = new MapView({
      container: "myMap",  // Reference to the DOM node that will contain the view
      map: map              // References the map object created in step 3
    });
  });

View solution in original post

6 Replies
TimWitt2
MVP Alum

Kitty,

some things have not been transferred from 3.X to the 4.0 version.

See here: Functionality matrix | ArcGIS API for JavaScript 4.0

Tim

KittyYiu
New Contributor II

Thanks for checking, Tim W.

So that means the problem is more of Esri API side. Which the v4.0 is currently still not as stable as the older v3.17?

Do you recommend I sticks with v3.17 for now doing my learning?

I'm using this book < ArcGIS for JavaScript Developers by Example | PACKT Books  >

0 Kudos
TimWitt2
MVP Alum

Roberts answer should be able to help you.

In general I will stick with 3.x versions until 4.0 is finished.

RobertScheitlin__GISP
MVP Emeritus

Kitty,

  A lot has changed between the two versions you can not just use your old 3.x code in a 4.x app. Here is the changes to make to your js code:

//default World Map view
//since no initial map extent setup yet
var map;
require([
    "esri/Map",
    "esri/views/MapView"
  ],
  function(Map, MapView) {
    map = new Map({
      basemap: "topo"
    });
    var view = new MapView({
      container: "myMap",  // Reference to the DOM node that will contain the view
      map: map              // References the map object created in step 3
    });
  });
ChrisSmith7
Frequent Contributor

Kitty,

There is a migration page that I suspect will become substantially larger as time goes on - Migrating from 3.x to 4.0 | ArcGIS API for JavaScript 4.0

I will be honest, this is a little scary:

Consider rewriting applications instead of simply trying to update them.

For those of us that have spent several years developing and enhancing a mapping application, using many custom modules and classes, this sure sounds painful!

And, with the functionality of 3.x not yet ported over, it may be difficult to start that process now. I understand why this must occur, I just hope that 3.x will receive bug fixes and be supported well into the future while we make the transition. I suppose the silver lining is job security!

KittyYiu
New Contributor II

Correction posted here (credit: rscheitlin) .

< http://codepen.io/yiuklh/pen/Vjrawp >

Thank-you all again!