AnsweredAssumed Answered

How do you add featurelayers and map services to the same javascript map?

Question asked by Chad_Kopplin on Dec 30, 2015
Latest reply on Dec 30, 2015 by Chad_Kopplin

I am new to javascript, so I have taken a sample map and added featurelayers, but know I am trying to add dyanamicmapservice to the same map, and it is not working.  Here is the code.   Thank you.  Please let me know if you need the rest of the code.

 

  <script>
    var map;
    require([
      "esri/map", "esri/layers/FeatureLayer", "esri/dijit/Legend",
      "dojo/_base/array", "dojo/parser",
      "dijit/layout/BorderContainer", "dijit/layout/ContentPane",
      "dijit/layout/AccordionContainer", "dojo/domReady!",
   "esri/layers/ArcGISDynamicMapServiceLayer",
   "esri/layers/ImageParameters"
    ], function(
      Map, FeatureLayer, Legend,
      arrayUtils, parser, ArcGISDynamicMapServiceLayer,
   ImageParameters
    ) {
      parser.parse();

      map = new Map("map", {
        basemap:"hybrid",
        center: [-107.38, 42.99],
        zoom: 7
      });
      var LQD_Active_Permits = new FeatureLayer("https://gis.deq.wyoming.gov/arcgis/rest/services/LQD_PERMIT_DATA/MapServer/0", {
        mode: FeatureLayer.MODE_ONDEMAND,
        outFields:["*"]
      });
      var LQD_County_Permits = new FeatureLayer("https://gis.deq.wyoming.gov/arcgis/rest/services/LQD_PERMIT_DATA/MapServer/1", {
        mode: FeatureLayer.MODE_ONDEMAND,
        outFields:["*"]
      });  
      var Coal_Boundary = new FeatureLayer("https://gis.deq.wyoming.gov/arcgis/rest/services/ACTIVE_COAL/MapServer/0", {
        mode: FeatureLayer.MODE_ONDEMAND,
        outFields:["*"]
      });
      var LQD_Terminated_Permits = new FeatureLayer("https://gis.deq.wyoming.gov/arcgis/rest/services/LQD_PERMIT_DATA/MapServer/2", {
        mode: FeatureLayer.MODE_ONDEMAND,
        outFields:["*"]
      });
      var LQD_DISTRICTS = new FeatureLayer("https://gis.deq.wyoming.gov/arcgis/rest/services/LQD_PERMIT_PUBLIC/MapServer/12", {
        mode: FeatureLayer.MODE_ONDEMAND,
  "opacity" : 0.5,
        outFields:["*"]
      });
        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("https://gis.deq.wyoming.gov/arcgis/rest/services/LQD_PERMIT_PUBLIC/MapServer", {
          "opacity" : 0.5,
          "imageParameters" : imageParameters
   });
      //add the legend
      map.on("layers-add-result", function (evt) {
        var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
          return {layer:layer.layer, title:layer.layer.name};
        });
        if (layerInfo.length > 0) {
          var legendDijit = new Legend({
            map: map,
            layerInfos: layerInfo
          }, "legendDiv");
          legendDijit.startup();
        }
      });

      map.addLayers([LQD_DISTRICTS, LQD_Active_Permits, Coal_Boundary,LQD_County_Permits, LQD_Terminated_Permits, dynamicMapServiceLayer]);
    });
  </script>

Outcomes