MrdodgerX

createLegend Openlayers

Nov 14th, 2020 (edited)
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var legendHTML = ""; // ni letak atas sekali as global pastu add kt HTML ko
  2. function createLegend(){
  3.    
  4.     var legend_query = '?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=';
  5.     var layerList = map.frameState_.layerStatesArray;
  6.     for(var i=0; i<layerList.length; i++){
  7.         //console.log(map.frameState_.layerStatesArray[i]);
  8.         if(layerList[i].visible){
  9.            
  10.             // console.log(layerList[i].layer.values_);
  11.             // console.log(sourceLayer.params_);
  12.             var sourceLayer= layerList[i].layer.values_.source;
  13.             if(typeof sourceLayer.url_ === 'undefined' ){
  14.  
  15.             }else{
  16.                 var legendtitle = layerList[i].layer.values_.title;
  17.                 var layerurl = sourceLayer.url_;
  18.                 var layerparam = sourceLayer.params_;
  19.                
  20.                 // console.log(layerparam);
  21.                 var imglegend = encodeURI(layerurl+legend_query+layerparam.LAYERS);
  22.                 legendHTML += "<div class='imglegend'><span>"+legendtitle+"</span>";
  23.                 // sini ko boleh control css die guna .imglegend>span or yg mana ko rase senang
  24.                 legendHTML += "<img src='"+imglegend+"'>";
  25.                 legendHTML += "</div>";
  26.             }
  27.         }
  28.     }
  29. }
  30.  
Add Comment
Please, Sign In to add comment