本文介绍了在LayerList小部件中可见的单层(ArcGIS JavaScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在此 ESRI中在地图上显示单个图层教程 LayerList小部件?

Is it possible to have a single layer visible on the map in this ESRI tutorial LayerList widget ?

每次单击图层时,上一个将被禁用.因此,您在地图上始终只有一层.

Each time you click on a layer, the previous one should deactivate. So you always have only one layer on the map.

米歇尔

推荐答案

我设法为您编写了代码.检查一下,让我知道:

I managed to write a code for you . Check it and let me know :

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Layer List Dijit</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.20/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css">
<script language="javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<style>
html, body, .container, #map {
height:100%;
width:100%;
margin:0;
padding:0;
margin:0;
font-family: "Open Sans";
}
#map {
padding:0;
}
#layerListPane{
width:25%;
}
.esriLayer{
  background-color: #fff;
}
.esriLayerList .esriList{
    border-top:none;
}
.esriLayerList .esriTitle {
  background-color: #fff;
  border-bottom:none;
}
.esriLayerList .esriList ul{
  background-color: #fff;
}

</style>
<script>var dojoConfig = { parseOnLoad: true };var busy=false;</script>
<script src="https://js.arcgis.com/3.20/"></script>
<script>
require([
"esri/arcgis/utils",
"esri/dijit/LayerList",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojo/domReady!"
], function(
arcgisUtils,
LayerList
) {
//Create a map based on an ArcGIS Online web map id
arcgisUtils.createMap("f63fed3f87fc488489e27c026fa5d434", "map").then(function(response){
    var myWidget = new LayerList({
       map: response.map,
       layers: arcgisUtils.getLayerList(response)
    },"layerList");

    myWidget.on("toggle",function(evt){
        if(busy) return;

        selectedLayerSubIndex = evt.subLayerIndex;
        if(selectedLayerSubIndex) return;

        selectedLayerIndex = evt.layerIndex;
        visibility = evt.visible;

        elm = $("#layerListPane input[type=checkbox][data-layer-index="+selectedLayerIndex+"]:not([data-sublayer-index])");


        otherCheckedElems = $("#layerListPane input[type=checkbox][data-layer-index!="+selectedLayerIndex+"]:not([data-sublayer-index]):checked");
        if(visibility){
            busy=true;
            otherCheckedElems.each(function () {
                $(this).click();
            });
            busy=false;
        }
        else{
            checkedLength = otherCheckedElems.length
            if(checkedLength==0) setTimeout("elm.click();", 100);
        }
    })

    myWidget.startup();
});

});
</script>
</head>
<body class="claro">
<div class="container" data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline',gutters:false">
<div id="layerListPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'">
    <div id="layerList"></div>
</div>
<div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"></div>
</div>
</body>
</html>

这篇关于在LayerList小部件中可见的单层(ArcGIS JavaScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 23:49