ArcGIS API for JavaScript实现分图层显示

文章首发于GISGO | GIS | 地理信息科学 - GIS研究中心:http://www.gisgo.top/
微信公众号


大家都知道,当用ArcGIS发布地图服务时,是把整个地图文档所有图层都发布出去的,如果展示的时候只想显示某个图层怎么办呢?或许你会用FeatureLayer,这样做当然也能实现,但是在地图文档中设置的渲染样式将会失效,你得重新设置渲染,这样就费时费力了。其实在ArcGISDynamicMapServiceLayer中提供一个方法,来设置显示的图层——ArcGISDynamicMapServiceLayer.setVisibleLayers(ids, doNotRefresh?)
- ids:表示一个整形数组,代表你要显示的图层的id值,这个值可以在ArcGIS Server Manager中查看
GIS

  • doNotRefresh:该参数可选,代表是否要刷新地图才能设置,默认是false

具体实现demo如下:

html代码:选择要显示的图层

<div class="radio">
    <label>
        <input type="radio" name="optionsRadios" id="jumingqu" value="-1" checked="" />清除</label>
</div>
<hr />
<div class="radio">
    <label>
        <input type="radio" name="optionsRadios" id="jumingqu" value="0" />居民区</label>
</div>
<hr />
<div class="radio">
    <label>
        <input type="radio" name="optionsRadios" id="shangye" value="1" />商业</label>
</div>
<hr />
<div class="radio">
    <label>
        <input type="radio" name="optionsRadios" id="yiliao" value="2" />医疗</label>
</div>
<hr />
<div class="radio">
    <label>
        <input type="radio" name="optionsRadios" id="yule" value="3" />娱乐</label>
</div>
<hr />
<div class="radio">
    <label>
        <input type="radio" name="optionsRadios" id="jiaoyu" value="4" />教育</label>
</div>

JS代码:

var dist=new ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/dist/MapServer/"); //初始化图层
dist.setVisibleLayers([-1]) //表示初始化所有图层都不显示
map.addLayer(dist) //添加图层到地图

//通过radio标签的value值来选择显示图曾
$("input[type='radio']").click(function(){
    var a = $(this).val();
    dist.setVisibleLayers([a])

})

效果:
GIS


淘宝店铺:GIS研究中心
GIS研究中心

猜你喜欢

转载自blog.csdn.net/agisboy/article/details/80772202