首先显示图例用的CSS以及Div布局代码为:
#legendContainer{ right:30px; top:100px; 248px !important; 250px; height:398px !important; height:400px; position:absolute; border:1px solid #6FAFF1; z-index:99; background-color:#6FAFF1; cursor:default; } #legendCaption { height:20px; text-align:left; vertical-align:middle; left:10px; top:5px; position:relative; color:White; font-family:"Microsoft YaHei"; font-size:16px; } #legendContent { 232px !important; 234px; height:362px !important; height:364px; background-color:White; border:1px solid White; margin:7px; overflow:auto; } //这里是地图控件放置位置 <div id="legendContainer"> <div id="legendCaption"> <span>图例</span> </div> <div id="legendContent"> </div> </div>
其中Javascript部分为:
var container = $get('legendContent'); var legend = new SuperMap.Web.Controls.Legend({'id':'legend','isShowOnlyVisibleLayer':false,'layers':[layer],'container':container}); map.addControls([legend]);