zoukankan      html  css  js  c++  java
  • Openlayers3加载天地图

    概述:

    在前文中分别讲到了在Arcgis for js、Openlayers2中去加载天地图,同时也讲到了天地图的离线加载方式。在本文,讲述在Openlayers3中实现在线/离线的天地图的加载。


    实现:

    直接贴代码吧,效果就不贴了:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>TDT</title>
    	<link rel="stylesheet" type="text/css" href="../../../../plugin/ol3/css/ol.css"/>
    	<style type="text/css">
    		body, #map {
    			border: 0px;
    			margin: 0px;
    			padding: 0px;
    			 100%;
    			height: 100%;
    			font-size: 13px;
    		}
    		#map{
    			background: url("../../images/bgImg.gif");
    			background-repeat: inherit;
    		}
    	</style>
    	<script type="text/javascript" src="../../../../plugin/ol3/build/ol-debug.js"></script>
    	<script type="text/javascript" src="../../../../plugin/jquery/jquery-1.8.3.js"></script>
    	<script type="text/javascript">
    		var map;
    		function init(){
    			var bounds = [73.4510046356223, 18.1632471876417,
    				134.976797646506, 53.5319431522236];
    			var projection = new ol.proj.Projection({
    				code: 'EPSG:4326',
    				units: 'degrees'
    			});
    			var vec_c = getTdtLayer("vec_c");
    			var cva_c = getTdtLayer("cva_c");
    			var wms = new ol.layer.Image({
    				source: new ol.source.ImageWMS({
    					ratio: 1,
    					url: 'http://localhost:8088/geoserver/lzugis/wms',
    					params: {
    						'FORMAT': 'image/png',
    						'VERSION': '1.1.1',
    						LAYERS: 'lzugis:capital',
    						STYLES: ''
    					}
    				})
    			});
    			var map = new ol.Map({
    				controls: ol.control.defaults({
    					attribution: false
    				}),
    				target: 'map',
    				layers: [vec_c,cva_c,wms],
    				view: new ol.View({
    					projection: projection,
    					minZoom:2,
    					maxZoom:8
    				})
    			});
    			map.getView().fitExtent(bounds, map.getSize());
    		}
    
    		function getTdtLayer(lyr){
    			var url = "http://localhost:8081/lzugis/tdttile?T="+lyr+"&X={x}&Y={y}&L={z}";
    //			var url = "http://t0.tianditu.com/DataServer?T="+lyr+"&X={x}&Y={y}&L={z}";在线
    			var projection = ol.proj.get("EPSG:4326");
    			var projectionExtent = [ -180, -90, 180, 90 ];
    			var maxResolution = (ol.extent.getWidth(projectionExtent) / (256 * 2));
    			var resolutions = new Array(16);
    			var z;
    			for (z = 0; z < 16; ++z) {
    				resolutions[z] = maxResolution / Math.pow(2, z);
    			}
    			var tileOrigin = ol.extent.getTopLeft(projectionExtent);
    			var layer = new ol.layer.Tile({
    				extent: [ -180, -90, 180, 90 ],
    				source: new ol.source.TileImage({
    					tileUrlFunction: function(tileCoord) {
    						var z = tileCoord[0]+1;
    						var x = tileCoord[1];
    						var y = -tileCoord[2]-1;
    						var n = Math.pow(2, z + 1);
    						x = x % n;
    						if (x * n < 0) {
    							x = x + n;
    						}
    						return url.replace('{z}', z.toString())
    								.replace('{y}', y.toString())
    								.replace('{x}', x.toString());
    					},
    					projection: projection,
    					tileGrid: new ol.tilegrid.TileGrid({
    						origin: tileOrigin,
    						resolutions: resolutions,
    						tileSize: 256
    					})
    				})
    			});
    			return layer;
    		}
    	</script>
    </head>
    <body onLoad="init()">
    <div id="map">
    </div>
    </body>
    </html>




  • 相关阅读:
    Android : iperf-2.0.4 网络测试工具
    Android : SELinux 简析&修改
    Android : 修改内核源码 and 编译、打包成新的boot.img
    Bluedroid: 音频数据的传输流程
    Bluedroid: 蓝牙协议栈源码剖析
    【Java】 剑指offer(54) 二叉搜索树的第k个结点
    【Java】 剑指offer(53-3) 数组中数值和下标相等的元素
    【Java】 剑指offer(53-2) 0到n-1中缺失的数字
    【Java】 剑指offer(53-1) 数字在排序数组中出现的次数
    【Java】 剑指offer(52) 两个链表的第一个公共结点
  • 原文地址:https://www.cnblogs.com/lzugis/p/6539791.html
Copyright © 2011-2022 走看看