5 <title>events example</title>
6 <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
7 <meta name="description" content="An example of basic interaction events">
8 <meta name="author" content="Ryan Westphal">
9 <link rel="stylesheet" type="text/css" href="css/style.css" />
10 <style type="text/css">
27 border-left: solid 2px #dedede;
37 <a href="../" class="docLink">< docs</a>
38 <a href="http://jsfiddle.net/ryanttb/fg6wv/embedded/" class="fiddleLink"><img src="img/jsfiddle.png" alt="" /> jsFiddle ></a>
41 <p>The basic interaction events are: move, click, dblclick, and bboxchange. jQuery Geo triggers then when a user interacts with the map.</p>
42 <table cellspacing="0">
54 <tr class="geomapmove">
56 move (<span class="date"></span>)
61 <tr class="geomapclick">
63 click (<span class="date"></span>)
68 <tr class="geomapdblclick">
70 dblclick (<span class="date"></span>)
75 <tr class="geomapbboxchange">
77 bboxchange (<span class="date"></span>)
86 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
87 <script src="http://code.jquerygeo.com/jquery.geo-1.0a4.min.js"></script>
91 // hook into all the events and update the screen when they're triggered
92 // we don't need to prefix the events with the widget's name during initialization
93 var map = $("#map").geomap({
94 center: [-71.0595678, 42.3604823],
97 // position events get a GeoJSON Point object
98 move: positionEventHandler,
99 click: positionEventHandler,
100 dblclick: positionEventHandler,
102 // bbox events get an object with a bbox property
103 bboxchange: bboxEventHandler
106 function positionEventHandler( e, geo ) {
107 // jQuery stores the event type in e.type
108 // outside of the initialization function,
109 // the jQuery UI widget events all have a widget prefix
110 // in this case it's: geomap
112 // this example builds a selector for the class
113 // of the table's row for this event
114 // if the event is, e.g., move, e.type is geomapmove and the row we want is .geomapmove
115 var eventRowClass = "." + e.type;
117 // update the time stamp for this event
118 $(eventRowClass + " .date").text($.now());
120 // contained in the geo argument as a GeoJSON Point object
122 // the coordinates property is an array,
123 // this example joins them with an extra space so they look a little nicer
124 var displayCoords = geo.coordinates.join( ", " );
127 // convert the map coordinates to pixel locations to show them as well
128 var displayPixels = map.geomap( "toPixel", geo.coordinates ).join( ", " );
130 // update the position data
131 $(eventRowClass + " .data").html("pixels: [ " + displayPixels + " ]<br>coordinates: [ " + displayCoords + " ]");
134 function bboxEventHandler( e, geo ) {
135 // again, build a selector for the class of the table's row for this event
136 // for example, the bboxchange event's e.type is geomapbboxchange
137 // and the row we want is .geomapbboxchange
138 var eventRowClass = "." + e.type;
140 // update the time stamp for this event
141 $( eventRowClass + " .date" ).text( $.now( ) );
143 // update the position data,
144 // contained in the geo argument as an object with a bbox property
145 // currently that's all the object has
146 $( eventRowClass + " .data" ).text( "[ " + geo.bbox.join( ", " ) + " ]" );
152 var _gaq = [['_setAccount', 'UA-26084853-1'], ['_trackPageview']];
154 var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; g.async = 1;
155 g.src = ('https:' == location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
156 s.parentNode.insertBefore(g, s);
157 } (document, 'script'));