当Chrome最大化窗口模式时,OpenLayers-3栅格图层未显示

时间:2016-04-10 22:53:49

标签: javascript google-chrome openlayers-3 mapserver

我在OpenLayers 3渲染Mapserver WMS图层时遇到了这个奇怪的问题。

当Chrome处于最大化模式时,网格不会显示。但是,当我切换到“窗口”视图或任何被调用的视图时,它可以完美地工作。

grid shows
grid does not show

编辑我刚发现mapserver将以下错误写入日志文件: [Mon Apr 11 15:08:46 2016] .291000 msWMSLoadGetMapParams():WMS服务器错误。图像大小超出范围,WIDTH和HEIGHT必须介于1到2048像素之间。显然增加窗口大小也会导致WMS生成更大的png?我应该如何解决这个问题? /编辑

这是Javascript代码:

    var waterFeature, farmerFeature;
    var waterStyle, farmerStyle;
    var waterSource, farmerSource;
    var layerOSM, layerBiomass, layerNDVI, layerFarmer, layerWater;
    var map;

    function initOpenLayers(){

        waterFeature = new ol.Feature({
            geometry: new ol.geom.Point([1, 15]),
            name: 'Null Island',
            population: 4000,
            rainfall: 500
        });

        farmerFeature = new ol.Feature({
            geometry: new ol.geom.Point([1, 16]),
            //name: 'Null Island',
            //population: 4000,
            //rainfall: 500
        });

        waterStyle = new ol.style.Style({
            image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
                anchor: [0.5, 46],
                anchorXUnits: 'fraction',
                anchorYUnits: 'pixels',
                src: 'images/waterIcon.png',
                scale: 0.03
            }))
        });

        farmerStyle = new ol.style.Style({
            image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
                anchor: [0.5, 46],
                anchorXUnits: 'fraction',
                anchorYUnits: 'pixels',
                src: 'images/farmerIcon.png',
                scale: 0.03
            }))
        });

        waterFeature.setStyle(waterStyle);
        farmerFeature.setStyle(farmerStyle);

        waterSource = new ol.source.Vector({
            features: [waterFeature]
        });

        farmerSource = new ol.source.Vector({
            features: [farmerFeature]
        });

        layerOSM = new ol.layer.Tile({
            source: new ol.source.OSM({
                attributions: [
                    'All maps © <a href="http://www.opencyclemap.org/">OpenCycleMap</a>',
                    ol.source.OSM.ATTRIBUTION
                ],
                url: 'http://{a-c}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png'
            })
        });

        //layerOSM.setVisible(false);

        layerBiomass = new ol.layer.Image({
            //extent: [-13884991, 2870341, -7455066, 6338219],
            //extent: [-18, -36, 52, 58],
            source: new ol.source.ImageWMS({
                projection: 'EPSG:3857',
                //url: '/cgi-bin/mapserv.exe?map=c:/Websites/SWIMM/apps/STAMP/maps/STAMP/MALI.map&service=wms&version=1.1.1&request=GetMap&layers=biomass&styles=&width=400&height=400&format=image%2Fpng&srs=EPSG:3857&bbox=-18,-36,52,58',
                url: '/cgi-bin/mapserv.exe?map=c:/Websites/SWIMM/apps/STAMP/maps/STAMP/MALI.map&service=wms&version=1.1.1&request=GetMap&layers=biomass&styles=&width=400&height=400&format=image%2Fpng&srs=EPSG:3857',
                params: {'LAYERS': 'Biomass'},
                serverType: 'mapserver'
            })
        });

        layerNDVI = new ol.layer.Image({
            //extent: [-13884991, 2870341, -7455066, 6338219],
            //extent: [-18, -36, 52, 58],
            source: new ol.source.ImageWMS({
                projection: 'EPSG:3857',
                //url: '/cgi-bin/mapserv.exe?map=c:/Websites/SWIMM/apps/STAMP/maps/STAMP/MALI.map&service=wms&version=1.1.1&request=GetMap&layers=biomass&styles=&width=400&height=400&format=image%2Fpng&srs=EPSG:3857&bbox=-18,-36,52,58',
                url: '/cgi-bin/mapserv.exe?map=c:/Websites/SWIMM/apps/STAMP/maps/STAMP/MALI.map&service=wms&version=1.1.1&request=GetMap&layers=biomass&styles=&width=400&height=400&format=image%2Fpng&srs=EPSG:3857',
                params: {'LAYERS': 'NDVI'},
                serverType: 'mapserver'
            })
        });


        layerFarmer = new ol.layer.Vector({
            source: farmerSource
        });

        layerWater = new ol.layer.Vector({
            source: waterSource
        });

        //initialize the raster visibilities. Start by default with the biomass raster
        layerNDVI.setVisible(false);
        layerBiomass.setVisible(true);


        map = new ol.Map({
            layers: [layerOSM, layerBiomass, layerNDVI, layerWater, layerFarmer],
            target: 'map',
            view: new ol.View({
                //projection: 'EPSG:3857',
                //center: [100000, 1000000],
                projection: 'EPSG:4326',
                center: [1,16],
                zoom: 6
            }),
            controls: ol.control.defaults().extend([
                new ol.control.ScaleLine()
            ])
        });

        //map.getView().setCenter([4,16]);

    };

    function toggleLayer() {
        layerBiomass.setVisible(!layerBiomass.getVisible());
        layerNDVI.setVisible(!layerBiomass.getVisible());
    }

这是地图文件内容:

MAP
  CONFIG "MS_ERRORFILE" "c:/temp/ms_error.txt"
  IMAGETYPE      PNG
  OUTPUTFORMAT
    NAME "png"
    DRIVER AGG/PNG8
    MIMETYPE "image/png"
    EXTENSION "png"
    TRANSPARENT ON
  IMAGEMODE RGBA
  FORMATOPTION "QUANTIZE_FORCE=on"
  FORMATOPTION "QUANTIZE_COLORS=256"
  FORMATOPTION "INTERLACE=OFF"
END

EXTENT        -18 -36 52 38
  PROJECTION
  'init=epsg:3857'
END

WEB
  IMAGEPATH "/Websites/SWIMM/tmp/"
  IMAGEURL  "/tmp/"
  METADATA
    'wms_enable_request' '*'
    'wms_title' 'MS'
  END
END

LAYER # MODIS raster layer begins here
  NAME         "NDVI"
  DATA         "./NDVI_2016022.img"
  STATUS       ON
  TYPE         RASTER
  #PROCESSING   "BANDS=1,2,3"
  OFFSITE      255 0 0

METADATA
  "wms_title" "NDVI"
  "wms_srs" "EPSG:4326"
  "wms_name" "NDVI"
  "wms_server_version" "1.1.1"
  "wms_format" "image/png"
  "wms_onlineresource" "http://localhost/cgi-bin/mapserv.exe?map=c:/Websites/SWIMM/apps/STAMP/maps/STAMP/MALI.map&"
END

PROJECTION
     "init=epsg:4326"
END
  CLASS EXPRESSION ([pixel] >= 0 and [pixel] <= 10)  STYLE COLOR 255 255 255 END NAME "Clouds" END
  CLASS EXPRESSION ([pixel] >= 11  and [pixel] <= 17) STYLE COLOR 100 128 255 END NAME "Water"  END
  CLASS EXPRESSION ([pixel] >= 19  and [pixel] <= 19) STYLE COLOR 100 128 255 END NAME "Water"  END
  CLASS EXPRESSION ([pixel] >= 20 and [pixel] <= 89) STYLE COLOR 176 96 48 END NAME "< 0.00" END
  CLASS EXPRESSION ([pixel] >= 90 and [pixel] <= 96) STYLE COLOR 255 255 0 END NAME "0.00-0.05" END
  CLASS EXPRESSION ([pixel] >= 97 and [pixel] <= 102) STYLE COLOR 255 255 128 END NAME "0.05-0.10" END
  CLASS EXPRESSION ([pixel] >= 103 and [pixel] <= 108) STYLE COLOR 255 255 128 END NAME "0.10-0.15" END
  CLASS EXPRESSION ([pixel] >= 109 and [pixel] <= 129) STYLE COLOR 191 223 96 END NAME "0.15-0.20" END
  CLASS EXPRESSION ([pixel] >= 130 and [pixel] <= 155) STYLE COLOR 128 192 64 END NAME "0.20-0.25" END
  CLASS EXPRESSION ([pixel] >= 156 and [pixel] <= 181) STYLE COLOR 64 160 32 END NAME "0.25-0.30" END
  CLASS EXPRESSION ([pixel] >= 182 and [pixel] <= 246) STYLE COLOR 0 128 0 END NAME "0.30-0.35" END
  CLASS EXPRESSION ([pixel] >= 247 and [pixel] <= 253) STYLE COLOR 0 64 0 END NAME "0.35-0.40" END
  CLASS EXPRESSION ([pixel] >= 254 and [pixel] <= 255) STYLE COLOR 255 255 255 END NAME "Missing" END
END # MODIS raster layer ends here

LAYER # MODIS raster layer begins here
  NAME         "BIOMASS"
  DATA         "./Biomass_2015.tif"
  STATUS       ON
  TYPE         RASTER
  #PROCESSING   "BANDS=1,2,3"
  TRANSPARENCY 60
  OFFSITE      255 0 0

  METADATA
    "wms_title" "BIOMASS"
    "wms_srs" "EPSG:4326"
    "wms_name" "BIOMASS"
    "wms_server_version" "1.1.1"
    "wms_format" "image/png"
    "wms_onlineresource" "http://localhost/cgi-bin/mapserv.exe?map=c:/Websites/SWIMM/apps/STAMP/maps/STAMP/MALI.map&"
END

PROJECTION
     #"proj=latlong"
     #"ELLPS=WGS84"
     #"datum=WGS84"
     "init=epsg:4326"
END
  CLASS EXPRESSION ([pixel] <= 0) STYLE COLOR 212 159 93 END NAME "0"       END
  CLASS EXPRESSION ([pixel] > 0  and [pixel] < 500) STYLE COLOR 233 205 137 END NAME "500"  END
  CLASS EXPRESSION ([pixel] >= 500  and [pixel] < 1000) STYLE COLOR 255 251 182 END NAME "1000"  END
  CLASS EXPRESSION ([pixel] >= 1000  and [pixel] < 5000) STYLE COLOR 199 237 124 END NAME "5000"  END
  CLASS EXPRESSION ([pixel] >= 5000) STYLE COLOR 143 223 67 END NAME "15000"  END
END # MODIS raster layer ends here

END

1 个答案:

答案 0 :(得分:3)

解决了它。

感谢bartvde。但具有讽刺意味的是,我必须添加 MAXSIZE到MAP文件。显然我的窗口大小略超过1024 px,这是默认情况下mapserver支持的最大值。通过设置MAXSIZE 2600,我能够解决问题。现在,地图也以最大窗口大小显示。