openlayer4 多图联动

 之前在ol2中多图联动需要监听地图move事件,在事件中对其他地图进行位置更新来达到多图联动的效果,在ol4中可以直接通过多个地图共享一个view来达到多图联动的效果。

直接上代码

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>多图联动</title>
    <link rel="stylesheet" href="ol.css" type="text/css"> 
    <style>
	body{
			 height: 100%;
				width: 100%;
			 position: absolute;
			 overflow: hidden;
	}

	.top{
		 height: 50%;
         width: 100%;
		 float:left;
	}

   .bottom{
		 height: 50%;
         width: 100%;
		 float:left;
	
	}

      .left_top {
        height: 100%;
        width: 50%;
		 float:left;
      }
	   .right_top {
        height: 100%;
        width: 50%;
		 float:left;
      }
	   .left_bottom {
        height: 100%;
        width: 50%;
		 float:left;
      }
	   .right_bottom {
        height: 100%;
        width: 50%;
		 float:left;
      }
    </style>
    <script src="ol.js" type="text/javascript"></script>  
   
  
</head>
<body> 

 
<div class="top">
	
    <div id="map1" class="left_top"> </div> 
	 <div id="map2" class="right_top"> </div> 

</div>

<div class="bottom">

	<div id="map3" class="left_bottom"> </div> 
	 <div id="map4" class="right_bottom"> </div> 
</div>
 

 
    <script>
		
		function createMap(_div , _view){ 
			var osm = new ol.layer.Tile({
	        	source: new ol.source.OSM()
	      	}); 
		    var map = new ol.Map({
		         target: _div,
		         layers:[osm],
		         view: _view 
		       });
			return map ;
		}
		 
		var view =	new ol.View({
	           center: [ 120, 30],
	           zoom: 10,
	           projection: 'EPSG:4326'
	         });
		
		var map1 = createMap('map1' , view);
		var map2 = createMap('map2' , view);
		var map3 = createMap('map3' , view);
		var map4 = createMap('map4' , view);
		
		
		 
	</script>
    
   
     </body>
</html>

 

 效果:

 

 

 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值