On Wed, Apr 8, 2009 at 2:06 PM, Aude <aude.wiki(a)gmail.com> wrote:
I have my own OpenLayers extension in development and
would like to merge
some of the code. What it does is parse a tag: <map lat="38.90962"
long="-77.04341" zoom="15" mode="osm">
The "mode" parameter allows specifying osm - OpenStreetMap as the map
source, or WorldWind and can allow other sources such as a custom WMS
server. There is a variable in LocalSettings.php to specify what modes are
enabled on the wiki. For what we are doing (just OSM to start with), we can
enable just the OSM mode. The "mode" parameter could be optional, but the
others required. If the "mode" parameter is not provided, then the default
mode (e.g. OSM) is used.
I was already going to hack SlippyMap*.php around to support this, but
it might be easier to use your extension as a starting point.
The JavaScript is included as a separate js file.
Here are code snippets from my Map.php (main extension file), which makes
calls to a Map.class.php file:
$wgHooks['ParserFirstCallInit'][] = 'wfMapParserInit';
function wfMapParserInit() {
global $wgParser;
$wgParser->setHook( 'map', 'wfMapRender' );
return true;
}
function wfMapRender( $input, $args, $parser ) {
/* $wgMap is as a public object, with the setupMap function available,
while other parts of the code are protected
*/
global $wgOut, $wgScriptPath, $wgMap;
/* pass variables to JavaScript. right now, there can only be one map
per page, but I would like to put the variables into a multidimensional
array, and handle multiple maps that way. I'm working on this.
*/
$wgOut->addScript( "<script type='text/javascript'>var
mode='" .
$args[mode] . "'; var lat=" . $args[lat] . ";var long=" .
$args[long] .
";var zoom =" . $args[zoom] . ";</script>");
/* it might be better to have the map.js script call and include the
OpenLayers.js script, rather than do it from php. That way, if a user does
not have JavaScript enabled, then the JavaScript won't load and things will
be faster
*/
$wgOut->addScript( "<script type='text/javascript' src='"
.
$wgScriptPath .
"/extensions/Map/OpenLayers/lib/OpenLayers.js'></script>" );
// add our custom js that implements and adds OpenLayers maps
$wgOut->addScript( "<script type='text/javascript' src='"
.
$wgScriptPath . "/extensions/Map/map.js'></script>" );
// code making calls to the OpenLayers.class.php file to setup the map
$text = $wgMap->setupMap($args[mode]);
// insert map where the <map> tag was in the wikicode
$wgOut->addHTML($text);
return htmlspecialchars( $input );
}
I would like to test if a user has JavaScript enabled, which can be done
with an Ajax call or other way. If they don't, then don't load all the
external JavaScript, so as to keep the code lightweight and fast. If the
user does have JavaScript enabled, then load the map.js script. Depending
on the mode selected, the OSM portion of the js can be loaded, or the
WorldWind portion, or other portion.
Or, if we provide a static map by default / slippy map on onclick()
the onclick() routine could take care of pulling in OpenLayers / other
required JS.
As for where to have the OpenLayers code, I would like
to have our own copy
which we can keep up-to-date as possible. It would not be good to reference
the OpenLayers.js directly from OpenLayers or OSM, since those will get
changed as others see fit. It could be that some change will break our
extension. When we do update our copy of OpenLayers.js, we can test it with
our extension and make sure everything is okay.
Yes, this goes without saying. Nothing deployed on Wikimedia will be
referencing 3rd party JavaScript as the current slippyMap extension is
doing both for JS and for .png images.
Anyway, in the next few days and over this upcoming
weekend, I can hack more
at the code where we integrate OpenLayers and MediaWiki. I can provide them
as patches or if I can get svn access to the extensions part of the
MediaWiki svn, then I can integrate code myself.
Please get a SVN account, send an e-mail to
wikitech-l(a)lists.wikimedia.org / brion(a)wikimedia.org with your ssh
public key, desired username and a note that you'll be working on
this.
This also goes for other interested parties, 2 of which I've given
these instructions already, and anyone else on this list who wants to
hack this too.