AnsweredAssumed Answered

Add a Dynamic Layer

Question asked by endlessdsire on Mar 5, 2015
Latest reply on Mar 5, 2015 by endlessdsire

Hello, im new programming in javascript (i used to developed flex applications) and im migrating a app that i made in flex to js.

Im having the following issue that will sound very simple:

 

1.- How can i add a dynamic layer to the map?

2.- is it possible throught the dynamic layer get some info or i need to do it with the feature layers?

 

 

I have this code but idk why it doesnt work. I read already the API and try the examples but still doesnt work.

Im new using require so im trying to learn how it works but this time it just load my featurelayer, not the dynamic one.

I hope u can help me guys

Thanks so much!

 

IdentityManager.js

var map;
var identityManagerOK ="NO";
//Establece todo lo requerido para funcionar. "LIBRERIAS"
  require([
      "dojo/_base/array",
      "dojo/parser",
      "esri/config",
      "esri/dijit/editing/Editor",
      "esri/dijit/editing/TemplatePicker",
      "esri/layers/FeatureLayer",
      "esri/layers/ArcGISDynamicMapServiceLayer",
        "esri/layers/ImageParameters",
      "esri/map",
      "esri/IdentityManager",
      "dojo/domReady!",
      "dijit/layout/ContentPane",
      "dijit/layout/BorderContainer"],
    function (arrayUtils, parser, esriConfig, Editor, TemplatePicker, ArcGISDynamicMapServiceLayer, ImageParameters,FeatureLayer, Map){


      parser.parse();
   esriConfig.defaults.io.proxyUrl = "/proxy/";

  //GENERA UN MAPA BASE
       map = new Map("map", {
          basemap: "topo",
          center: [-71.0659,-32.9252], // longitude, latitude
          zoom: 8
      });
     
      //add editor when secureLayer is added.
      map.on("layers-add-result", initEditing);


      //add the secure service - token is required
      var secureLayer = new FeatureLayer("",
       { mode: FeatureLayer.MODE_ONDEMAND,outFields: ["nombre"] });
     
     
      var imageParameters = new ImageParameters();
        imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.

        //Takes a URL to a non cached map service.
        var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://maps.decaturil.gov/arcgis/rest/services/Public/InternetVector/MapServer", {
          "opacity" : 0.5,
          "imageParameters" : imageParameters});
       
        //Agrega los layers al mapa 
      map.addLayers([secureLayer,dynamicMapServiceLayer]);
     
      //Genera el infowindow para mostrar datos
      map.infoWindow.resize(200, 200);


      function initEditing(event){
      alert("entre");
      var results = event.layers;
        var featureLayerInfos = arrayUtils.map(results, function (result){
          return {
            "featureLayer": result.layer
          };
        });
        var layers = arrayUtils.map(results, function (result){
          return result.layer;
        });


        var templatePicker = new TemplatePicker({
          featureLayers: layers,
          rows: 'auto',
          columns: 2
        }, "templatePickerDiv");


        templatePicker.startup();


        //setup the editor widget
        var settings = {
          map: map,
          templatePicker: templatePicker,
          layerInfos: featureLayerInfos
        };
        var params = {
          settings: settings
        };


        var editorWidget = new Editor(params);
        map.enableSnapping();
        editorWidget.startup();
       
       //VARIABLE PARA SABER SI EL LOGIN CORRESPONDE O NO
       
       identityManagerOK="YES";
       //alert(identityManagerOK);
      } 
      identityManagerOK="NO";
      // alert(identityManagerOK);
    });

Outcomes