OpenLayers - Accessible Map(1) - zoom操作

This page's map element has its tabindex attribute set to "0", that makes it focusable. To focus the map element you can either navigate to it using the "tab" key or use the skip link. When the map element is focused the + and - keys can be used to zoom in and out and the arrow keys can be used to pan.

Clicking on the "Zoom in" and "Zoom out" buttons below the map zooms the map in and out. You can navigate to the buttons using the "tab" key, and press the "enter" key to trigger the zooming action.

本例子主要涉及图层放大缩小相关:zoom 操作。

   var map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        target: 'map',
        controls: ol.control.defaults({
          attributionOptions: {
            collapsible: false
          }
        }),
        view: new ol.View({
          center: [0, 0],
          zoom: 2
        })
      });
document.getElementById('zoom-out').onclick = function(){
    var view=map.getView();
    var zoom=view.getZoom();
    view.setZoom(zoom-1);
};
 

你可能感兴趣的:(OpenLayers - Accessible Map(1) - zoom操作)