自从5.0.3更新到5.2.0以来,ViewPort上的addEventListener方法不起作用。
map.getViewport().addEventListener('mouseup', function(evt){
alert('MouseUp');
}, false);
这里是一个例子。它适用于v5.0.3,但不适用于v5.2.0
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.getViewport().addEventListener('mouseup', function(evt){
alert('MouseUp');
}, false);
<link rel="stylesheet" href="https://openlayers.org/en/v5.2.0/css/ol.css" type="text/css">
<script src="https://openlayers.org/en/v5.2.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>
一些想法和建议的解决方案?