openlayers加载切片地图

简介:

使用的软件是tilemile。openlayers2和openlayers3加载切片地图使用的接口是不同的。下面做分析。

openlayers2:

layerName为图层名字,tileUrl为切片所在路径

function getTileLayerFunc(layerName,tileUrl){
	var mapMinZoom = 16;
    var mapMaxZoom = 23;
    var mapBounds = new OpenLayers.Bounds( 120.215163348, 30.2106933606, 120.216941889, 30.2125873624);
	
    //新建切片图层
    var tileLayer = new OpenLayers.Layer.TMS( layerName, "",
            {
                serviceVersion: '.', 
                layername: layerName, 
                alpha: true,
				type: 'jpg', 
				getURL: overlay_getTileURL
            });

		//获取每个小切片路径函数
        function overlay_getTileURL(bounds) {
			bounds = this.adjustBounds(bounds);
            var res = this.map.getResolution();
            var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
            var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
            var z = this.map.getZoom();
			var path = tileUrl+"/_alllayers/" + z + "/" + x + "/" + y + "." + this.type+"?time="+new Date().getTime();
			var url = tileUrl+"/_alllayers/";
			
	        if (mapBounds.intersectsBounds( bounds ) && z >= mapMinZoom && z <= mapMaxZoom) {
              
	        	return path;
	        } else {
//               return "http://www.maptiler.org/img/none.png";
            }
        }
		
	
    //返回切片图层
	//return tileLayer;
   
	map.addLayer(tileLayer);
	tileLayer.setZIndex(0);
}

openlayers3:

layerName为图层名字,tileUrl为切片所在路径

function getTileLayerFunc(layerName,tileUrl){
	var projectionExtent = Map.projection.getExtent();
	var maxResolution = ol.extent.getWidth(projectionExtent) / (Map.tileSize * 2);
	var resolutions = new Array(23);
	var z;
	for (z = 0; z < resolutions.length; ++z) {
		resolutions[z] = maxResolution / Math.pow(2, z);
	}

	var urlTemplate = tileUrl+'/_alllayers/{z}/{x}/{y}.jpg'+"?time="+new Date().getTime();
	
	var tileLayer = new ol.layer.Tile({
		/* ol.source.XYZ and ol.tilegrid.TileGrid have no resolutions config */
		source: new ol.source.TileImage({
			tileUrlFunction: function(tileCoord, pixelRatio, projection) {
			var z = tileCoord[0];
			var x = tileCoord[1];
			var y = Math.pow(2, z) + tileCoord[2];
			// wrap the world on the X axis
			var n = Math.pow(2, z + 1); // 2 tiles at z=0
			x = x % n;
			if (x * n < 0) {
				// x and n differ in sign so add n to wrap the result
				// to the correct sign
				x = x + n;
			}
			return urlTemplate.replace('{z}', z.toString())
			.replace('{y}', y.toString())
			.replace('{x}', x.toString());
			},
			projection: Map.projection,
			tileGrid: new ol.tilegrid.TileGrid({
				origin: ol.extent.getTopLeft(projectionExtent),
				resolutions: resolutions,
				tileSize: Map.tileSize
			})
		}),
		name:layerName
	});
	
	//return tileLayer;
	
	map.addLayer(tileLayer);
	//tileLayer.setZIndex(0)
}


相关文章
|
小程序 定位技术
微信小程序:map地图自动缩放自适应大小
微信小程序:map地图自动缩放自适应大小
765 0
|
JSON 数据可视化 定位技术
【D3.js - v5.x】(7)绘制地图 | Geo布局 | 完整代码
【D3.js - v5.x】(7)绘制地图 | Geo布局 | 完整代码
725 0
【D3.js - v5.x】(7)绘制地图 | Geo布局 | 完整代码
|
9月前
|
定位技术 API
Cesium开发:关于加载CGCS2000切片
Cesium开发:关于加载CGCS2000切片
423 0
|
算法 JavaScript 数据可视化
基于leaflet-velocity的二维动态风场展示
本文讲解了leaflet-velocity插件,并利用插件进行了模拟的动态风场、洋流等信息的综合展示,让读者掌握集成方式。
758 0
基于leaflet-velocity的二维动态风场展示
|
定位技术
在地图上基于OpenLayers实现点/线/面静态的绘制显示
在地图上基于OpenLayers实现点/线/面静态的绘制显示
537 0
在地图上基于OpenLayers实现点/线/面静态的绘制显示
|
定位技术
openlayers控制地图显示范围
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gisdoer/article/details/83108903 openlaye...
2787 0
|
定位技术
openlayers加载bing地图
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gisdoer/article/details/82961448 openlaye...
1440 0
|
移动开发 定位技术
leaflet加载视频图层
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gisdoer/article/details/82863039 适用场景: 动态云图 台风、风场、地图变迁等 原理: h5 video标签 L.
1084 0
openlayers加载动态ArcGIS服务
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gisdoer/article/details/82853801 openlaye...
1926 0
openlayers5之加载KML数据
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gisdoer/article/details/81989496 openlayer...
1395 0

热门文章

最新文章