OL5的ScaleLine不适用于EPSG:25832

时间:2018-06-28 08:40:52

标签: javascript openlayers

我尝试将Map-Viewer从OL 4.6.5迁移到最新的5.0.0,但ScaleLine出现问题。

这是示例代码,您可以看到ScaleLine显示错误的值,并且还会更改平移地图上的长度。

example code

proj4.defs("EPSG:25832", "+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs");

var extent = [365000, 5654000, 450000, 5733500];
var rasterLayer = new ol.layer.Image({
	extent: extent,
	source: new ol.source.ImageWMS({
		url: 'http://geoportal.iserlohn.de/cgi-bin/mapserv.exe?map=c:/intranet/html/map/kaskade_stadtplan_grau.map&',
		params: {
			'LAYERS': 'stadtplan,sie02_f,gew01_f,ver03_f,veg02_f,veg01_f,veg03_f,ver04_f,ver01_f,gew01_l,ver03_l_u,ver02_l,ver01_l_2_1,ver01_l,ver01_l_2,ver03_l_o,ver02_l_2,ver01_l_d,ver02_l_d,ver01_l_d2,ver01_l_d3,ver01_l_d3_2,ver01_bab_ausfahrten,sie01_f_a,ax_gebaeude_pg_shadow1,ax_gebaeude_pg_shadow2,ax_gebaeude_pg,ax_gebaeude_pg_uebersicht,beschr_hnr,stadtgeb,stadtgrenze', 
			'FORMAT' : 'image/jpeg', 
			transparent: false},
		ratio: 1.1,
		serverType: 'mapserver'
	})
});
	

var map = new ol.Map({
  layers: [rasterLayer],
  target: 'map',
  logo:false,
  view: new ol.View({
	projection: new ol.proj.Projection({
        code: 'EPSG:25832',
        extent: extent,
        units: 'm'
      }),
    center: [406523.08, 5693898.11],
    minZoom: 1,
	maxZoom: 10,
	zoom: 3
  })
});

map.addControl(new ol.control.ScaleLine());  
<link rel="stylesheet" href="https://openlayers.org/en/v5.0.0/css/ol.css" type="text/css">
<script src="https://openlayers.org/en/v5.0.0/build/ol.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4-src.js" type="text/javascript"></script>
<div id="map" style="width:100%;height:100%;padding:0; margin:0;"></div>

同一示例适用于v4.6.5,没有任何问题。

1 个答案:

答案 0 :(得分:2)

当移至Openlayers 5时,必须先在openlayers中注册全局变量,然后才能将proj4的全局变量使用。

这是通过致电ol.proj.proj4.register(proj4)

完成的

请在此处查看第5版的更改说明:Release v5.0.0