Select to view content in your preferred language

Import and export 'map' and 'view'

879
4
Jump to solution
07-26-2023 08:11 AM
Med-Karim-Rouissi
New Contributor III

Is there a way to import and export 'map' and 'view' whether using the AMD or ESM module, knowing that I work in CDN mode with API JS Arcgis 4.24, my code is very long and contains two blocks that depend on 'map' and 'view', so I'm trying to separate the blocks into two distinct files, one main file that needs to export 'map' and 'view' to the second one, I tested with AMD module and then with the ESM module with the necessary modifications including the 'type' in index.html, but without success, I also put test variables or test constants, I manage to export and import them without problems , but not 'map' and 'view'!

Does anyone have any idea on the correct method to import and export 'map' and 'view'?

Tags (4)
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II

When using CDN with AMD and you want to import local packages, it's the same for 3 and 4. The 4x documentation has some information here.

https://developers.arcgis.com/javascript/latest/amd-build/#configure-amd-to-load-custom-modules

 

When using ESM, you can import local ESM modules like any other ESM application. You said you want to export Map and View from your module? That could look like this.

 

 

// Edit, because I don't think this first option would work, since both
// are defaults and aren't named, better to use another option below.
// export * from 'https://js.arcgis.com/4.27/@arcgis/core/Map.js';
// export * from 'https://js.arcgis.com/4.27/@arcgis/core/views/MapView.js';

// another option
import Map from 'https://js.arcgis.com/4.27/@arcgis/core/Map.js';
import MapView from 'https://js.arcgis.com/4.27/@arcgis/core/views/MapView.js';

export Map;
export MapView;

// or
export { Map, MapView };

 

 

 

You just need to remember, the ESM CDN is for testing purposes only, you should not use it for a production application. 

View solution in original post

4 Replies
ReneRubalcava
Frequent Contributor II

Not quite sure exactly what you are trying to do. Do you have a simple github repo or something to share? You mention CDN and ESM, but they are both very different in how you would build your apps.

If using the CDN, you can create local packages you can consume. The 3x documentation has some information about this.

https://developers.arcgis.com/javascript/3/jshelp/intro_javascript_classes.html#step2

 

Maybe that will help.

0 Kudos
Med-Karim-Rouissi
New Contributor III

I don't have a Guithb repository, I'm still in the test phase, I'm developing with Api JS for Arcgis 4, not 3, I generally work in CDN(AMD), but the import/export hasn't worked, I wanted to see if it works in CDN(ESM).

https://developers.arcgis.com/javascript/latest/tooling-intro/

 

0 Kudos
ReneRubalcava
Frequent Contributor II

When using CDN with AMD and you want to import local packages, it's the same for 3 and 4. The 4x documentation has some information here.

https://developers.arcgis.com/javascript/latest/amd-build/#configure-amd-to-load-custom-modules

 

When using ESM, you can import local ESM modules like any other ESM application. You said you want to export Map and View from your module? That could look like this.

 

 

// Edit, because I don't think this first option would work, since both
// are defaults and aren't named, better to use another option below.
// export * from 'https://js.arcgis.com/4.27/@arcgis/core/Map.js';
// export * from 'https://js.arcgis.com/4.27/@arcgis/core/views/MapView.js';

// another option
import Map from 'https://js.arcgis.com/4.27/@arcgis/core/Map.js';
import MapView from 'https://js.arcgis.com/4.27/@arcgis/core/views/MapView.js';

export Map;
export MapView;

// or
export { Map, MapView };

 

 

 

You just need to remember, the ESM CDN is for testing purposes only, you should not use it for a production application. 

Med-Karim-Rouissi
New Contributor III

Merci René 🙂 

0 Kudos