In a previous question, I was trying to implement this Azure Maps Animations sample with TypeScript: https://samples.azuremaps.com/animations/animate-marker-along-path
Trying to merge 'azure-maps-control' and 'azure-maps-animations' under the atlas namespace while using the AMD mode in Tyepscript, I had issues as 'azure-maps-animations' is built for ESNext.
I redo my project but smaller, with:
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"declaration": false,
"lib": ["ES6", "DOM"],
"resolveJsonModule": true,
"downlevelIteration": true,
"outDir": "./js",
"rootDir": "./ts",
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"typeRoots": [
"./node_modules/@types",
"./types"
],
"baseUrl": "./",
"paths": {
"azure-maps-control": ["./node_modules/azure-maps-control/dist/atlas"]
}
},
the index.html file has:
/// <reference path="../types/azure-maps-control.d.ts" />
import * as atlas from "azure-maps-control";
function main() {
try {
console.log("main start !");
//var map: atlas.Map = new atlas.Map("", {});
} catch (error) {
console.error('Error initializing game:', error);
}
console.log("main ends");
}
and index.html has:
<script type="module" src="./node_modules/azure-maps-control/dist/atlas.js" defer></script>
<script type="module" src="./js/main.js" defer></script>
As long as var map: atlas.Map = new atlas.Map("", {}); is commented out, web page loads in Chrome, the Network tab shows status of 200 of each files and files are in the Sources tab.
When I uncomment var map: atlas.Map = new atlas.Map("", {});, all files still have a status of 200 but main.js is not in Sources anymore and the message TypeError: Failed to resolve module specifier "azure-maps-control" rise.
The generated main.js file as import * as atlas from "azure-maps-control"; and I feel that javascript cannot find it.
I'm confused with all the different modes that can be used in Typescript and seems it changes everything dependending on the choice.
If you can see anything that could help me, thanks alot.
Edit : 2024 09 07
I commented out everything and started again adding bits by bits. I load only one JS in my index.html:
main.js :
/// <reference path="../types/azure-maps-control.d.ts" />
import * as atlas from 'azure-maps-control';
import 'azure-maps-control/dist/atlas.min.css';
VSCode doesn't complain but at runtime in Chrome I have about 'azure-maps-control': Failed to resolve module specifier "azure-maps-control". Relative references must start with either "/", "./", or "../".
I assumed it can be from settings in TSConfig.json, I'm using this as it seemed to be the most recent settings:
{
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"typeRoots": [
"./node_modules/@types",
"./types"
],
"paths": {}
}
,"include": ["ts/**/*", "types/**/*"]
,"exclude": ["node_modules", "**/*.spec.ts"]
Also, I am not using any bundler.
Any idea what I can do to fix this ?
Do you think it could work and if any one has any sample, to load atlas just in time ? Like in
if(this.provider == "Azure") {
const { atlas } = await import("a CDN or local file");
map = new atlas.Map(...)
}
Thanks

