代码改变世界

给要素渲染不同的显示色彩

2019-02-22 16:21  yangol  阅读(374)  评论(0编辑  收藏  举报

在城市规划中,用色彩强调感兴趣的房屋十分重要。

var map = new WebMap({

  portalItem:{id:"03a9607d96244883af64c7f8c7e5de1b"}

});

var view = new SceneView({

  container:"viewDiv",

  map:map

});

var layer = new SceneLayer({

  portalItem:{id:"5ecba5273b2d41ff9f6f1eb33f238d18"}

});

map.add(layer);

==============================================

function setSymbol(){

  return {

    type:"unique-value",

    field:"usage",

    defaultSymbol:{

      type:"mesh-3d",

      symbol:{

        type:"fill",

        material:{

          color:[230, 230, 230, 0.7],

          colorMixMode:"replace"

        }

      }

    },

    uniqueValueInfos:[{

      value:"general or commerial",

      label:"commerial building",

      symbol:{

        type:"mesh-3d",

        symbolLayers:[{

          type:"fill",

          material:{

            color:color,

            colorMixMode:colorMixMode

          }

        }]

      }

    }]

  }

}

function setRenderer(type){

  if(type === "origin"){

    layer.renderer = null;

  }

  else if (type === "select"){

    layer.renderer = setSymbol(null,null);

  }

  else if(type === "emphasize"){

    layer.renderer = setSymbol("skyblue","tint");

  }

  else{

    var colorMixMode = (type === "desaturate")?"tint":"replace";

    layer.renderer = {

      type:"simple",

      symbol:{

        type:"mesh-3d",

        symbolLayers:{

          type:"fill",

          material:{color:"white",colorMixMode:colorMixMode}

        }

      }

    }

  }

}

document.getElementById("colorMixMode").addEventListener("change",function(event){

   setRenderer(event.target.id);

});