var setTiledLayer = function(URL) { var tuID = makeid(); tuID = new esri.layers.ArcGISTiledMapServiceLayer(URL, {id: tuID + 'ID'}); return tuID; };
ms: function (l) { if (l.type === 'dynamic') { var imageParameters = new esri.layers.ImageParameters(); imageParameters.format = l.imageFormat; imageParameters.dpi = l.dpi; var layer = new esri.layers.ArcGISDynamicMapServiceLayer(l.url, { id: l.id, imageParameters: imageParameters, visible: l.visible, opacity: l.opacity }); layer.layer_params = l; //add params to layer object app.map.addLayer(layer); //create control var control = '<div style="padding:6px 0 3px; margin-bottom:3px; border-bottom:solid 1px #000;">' + '<input id="' + l.id + '_layer_control" />' + ' ' + l.name + '</div>'; //place contol dojo.place(control, 'left', 'first'); //create checkbox var checkbox = new dijit.form.CheckBox({ checked: l.visible, //set checked same as default visibility onChange: function () { //onChange function to toggle layer using the layer object itself if (layer.visible) { layer.hide() } else { layer.show() } } }, l.id + '_layer_control'); } else if (l.type === 'tiled') { //add tiled layer } }
var setChkBox = function(lyr, layerName) { "use strict"; if(lyrIDs.indexOf(lyr) > 1) { layerName.suspend(); lyrIDs.splice(lyrIDs.indexOf(lyr), 1); } else if (!(lyrIDs.hasOwnProperty(lyr))) { lyrIDs.push(lyr); layerName.resume(); } };
var config = { layersMapService: [ { url: 'http://www.sample.com/arcgis/rest/services/some_layer/MapServer', //url type: 'dynamic', //type (dynamic or tiled) name: 'Some Layer', //name as shown in toc and elsewhere id: 'somelayer', //id must be unique visible: false, //initial visibility opacity: 1, //initial opacity imageFormat: 'png32', //image format dpi: 96, //dpi legend: true, //legend in toc and map identify: false, //is layer available in identify widget identifyLayers: [], //which layers query: false, //is layer available in query widget queryLayers: [] //which layers }, { url: 'http://www.sample.com/arcgis/rest/services/another_layer/MapServer', type: 'dynamic', name: 'Another Layer', id: 'anotherlayer', visible: false, opacity: 0.5, imageFormat: 'png32', dpi: 96, legend: true, identify: true, identifyLayers: [0,1,6], query: true, queryLayers: [0,1,3,4,5,6] } ] };
var app = { build: function() { //build viewer, load mods, etc //map app.map = new esri.Map('map', {}); //add layers dojo.forEach(config.layersMapService, app.layers.add.ms); }, layers: { add: { ms: function(l) { //l is the object with all the params if (l.type === 'dynamic') { var imageParameters = new esri.layers.ImageParameters(); imageParameters.format = l.imageFormat; imageParameters.dpi = l.dpi; var layer = new esri.layers.ArcGISDynamicMapServiceLayer(url, { id: l.id, imageParameters: imageParameters, visible: l.visible, opacity: l.opacity }); /* //because the layer is an object I add the params object //directly to the layer object in case I want them //again for some other functionality // //this is an important concept to really leverage the api // //for example: when the query widget gets the json object //back from the server for each map service layer that information //(fields, domains, etc) will be stored as an object in the //corresponding layerIds object */ layer.layer_params = l; app.map.addLayer(layer); /* //this is the time to do all the extra things //while we have the layer variable */ app.toc.add(layer, l.legend); if (l.identify) { app.identify.add(layer, l.identifyLayers) } if (l.query) { app.query.add(layer, l.queryLayers) } } else if (l.type === 'tiled') { //add tiled layer } } } } };
var lyrHldr = {}; var setTiledLayer = function(URL, lyrNm) { var temp = makeid(); lyrHldr[temp] = new esri.layers.ArcGISTiledMapServiceLayer(URL, {id: lyrNm}); return lyrHldr[temp]; };
var setTiledLayer = function(URL) { var tuID = makeid(); //here tuID is whatever makeid() returns //now tuID is is the layer object tuID = new esri.layers.ArcGISTiledMapServiceLayer(URL, {id: tuID + 'ID'}); //you are trying to use an object for part of the string "id" return tuID; //this should throw an error - are you watching this in firebug? };
var setTiledLayer = function(URL) { var tuID = makeid(); var layer = new esri.layers.ArcGISTiledMapServiceLayer(URL, {id: tuID + 'ID'}); return layer; };
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.