<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 41,  comments - 90,  trackbacks - 0
    openlayers提供了幾十個示例,雖然每個示例都很簡單,但卻很具有代表性,值得初學者學習。
    現(xiàn)在我想做一個測試,包含多個圖層、縮放條、工具條、鼠標位置、彈出窗口,其中圖層分別來自geoservr
    提供的WMS和WFS服務接口。
    主要代碼如下:
    樣式定義,定義地圖大小,工具條位置和替換按鈕圖片。
    <style type="text/css">
            #map {
                width: 640px;
                height: 475px;
                border: 1px solid black;
            }

            .olControlPanel div {
              display:block;
              position: absolute;
                        top: 0px;
                        left: 190px;
              width:  60px;
              height: 23px;
              margin: 5px;
            }
            .olControlPanel .olControlMouseDefaultsItemActive {
              background-image: url("/openlayers/img/Pan.gif");
            }
            .olControlPanel .olControlMouseDefaultsItemInactive {
              background-image: url("/openlayers/img/PanSelected.gif");
            }
            .olControlPanel .olControlZoomBoxItemInactive {
              width:  60px; 
              height: 23px;
              position: absolute;
                        top: 0px;
                        left: 250px;
              background-image: url("/openlayers/img/ZoomInSelected.gif");
            }
            .olControlPanel .olControlZoomBoxItemActive {
              width:  60px; 
              height: 23px;
              position: absolute;
                        top: 0px;
                        left: 250px;
              background-image: url("/openlayers/img/ZoomIn.gif");
            }
             .olControlPanel .olControlSelectFeatureItemInactive {
              width:  60px; 
              height: 23px;
              position: absolute;
                        top: 0px;
                        left: 310px;
              background-image: url("/openlayers/img/InfoSelected.gif");
            }
            .olControlPanel .olControlSelectFeatureItemActive {
              width:  60px; 
              height: 23px;
              position: absolute;
                        top: 0px;
                        left: 310px;
              background-image: url("/openlayers/img/Info.gif");
            }
        </style>
    JS代碼,核心部分。
    <script src="/openlayers/OpenLayers.js"></script>
        <script type="text/javascript">
            <!--
            //定義全局變量
            var map, layer, selectControl, selectedFeature;
            //關(guān)閉彈出窗口的函數(shù)
            function onPopupClose(evt) {
                selectControl.unselect(selectedFeature);
            }
            //構(gòu)造彈出窗口的函數(shù)
            function onFeatureSelect(feature) {
                selectedFeature = feature;
                popup = new OpenLayers.Popup.Anchored("chicken",
                                         feature.geometry.getBounds().getCenterLonLat(),
                                         new OpenLayers.Size(250,75),
                                         "<div style='font-size:.8em'>" + feature.attributes['cq:LNAME'] +"</div>",
                                         null, true, onPopupClose);
                feature.popup = popup;
                map.addPopup(popup);
            }
            //銷毀彈出窗口的函數(shù)
            function onFeatureUnselect(feature) {
                map.removePopup(feature.popup);
                feature.popup.destroy();
                feature.popup = null;
            }
            //地圖和頁面加載函數(shù)
            function init(){
                //設置地圖縮放范圍和縮放等級,0級比例尺最小
                map = new OpenLayers.Map( $('map'), {  maxScale: 500, minScale: 500000, numZoomLevels: 5 });
                //加載行政區(qū)圖層,WMS柵格圖像
                layer = new OpenLayers.Layer.WMS( "District",
                        "http://192.98.151.17:8081/geoserver/wms", {layers: 'cq:GMAP_DISTRICT'} );
                map.addLayer(layer);
                //加載水系圖層,WMS柵格圖像
                layer = new OpenLayers.Layer.WMS( "Water",
                        "http://192.98.151.17:8081/geoserver/wms", {layers: 'cq:GMAP_LAKE', 'transparent': true, format: 'image/png' } );
                map.addLayer(layer);
                //加載單位圖層,WFS矢量數(shù)據(jù),由openlayers在客戶端繪制,注意:數(shù)量太多會導致速度緩慢
                layer = new OpenLayers.Layer.WFS( "Unit",
                        "http://192.98.151.17:8081/geoserver/wfs", {typename: 'cq:GPOI_GOV'},
                   { 
                          typename: 'unit',
                          featureNS: 'http://www.openplans.org/cq',
                          extractAttributes: true,
                          maxfeatures: 10,
                          textAttrToDisplay: 'lname'
                   } );
                map.addLayer(layer);
                //在地圖上添加按鈕和工具條
                zb = new OpenLayers.Control.ZoomBox();
                var panel = new OpenLayers.Control.Panel({defaultControl: zb});
                selectControl = new OpenLayers.Control.SelectFeature(layer, {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect, hover: true});
                panel.addControls([
                    new OpenLayers.Control.MouseDefaults(), zb, selectControl
                ]);
                map.addControl(panel);
              
                map.addControl(new OpenLayers.Control.PanZoomBar({zoomWorldIcon:false}));
                map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
                map.addControl(new OpenLayers.Control.MousePosition());
                //設置初始地圖的中心坐標和縮放等級
                map.setCenter(new OpenLayers.LonLat(106.5, 29.5), 3);
               
            }
            // -->
        </script>
    HTML代碼
    <body onload="init()">
        <h1>OpenLayers Test</h1>
        <div id="panel"></div>
        <div id="map"></div>
        <textarea style="display:none" id="serialize" cols="96" rows="10"/>
      </body>

    posted on 2007-11-26 10:58 天狼 閱讀(31658) 評論(15)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 亚洲综合伊人制服丝袜美腿| 亚洲高清国产拍精品26U| 亚洲av无码片在线观看| 最近高清中文字幕免费| 久久久无码精品亚洲日韩按摩| 四虎影视在线影院在线观看免费视频 | 亚洲高清最新av网站| 激情婷婷成人亚洲综合| 免费a在线观看播放| 国产亚洲综合视频| 亚洲另类少妇17p| 在线观看免费黄网站| 久久夜色精品国产亚洲| 最近2018中文字幕免费视频| 亚洲区精品久久一区二区三区| 好先生在线观看免费播放| 亚洲heyzo专区无码综合| 免费99热在线观看| 久久99免费视频| 亚洲人成免费电影| 精品剧情v国产在免费线观看 | 美女视频黄.免费网址| 久久精品国产亚洲5555| 中文字幕无码日韩专区免费| 亚洲精品人成电影网| 免费观看男人免费桶女人视频 | 无码国产精品一区二区免费式芒果| 亚洲综合无码一区二区| 四虎永久在线精品免费网址| 美女被免费视频网站a| 国产aⅴ无码专区亚洲av| 国产1000部成人免费视频| 亚洲JLZZJLZZ少妇| 亚洲AV日韩AV高潮无码专区| 免费三级毛片电影片| 一区二区免费在线观看| 亚洲精品美女久久久久9999| 午夜国产羞羞视频免费网站| 久久免费美女视频| 亚洲一区二区三区丝袜| 久久精品国产精品亚洲精品 |