14 March 2008

JSLinted and namespaced Mapstraction

I've been using Mapstraction in work over the past few months and now my current project has come to an end I've generated a few Subversion patches of my changes, which include:

  • JSLinting the source
  • Adding simple namespacing (read "hacking in") with backward compatibity "pollute" mode
  • Adding ability to execute event handlers in a particular scope along with a general rework of the event implementation to allow easier extensibility
  • Fixing several bugs with the Multimap implementation
  • Adding new and refining existing JSDoc comments


Should probably point out that I'm not part of the team that maintain Mapstraction and these aren't "official" patches. Hopefully the bug fixes at least will make it back into the repository though.


The namespacing is on by default so to get it to work with an old page you do need to call mxn.activatePolluteMode() first. Additionally there are a few loose utility functions in the mapstraction file that are also within the namespacing. You can get to three of them (metresToLon, lonToMetres and loadScript) from the mxn.fn namespace so if you have been making use of those you'd have to change your code to mxn.fn.metresToLon() for example. I'm not sure which of the other functions in there people would be likely to make use of so I left it at those three to try and minimise surface area but it wouldn't be a problem to add them all to fn.

There is also some backward compatibility stuff in the events implementation. I modified events so that they pass an eventArgs object rather than the arguments individually, that way the signature of all handlers is the same. This is only activated when you pass the third "scope" argument to addEventListener so old implementations should work as before either being passed no argument for move or a LatLonPoint for click.

1 comment:

maschek said...

Great stuff Derek, i will check your code out. Although i only found Mapstraction yesterday, i found the same shortcomings. I just checked out their mailing list, latest post also asks for namespacing, and indeed it would be an easy thing to do, so probably they will do it in the future.
About the events, yes, I miss marker events very much, i will see how your code deals with it.