Changeset 6571
- Timestamp:
- 03/21/08 11:45:54 (5 months ago)
- Files:
-
- trunk/openlayers/examples/click.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/examples/click.html
r6497 r6571 13 13 <script src="../lib/OpenLayers.js"></script> 14 14 <script type="text/javascript"> 15 OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { 16 defaultHandlerOptions: { 17 'single': true, 18 'double': false, 19 'pixelTolerance': 0, 20 'stopSingle': false, 21 'stopDouble': false 22 }, 23 24 initialize: function(options) { 25 this.handlerOptions = OpenLayers.Util.extend( 26 {}, this.defaultHandlerOptions 27 ); 28 OpenLayers.Control.prototype.initialize.apply( 29 this, arguments 30 ); 31 this.handler = new OpenLayers.Handler.Click( 32 this, { 33 'click': this.trigger, 34 }, this.handlerOptions 35 ); 36 }, 37 38 trigger: function(e) { 39 var lonlat = map.getLonLatFromViewPortPx(e.xy); 40 alert("You clicked near " + lonlat.lat + " N, " + 41 + lonlat.lon + " E"); 42 }, 43 44 }); 15 45 var map; 16 46 function init(){ … … 30 60 // map.setCenter(new OpenLayers.LonLat(0, 0), 0); 31 61 map.zoomToMaxExtent(); 32 map.events.register("click", map, function(e) {33 var lonlat = map.getLonLatFromViewPortPx(e.xy);34 alert("You clicked near " + lonlat.lat + " N, " +35 + lonlat.lon + " E");36 }); 62 63 var click = new OpenLayers.Control.Click(); 64 map.addControl(click); 65 click.activate(); 66 37 67 } 38 68 </script> … … 45 75 46 76 <p id="shortdesc"> 47 This example shows the use of the register and getLonLatFromViewPortPx functions to trigger events on mouse click. 77 This example shows the use of the click handler and getLonLatFromViewPortPx functions to trigger events on mouse click. 78 48 79 </p> 49 80 50 81 <div id="map"></div> 51 82 52 <div id="docs"></div> 83 <div id="docs"> 84 Using the Click handler allows you to (for example) catch clicks without catching double clicks, something that standard browser events don't do for you. (Try double clicking: you'll zoom in, whereas using the browser click event, you would just get two alerts.) This example click control shows you how to use it. 85 </div> 53 86 </body> 54 87 </html>
