Philip,
That would involve using watchUtils. 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>Legend widget - 4.6</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.6/esri/css/main.css">
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
<script src="https://js.arcgis.com/4.6/"></script>
<script>
require([
"esri/views/MapView",
"esri/widgets/Legend",
"esri/WebMap",
"esri/core/watchUtils",
"dojo/domReady!"
],
function(
MapView, Legend, WebMap, watchUtils
) {
var webmap = new WebMap({
portalItem: {
id: "4abe6a830b8f466dacf8abfde567a781"
}
});
var view = new MapView({
container: "viewDiv",
map: webmap
});
view.when(function() {
var featureLayer = webmap.layers.getItemAt(0);
var legend = new Legend({
view: view,
layerInfos: [{
layer: featureLayer,
title: "NY Educational Attainment"
}]
});
watchUtils.when(legend ,"container", function(){
legend.container.style.display = 'none';
})
view.ui.add(legend, "bottom-right");
view.watch("scale", function(scale) {
if (scale > 1500000) {
legend.container.style.display = 'none';
} else {
legend.container.style.display = 'block';
}
});
});
});
</script>
</head>
<body class="calcite">
<div id="viewDiv"></div>
</body>
</html>