openlayers實現多圖顯示,openlayers實現多圖

來源:互聯網
上載者:User

openlayers實現多圖顯示,openlayers實現多圖

概述:

本文講述在openlayers中如何?多圖聯動。


思路:

1、判斷滑鼠在哪個地圖上;

2、添加該地圖的地圖移動事件;

3、設定另外一個地圖的bound為該地圖的。


代碼:

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title>openlayers map</title>    <link rel="stylesheet" href="http://localhost/olapi/theme/default/style.css" type="text/css">    <style>        html, body, table{            padding:0;            margin:0;            height:100%;            width:100%;            overflow: hidden;        }        #map1,#map2{            width: 100%;            height: 100%;        }    </style>    <script src="http://localhost/olapi/OpenLayers.js"></script>    <script src="http://localhost/olapi/lib/OpenLayers/Lang/zh-CN.js"></script>    <script src="http://localhost/jquery/jquery-1.8.3.js"></script>    <script>        var map1,map2;        $(window).load(function() {            var bounds = new OpenLayers.Bounds(                    73.45100463562233, 18.16324718764174,                    134.97679764650596, 53.531943152223576            );            var options = {                controls: [],                maxExtent: bounds,                maxResolution: 0.2403351289487642,                projection: "EPSG:4326",                units: 'degrees'            };            map1 = new OpenLayers.Map('map1', options);            map2 = new OpenLayers.Map('map2', options);            map1.addLayer(getWms("china"));            map1.addControl(new OpenLayers.Control.Zoom());            map1.addControl(new OpenLayers.Control.Navigation());            map1.zoomToExtent(bounds);            map2.addLayer(getWms("province"));            map2.addControl(new OpenLayers.Control.Zoom());            map2.addControl(new OpenLayers.Control.Navigation());            map2.zoomToExtent(bounds)            $("table").on("mousemove", function(e){                var _x = e.clientX;                var _tabWidth = $("table").width();                if(_x>0 && _x<_tabWidth/2){                    map1.events.register("move",map1,function(){                        map2.zoomToExtent(map1.getExtent());                    });                }                else{                    map2.events.register("move",map2,function(){                        map1.zoomToExtent(map2.getExtent());                    });                }            })        });        function getWms(layer){            return new OpenLayers.Layer.WMS(                    "Geoserver layers - Tiled",                    "http://localhost:8081/geoserver/lzugis/wms",                    {                        "LAYERS": layer,                        "STYLES": '',                        format: 'image/png'                    },                    {                        buffer: 0,                        displayOutsideMaxExtent: true,                        isBaseLayer: true,                        yx : {'EPSG:4326' : true}                    }            );        }    </script></head><body><table cellpadding="0" cellspacing="0" width="100%" height="100%">    <tr>        <td style="width: 50%; height: 100%; border-right: 1px solid #000;">            <div id="map1"></div>        </td>        <td style="width: 50%; height: 100%; border-right: 1px solid #000;">            <div id="map2"></div>        </td>    </tr></table></body></html>




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.