<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1127014383786493769</id><updated>2024-08-31T06:38:49.958-04:00</updated><category term="gdal"/><category term="ogr"/><category term="openlayers"/><category term="proj"/><category term="projections"/><category term="rightclick"/><category term="globe"/><category term="handler keyMask"/><category term="hit counter"/><category term="keyIMask"/><category term="osr"/><category term="php"/><category term="python"/><category term="revolvermaps"/><category term="swig"/><category term="wkt"/><title type='text'>SpatialNotes</title><subtitle type='html'>Odds and ends, primarily about working with spatial applications.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://spatialnotes.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://spatialnotes.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>mgleahy</name><uri>http://www.blogger.com/profile/17482269158762010855</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1127014383786493769.post-1682120567107963307</id><published>2011-06-15T12:05:00.000-04:00</published><updated>2011-06-15T12:05:27.279-04:00</updated><title type='text'>Fix for Quantum GIS and Python bindings mismatch in Ubuntu 10.10</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;I&#39;m one version behind on my Ubuntu distro (I&#39;ve decided to wait until the next LTS before upgrading again, since I really need the time to get work done), so this may not be applicable to the latest version of Ubuntu (11.04).  In any case, I recently noticed that Quantum GIS  (QGIS) installed from the Ubutnu GIS &#39;unstable&#39; repository was unable to link to the &quot;Python/C++ bindings generator runtime library&quot; (python-sip). &amp;nbsp;The reported error when starting QGIS is as follows:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Traceback (most recent call last):&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; File &quot;&quot;, line 1, in&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;RuntimeError: the sip module implements API v8.0 but the qgis.core module requires API v7.1&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;-qt-block-indent: 0; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;-qt-block-indent: 0; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;&quot;&gt;This shouldn&#39;t be a big surprise, since QGIS is being installed from a repository deliberately labelled &#39;unstable&#39;.  However, I was not interested in downgrading QGIS and/or any of the other packages that I draw from the Ubuntu GIS repository, and as far as I can tell, &#39;unstable&#39; for this repository usually just means &#39;up-to-date&#39;, considering that the projects delivered through this repository are high quality as far as I am aware. &amp;nbsp;Although, using this repo does require a bit of care; you may have to account for significant changes in new software versions in any dependent applications you have (e.g., MapServer brought a number of changes in the latest 6.0 release, which would have required users/web developers to update their mapfiles and/or scripted code).&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
After a bit of googling around, I eventually found that I needed to downgrade two packages to maintain compatibility with QGIS: python-sip and python-qt4.  I don&#39;t recall the original source (this was a few months ago), but if you a) want the latest Open Source GIS packages, and b) want to be able to use python-based capabilities/plug-ins on Ubuntu 10.10, then here&#39;s the steps:&lt;br /&gt;
&lt;br /&gt;
1. If you don&#39;t have it already, setup the Ubuntu GIS unstable repo, and install the latest QGIS package (1.7.0 at the time of this writing):&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; # sudo add-apt-repository&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 18px;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ppa:ubuntugis/ubuntugis-unstable&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 18px;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; # sudo apt-get install qgis&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 18px;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;2. Downgrade python-sip and python-qt4:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; # sudo apt-get install python-sip=4.10.5-0ubuntu1 python-qt4=4.7.4-0ubuntu1&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;3. If this works for you, you can consider &#39;pinning&#39; the versions of these two packages so they don&#39;t get replaced the next time you install updates. &amp;nbsp;You can choose whichever method is most appropriate for you here:&amp;nbsp;&lt;a href=&quot;https://help.ubuntu.com/community/PinningHowto&quot;&gt;https://help.ubuntu.com/community/PinningHowto&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;I should note that QGIS will run without downgrading these python packages (albeit, after reporting the Python API errors on each startup). &amp;nbsp;However, it will be necessary if you want to use plug-ins that require Python (e.g., the OpenLayers plugin - I&#39;ve been using this version:&amp;nbsp;&lt;a href=&quot;https://github.com/TheGeoist/qgis-openlayers-plugin/&quot;&gt;https://github.com/TheGeoist/qgis-openlayers-plugin/&lt;/a&gt;).&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;I&#39;d be interested to know if anyone has run into this problem with Ubuntu 11.04.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://spatialnotes.blogspot.com/feeds/1682120567107963307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://spatialnotes.blogspot.com/2011/06/fix-for-quantum-gis-and-python-bindings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/1682120567107963307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/1682120567107963307'/><link rel='alternate' type='text/html' href='http://spatialnotes.blogspot.com/2011/06/fix-for-quantum-gis-and-python-bindings.html' title='Fix for Quantum GIS and Python bindings mismatch in Ubuntu 10.10'/><author><name>mgleahy</name><uri>http://www.blogger.com/profile/17482269158762010855</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1127014383786493769.post-3643983399399845138</id><published>2011-02-28T20:44:00.001-05:00</published><updated>2011-02-28T20:47:37.525-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gdal"/><category scheme="http://www.blogger.com/atom/ns#" term="ogr"/><category scheme="http://www.blogger.com/atom/ns#" term="osr"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="proj"/><category scheme="http://www.blogger.com/atom/ns#" term="projections"/><category scheme="http://www.blogger.com/atom/ns#" term="swig"/><title type='text'>Converting WKT projection info to Proj4 (and back) - the PHP edition</title><content type='html'>As noted in a &lt;a href=&quot;http://spatialnotes.blogspot.com/2010/11/converting-wkt-projection-info-to-proj4.html&quot;&gt;previous post&lt;/a&gt;, it is fairly easy to utilize the language bindings for the GDAL project to work with projections.  However, if you&#39;re working in PHP, the corresponding GDAL bindings are not maintained and currently do not work as-is from the GDAL project.  As-of GDAL 1.8.0, a bit of tinkering will get the PHP modules to compile, but they still do not work as expected.&lt;br /&gt;
&lt;br /&gt;
However, you can get the php_osr.so module to work with some basic functions using the patch posted at &lt;a href=&quot;http://pastebin.com/SXKKfe6v&quot;&gt;http://pastebin.com/SXKKfe6v&lt;/a&gt;.  Save this to a file, and apply the patch to the gdal 1.8.0 source like so:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;cd /path/to/gdal/src
 patch -p0 &lt; /path/to/patch
&lt;/pre&gt;
Then build and install the gdal code as follows:

&lt;pre&gt;./configure --with-php
 make
 make install
 sudo cp swig/php/php_osr.so /usr/lib/php5/20090626/
 sudo su -c \
  &#39;echo extension=php_osr.so &gt; /etc/php5/conf.d/osr.ini&#39;
 sudo service apache2 restart
&lt;/pre&gt;The above assumes:
- You&#39;re doing this on a typical/recent Ubuntu installation
- You already have Apache and PHP configured
- You already have all the required dependencies for building gdal and the swig bindings installed (if not, run &quot;&lt;pre style=&quot;display:inline&quot;&gt;sudo apt-get build-dep libgdal-1.x.x&lt;/pre&gt;&quot;, and also you may need to install php5-devel and php5-cli packages).

Once you&#39;ve got gdal and the php_osr.so module compiled and installed, try the following PHP script:

&lt;pre&gt;&amp;lt;?php
 include(&quot;/path/to/gdal/src/swig/php/osr.php&quot;);
 $sr = new SpatialReference();
 $sr-&gt;ImportFromProj4(&#39;+init=epsg:4326&#39;);
 echo $sr-&gt;ExportToProj4();
?&amp;gt;
&lt;/pre&gt;The result from that script should be the following Proj4 string:

&lt;pre&gt;+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs
&lt;/pre&gt;&lt;br /&gt;
Clearly, this is not as good as having all of the GDAL/OGR libraries accessible from PHP, but it&#39;s a start.  You can review the swig/php/osr.php file to see what objects/functions are available through the php_osr.so module.</content><link rel='replies' type='application/atom+xml' href='http://spatialnotes.blogspot.com/feeds/3643983399399845138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://spatialnotes.blogspot.com/2011/02/converting-wkt-projection-info-to-proj4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/3643983399399845138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/3643983399399845138'/><link rel='alternate' type='text/html' href='http://spatialnotes.blogspot.com/2011/02/converting-wkt-projection-info-to-proj4.html' title='Converting WKT projection info to Proj4 (and back) - the PHP edition'/><author><name>mgleahy</name><uri>http://www.blogger.com/profile/17482269158762010855</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1127014383786493769.post-4784589677137265854</id><published>2011-02-05T14:01:00.001-05:00</published><updated>2011-02-05T14:04:18.805-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="globe"/><category scheme="http://www.blogger.com/atom/ns#" term="hit counter"/><category scheme="http://www.blogger.com/atom/ns#" term="revolvermaps"/><title type='text'>A web page hit counter that plots your visitors on a globe.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;While reading someone&#39;s NASA blog, I came across this neat little widget that plots all of your visitors as points on a revolving globe (or flat static map if you prefer):&amp;nbsp;&lt;a href=&quot;http://www.revolvermaps.com/&quot;&gt;http://www.revolvermaps.com&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
It&#39;s free to use, and you can select from a variety of options to choose the coloring and style so that it fits into the layout of your website, and it can run using Flash or it will&amp;nbsp;fail-over&amp;nbsp;to Java (or neither if you choose a static map). &amp;nbsp;I&#39;m sure this isn&#39;t entirely new to everyone, as the site has been around for over two years, but it&#39;s fairly impressive regardless. &amp;nbsp;I also gather that it collects visitor information for your site in their own database somewhere (it&#39;s not clear from the info available how this is done), so if privacy is a concern for users on your site, you may not want to add this to your site.&lt;br /&gt;
&lt;br /&gt;
I&#39;ve added a sample below - I imagine the dots will remain fairly sparse for this blog.  :)&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://jc.revolvermaps.com/r.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;rm_f1st(&#39;6&#39;,&#39;220&#39;,&#39;true&#39;,&#39;false&#39;,&#39;000000&#39;,&#39;2ng16dtxv3k&#39;,&#39;true&#39;,&#39;4bc4bc&#39;);&lt;/script&gt;&lt;noscript&gt;&lt;applet codebase=&quot;http://rc.revolvermaps.com/j&quot; code=&quot;core.RE&quot; width=&quot;220&quot; height=&quot;220&quot; archive=&quot;g.jar&quot;&gt;&lt;param name=&quot;cabbase&quot; value=&quot;g.cab&quot; /&gt;&lt;param name=&quot;r&quot; value=&quot;true&quot; /&gt;&lt;param name=&quot;n&quot; value=&quot;false&quot; /&gt;&lt;param name=&quot;i&quot; value=&quot;2ng16dtxv3k&quot; /&gt;&lt;param name=&quot;m&quot; value=&quot;6&quot; /&gt;&lt;param name=&quot;s&quot; value=&quot;220&quot; /&gt;&lt;param name=&quot;c&quot; value=&quot;4bc4bc&quot; /&gt;&lt;param name=&quot;v&quot; value=&quot;true&quot; /&gt;&lt;param name=&quot;b&quot; value=&quot;000000&quot; /&gt;&lt;param name=&quot;rfc&quot; value=&quot;true&quot; /&gt;&lt;/applet&gt;&lt;/noscript&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://spatialnotes.blogspot.com/feeds/4784589677137265854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://spatialnotes.blogspot.com/2011/02/next-generation-of-web-page-hit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/4784589677137265854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/4784589677137265854'/><link rel='alternate' type='text/html' href='http://spatialnotes.blogspot.com/2011/02/next-generation-of-web-page-hit.html' title='A web page hit counter that plots your visitors on a globe.'/><author><name>mgleahy</name><uri>http://www.blogger.com/profile/17482269158762010855</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1127014383786493769.post-2122881446673637194</id><published>2011-01-13T14:30:00.000-05:00</published><updated>2011-01-13T14:30:13.937-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="handler keyMask"/><category scheme="http://www.blogger.com/atom/ns#" term="keyIMask"/><category scheme="http://www.blogger.com/atom/ns#" term="openlayers"/><category scheme="http://www.blogger.com/atom/ns#" term="rightclick"/><title type='text'>Creating a global control in OpenLayers for specific key combinations</title><content type='html'>This is largely a follow-up to a previous post I made discussing how to effectively &lt;a href=&quot;http://spatialnotes.blogspot.com/2010/11/capturing-right-click-events-in.html&quot;&gt;capture right clicks&lt;/a&gt; on an OpenLayers map object. &amp;nbsp;That had been related to another objective that I had, which was to have a global control that always responds to the right click in order to display a basic context menu on the map. &amp;nbsp;It&#39;s easy enough to get this working on the right-click, with all other controls working using the left click event - but what about Mac users, or people suffering from some kind of right-click impairment? &amp;nbsp;This needs a modifier key to go along with the left-click, but then there needs to be some way to prevent other controls from being triggered at the same time.&lt;br /&gt;
&lt;br /&gt;
In OpenLayers, there is a common property that can be passed to handlers/controls, called keyMask. &amp;nbsp;It is used in a bitwise comparison in the checkModifiers method of the OpenLayers.Handler class. &amp;nbsp;The main issue I had was that it currently only works to allow a given control to be restricted to a specified key combination. &amp;nbsp;It also does not allow you to have a single control that responds to different keys. &amp;nbsp;Rather,&amp;nbsp;any event keys added to the keyMask property of a control/handler must ALL be present in order for checkModifers to return true. &amp;nbsp;However,&amp;nbsp;here&#39;s the situation I wanted:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Global control (context menu): triggers on right click, or left-click + alt, or left-click + ctrl (this allows users with a one-button mouse to still access the menu), and&lt;/li&gt;
&lt;li&gt;All other controls: trigger on any left-click event that &lt;b&gt;excludes&lt;/b&gt;&amp;nbsp;the alt or ctrl keys.&lt;/li&gt;
&lt;/ol&gt;So to accomplish what I needed, I added a bit of code the checkModifiers function in the OpenLayers.Handler class to make it also check for a keyIMask property (i.e., an inverse key mask...though maybe that&#39;s not the best name for it). &amp;nbsp;Where the current keyMask must match all keys included in the event in order for checkModifiers function to return true, if the keyIMask matches &lt;b&gt;any&lt;/b&gt;&amp;nbsp;keys included in the event, then checkModifiers returns false. &amp;nbsp;Here&#39;s what it looks like:&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;checkModifiers: function (evt) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(this.keyMask == null &amp;amp;&amp;amp; this.keyIMask == null) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return true;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/* calculate the keyboard modifier mask for this event */&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;var keyModifiers =&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;(evt.shiftKey ? OpenLayers.Handler.MOD_SHIFT : 0) |&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;(evt.ctrlKey &amp;nbsp;? OpenLayers.Handler.MOD_CTRL &amp;nbsp;: 0) |&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;(evt.altKey &amp;nbsp; ? OpenLayers.Handler.MOD_ALT &amp;nbsp; : 0);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/* if it differs from the handler object&#39;s key mask,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;bail out of the event handler */&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return ((this.keyMask == null || keyModifiers == this.keyMask)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;amp;&amp;amp; (this.keyIMask == null || (keyModifiers &amp;amp; this.keyIMask) == 0));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;With the Handler modified in this way, I can tell any control to &lt;b&gt;not&lt;/b&gt;&amp;nbsp;respond if any key in an event matches keyIMask. &amp;nbsp;In my global control, it internally checks if the event is either right-click, or if it&#39;s a left-click with either the ctrlKey or altKey present. &amp;nbsp;All of my other controls are set with the property &quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;keyIMask =&amp;nbsp;OpenLayers.Handler.MOD_CTRL | OpenLayers.Handler.MOD_ALT;&lt;/span&gt;&quot;, which prevents controls from being triggered when the menu is displayed, and still leaves room for MOD_SHIFT to be used either as a keyMask, or to internally modify the&amp;nbsp;behaviour&amp;nbsp;of control&#39;s events (e.g., the freehand toggle in the OpenLayers.Handler.Path class).&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://spatialnotes.blogspot.com/feeds/2122881446673637194/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://spatialnotes.blogspot.com/2011/01/creating-global-control-in-openlayers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/2122881446673637194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/2122881446673637194'/><link rel='alternate' type='text/html' href='http://spatialnotes.blogspot.com/2011/01/creating-global-control-in-openlayers.html' title='Creating a global control in OpenLayers for specific key combinations'/><author><name>mgleahy</name><uri>http://www.blogger.com/profile/17482269158762010855</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1127014383786493769.post-2348637016016910119</id><published>2010-11-21T19:59:00.002-05:00</published><updated>2011-02-28T20:49:39.779-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="openlayers"/><category scheme="http://www.blogger.com/atom/ns#" term="rightclick"/><title type='text'>Capturing right-click events in OpenLayers</title><content type='html'>I&#39;ve been looking at using OpenLayers as the mapping API for an application I&#39;ve been working on for some time. &amp;nbsp;One of the key features of the application requires capturing mouse click events on the map. &amp;nbsp;This is fairly normal with OpenLayers for many of its controls, but when the right-click event is involved, I would always get the default context menu from the browser, and OpenLayers didn&#39;t seem to capture the rightclick event on its own. &amp;nbsp;There are a few workarounds posted on the web...but I found they were not easily adaptable, or didn&#39;t quite work the way I wanted. &amp;nbsp;So here&#39;s what I came up with - paste the code below at the end of the init() function in any of OpenLayers&#39; examples:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;===================================================&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;// Get control of the right-click event:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;document.getElementById(&#39;map&#39;).oncontextmenu = function(e){&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;e = e?e:window.event;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;if (e.preventDefault) e.preventDefault(); // For non-IE browsers.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;else return false; // For IE browsers.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;// A control class for capturing click events...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; defaultHandlerOptions: {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &#39;single&#39;: true,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &#39;double&#39;: true,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &#39;pixelTolerance&#39;: 0,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &#39;stopSingle&#39;: false,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &#39;stopDouble&#39;: false&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; },&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; handleRightClicks:true,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; initialize: function(options) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  this.handlerOptions = OpenLayers.Util.extend(&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;   {}, this.defaultHandlerOptions&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  OpenLayers.Control.prototype.initialize.apply(&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;   this, arguments&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  );&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  this.handler = new OpenLayers.Handler.Click(&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;   this, this.eventMethods, this.handlerOptions&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  );&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; },&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; CLASS_NAME: &quot;OpenLayers.Control.Click&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;});&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;// Add an instance of the Click control that listens to various click events:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;var oClick = new OpenLayers.Control.Click({eventMethods:{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&#39;rightclick&#39;: function(e) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;alert(&#39;rightclick at &#39;+e.xy.x+&#39;,&#39;+e.xy.y);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;},&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&#39;click&#39;: function(e) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;alert(&#39;click at &#39;+e.xy.x+&#39;,&#39;+e.xy.y);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;},&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&#39;dblclick&#39;: function(e) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;alert(&#39;dblclick at &#39;+e.xy.x+&#39;,&#39;+e.xy.y);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;},&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&#39;dblrightclick&#39;: function(e) {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;alert(&#39;dblrightclick at &#39;+e.xy.x+&#39;,&#39;+e.xy.y);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}});&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;map.addControl(oClick);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;oClick.activate();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;===================================================&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;The first bit overrides the oncontextmenu event that causes the browser to display a context menu when the right-click event happens. &amp;nbsp;The next bit creates a simple control class for handling the click events, with the handleRightClicks option enabled. &amp;nbsp;After that, an instance of the control class is created, with functions for the four different click event types included in the eventMethods option. &amp;nbsp;Finally, this control is added to the map and activated...any better solutions are welcome.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;EDIT: &lt;/b&gt;This has been corrected to&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt; utilize the &#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;handleRightClicks&#39; property in the OpenLayers class.  Other than this, all that is essentially needed is the overridden oncontextmenu function, which uses preventDefault (for non-IE browsers), or returns false (for IE browsers).&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://spatialnotes.blogspot.com/feeds/2348637016016910119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://spatialnotes.blogspot.com/2010/11/capturing-right-click-events-in.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/2348637016016910119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/2348637016016910119'/><link rel='alternate' type='text/html' href='http://spatialnotes.blogspot.com/2010/11/capturing-right-click-events-in.html' title='Capturing right-click events in OpenLayers'/><author><name>mgleahy</name><uri>http://www.blogger.com/profile/17482269158762010855</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1127014383786493769.post-7285359033792382239</id><published>2010-11-21T16:43:00.000-05:00</published><updated>2010-11-21T20:51:25.975-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gdal"/><category scheme="http://www.blogger.com/atom/ns#" term="ogr"/><category scheme="http://www.blogger.com/atom/ns#" term="proj"/><category scheme="http://www.blogger.com/atom/ns#" term="projections"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="wkt"/><title type='text'>Converting WKT projection info to Proj4 (and back)</title><content type='html'>I&#39;ve had many occasions where I&#39;ve had WKT-style projection text (e.g., the contents of the *.prj files that normally accompany ESRI Shapefiles, or the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;srtext&lt;/span&gt; field in the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;spatial_ref_sys&lt;/span&gt; table in PostGIS), and I needed to get that to an&amp;nbsp;equivalent Proj4-compatible projection string (and vice versa). &amp;nbsp;I&#39;ve known for some time there had to be an automated way to do this...as the GDAL/OGR libraries have been doing this internally for some time. &amp;nbsp;I ran into the issue again today, so I decided to poke around a bit, and found the API functions that are available to do this...I wrote my first ever Python scripts that use the GDAL/OGR python bindings (specifically, OSR). &amp;nbsp;These scripts simply convert WKT projection text to Proj4 (wkt2proj.py) and back (proj2wkt.py). &amp;nbsp;Maybe there are some better examples elsewhere...but I didn&#39;t quite find what I was looking for. &amp;nbsp;Since my work is mostly in PHP right now, I&#39;d love to see the GDAL/OGR PHP bindings maintained someday, but this will do for now:&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;================== wkt2proj.py =======================&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#!/usr/bin/env python&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;import os&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;import sys&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;import string&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;import osgeo.osr&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if (len(sys.argv) &amp;lt;&amp;gt; 2):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print &#39;Usage: wkt2proj.py [WKT Projection Text]&#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;else:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;srs = osgeo.osr.SpatialReference()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;srs.ImportFromWkt(sys.argv[1])&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print srs.ExportToProj4()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;======================================================&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;================== proj2wkt.py =======================&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#!/usr/bin/env python&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;import os&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;import sys&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;import string&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;import osgeo.osr&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if (len(sys.argv) &amp;lt;&amp;gt; 2):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print &#39;Usage: proj2wkt.py [Proj4 Projection Text]&#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;else:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;srs = osgeo.osr.SpatialReference()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;srs.ImportFromProj4(sys.argv[1])&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print srs.ExportToWkt()&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;======================================================&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;On Ubuntu, provided you have the python-gdal package installed, the above files executed by python will accept the first argument as a wkt/proj projection string, and return the proj/wkt equivalent. &amp;nbsp;For proj2wkt.py, you can also take advantage of known EPSG numbers. &amp;nbsp;For example, the WKT for the Spherical Mercator projection used by most free online mapping services (e.g., Google Maps, OpenStreetMap, etc) will be returned by: &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;proj2wkt.py &#39;+init=epsg:3857&#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;I haven&#39;t tested this on Windows - but as long as the Proj library is installed and the GDAL Python modules are installed and accessible to the Python environment, I imagine they will work the same.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://spatialnotes.blogspot.com/feeds/7285359033792382239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://spatialnotes.blogspot.com/2010/11/converting-wkt-projection-info-to-proj4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/7285359033792382239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1127014383786493769/posts/default/7285359033792382239'/><link rel='alternate' type='text/html' href='http://spatialnotes.blogspot.com/2010/11/converting-wkt-projection-info-to-proj4.html' title='Converting WKT projection info to Proj4 (and back)'/><author><name>mgleahy</name><uri>http://www.blogger.com/profile/17482269158762010855</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>