I have a mapserver
http:// mymapserver/services/rest/xxx/mapserver/
which contains 7 layers with /mapserver /1 /through mapserver/7
If a define an ArcGISDynamicMapServiceLayer and 7 FeatureLayers in OnDemand Mode, everything gets displayed and I can query every layer based on the infoTemplate. There is however one small glitch: the ArcGISDynamicMapServiceLayer has 1-x default visible layers which are not queryable and have a slight offset.
Is there a way, to define the ArcGISDynamicMapServiceLayer, retrieve all included FeatureLayers and add them on the fly to a) the basemap and b) the Layerlist, while retrieving c) the Legend?
Bonuspoints for keeping the hints borderline simple; I am a javascript novice and I hate dojo.
Kind regards
this is the actual code:
var visible = [];
var ml = [];
require(["dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/layout/AccordionContainer", "esri/dijit/Legend", "dojo/_base/array", "dijit/form/Button"]);
require(["dgrid/OnDemandGrid", "dgrid/Selection", "dojo/store/Memory", "esri/map", "esri/layers/FeatureLayer", "dojo/_base/declare", "dojo/number", "dojo/parser", "dojo/domReady!", "dojo/on", "dojo/dom", ],
function (Grid, Selection, Memory, Map, FeatureLayer, declare, dojoNum, parser, array, on, dom) {
parser.parse();
window.infoTemplate = new esri.InfoTemplate("Attributes", "${*}");
window.map = new esri.Map("map", {
basemap: "topo",
center: [12.8, 51],
zoom: 9
});
on(dom.byId("btnStreets"), "click", function () {
window.map.setBasemap("streets");
});
on(dom.byId("btnSatellite"), "click", function () {
window.map.setBasemap("satellite");
});
on(dom.byId("btnHybrid"), "click", function () {
window.map.setBasemap("hybrid");
});
on(dom.byId("btnTopo"), "click", function () {
window.map.setBasemap("topo");
});
on(dom.byId("btnGray"), "click", function () {
window.map.setBasemap("gray");
});
on(dom.byId("btnNatGeo"), "click", function () {
window.map.setBasemap("national-geographic");
});
window.MapServiceURL = "http://theserver/ArcGIS/rest/services/xxx/MapServer/";
window.HWSUrl = "http://theserver/ArcGIS/rest/services/xxx/MapServer/1";
window.outFields = ["OBJECTID", "HOCHWERT", "SchadenNr", "STATUS"];
var fl = new FeatureLayer(window.HWSUrl, {
id: "schaden",
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: window.outFields,
infoTemplate: infoTemplate
});
/** excluded FeatureLayers 2-7 **/
ml = new esri.layers.ArcGISDynamicMapServiceLayer(window.MapServiceURL);
dojo.connect(fl, "onLoad", function (fl) {
fl.maxScale = 0;
fl.setSelectionSymbol(new esri.symbol.SimpleFillSymbol().setOutline(null).setColor("#AEC7E3"));
});
dojo.connect(map, "onLoad", function (map) {
// show the border container now that the dijits
// are rendered and the map has loaded
dojo.style(dijit.byId("container").domNode, "visibility", "visible");
});
//add the legend
dojo.connect(map, 'onLayersAddResult', function (results) {
var layerInfo = dojo.map(results, function (layer, index) {
return { layer: layer.layer, title: layer.layer.name };
});
if (layerInfo.length > 0) {
var legendDijit = new esri.dijit.Legend({
map: map,
layerInfos: layerInfo
}, "legendDiv");
legendDijit.startup();
}
});
if (ml.loaded) {
buildLayerList(ml);
} else {
dojo.connect(ml, "onLoad", buildLayerList);
}
map.addLayers([fl]);
});
/*building LayList function*/
function buildLayerList(layer) {
var items = dojo.map(layer.layerInfos, function (info, index) {
if (info.defaultVisibility) {
visible.push(info.id);
}
return "<input type='checkbox' class='list_item' " + (info.defaultVisibility ? "checked=checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><label for='" + info.id + "'>" + info.name + "</label><br />";
});
dojo.byId("layer_list").innerHTML = items.join(' ');
layer.setVisibleLayers(visible);
map.addLayer(layer);
}
function updateLayerVisibility() {
var inputs = dojo.query(".list_item"), input;
visible = [];
dojo.forEach(inputs, function (input) {
if (input.checked) {
visible.push(input.id);
}
});
if (visible.length === 0) {
visible.push(-1);
}
ml.setVisibleLayers(visible);
}