Hi,
There is no order by geometry type in a legend created with a legend widget.
How layers can be ordered? Generally, we need to implement the rule:
- points
- lines
- polygons
bottom - polygons.
Any help will be appreciated.
the property define the layer order on Legend Widget according to the Javascript Help is the LayerInfos
see below.
<Object[] > layerInfos | Optional | Specify a subset of the layers in the map to display in the legend. If not set, all layers in the map will display in the legend. The order of the layers in the legend depends on the layerInfo array. See the layerInfos property description for a description of its object properties. |
So during the layer load on the map change the layer order.
this is a sample code
......
//add the legend
map.on("layers-add-result", function (evt) {
var layerInfoLines = [];
arrayUtils.map(evt.layers, function (layer, index) {
if (layer.layer.geometryType === "esriGeometryPolyline"){
layerInfoLines.push({layer:layer.layer, title:layer.layer.name});
}
});
var layerInfoPolygons = [];
arrayUtils.map(evt.layers, function (layer, index) {
if (layer.layer.geometryType === "esriGeometryPolygon"){
layerInfoPolygons.push({layer:layer.layer, title:layer.layer.name});
}
});
var layerInfo = layerInfoPolygons.concat(layerInfoLines);
if (layerInfo.length > 0) {
var legendDijit = new Legend({
map: map,
layerInfos: layerInfo
}, "legendDiv");
legendDijit.startup();
}
});
.....
and here see a live sample
Thank you for response, Panagiotis Papadopoulos.
Unfortunately, we have no geometry type when working with ArcGISDynamicMapServiceLayer.
So, how we obtain that geometryType?
See this discussion: https://community.esri.com/message/80485