Hy,
I need to display loading icon when map is loading.
With API JavaScript 3.X it is possible with map event's onUpdateStart/onUpdateEnd, like in following sample :
Show loading icon | ArcGIS API for JavaScript 3.25
Equivalent is not available in version 4, so how to do that ? Is there a way to do like in version 3 globally on Map (or View) ?
Regards,
Flavie
Solved! Go to Solution.
Flavie,
In 4.x you watch properties of the view like updating
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Intro to MapView - Create a 2D map - 4.8</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
.visible {
display: block !important;
}
.loading{
position: absolute;
top: 100px;
left: 100px;
background-color: black;
color: white;
display: none;
padding: 8px;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.8/esri/css/main.css">
<script src="https://js.arcgis.com/4.8/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"dojo/dom-class",
"dojo/domReady!"
], function(Map, MapView, domClass) {
var map = new Map({
basemap: "streets"
});
var view = new MapView({
container: "viewDiv",
map: map,
zoom: 4,
center: [15, 65] // longitude, latitude
});
view.watch('updating', function(evt){
if(evt === true){
domClass.add('loadingDiv', 'visible');
}else{
domClass.remove('loadingDiv', 'visible');
}
})
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="loadingDiv" class="loading">Updating...</div>
</body>
</html>
Flavie,
In 4.x you watch properties of the view like updating
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Intro to MapView - Create a 2D map - 4.8</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
.visible {
display: block !important;
}
.loading{
position: absolute;
top: 100px;
left: 100px;
background-color: black;
color: white;
display: none;
padding: 8px;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.8/esri/css/main.css">
<script src="https://js.arcgis.com/4.8/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"dojo/dom-class",
"dojo/domReady!"
], function(Map, MapView, domClass) {
var map = new Map({
basemap: "streets"
});
var view = new MapView({
container: "viewDiv",
map: map,
zoom: 4,
center: [15, 65] // longitude, latitude
});
view.watch('updating', function(evt){
if(evt === true){
domClass.add('loadingDiv', 'visible');
}else{
domClass.remove('loadingDiv', 'visible');
}
})
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="loadingDiv" class="loading">Updating...</div>
</body>
</html>
I will use this property, thanks Robert Scheitlin, GISP!
Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.