【问题标题】:I want the map to show the Netherlands only我希望地图仅显示荷兰
【发布时间】:2023-04-08 01:21:01
【问题描述】:

这是我加载地图的初始化函数,我希望它只显示荷兰,放大应该是可能的,但缩小不应该。我到处搜索,但找不到有关如何执行此操作的正确解释。

var config = {
zoom: 14,
zoomStart: 8,
centerPoint: new OpenLayers.LonLat(622044.536098, 6797086.3022847),
strokeColor: "#941B80",
strokeColor_allloc: "#575757",
strokeOpacity: 0.8,
strokeOpacity_allloc: 0.9,
strokeWeight: 2,
trackWeight: 5,
fillColor: "#941B80",
fillColor_allloc: "#575757",
fillOpacity: 0.25,
fillOpacity_allloc: 0.40,
pointRadius: 5,
fontColor: "black",
fontSize: 10,
fontFamily: "Arial",
scaleFactor: 1000000,
extent: new OpenLayers.Bounds(-5037508, -5037508, 5037508, 5037508.34),
units: 'm',
resolution: 156543.0339,
displayProjection: new OpenLayers.Projection("EPSG:4326"),
projection: new OpenLayers.Projection("EPSG:900913"),
controls: [
new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.Attribution()],
copyright: 'Map data &copy; 2010 <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a><br /><a href="http://openstreetmap.org">OpenStreetMap.org</a> contributors',
numZoomLevels: 10,
numberPlateTail: new OpenLayers.Size(117.333, 42),
numberPlate: new OpenLayers.Size(117.333, 25),
iconSize: new OpenLayers.Size(32, 37)
};

var myLayers = {
base: new OpenLayers.Layer.OSM('', '', {
    attribution: config.copyright,
    transitionEffect: 'resize',
    layers: 'basic'
}, {
    isBaseLayer: true
}),
vector: new OpenLayers.Layer.Vector('Vormen aan/uit', {
    styleMap: my_style,
    renderers: ['Canvas', 'SVG', 'VML']
}),
allloc_vector: new OpenLayers.Layer.Vector('Vormen aan/uit', {
    styleMap: my_style,
    renderers: ['Canvas', 'SVG', 'VML']
}),
markers: new OpenLayers.Layer.Markers('Markers')
};
init: function (canvas) {
    this.canvas = canvas;
    $('#' + canvas).append('<input type="button" class="button" value="Volledig scherm" onclick="tbMap.toggleFs();" />');
    this.map = new OpenLayers.Map(this.canvas, {
        controls: config.controls,
        displayProjection: config.displayProjection,
        Projection: config.projection,
        maxExtent: config.extent,
        maxResolution: config.resolution,
        units: config.units,
        numZoomLevels: config.numZoomLevels,
        theme: null
    });
    tbMap.zoom();
    this.map.addLayers([myLayers.base, myLayers.vector]);
    this.map.setCenter(config.centerPoint, config.zoomStart);
},
zoom: function () {
    OpenLayers.Control.Navigation.prototype.counter = 0;
    //Inzoomgevoeligheid
    OpenLayers.Control.Navigation.prototype.wheelUp = function (evt) {
        this.counter++;
        if (this.counter > 2) {
            this.counter = 0;
            this.wheelChange(evt, 1);
        }
    };
    //Uitzoomgevoeligheid
    OpenLayers.Control.Navigation.prototype.wheelDown = function (evt) {
        this.counter--;
        if (this.counter < -2) {
            this.counter = 0;
            this.wheelChange(evt, -1);
        }
    };
},

【问题讨论】:

    标签: zooming openlayers country pan


    【解决方案1】:

    您可以设置配置属性maxExtent。在你的配置中使用你现有的界限,它看起来像这样,

    maxExtent : new OpenLayers.Bounds(-5037508, -5037508, 5037508, 5037508.34)
    

    您可以在初始化时将其添加到地图配置中。

    你可能还想看看restrictedExtent

    希望对你有帮助

    【讨论】:

    • 我已经尝试过restrictedExtent 和maxExtent,但是这样你仍然可以进一步缩小。唯一受到限制的是平移。
    • @Pepijn 您能列出您尝试过的内容吗?你看过这个页面吗? trac.osgeo.org/openlayers/wiki/SettingZoomLevels
    • 我尝试了列表中的所有内容,似乎与 OSM 不兼容。找到一个带有解决方法和补丁的网站。将等到他们在新的 openlayers 版本中更正此问题
    【解决方案2】:

    也许可以帮助你:

    /**
     * 
     * @type {int}
     * @constant
     */
    var MAX_ZOOM_LEVEL = 6;
    
    /**
     * The OpenLayers object that sets the map extent to the Europe scale
     * @type {OpenLayers.Bounds}
     * @var
     */
    var europeGoogleExtent = new OpenLayers.Bounds(-4931105.5677773, 2641663.6973633, 8570731.1060977, 12425603.316113);
    
    
    
    Zoom in?
    
    //triggered after a zoom completes
    mp.events.register('zoomend', this, checkZoom);
    
    function checkZoom() {
        var zoom = mp.getZoom();
    
        if(MAX_ZOOM_LEVEL >= zoom ) {
            J('#dialog').html('You reached the maximum zoom level. <strong>The spatial accuracy is of the order of X km.</strong>');
            J('#dialog').attr('title', 'Warning message');
            J('#dialog').dialog({
                height: 140,
                modal: true
            });
        } else {
            return true;
        }   
    }
    
    //Loading the initial extent
    if (!mp.getCenter()) {
        if (document.getElementById('userMapExtent').value != '') {
            var sExtent = document.getElementById('userMapExtent').value.split(',');
            mp.zoomToExtent(new OpenLayers.Bounds(sExtent[0], sExtent[1], sExtent[2], sExtent[3]), true);
        } else {
            mp.zoomToExtent(europeGoogleExtent);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 2016-12-14
      • 1970-01-01
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      相关资源
      最近更新 更多