summaryrefslogtreecommitdiff
path: root/misc/openlayers/examples/restricted-extent.html
blob: 7ab4ca858497134339de070e53e4c05f7a81b947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>OpenLayers Restricted Extent Example</title>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css">
    <link rel="stylesheet" href="style.css" type="text/css">
    <script src="../lib/Firebug/firebug.js"></script>
    <script src="../lib/OpenLayers.js"></script>
    <script type="text/javascript">
        var map = null;
        var extent = new OpenLayers.Bounds(8, 44.5, 19, 50);

        function init() {
            var options = {
                restrictedExtent: extent
            };
            map = new OpenLayers.Map('map', options);

            var wms = new OpenLayers.Layer.WMS(
                "OpenLayers WMS", 
                "http://vmap0.tiles.osgeo.org/wms/vmap0?",
                {layers: 'basic'}
            ); 

            map.addLayers([wms]);
            map.zoomToExtent(extent);
            document.getElementById("toggle").checked = true;
        }
        
        function toggleRestrictedExtent() {
            if(map.restrictedExtent == null) {
                map.setOptions({restrictedExtent: extent});
            } else {
                map.setOptions({restrictedExtent: null});
            }
        }
    </script>
  </head>
  <body onload="init()">
    <h1 id="title">OpenLayers Restricted Extent Example</h1>
    <div id="tags">
        map, restrict, restrictedextent, extent, light
    </div>    
    <p id="shortdesc">
      Don't let users drag outside the map extent: instead, limit dragging such
      that the extent of the layer is the maximum viewable area.
    </p>
    <div id="map" class="smallmap"></div>
    <p>
        Map navigation is limited by a combination of map and layer properties.
        The base layer resolutions array controls the resolutions (or zoom
        levels) available.  The resolutions can be limited by setting a
        maxResolution property or by explicitly specifying a resolutions
        array.
    </p>
    <p>
        Navigation limited by the maxExtent property.  A map cannot be panned
        so that the center of the viewport is outside of the bounds specified
        in maxExtent.  If you wish to further restrict panning, use the
        restrictedExtent property.  With restrictedExtent set, the map cannot
        be panned beyond the given bounds.  If the maxResolution allows the
        map to be zoomed to a resolution that displays an area bigger than
        the restrictedExtent, the viewport will remain centered on the
        restrictedExtent.
    </p>
    <p>
        <input type="checkbox" id="toggle" checked="checked"
               onclick="toggleRestrictedExtent();" />
        <label for="toggle">
            Toggle restricted extent (to [8, 44.5, 19, 50]).
        </label>
    
  </body>
</html>