Unfortunately I haven't extended Lime Survey as such (So contributing directly via svn isn't an option unless its refactored) - I've created a stand alone map class with all the SQL functions I need.
This differs from the "Use mapping service" question type - in that users are not asked to put their location on a map - it is automatically geocoded from their response to a town/city question. (Usually a select box)
I don't know how much of this is useful for you - but in general terms- this is what was done:
- Created table "lime_geo" with the following fields
sid rid lat lng
Survey ID , Response Id, Latitude, Longitude
- For each survey - define what the geo question is for that survey (Usually acity, but sometimes a region - "What town do you live in?") - and the corresponding response field
eg:
define('CITY_RESPONSE_FIELD',"41781X34X1350");
define('CITY_QUESTION_ID','1350');(All surveys had an applicable list of all cities and town imported for the region they were surveying as responses for that question)
- Create an SQL INDEX on the response field to queries are efficient
- Every time the map is loaded- it searches for any responses with lat/lng - then geocodes them based on their response to the geo question (This could be cron scheduled- or run manually. It can also be disabled once the survey is finished )
- The lime geo table is then used to provide a json response for any request (So that different questions can be displayed on the map)
eg: ajax/grampians_map_json.php?question_id=1375
- The json is loaded by javascript/jquery - which is reasonably straight forward , but you can view the source from those links
eg:
www.cecc.com.au/maps/grampians_map.js
The json response also includes the url for the Google Charts pie chart marker
eg:
{"city":"Yarriambiack Shire Council","city_code":"13","question_id":1373,"lat":"-36.253202","lng":"142.402596","chart_url":"http:\/\/chart.googleapis.com\/chart?cht=p&chs=100x100&chd=t:5,13,21,34,15,6&chco=33FF33|88FF88|BBFFBB|FFCC00|FF3300|333333&chf=bg,s,ffffff00|a,s,00000099","num_responses":"94","legend_chart_url":"http:\/\/chart.googleapis.com\/chart?cht=p3&chs=300x50&chd=t:1,1,1,1,1,1&chco=33FF33|88FF88|BBFFBB|FFCC00|FF3300|333333&chl=Excellent|Very good|Good|Fair|Poor|No Answer&chf=bg,s,ffffff00|a,s,000000aa","map_name":"How would you rank the quality of mobile phone coverage in your local government area?"} www.cecc.com.au/ajax/grampians_map_json...._type=mobile_quality
Specific things to my solution
- Local Government Areas (LGA's) - have their location hardcoded - and have an associated KML file - this would not work worldwide
Since every town belongs to an LGA - this allows different levels of clustering - cluster results by town, or cluster by LGA (This could expand to state/country etc)
www.cecc.com.au/grampians_map.php
- The colour code pie chart scales are based on a very specific range of questions - and may not make sense if applied to any question (eg: Do the responses go from Good -> Bad, or Bad -> Good - or neither, 1-5, 1-7 ?)
- Colours are also hardcoded- they'd be better off customisable in the database
eg:
$COLOR_SCALES [5]= array("FF3300","FFCC00","BBFFBB","88FF88","33FF33");
- The jquery dialog- is focused on a specific set of 4 question groups
- There are some hardcoded question names to stop them displaying on the map when they don't make sense.
- Theres a bit of fuzzy logic to look for certain words in surveys and abbreviate them to they fit on the map/graphs