2014-09-23 4 views
0

Я работаю над проектом, пытающимся добавить функциональные слои из ArcGIS online в приложение веб-карты с использованием JavaScript API, в котором пользователь может включать и выключать слои с помощью галочки HTML. Уровни импортируются правильно и отображаются, когда флажки галочки обходят, но я могу заставить его работать с тикбоксами. Я взломал код из образцов ArcGIS и т. Д., Поэтому это должно быть небольшая вещь, которую я не вижу!ArcGIS Javascript API - addLayers

Вот код - в основном все, что я хочу, чтобы слои включения и выключения на верхней части постоянной базовой карты на основе которой Флажки пользователь помечает и выключаться

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
     on iOS devices--> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> 
    <title>Select with feature layer</title> 
    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/tundra/tundra.css"> 
    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css"> 
    <style> 
     html, body, #mapDiv { 
     padding: 0; 
     margin: 0; 
     height: 100%; 
     } 
     #messages{ 
     background-color: #fff; 
     box-shadow: 0 0 5px #888; 
     font-size: 1.1em; 
     max-width: 15em; 
     padding: 0.5em; 
     position: absolute; 
     right: 20px; 
     top: 20px; 
     z-index: 40; 
     } 
    </style> 
    <script src="http://js.arcgis.com/3.10/"></script> 
    <script> 

     var map; 
     require([ 
     "esri/map", "esri/layers/FeatureLayer", 
     "esri/tasks/query", "esri/geometry/Circle", 
     "esri/graphic", "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol", 
     "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/renderers/SimpleRenderer", 
     "esri/config", "esri/Color", "dojo/dom", "dojo/domReady!", "dojo/on", "dojo/query", "dojo/domReady!", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/ImageParameters", 
     ], function (
     Map, FeatureLayer, 
     Query, Circle, 
     Graphic, InfoTemplate, SimpleMarkerSymbol, 
     SimpleLineSymbol, SimpleFillSymbol, SimpleRenderer, 
     esriConfig, Color, dom, on, query, ArcGISDynamicMapServiceLayer, ImageParameters 
    ) { 
      // use a proxy page if a URL generated by this page is greater than 2000 characters 
      // 
      // this should not be needed as nearly all query & select functions are performed on the client 
      esriConfig.defaults.io.proxyUrl = "/proxy"; 

      map = new Map("mapDiv", { 
       basemap: "streets", 
       center: [-120.303130, 36.542750], 
       zoom: 5, 
       slider: false 
      }); 

      //add the census block points in on demand mode. Note that an info template has been defined so when 
      //selected features are clicked a popup window will appear displaying the content defined in the info template. 
      var Offices = new FeatureLayer("URL", { 
       infoTemplate: new InfoTemplate("Block: ${BLOCK}", "${*}"), 
       outFields: ["*"] 
      }); 

      var Northridge = new FeatureLayer("URL", { 
       infoTemplate: new InfoTemplate("Block: ${BLOCK}", "${*}"), 
       outFields: ["*"] 
      }); 

      var Associates = new FeatureLayer("URL", { 
       infoTemplate: new InfoTemplate("Block: ${BLOCK}", "${*}"), 
       outFields: ["*"] 
      }); 

      // selection symbol used to draw the selected census block points within the buffer polygon 
      var symbol = new SimpleMarkerSymbol(
      SimpleMarkerSymbol.STYLE_CIRCLE, 
      12, 
      new SimpleLineSymbol(
      SimpleLineSymbol.STYLE_NULL, 
      new Color([247, 34, 101, 0.9]), 
      1 
     ), 
      new Color([207, 34, 171, 0.5]) 
     ); 
      Offices.setSelectionSymbol(symbol); 

      //make unselected features invisible 
      var nullSymbol = new SimpleMarkerSymbol().setSize(10); 
      var RedCircle = new SimpleMarkerSymbol().setSize(8); 

      Offices.setRenderer(new SimpleRenderer(nullSymbol)); 

      on(dom.byId("layer0CheckBox"), "change", updateLayerVisibility); 
      on(dom.byId("layer1CheckBox"), "change", updateLayerVisibility); 
      on(dom.byId("layer2CheckBox"), "change", updateLayerVisibility); 

      function updateLayerVisibility() { 
       var inputs = query(".list_item"); 
       var inputCount = inputs.length; 
       //in this application layer 2 is always on. 
       visibleLayerIds = [2]; 

       for (var i = 0; i < inputCount; i++) { 
        if (inputs[i].checked) { 
         visibleLayerIds.push(inputs[i].value); 
        } 
       } 

       if (visibleLayerIds.length === 0) { 
        visibleLayerIds.push(-1); 
       } 

       map.addLayers(visibleLayerIds); 
      } 
     }); 

    </script> 
    </head> 

    <body> 
<br /> 
    <br /> 
     Layer List : <span id="layer_list"><input type='checkbox' class='list_item' id='layer0CheckBox' value="Northridge" />Earthquake 
      <input type='checkbox' class='list_item' id='layer1CheckBox' value="Offices" />Offices 
      <input type='checkbox' class='list_item' id='layer2CheckBox' value="Associates" />Associates 
     </span><br /> 
     <br /> 


    <div id="mapDiv"></div> 

    </body> 
</html> 

ответ

0

Совершено это давно

changeVLayerVisibility: function(names) { 
    Ext.Array.each(map.graphicsLayerIds, function(id) { 
     map.getLayer(id).setVisibility(names.indexOf(id) !== -1); 
    }); 
}, 

Проверить пример здесь: http://smart-tech-group.com/arcgismap/ карты связанной логика хранится в http://smart-tech-group.com/arcgismap/APP/view/ArcMapViewer.js я был JS-новичок тогда, так что не стесняйся спорить на моем стиле кода;)

0
  1. В функции updateLayerVisibility использование map.addLayers неверно. вы должны добавить плагины, графические слои, динамические слои или слоистые слои, а не идентификаторы, если вы не сохраните их в массиве visibleLayerIds.

  2. Вы можете использовать ArcGISDynamicMapServiceLayer для управления видимыми идентификаторами слоев. Затем используйте API setVisibleLayers см. https://developers.arcgis.com/javascript/jsapi/arcgisdynamicmapservicelayer-amd.html

  3. FeatureLayer обычно предназначен для одного уровня, используйте службу, такую ​​как MapServer/2 или FeatureServer/2.

Смежные вопросы