图层Layers的介绍
图层包含的要素可以是矢量形式的也可以是栅格形式的。
这里介绍其中一种:添加tilelayer.(加载image类型的图层)
引用:"esri/layers/tilelayer"
举例:1.获取图层信息
var houselayer = new tilelayer({
url:"https://tiles.arcgis.com/tiles/ngt4qxsblgdfejn9/arcgis/rest/services/new_york_housing_density/mapserver",
id:"houses",//为每一个tile图层设置id
opacity:0.9});
var streetlayer = new tilelayer({
url:"https://server.arcgisonline.com/arcgis/rest/services/reference/world_transportation/mapserver",
id:"streets",
visible:false});
2.添加到图上(两种方式)
var map = new map({
basemap:"oceans",
layers:[houselayer]});
或者map.add(streetlayer);
3.因为地图初始时是用三维球体显示,所以这里用sceneview来显示
var view = new sceneview({
container:"viewdiv",
map:map});
4.当然也可以获取加载之后的图层信息
view.on("layerview-create",function(event){
if(event.layer.id === "houses"){
console.log("house created!",event.layerview)}
if(event.layer.id === "streets"){
console.log("street created!",event.layerview)}
})
5.开始的时候streets图层的visible属性是false,怎么样将他显示呢,这里添加个性化显示功能:随着checkbox状态的改变而改变
var toggle = document.getelementbyid("streetlayer");
toggle.addeventlistener("change",function(){
streetlayer.visible = toggle.checked});
上一篇: jQuery 练习:tab 切换
下一篇: go Context的使用