Demo entry 6697426

java

   

Submitted by anonymous on Jan 24, 2018 at 15:47
Language: JavaScript. Code size: 1.2 kB.

	nauticalSource = new ol.source.TileImage({ 				// 实例化海图的数据源
		attributions : [ attribution ],
		tileUrlFunction : function(tileCoord, pixelRatio, projection) {
			if (this.tileGrid != null) { 					// 判断返回的当前级数的行号和列号是否包含在整个地图范围内
				var tileRange = this.tileGrid.getTileRangeForExtentAndZ(extent,
						tileCoord[0], tileRange);
				if (!tileRange.contains(tileCoord)) {
					return;
				}
			}
			var z = tileCoord[0];
			var x = tileCoord[1];
			var y = parseInt(Math.pow(2, z - 1) - 1 - tileCoord[2]);

			var size = resolutions[z] * tileSize;
			var left_lon = -180 + size * x;
			var left_lat = 90 - size * (y + 1);
			var right_lon = left_lon + size;
			var right_lat = left_lat + size;

			return urlTemplate.replace('{z}', z.toString()).replace('{y}',
					y.toString()).replace('{x}', x.toString());
		},

		projection : projection, 				// 投影坐标系
		tileGrid : new ol.tilegrid.TileGrid({
			origin : origin, 					// 原点,数组类型,如[0,0],
			resolutions : resolutions, 			// 分辨率数组
			tileSize : tileSize					// 瓦片图片大小 256* 256
		})
	});
	
	nauticalLayers = new ol.layer.Tile({
		source : nauticalSource
	});

	map.addLayer(nauticalLayers); 				// 添加海图图层
	loadMarker(url);							// 添加航标

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).