Hello All,<br><br>i was investigating how to add the popup menu to the right click event. as of now, i found a code piece so that i can capture the coordinate of right click. i also found "OpenLayers.Popup" function. however, when i use ""OpenLayers.Popup"" function, the popup appears on top of the map. instead, i want it to appear at mouse cursor when the user right clicks. <br>
<br>i think i need to combine the right click event with the popup creation but since i am a total newbie with coding, i cannot do it. can anyone help me?<br><br>thanks.<br><br>this is my code<br><br>----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
<br><!DOCTYPE html><br><html lang='en'><br><head><br><meta charset='utf-8' /><br><title>ismetb map</title><br><script type='text/javascript' src='OpenLayers.js'></script><br>
<script type='text/javascript'><br><br>var map;<br><br>function init() {<br>map = new OpenLayers.Map('map_element', {});<br>var wms = new OpenLayers.Layer.WMS(<br>'OpenLayers WMS',<br>'<a href="http://vmap0.tiles.osgeo.org/wms/vmap0">http://vmap0.tiles.osgeo.org/wms/vmap0</a>',<br>
{layers: 'basic'},<br>{}<br>);<br><br>map.addLayer(wms);<br>if(!map.getCenter()){<br>map.zoomToMaxExtent();<br>}<br>// Get control of the right-click event:<br>document.getElementById('map_element').oncontextmenu = function(e){<br>
e = e?e:window.event;<br> if (e.preventDefault) e.preventDefault(); // For non-IE browsers.<br> else return false; // For IE browsers.<br>};<br><br><br>// A control class for capturing click events...<br>OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { <br>
<br>defaultHandlerOptions: {<br>'single': true,<br>'double': true,<br>'pixelTolerance': 0,<br>'stopSingle': false,<br>'stopDouble': false<br>},<br>handleRightClicks:true,<br>initialize: function(options) {<br>
this.handlerOptions = OpenLayers.Util.extend(<br>{}, this.defaultHandlerOptions<br>);<br>OpenLayers.Control.prototype.initialize.apply(<br>this, arguments<br>); <br>this.handler = new OpenLayers.Handler.Click(<br>this, this.eventMethods, this.handlerOptions<br>
);<br>},<br>CLASS_NAME: "OpenLayers.Control.Click"<br><br>});<br><br><br>// Add an instance of the Click control that listens to various click events:<br>var oClick = new OpenLayers.Control.Click({eventMethods:{<br>
'rightclick': function(e) {<br>alert('rightclick at '+e.xy.x+','+e.xy.y);<br>},<br>//'click': function(e) {<br>//alert('click at '+e.xy.x+','+e.xy.y);<br>//},<br>//'dblclick': function(e) {<br>
//alert('dblclick at '+e.xy.x+','+e.xy.y);<br>//},<br>//'dblrightclick': function(e) {<br>//alert('dblrightclick at '+e.xy.x+','+e.xy.y);<br>//}<br>}});<br>map.addControl(oClick);<br>
oClick.activate();<br><br>}<br><br> </script><br></head><br><br><body onload='init();'><br><div id='map_element' style='width: 400px; height: 400px;'><br></div><br></body><br>
</html><br><br>----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
and this is popup example:<br><br><blockquote><pre class="prettyprint"><span class="pln">popup </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">OpenLayers</span><span class="pun">.</span><span class="typ">Popup</span><span class="pun">(</span><span class="str">"chicken"</span><span class="pun">,</span><span class="pln"><br>
</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">OpenLayers</span><span class="pun">.</span><span class="typ">LonLat</span><span class="pun">(</span><span class="lit">5</span><span class="pun">,</span><span class="lit">40</span><span class="pun">),</span><span class="pln"><br>
</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">OpenLayers</span><span class="pun">.</span><span class="typ">Size</span><span class="pun">(</span><span class="lit">200</span><span class="pun">,</span><span class="lit">200</span><span class="pun">),</span><span class="pln"><br>
</span><span class="str">"example popup"</span><span class="pun">,</span><span class="pln"><br> </span><span class="kwd">true</span><span class="pun">);</span><span class="pln"><br>
<br>map</span><span class="pun">.</span><span class="pln">addPopup</span><span class="pun">(</span><span class="pln">popup</span><span class="pun">);<br><br><br></span></pre></blockquote><br>