7. Separation of Concerns: Getting the countries to work!

Last time I found out that the globe we were using for this project had its data set up in a way that was hard for me to use. That's sometimes how it is, we can't expect someone else to do all the hard work, or for everything to be easy!



Let's have a look at this, just for curiosity. This place with the colourful buildings is in the country of Cuba, and here's its data  and numbers which tell the map how to draw the outline of the island.

{
                "type": "Polygon",
                "arcs": [
                    [249]
                ],
                "id": "192",
                "properties": {
                    "name": "Cuba"
                }
}
...
[63448, 67449],[109, -510],[137, -135],[47, -207],[190, -249],[16, -243],[-27, -197],[35, -199],[80, -165],[37, -194],[41, -145]



Arrgh! I just can't get it to work. I've given up and I'm going to try a new direction. What I really need is something to show for each country, some music, a video, some information like how many people live there, what they are famous for, and so on.

This is the important stuff, there will be a lot of it, and I need to put this information somewhere. I could try to combine it with this map information that I don't really like, or I could make it separate. If it's separate that's better, because if I decide to use a different map in the future, I don't need to change everything else as well.

This is very important in computer science, it's called 'separation of concerns', and means we try not to start the whole project again every time one bit of it needs to change.

So what I'm going to do is write a whole new load of countries with their information all nicely arranged like this:

{
    "name"          : "Cuba",
    "alpha-3"       : "CUB",
    "id"            : "192",
    "music"         : "Salsa",
    "famous-person" : "Fidel Castro",
    "product"       : "Cigars"
    etc...
}

Then I can link them with the map, because they both have an 'id' of 192, like in the green bit.

This was pretty easy, take a look at the new version of the globe:



One country turns red, AND if you click F12 the console will tell you the name of that country as well. It's starting to take shape, but there's a massive problem, as I've just realised...

Comments