I'm working on API 4.x
<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
<link rel="stylesheet" href="https://esri.github.io/calcite-maps/dist/css/calcite-maps-arcgis-4.x.min-v0.7.css">
How can I display current map scale (1:xxxxxxx)? Please help.
Solved! Go to Solution.
Here is a sample:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Load a basic WebMap - 4.13</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#vScale {
padding: 10px;
}
</style>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.13/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.13/"></script>
<script>
require(["esri/views/MapView", "esri/WebMap"], function(MapView, WebMap) {
/************************************************************
* Creates a new WebMap instance. A WebMap must reference
* a PortalItem ID that represents a WebMap saved to
* arcgis.com or an on-premise portal.
*
* To load a WebMap from an on-premise portal, set the portal
* url with esriConfig.portalUrl.
************************************************************/
var webmap = new WebMap({
portalItem: {
// autocasts as new PortalItem()
id: "f2e9b762544945f390ca4ac3671cfa72"
}
});
/************************************************************
* Set the WebMap instance to the map property in a MapView.
************************************************************/
var view = new MapView({
map: webmap,
container: "viewDiv"
});
view.watch('scale', function(evt){
document.getElementById('vScale').innerHTML = '1:' + evt.toFixed(2);
});
view.ui.add(vScale, 'bottom-left')
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="vScale" class="esri-widget"></div>
</body>
</html>
Here is a sample:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Load a basic WebMap - 4.13</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#vScale {
padding: 10px;
}
</style>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.13/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.13/"></script>
<script>
require(["esri/views/MapView", "esri/WebMap"], function(MapView, WebMap) {
/************************************************************
* Creates a new WebMap instance. A WebMap must reference
* a PortalItem ID that represents a WebMap saved to
* arcgis.com or an on-premise portal.
*
* To load a WebMap from an on-premise portal, set the portal
* url with esriConfig.portalUrl.
************************************************************/
var webmap = new WebMap({
portalItem: {
// autocasts as new PortalItem()
id: "f2e9b762544945f390ca4ac3671cfa72"
}
});
/************************************************************
* Set the WebMap instance to the map property in a MapView.
************************************************************/
var view = new MapView({
map: webmap,
container: "viewDiv"
});
view.watch('scale', function(evt){
document.getElementById('vScale').innerHTML = '1:' + evt.toFixed(2);
});
view.ui.add(vScale, 'bottom-left')
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="vScale" class="esri-widget"></div>
</body>
</html>