我尝试将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,没有任何问题。
最佳答案
移至Openlayers 5时,必须先在openlayers中注册全局变量,才能使用proj4的全局变量。
这是通过调用ol.proj.proj4.register(proj4)
完成的
请在此处查看有关版本5更改的注释:Release v5.0.0