]> dev.renevier.net Git - syp.git/blob - openlayers/examples/custom-control.html
initial commit
[syp.git] / openlayers / examples / custom-control.html
1 <html xmlns="http://www.w3.org/1999/xhtml">
2     <head>
3         <title>Custom Control Example</title>
4         <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
5         <link rel="stylesheet" href="style.css" type="text/css" />
6         <script src="../lib/OpenLayers.js"></script>
7         <script type="text/javascript">
8             var lon = 5;
9             var lat = 40;
10             var zoom = 5;
11             var map, layer;
12
13             function init(){
14                 map = new OpenLayers.Map('map');
15                 layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
16                         "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
17
18                 var control = new OpenLayers.Control();
19                 OpenLayers.Util.extend(control, {
20                     draw: function () {
21                         // this Handler.Box will intercept the shift-mousedown
22                         // before Control.MouseDefault gets to see it
23                         this.box = new OpenLayers.Handler.Box( control,
24                             {"done": this.notice},
25                             {keyMask: OpenLayers.Handler.MOD_SHIFT});
26                         this.box.activate();
27                     },
28
29                     notice: function (bounds) {
30                         var ll = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.left, bounds.bottom)); 
31                         var ur = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.right, bounds.top)); 
32                         alert(ll.lon.toFixed(4) + ", " + 
33                               ll.lat.toFixed(4) + ", " + 
34                               ur.lon.toFixed(4) + ", " + 
35                               ur.lat.toFixed(4));
36                     }
37                 });
38
39                 map.addLayer(layer);
40                 map.addControl(control);
41                 map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
42             }
43         </script>
44     </head>
45     <body onload="init()">
46         <h1 id="title">Custom Control Example</h1>
47
48           <div id="tags">
49         </div>
50
51         <p id="shortdesc">
52             Demonstrate the addition of a draggable rectangle to the OpenLayers window.
53         </p>
54       
55         <div id="map" class="smallmap"></div>
56
57         <div id="docs"></div>
58     </body>
59 </html>