前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >openlayers3中如何叠加png图片

openlayers3中如何叠加png图片

作者头像
lzugis
发布2018-10-23 11:32:27
2.4K0
发布2018-10-23 11:32:27
举报

概述

本文讲述如何在OL3中叠加展示PNG图片。

实现思路

在OL3中,可通过ImageStatic资源来添加展示一个PNG图片,代码如下:

代码语言:javascript
复制
		image = new ol.layer.Image({
	            source: new ol.source.ImageStatic({
	               url: "img/china2.png",
	               imageExtent: extent
	            })
	        })

在此过程中,需要注意PNG图片的四至,即最大/最小经纬度,例如图片的四至信息如下:

代码中,定义extent的时候,extent的定义如下:

代码语言:javascript
复制
var extent = [63.9796331669, 14.7451916711, 140.1812559169, 55.4673388687];

实现后如下:

实现代码

代码语言:javascript
复制
	<script type="text/javascript">
		var map, image;
		function init(){
			var bounds = [72.985, 17.006, 134.416, 54.815];
			var extent = [63.9796331669, 14.7451916711, 140.1812559169, 55.4673388687];
			image = new ol.layer.Image({
	            source: new ol.source.ImageStatic({
	               url: "img/china2.png",
	               imageExtent: extent
	            })
	        })
			
			var projection = new ol.proj.Projection({
				code: 'EPSG:4326',
				units: 'degrees'
			});
			var vec_c = getTdtLayer("vec_w");
			var province = new ol.layer.Image({
		        source: new ol.source.ImageWMS({
			          ratio: 1,
			          url: 'http://10.16.48.185:8086/geoserver/my_test/wms',
			          params: {
			          		'FORMAT': 'image/png',
			                'VERSION': '1.1.1',
			                STYLES: '',
			                LAYERS: 'my_test:province_line',
			          }
		        })
		    });
			map = new ol.Map({
				controls: ol.control.defaults({
					attribution: false
				}),
				target: 'map',
				layers: [vec_c,image,province],
				view: new ol.View({
					projection: projection,
					minZoom:4,
					maxZoom:18
				})
			});
			map.getView().fit(bounds, map.getSize());
		}

		function getTdtLayer(lyr){
			var url = "http://t0.tianditu.com/DataServer?T="+lyr+"&X={x}&Y={y}&L={z}";
    		var layer = new ol.layer.Tile({
				source: new ol.source.XYZ({
			        url:url
			    })
			});
			return layer;
		}
	</script>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年05月09日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档