0

I need to store one and possibly more values for each and every country so that I can populate an interactive SVG world map. This data will be updated often by hand by one of the content moderators. So it should be easy to maintain by someone with basic drupal content editing knowledge.

So far I have tried:

  • My initial work had me use a Field Collection, in which I had a dropdown field with all the countries, and another dropdown to select which data point to use for that specific country. This works, but gets extremely memory intensive as the country goes up. It becomes exceptionally difficult to find a country as well since they are not in alphabetical order. I attempted to create each Field collection item prefilled for each country upon creating the node create form. but I would constantly run out of execution time, with it taking more then 4 minutes to get to 200 countries, and getting exponentially slower as the country count went up. Never managing to get to 250.

  • I then tried to use TableField, and import the data from a CSV, with one column for the iso2 code, one for the name, and one with the numerical value for the value on the chart. This was okay, but nearly always crash when trying to import an updated version of the csv. It also was difficult to ensure the integrity of the country codes and names, since anyone could easily make a inadvertant change when modify data. This would then break either the map, or the translation of the names.

So my question is, how can I go about structuring a content type, so that I can list all the countries and set a value for them which I can choose from a select list, that allows me to view the data, sorted by country, and doesn't bring the browser to a standstill?

Note: I'm using Ammaps to display the data on the front.

1

I did something similar sometime ago.
My svg had a path per country with each path being identified by a unique id (namely the country name camelcased). These were stored directly in the template.
I created a taxonomy with all the country ids, and a content type for the user-contributed country data, with a reference to the country-ids taxonomy.
After that I used EntityFieldQuery to get the list of country-ids with published data, so as to display them highlighted in the map.
Then on click of a country I'd retreive the country data via an AJAX request and display it besides the map using jquery.

Beyond my original implementation you could probably load all data via EntityFieldQuery and then just handle it via javascript without further requests.

Does that make sense to you ?

  • Makes some sense :P Did you create one node per country, and tag it from the country taxonomy? With the data for that country in a field in the node? – Mark Cameron Mar 4 '15 at 14:00
  • That's right. I had a content type allowing contributors to enter the data relevant to a country, a choose the country concerned from the taxonomy. Not all conuntries had data. – rtome Mar 4 '15 at 14:26
  • And the svg path data for a country was in the template itself since that doesn't change. – rtome Mar 4 '15 at 14:26
  • Okay I see, still trying to find a way of having it in one node since there will be multiple maps – Mark Cameron Mar 4 '15 at 15:12
  • Just define some sort of map category taxonomy and add it to your country data content type and to the EntityFieldQuery. – rtome Mar 4 '15 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.