Hello All,
Was just wondering if I there is a way to hide or not show the REST service name "USA" in the legend widget? Please see the screenshot and the code that I have. Any help would be appreciated. Thanks.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Legend</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.28/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.28/esri/css/esri.css">
<style>
html, body, #mapDiv {
padding:0;
margin:0;
height:90%;
}
#legendDiv {
left:40px;
top:30px;
width: 200px;
height: 350px;
background-color: white;
}
</style>
<script src="https://js.arcgis.com/3.27/"></script>
<script>
var map, layer;
require([
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/ImageParameters",
"esri/layers/FeatureLayer",
"esri/dijit/Legend"
],
function (Map, ArcGISDynamicMapServiceLayer, ImageParameters,FeatureLayer,Legend)
{
layer = new ArcGISDynamicMapServiceLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",{
});
map = new Map("mapDiv", {
//basemap: "topo",
center: [-100.015, 38.652],
zoom: 11
});
layer.setVisibleLayers([3]);
map.addLayer(layer);
const legend = new Legend(
{
map: map,
}, "legendDiv");
legend.startup();
});
</script>
</head>
<body class="claro">
<div id="mapDiv"></div>
<div id="legendDiv"></div>
</body>
</html>
Solved! Go to Solution.
can we not use the legend widget at all? maybe create a custom legend with the layer's service predefined symbology published from the .mxd and add in the layer title or wording however we want? At the end of the day I want to be able to dynamically display the layer name/title based on the language that the users selected, i.e. water for english, aqua for spanish
I have overlooked one easy way to get rid of that text. You can use the layerInfos property to add a blank title
const legend = new Legend(
{
map: map,
layerInfos: [{
layer: layer,
title: " "
}]
}, "legendDiv");