1. New Alaveteli upgrade

    It's Loud, by Caterpiya

    Version 0.6 of Alaveteli, our Right to Know platform, has just been released. Some of the major features of the new release are for users, some for Admin:

    • We’re all so used to the concept of getting updates on a ‘wall’ or a ‘stream’, thanks to Facebook and Twitter – and now users can do the same on Alaveteli sites.
    • It’s difficult to moderate all unsuitable requests when you are running a high-traffic site – but now you can tap into the power of the crowd, with ‘report this request’ buttons (and a moderation list in Admin).
    • The back-end looks extra smart now, thanks to some nifty code “built for and by nerds” by Twitter (Bootstrap).
    • And – one for developers – Alaveteli is now using Bundler wherever possible.

    Seb’s also written a round-up of the most interesting changes and bug-fixes. If you’re running an Alaveteli site, or just thinking about it, you should head over there for a read.

    Image by Caterpiya.

  2. Extracting Administrative Boundaries from OpenStreetMap – Part 1

    Boundary Stone between Yorkshire and Lancashire

    "Boundary Stone 1" taken by Tim Green (CC-BY-licensed from Flickr)

    This is the first part of a two-part blog post about some of our work on making it easier to deploy FixMyStreet and MapIt in new countries.  This part describes how to generate KML for a given boundary in OpenStreetMap. Update: the second part is now available.

    As mentioned in a previous post, we’re looking at ways of making it smoother to deploy FixMyStreet for a new country, city or use-case.  Essentially there are two fundamental bits of data that you need for this:

    1. a mapping between a latitude and longitude (or postcode) to all the adminstrative areas that cover that point.
    2. a mapping between problem type and adminstrative areas to an appropriate email address for reporting that problem.

    The first of those is typically provided by a service called MapIt, an open source GeoDjango web application written by Matthew Somerville.  In the UK we are fortunate that official boundary data and the postcode database have now been released under an open data license from the Ordnance Survey.  However, in other many other countries similar data is unavailable, or not available under reasonable licensing conditions.  In such cases, though, all is not lost thanks to the extraordinary work of contributors to the OpenStreetMap project.  OpenStreetMap contains high-quality administrative boundary data for many countries of the world, and we know that data submitted to the project is available under the Creative Commons Attribution-ShareAlike license, so we can reuse it in a web service like MapIt.

    The first step towards being able to build an instance of MapIt based on OpenStreetMap boundary data is to be able to generate a shapefile that represents a boundary in the project.  (In OpenStreetMap’s data model, boundaries are represented as either ways or relations, and those that we are interested in are tagged with boundary=administrative.)  Matthew had previously written code to generate KML files for boundaries in Norway in order to help to set up an instance of MapIt for Norway, which is used by FiksGataMi.  However, that script was quite specific to the organization of boundaries in that country, and it did not deal with more complex boundary topologies (e.g. enclaves), or different representations of boundaries (e.g. multiply nested relations).

    So, Matthew and I wrote a new version of the code to extract a boundary from OpenStreetMap and generate a KML representation of it. The new version uses the Overpass API instead of XAPI, since it allows us to specify multiple predicates in the query and recursively fetch the ways and nodes that are contained in a relation.  Once all the ways that make up a relation have been fetched (ignoring those with roles like “defaults” or “subarea”), the script tries to join each unclosed way to any other with which it shares an endpoint.  We should end up with a series of closed polygons – the script exits in error if there are any unclosed ways left.  We can then directly create KML from these polygons, the only subtlety being that we need to mark certain boundaries as being an inner boundary (i.e., creating a hole in a boundary) if they had the role “enclave” or “inner” in an OpenStreetMap relation. For example, the South Cambridgeshire District Council boundary has a Cambridge City Council-shaped hole in it:

    South Cambridgeshire District Council boundary

    Similarly, the script has to cope with multiple distinct polygons, such as the boundary of Orkney.

    If you want to use this code to generate a KML representation of a closed way or boundary relation from OSM, just clone the MapIt repository and run bin/boundaries.py:

    $ bin/boundaries.py --help
    Usage: boundaries.py [options]
    
    Options:
      -h, --help            show this help message and exit
      --test                Run all doctests in this file
      --relation=<RELATION_ID>
                            Output KML for the OSM relation <RELATION_ID>
      --way=<WAY_ID>        Output KML for the OSM way <WAY_ID>

    For example, to generate a KML boundary for the Hottingen area of Zürich, you can do:

    $ bin/boundaries.py --relation=1701449 > hottingen.kml

    In the next blog post in this series, we will discuss extracting such boundaries en masse and creating a service based on them.

  3. DIY mySociety

    The Load by Kennymatic

    mySociety’s sites are all open-source, which means that anyone can take our code and build their own sites with it. That’s been a core mySociety principle from the very beginning, but as time has passed, we’ve realised that we could have made the process easier.

    Until recently, you had to be pretty techie to use our code. But now, under the banner DIY mySociety, we’re actively working to lower the bar. Firstly, and most importantly, we’re in the process of rewriting much of our code so that it’s nearer ‘plug and play’ status than previously. Then, we’re backing it up with documentation in the form of easy-to-read handbooks, and supportive communities.

    If you’ve ever thought of replicating a mySociety-style site in your own neck of the woods, take a peek at DIY mySociety. We’ll be regularly updating with news and advice.

    Image by Kenny Louie, used with thanks under the Creative Commons licence.

  4. Platforms and Components: mySociety’s tools for you to re-use

    Keen on the idea of setting up a mySociety-style site like FixMyStreet.com or WhatDoTheyKnow.com? Not sure what you need? Then read on.

    At mySociety, we’re working really hard to create software tools that are attractive and easy to set up in diverse countries, cities and regions. Now we want to make sure everyone knows what we offer, and how it can be useful. This is a beginners’ guide to what mySociety can offer in the way of software tools.

    First up, the basics:

    • All our code is open source.
    • Some of our code is available in simple-to-use packages.
    • There are two types of package. We call them Platforms and Components. This post is about explaining the difference.

    Platforms

    You can think of Platforms as flat-pack websites – like furniture that arrives in a cardboard box, with all the screws, instructions and tools included. Our Platforms provide everything you need to replicate a site like FixMyStreet.com or WhatDoTheyKnow.com in your own country, city or region, but you need to do a little work to get it up and running.

    Platforms are great for people who don’t want to spend a long time reinventing the wheel, and who want to get a basic, functional site up and running as fast as possible.

    We provide the software, and you just need to add:

    1. Data to populate it
      For example, if you’re setting up a website using the FixMyStreet platform, you need the names and email addresses of every bit of government that you want to send reports to. (This isn’t as daunting as it might sound – it might just be one authority and one email address! And if not, well, we’ve had lots of success with crowd-sourcing this sort of information).
    2. A server to host it on
      We can help you here, if it’s a problem for you. See step 1 on this page.
    3. Enthusiastic people to run it
      Don’t forget this vital consideration! Computers are great, but they can’t do everything themselves. You will need people – volunteers or paid staff – to promote, improve, and interact with the users of your website.

    The following platforms are available to download and install:

    • FixMyStreet
      For reporting common street problems such as potholes or broken streetlights. Creates transparency about local government, at the same time as providing a practical service to users.
    • Alaveteli
      Our Freedom-of-Information Platform. Whether or not your country has a Right to Know law, this Platform lets people ask questions to public authorities, – and it publishes all the conversations online.
    Please note, at the moment these Platforms are not easy enough for anyone to install: you will need some technical knowledge. However, we are working all the time to make it easier to set up websites built on these platforms, and we have mailing lists and IRC channels where you can ask for help. These are linked to from the Alaveteli and FixMyStreet Platform homepages.
    Components are handy code modules that you can incorporate into any website build, saving yourself an awful lot of time and effort. They’re the result of mySociety’s years of experience in building tools that work (and refining those that didn’t work as well as we wanted them to).
    At the moment, we reckon our Components will be of most use to people building Parliamentary Monitoring websites, like our site TheyWorkForYou.com, or the Kenyan site Mzalendo.com.

    If Platforms are like a flat-pack piece of furniture, Components are more like the parts of a kitchen. When you have a kitchen built, you get to choose from a number of parts that fit together: cupboards, drawers, shelves, etc. You can ignore things you don’t want, and add in things you do – and you end up with a kitchen that suits your needs.

    Components will save you a lot of time because you won’t need to create database structures, APIs, search mechanisms, admin interfaces, and so on. Just slot in a Component – like you might slot in a dishwasher – and it’s all done for you. We’ve done our best to make them easy to deploy, easy to customise, and easy to connect together.

    You will definitely need technical skills, although we are working on lowering that barrier. Components cannot run on their own – they need a website to fit into. And just as with our Platforms, you’ll need data. But you don’t need a server – we host the Components ourselves.

    Right now we just have one component which is fully documented and ready to use, but we’re working on followups right now. This component is called MapIt.

    • MapIt 
      MapIt is a web service which you can use to work out which boundaries a point or postcode exists within. An essential foundation for geographic lookups of all kinds. You can play with the UK instance here. We use it on:

      • Our parliamentary monitoring website TheyWorkForYou.com. Users are shown their own MP’s data even if they don’t know who that MP is – all they have to do is input their postcode.
      • Our ‘contact your representative’ site WritetoThem.com. Users input their postcode and are shown everyone who represents them, from local to European level.
      • Our street problem-reporting site FixMyStreet.com. It sends problem reports to the relevant local council, based on the co-ordinates of where the problem was reported.

    We are also working on a new component for building Parliamentary Monitoring Websites on top of, called PopIt. It isn’t quite ready for prime time yet, but if you join the Poplus email list, you can follow progress.

     

    Where can I get these Platforms and Components ?

    They’re all on Github, as is all our code (including a lot that we haven’t made easy to re-install yet). As it’s open source code, you can take them for free.

    If you want to use MapIt, or learn about our future components, please sign up for the Poplus mailing list at the same time – it can be an invaluable place to get support when you have questions. You can also improve the code – sharing your improvements with us is a great way to say thank you. Plus, if you have ideas for other Components that will work well with ours, we’d love to hear about them.

    What next?

    We don’t just build this stuff, we also help people install and run it. Keep in touch and let us know how you’re using our code, and what is or is not working. If you hit any problems, there is always someone who can help.

  5. FixMyStreet’s been redesigned

    FixMyStreet, our site for reporting things like potholes and broken street lights, has had something of a major redesign, kindly supported in part by Kasabi. With the help of Supercool, we have overhauled the look of the site, bringing it up to date and making the most of some lovely maps. And as with any mySociety project, we’d really appreciate your feedback on how we can make it ever more usable.

    The biggest change to the new FixMyStreet is the use of responsive design, where the web site adapts to fit within the environment in which it’s being viewed. The main difference on FixMyStreet, besides the obvious navigation changes, is that in a small screen environment, the reporting process changes to have a full screen map and confirmation step, which we thought would be preferable on small touchscreens and other mobiles. There are some technical details at the end of this post.

    Along with the design, we’ve made a number of other improvements along the way. For example, something that’s been requested for a long time, we now auto-rotate photos on upload, if we can, and we’re storing whatever is provided rather than only a shrunken version. It’s interesting that most photos include correct orientation information, but some clearly do not (e.g. the Blackberry 9800).

    We have many things we’d still like to do, as a couple of items from our github repository show. Firstly, it would be good if the FixMyStreet alert page could have something similar to what we’ve done on Barnet’s planning alerts service, providing a configurable circle for the potential alert area. We also are going to be adding faceted search to the area pages, allowing you to see only reports in a particular category, or within a certain time period.

    Regarding native phone apps – whilst the new design does hopefully work well on mobile phones, we understand that native apps are still useful for a number of reasons (not least, the fact photo upload is still not possible from a mobile web app on an iPhone). We have not had the time to update our apps, but will be doing so in the near future to bring them more in line with the redesign and hopefully improve them generally as well.

    The redesign is not the only news about FixMyStreet today

    As part of our new DIY mySociety project, we are today publishing an easy-to-read guide for people interested in using the FixMyStreet software to run versions of FixMyStreet outside of Britain. We are calling the newly upgraded, more re-usable open source code the FixMyStreet Platform.

    This is the first milestone in a major effort to upgrade the FixMyStreet Platform code to make it easier and more flexible to run in other countries. This effort started last year, and today we are formally encouraging people to join our new mailing list at the new FixMyStreet Platform homepage.

    Coming soon: a major upgrade to FixMyStreet for Councils

    As part of our redesign work, we’ve spoken to a load of different councils about what they might want or need, too. We’re now taking that knowledge, combining it with this redesign, and preparing to relaunch a substantially upgraded FixMyStreet for Councils product. If you’re interested in that, drop us a line.

    Kasabi: Our Data is now in the Datastore

    Finally, we are also now pushing details of reports entered on FixMyStreet to Kasabi’s data store as open linked data; you can find details of this dataset on their site. Let us know if it’s useful to you, or if we can do anything differently to help you.

    Technical details

    For the web developers amongst you – we have a base stylesheet for everyone, and another stylesheet that is only included if your browser width is 48em or above (an em is a unit of measurement dependent on your font size), or if you’re running Internet Explorer 6-8 (as they don’t handle the modern CSS to do this properly, we assume they’ll want the larger styles) using a conditional comment. This second stylesheet has slight differences up to 61em and above 61em. Whilst everything should continue to work without JavaScript, as FixMyStreet has done with its map-based reporting since 2007, where it is enabled this allows us to provide the full screen map you can see at large screen sizes, and the adjusted process you see at smaller resolutions.

    We originally used Modernizr.mq() in our JavaScript, but found that due to the way this works (adding content to the end of the document), this can cause issues with e.g. data() set on other elements, so we switched to detecting which CSS is being applied at the time.

    On a mobile, you can see that the site navigation is at the end of the document, with a skip to navigation link at the top. On a desktop browser, you’ll note that visually the navigation is now at the top. In both cases, the HTML is the same, with the navigation placed after the main content, so that it hopefully loads and appears first. We are using display: table-caption and caption-side: top in the desktop stylesheet in order to rearrange the content visually (as explained by Jeremy Keith), a simple yet powerful technique.

    From a performance point of view, on the front page of the site, we’re e.g. using yepnope (you can get it separately or as part of Modernizr) so that the map JavaScript is downloading in the background whilst you’re there, meaning the subsequent map page is hopefully quicker to load. I’m also adding a second tile server today – not because our current one isn’t coping, it is, but just in case something should happen to our main one – we already have redundancy in our postcode/area server MapIt and our population density service Gaze.

    If you have any technical questions about the design, please do ask in the comments and I’ll do my best to answer.

  6. 5 Years On: Why Understanding Chris Lightfoot Matters Now More Than Ever

    My friend and mySociety’s first developer Chris Lightfoot died five years ago today. He killed himself in his own flat for reasons that we will never really know, but which are doubtless linked to the depression which he’d been fighting for years. He was just 28, but had already achieved so much that The Times ran an obituary of him. He would have laughed mightily about the fact that this is now behind a paywall.

    To mark this occasion I wanted to write something for mySociety staff and volunteers who never knew Chris, and for a wider audience of people who work in places like GDSCode For America or indeed anyone with an interest in politics and governance. What Chris represented is too important to be lost in the grief at his passing.

    The basic fact to understand about Chris was that he was a very specific kind of polymath – one perfectly suited to the internet age. What I mean by this is that he did much more than simply master varying disciplines:  he saw and drew connections between fields. He wouldn’t just master cartographic principles, engage in politics and, as Francis Irving put it, ‘write Perl like other people write English’: he invariably saw the connections and mixed them up in meaningful and often pioneering ways.

    Moreover, this mixing of disciplines was conducted at a furious, restless pace, and knew absolutely no concept of ‘too hard’ – problems were either fundamentally impossible, or ‘trivially soluble’, to use one of his favourite and most gloriously under-stated phrases. Who else would build the technology to break a captcha, just to investigate what American truck rental costs tell us about internal migration in America, for fun?  The answer is trivial.

    That he was a genius is not what I want you to understand. Telling you that someone you never met was smarter than you is not helpful, and doesn’t fulfil my promise to tell you why understanding Chris matters.

    What is fundamentally valuable about Chris’ legacy (besides piles of code that power services still running today) is that his story signals how we all need to change our conception of what it means to be ‘wise enough to rule’. Let me explain.

    Unlike most of us, Chris had the luxury of being able to pick any field of study that interested him, dig up some books and papers, and teach himself a graduate-level understanding in what felt like a few days. It is hard to express quite how fast he could consume and internalise complex new information, and how relentlessly he went at it. To note that he got six A grades at A-level is too puerile a précis, but it is indicative.*

    Again, I am not telling you this to make you feel stupid: what matters is what he chose to do with this gift.  What he chose to do was built an ever-expanding palette of skills from which he could paint as he pleased. And what he chose to paint was a vision of a better, saner world.

    This painting ranged across a huge expanse of topics and disciplines: nuclear engineering, political ideologies, constitutional law, military history, statistics, psephology, economics, security engineering, behavioural psychology, propaganda, intellectual propery law and more. His favourite brushes were Perl and a blog composed of prose so sharp and funny that George Bernard Shaw would not have been displeased by the comparison. I still wish I could write half as well as him.

    What I want to communicate most is this: the disciplines he chose to study form a combined19th, 20th and 21st century curriculum of skills required by modern leaders, both leaders of political organisations and government bureaucracies.  Chris’s life was the invention of a massively expanded, far more up to date version of the traditional Politics, Philosophy and Economics course that this country still uses to educate its elites.

    Some of these disciplines are timeless, like the understanding of ideologies or economics. Some represent vital new issues that emerged in the 20th century, like nuclear energy and world-scale warfare. But mixed in there are wholly new, alien group of skills that the recent SOPA, Wikileaks and ID cards debacles show that modern leaders haven’t got anywhere near to internalising: they include knowledge about security engineering, intellectual property and how new technologies clash with old laws and ideologies. They are skills that nobody used to think were political, but which are now centre stage in a polity that can’t keep up.

    This doesn’t mean Chris would have made a perfect leader: I used to argue with him a lot about how he weighed up the costs and benefits of different issues. But what he fundamentally had right was the understanding that you could no longer run a country properly if the elites don’t understand technology in the same way they grasp economics or ideology or propaganda. His analysis and predictions about what would happens if elites couldn’t learn were savage and depressingly accurate.

    The canon of Chris’s writings and projects embody the idea that what good governance and the good society look like is now inextricably linked to an understanding of the digital. He truly saw how complex and interesting the world was when you understood power as well as networking principles in a way that few have since.

    There is, of course, much more to say about Chris’s life. His blog, built on software that foresaw Posterous, is wonderful, hilarious and utterly readable, so you can learn more yourself. Martin Keegan’s obituary is touching and a much better portrait of how much fun it was to be friends with Chris. I hope to memorialise what he represents to me, if I can. But for now, I’ll sign off with a quote from a blog commentor:

    “Chris was kind enough to take the time to reply to me, an internet nobody whom he didn’t know from a bar of soap, on a fairly complex statistical question once. He took a lot of time and effort in his response, and he made sure I understood it properly. It’s not often you find knowledgeable people willing to take their own time to educate an unknown person. We need more people like him, not less.”

    * For US readers, this is like having a GPA of 4.0, but achieved across twice as many subjects as you actually need to take.
  7. Welcome, Mzalendo – Monitoring Kenya’s MPs and Parliament

    When TheyWorkForYou was built by a group of volunteer activists, many years ago, it was a first-of-a-kind website. It was novel because it imported large amounts of parliamentary data into a database-driven website, and presented it clearly and simply, and didn’t supply newspaper-style partisan editorial.

    These days dozens of such sites exist around the world. But today sees the launch of a rather-special new transparency site: Mzalendo, covering the Parliament of Kenya.

    Mzalendo (which means ‘Patriot’ in Swahili) has been around for a few years too, as a blog and MP data website founded by volunteer activists Conrad and Ory. However, over the last few months mySociety’s team members Paul, Jessica and Edmund, plus the team at Supercool Design have been helping the original volunteers to rebuild the site from the ground up. We think that what’s launched today can stake a claim to being a true ‘second generation’ parliamentary monitoring site, for a few reasons:

    • It is entirely responsively designed, so that it works on the simplest of mobile web browsers from day one.
    • All the lessons we learned from storing political data wrongly have been baked into this site (i.e we can easily cope with people changing names, parties and jobs)
    • Every organisation, position and place in the system is now a proper object in the database. So if you want to see all the politicians who went to Nairobi University, you can.
    • There is lots of clear information on how parliament functions, what MPs and committees do, and so on.
    • It synthesizes some very complex National Taxpayer’s Association data on missing or wasted money into a really clear ‘scorecard‘, turning large sums of money into numbers of teachers.

    The codebase that Mzalendo is based on is free and open source, as always. It is a complete re-write, in a different language and framework from TheyWorkForYou, and we think it represents a great starting point for other projects. Over the next year we will be talking to people interested in using the code to run such sites in their own country. If this sounds like something of interest to you, get in touch.

    Meanwhile, we wish Ory and Conrad the best of luck as the site grows, and we look forward to seeing what the first users demand.

  8. Mobile operators altering (and breaking) web content

    We had a complaint that FixMyStreet maps weren’t displaying on someone’s computer. We hadn’t had any other complaints, and we quickly narrowed it down to the fact that the person was on the internet using a tethered T-Mobile phone.

    T-Mobile (and Orange, and quite possibly others) are injecting JavaScript and altering content served over their networks. Their reason for doing this, according to their websites (T-Mobile, Orange), is to compress images and video sent to your browser, so as to speed up your browsing. Seeing it in action, they also inline some CSS and JavaScript, though not all, and remove comments from external files.

    However, their implementation breaks things. In this particular instance, the T-Mobile JavaScript comment stripper appears to be searching for “/*” and “*/” and removing everything inbetween. This might work in most cases; however in the jQuery library, we find a string containing “*/*”, and later down the file, another string containing “*/*”. T-Mobile remove everything between the things it thinks are comment markers, even though they’re actually contained within strings, causing the jQuery library to be invalid JavaScript and stopping anything using jQuery from running.

    Their decision to inline lots of the CSS also seems a bit odd – sure, on a mobile this might be quicker, but even ignoring tethering nowadays plenty of mobiles have caches too and having the CSS download once and be cached would seem better than adding weight to every page download. But I’m sure they’ve studied their decision there, and it doesn’t make any difference to the actual browsing, as opposed to the comment removal.

    To turn off this feature on your mobile phone or broadband, visit accelerator.t-mobile.co.uk or accelerator.orange.co.uk on your connection and pick the relevant option – if anyone knows of similar on other networks, do leave updates in the comments.

    From a FixMyStreet point of view – whilst FixMyStreet functions just fine without JavaScript, I had made the (perhaps incorrect) decision to put the map inside a <noscript> element, to prevent a flash of map-oddity as the JavaScript map overlaid the non-JS one. However, this meant in this circumstance the map did not work, as JavaScript was enabled, but jQuery was unable to be loaded. I haven’t decided whether to change this behaviour yet; obviously it would help people in this situation as the map would still display and function as it does for all those without JavaScript, but for those with JavaScript it does look a bit jarring as the page loads. Any suggestions on a better approach welcome 🙂

  9. Technical look at the new FixMyStreet maps

    This post explains how various aspects of the new FixMyStreet maps work, including how we supply our own OS StreetView tile server and how the maps work without JavaScript.

    Progressive enhancement

    During our work on FiksGataMi (the Norwegian version of FixMyStreet) with NUUG, we factored out the map code (for the Perlmongers among you, it’s now using Module::Pluggable to pick the required map) as FiksGataMi was going to be using OpenStreetMap, and we had plans to improve our own mapping too. Moving to OpenLayers rather than continuing to use our own slippy map JavaScript dating from 2006 was an obvious decision for FiksGataMi (and then FixMyStreet), but FixMyStreet maps have always been usable without JavaScript, utilising the ancient HTML technology of image maps to provide the same functionality, and we wanted to maintain that level of universality with OpenLayers. Thankfully, this isn’t hard to do – simply outputting the relevant tiles and pins as part of the HTML, allowing latitude/longitude/zoom to be passed as query parameters, and a bit of maths to convert image map tile clicks to the actual latitude/longitude selected. So if you’re on a slow connection, or for whatever reason don’t get the OpenLayers JavaScript in some way, the maps on FixMyStreet should still work fine. I’m not really aware of many people who use OpenLayers that do this (or indeed any JavaScript mapping API), and I hope to encourage more to do so by this example.

    Zooming

    We investigated many different maps, and as I wrote in my previous blog post, we decided upon a combination of OS StreetView and Bing Maps’ OS layer as the best solution for the site. The specific OpenLayers code for this (which you can see in map-bing-ol.js is not complicated (as long as you don’t leave in superfluous commas breaking the site in IE6!) – overriding the getURL function and returning appropriate tile URLs based upon the zoom level. OpenLayers 2.11 (due out soon) will make using Bing tiles even easier, with its own seamless handling of them, as opposed to my slight bodge with regard to attribution (I’m displaying all the relevant copyright statements, rather than just the one for the appropriate location and zoom level which the new OpenLayers will do for you). I also had to tweak bits of the OpenLayers map initialisation so that I could restrict the zoom levels of the reporting map, something which again I believe is made easier in 2.11.

    OpenStreetMap

    Having pluggable maps makes it easy to change them if necessary – and it also means that for those who wish to use it, we can provide an OpenStreetMap version of FixMyStreet. This works by noticing the hostname and overriding the map class being asked for; everything necessary to the map handling is contained within the module, so the rest of the site can just carry on without realising anything is different.

    OS StreetView tile server

    Things started to get a bit tricky when it came to being ready for production. In development, I had been using http://os.openstreetmap.org/ (a service hosted on OpenStreetMap’s development server) as my StreetView tile server, but I did not feel that I could use it for the live site – OpenStreetMap rightly make no reliability claims for it, it has a few rendering issues, and we would probably be having quite a bit of traffic which was not really fair to pass on to the service. I wanted my own version that I had control over, but then had a sinking feeling that I’d have to wait a month for something to process all the OS TIFF files (each one a 5km square) into millions and millions of PNG tiles. But after many diversions and dead ends, and with thanks to a variety of helpful web pages and people (Andrew Larcombe’s guide [dead link removed] to his similar install was helpful), I came up with the following working on-demand set-up, with no pre-seeding necessary, which I’m documenting in case it might be useful to someone else.

    Requests come in to our tile server at tilma.mysociety.org, in standard OSM/Google tile URL format (e.g. http://tilma.mysociety.org/sv/16/32422/21504.png. Apache passes them on to TileCache, which is set up to cache as GoogleDisk (ie. in the same format as the URLs) and to pass on queries as WMS internally to MapServer using this layer:

    [sv]
    type=WMS
    url=path/to/mapserv.fcgi?map=os.map&
    layers=streetview
    tms_type=google
    spherical_mercator=true

    MapServer is set up with a Shapefile (generated by gdaltindex) pointing at the OS source TIFF and TFW files, meaning it can map tile requests to the relevant bits of the TIFF files quickly and return the correct tile (view MapServer’s configuration* – our tileserver is so old, this is still in CVS). The OUTPUTFORMAT section at the top is to make sure the tiles returned are anti-aliased (at one point, I thought I had a choice between waiting for tiles to be prerendered anti-aliased, or going live with working but jaggedy tiles – thankfully I persevered until it all worked 🙂 ).

    Other benefits of OpenLayers

    As you drag the map around, you want the pins to update – the original OpenLayers code I wrote used the Markers layer to display the pins, which has the benefit of being simple, but doesn’t fit in with the more advanced OpenLayers concepts. Once this was switched to a Vector layer, it now has access to the BBOX strategy, which just needs a URL that can take in a bounding box and return the relevant data. I created a subclass of OpenLayers.Format.JSON, so that the server can return data for the left hand text columns, as well as the relevant pins for the map itself.

    Lastly, using OpenLayers made adding KML overlays for wards trivial and made those pages of the site much nicer. The code for displaying an area from MaPit is as follows:

        if ( fixmystreet.area ) {
            var area = new OpenLayers.Layer.Vector("KML", {
                strategies: [ new OpenLayers.Strategy.Fixed() ],
                protocol: new OpenLayers.Protocol.HTTP({
                    url: "/mapit/area/" + fixmystreet.area + ".kml?simplify_tolerance=0.0001",
                    format: new OpenLayers.Format.KML()
                })
            });
            fixmystreet.map.addLayer(area);
            area.events.register('loadend', null, function(a,b,c) {
                var bounds = area.getDataExtent();
                if (bounds) { fixmystreet.map.zoomToExtent( bounds ); }
            });
        }

    Note that also shows a new feature of MaPit – being able to ask for a simplified KML file, which will be smaller and quicker (though of course less accurate) than the full boundary.

     

    *Broken link removed, Nov 2014

  10. FixMyStreet in Norway

    At mySociety we love our site FixMyStreet – it’s the epitome of a web tool that gives simple tangible benefits whilst generating a little accountability at the same time. Reports through the site were up 40% last year, so it’s clear that users quite like it too.

    FixMyStreet has been copied in many different countries, which makes everyone in mySociety very happy, too, even apparently appearing in a slide deck the White House uses to show innovative services. However, it turns out that the cheerfully minimalist, almost wantonly unfashionable user-interface has an unfortunate down side: most people who copy the site look at it, think “That looks easy!” and then cheerfully start coding their own clone.

    Deceptive simplicity

    Alas – the very simplicity that makes the site good hides the fact that making a site like FixMyStreet really work well is actually way harder than it looks. What will you do when a government email inbox fills up? What about when administrative boundaries change, due to an election or restructuring? How do you know you’re not scaring users away with careless wording? All the hard-won lessons from these questions have been baked into the FixMyStreet codebase, and we’re only too keen to talk to people about them.

    We were therefore particularly pleased when the Nowegian Unix User’s Group (NUUG) came to us to ask if we could help improve FixMyStreet to make it easier for them to install. Over the last month mySociety Senior Developer Matthew Somerville has been working hard with Petter Reinholdtsen and Christer Gundersen of NUUG, and here’s what they’ve managed in just a handful of weeks.

    • The launch of a Norwegian FixMyStreet called Fiksgatami, covering nearly every corner of Norway’s 300,000 square kilometers.
    • Problems reported anywhere within Norway will be correctly directed to any of the 400+ responsible municipalities, thanks to Petter and Christer’s amazing data sourcing skills.
    • As a necessary side-effect of developing this, Norway now has a free, public administrative web service gazeteer – http://mapit.nuug.no. If Norway is anything like the UK this will soon become an indispensable service for many other web sites and mobile tools.
    • The standard mapping is now OpenStreetMap, pulled together by the brilliant Norwegian OpenStreetMap community*. We couldn’t take a technological step backward, and so whilst the site uses OpenLayers if you have JavaScript, the map continues to work just fine without as well.
    • The open source FixMyStreet codebase has been upgraded to make it easier to translate into other languages, easier to use different mapping with, and easier to install. These efforts will continue, as we realise this has been one reason why others have made their own versions.
    • All this has been done without forking, so various major upgrades we have planned for the UK version will be exportable later in the year.

    NUUG’s Fiksgatami is the epitome of what makes civic open source at its best so unmatchably good. It was developed incredibly quickly: just a month to create what is effectively a fully fledged, best-of-breed nationwide e-government service – albeit an unofficial one. Thanks to the hard work of the public servants who fix problem reports, it will make small but meaningful improvements to the lives of a lot of people in Norway.  And it has made the free FixMyStreet codebase better and easier for other people to use to help them do the same thing in other countries.

    I know that at mySociety we are all looking forward to working with NUUG again. And I hope that this story inspires others to look at our code, and to work with mySociety to make FixMyStreet a service that can help everyone who would benefit from it.

    * We’ll be rolling out updated mapping (including OSM) and more in the UK, soon.