首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >地图大小没有在map.updateSize()上更新

地图大小没有在map.updateSize()上更新
EN

Stack Overflow用户
提问于 2021-02-20 05:47:23
回答 1查看 474关注 0票数 0

我正在使用开放层发布一个地图。但我想不出如何使地图大小根据屏幕大小动态变化。因为地图在每个屏幕上都是一样的,不管屏幕大小如何。我还尝试了map.updatesize()。但这也不起作用。我的密码是

代码语言:javascript
复制
        layer = new ol.layer.Tile({
        title: 'Basemap',
        baseLayer: true,
        visible: true,
        
        

        source: new ol.source.TileWMS({
            url: 'http://mlinfomaps.in/geoserver/wms',
            params: { 'LAYERS': 'MSSDS_WS:MSSDS_BASEMAP', 'TILED': true },
            serverType: 'geoserver',
          
            // Countries have transparency, so do not fade tiles:
            transition: 0,
            crossOrigin: "anonymous"
        })
    });


    var mousePositionControl = new ol.control.MousePosition({
        coordinateFormat: ol.coordinate.createStringXY(4),
        projection: 'EPSG:4326',
        // comment the following two lines to have the mouse position
        // be placed within the map.
        //className: 'custom-mouse-position',
        target: document.getElementById('mouse-position'),
        //undefinedHTML: ' '
    });


    var projection = new ol.proj.Projection({
        //code: 'EPSG: 4326', // *code says: 5261 ...try to see if this is right
        //extent: [71.6142, 22.3645, 81.8754, 15.1508],
        extent:[7970828.0670139585, 1681517.1260521673, 9127778.927138386, 2541280.8202038296]
    })
    function scaleControl() {
        control = new ol.control.ScaleLine({
            units: 'metric',
            bar: true,
            steps: 4,
            text: true,
            
            minWidth: 100
        });
        return control;
    }

    var sourceMeasure = new ol.source.Vector({
        crossOrigin: "anonymous",

        
    });
    var vectorMeasure = new ol.layer.Vector({
       
        source: sourceMeasure,
        style: new ol.style.Style({
            fill: new ol.style.Fill({
                color: 'rgba(255, 255, 255, 0.2)'
            }),
            stroke: new ol.style.Stroke({
                color: '#df1c29',
                width: 2
            }),
            image: new ol.style.Circle({
                radius: 6,
                fill: new ol.style.Fill({
                    color: '#df1c29'
                })
            })
        }),
        title: 'Measure Overlay',
    });

    // The Map
    //var overlay = new ol.Overlay
    //    ({
    //        element: container,
    //        autoPan: true,
    //        autoPanAnimation: {
    //            duration: 250
    //        }
    //    });


    var view = new ol.View
        ({
            center: ol.proj.transform([76.7997, 18.6298], 'EPSG:4326','EPSG:3857'),
            zoom: 7,
            extent: projection.getExtent(),
            //minZoom:7,
            maxZoom: 12

        });

    var map = new ol.Map
        ({
            target: 'map',
            controls: ol.control.defaults().extend([mousePositionControl, scaleControl()]),
            view: view,   
            //fit: view.fit(),
            //overlays: [overlay],
            layers: [layer]
            
        });
    const extent = projection.getExtent()
    map.getView().fit(extent);
    map.updateSize();


    window.onresize = function()
        {
    setTimeout( function() { map.updateSize();}, 200);
        }

    '''

不同屏幕上的地图看起来如下:在我的屏幕上,它看起来像https://i.stack.imgur.com/KIYio.png

在我同事的屏幕上,它看起来像https://i.stack.imgur.com/6c4zk.png

请帮我渡过难关。

提前谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-24 13:28:13

你好,我也有同样的问题,我就是这么做的。

ts:

html:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66288431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档