Skip to content

Instantly share code, notes, and snippets.

@espinielli
Last active April 23, 2017 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espinielli/9ea56e041f6847dbe944 to your computer and use it in GitHub Desktop.
Save espinielli/9ea56e041f6847dbe944 to your computer and use it in GitHub Desktop.
D3.js Boetti
license: mit

Boetti's map using D3

ToDo's:

Due to their peculiar bounding boxes (see Jason Davies nice visualization) some countries need special treatment

  • France: split Guyana and map French flag accordingly
  • USA: map the flag separately to Contiguous USA and Alaska (given the scale probably ignoring all off-shore United States territories and possessions will not be visible)
  • Kosovo: cope with its lack of UN code in order to plot the flag.

For these special cases we could:

  1. use a topojson file for the parts we are interested and replot mapping the relevant flag.
    For USA: Alaska and Continental USA.
    For France: Metropolitan France (i.e. includes Corsica) and Guiana
  2. add an entry for Kosovo (special iso code and flag entry)

Inspired by [rveciana]](http://bl.ocks.org/rveciana/)'s block 'Flag map with D3js - SVG'

@@ (BF00 �%nB  �h h�x(@� @���������������������������������������������������������ɿ��������������������������������������~���~�����������������������������������������������������}�������������������������������������������������������������������������������������������������������������������������������������������̳��˨����Y��w=��x7��y7��x7��x7��x8��x7��x8�ÀH�āJ��z>��y9��z9��z9��z:��|=�ЎY��ĩ��ҿ������м��̶��Ŭ�ݴ��Ҙh�ʀB��w6��x6��y7��x7��y7��z:�ƥ����������������������������������������������������������������������������������������������������������������������ί��ȁG��};��}<��};��}=��~=��}=�̕g�ؾ���ʽ��ɽ��ʻ�ֽ���˳��ʹ��ѻ���������������������������������������������ܩ�΄G��}=��}=��}=��@�կ�������������������������������������������������������������������������������������������������������������������³�Ɏ]�ȁF��~B�ʂG�ʇO��|<��};�֞o�������������������������������������������������������������������������������������亘��?��}<��}<��}<��{;�ϗj��������������������������������������������������������������������������������������������������������������������������Ǹ�����ι��Ϭ��ڵ���ɸ����������������������������������������������������������������������������������ŧ�ٝk��};��}<��};��}<��};��|;�̉R�ع������������������������������������������������������������������������������������������������������������������������������������������ҷ�������������������������������������������������������������������������������}>��z:��{:��{:��{:��{:��{:��|=�ˏ]��Ű������������������������������������������������������������������������������������������������������������������������������������������ȵ��������������������������������������������������������������������������п�ٴ��۷��ӣ{�ӣz�׬��ը��џv�׳��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Ȳ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Ը���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������˻�������������������������������������������������������������������������������������������������������������������������������������������������Ĩ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ָ��������������ʵ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ջ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������++�˚���������������������������������������������������������������������������������������������������������������������������������������������������������������������������ı�������������������������������������������������������������Ì�����������������,,�������������������������������������������������������������������������������������������������������������ԩ��⼒���t��Ѩ���������������������������������������������~�Q��x]����������������������������������������������������������JJ��00��rr��**�����ć����������������������������������������������������������������������������������������������������������Ѣv�۩t���>���c������������������������������������������Ƽ�?t@�y�=��ж������������������������������������������������������QQ������������EE���������������������������������������������������������������������������������������������������������֬��ڢl���C�o�^���������������������������������������������a�O�x������������������������������������������������������������bw�}H��*@��2I������))���������������������������������������������������������������������������������������������������������Òg�״������<�{��ܳ������������������������������������������k��h]��F�����������������������������������������������������������zF���i���2P��$#����NN���������������������������������������������������������������������������������������������������������rv.�em��yPI�1���T�M�����������������������������������������rUw�`ls�9z�����������غ������������������������������������������������������6S������{{���������������������������������������������������������������������������������������������������������3�i�&�u�o8�D���,���������������������������������������{gO��]F�dw��#;��������������������������������������������������������������02��X������ѧ������������������������������������������������������������������������������������������������������v������'���x3 �W�����������������������������������������7+$�+� {A�S�w{l��������������������������������������������������������������7R��?>��bb���������������������������������������������������������������������������������������������������������aa��m��K`e��G�_���
���������������������������������������7DH�:'� s"�%CU�px7��������������������������������������������������������������on��jj�Ъ����������������������������������������������������������������������������������������������������������io��t��d����mF�K�x�ƪ��Ƃ���������������������������������]b��(2`�wj�5c=���0���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������e�B�&�R�C���|,�8���(�I�e�7���������������������������������YU��\A���{�Ed.���J���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������i�G�4� �,�}�VYJ�*�|�4�
�q�I���������������������������������a��MF��Ԃ"�Py(�gb�������������������������������������������������������������������������deo�����������������������������������������������������������������������������������������������������i���8��*�Q����,�H�f�9��������������������������������������}K�i\��wg}�V�/�;{S�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������`���STm�:� �9��%�l�|�l�����������������������������������������n�{��vG�BN��/k��4L��û����������������������������������������������\N��th�����������������������������������������������������������������������������������������������������������������������qW�y?�=[G�?��Q�-������������������������������������������Ż�Xvz��y(��es�E��.2����|��������������������������������������x�������}��xo��������������������������������������������������������������������������������������������������������������������������H���QB]�Ekc�w����������������������������������������������1}���zF��}.�1jF�)+q��^��������������������������������������������������������������������������������������������������������������������������������������������������������������������������i���0���lQB��x�������������������������������������]�|�d�a�����I���k���w{u�B]��@]��U_����������������������������������������������������������������������������������������������������������������������������������������������������������������������Ƚ������0���F���������������������������������������]�z�H��F�d��ƕ�I�t�Dn��R7A�+J��B��������ʼ�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������[���0�a�/~��D�J���l�F{M�l��*7&�9E?�Ku6���x���������������������Y�a�����������������l[����������Ƽ���������������������������������������������������������������������������������������������������������������̲���������������������������������������������T�}�-�J� ���=�[�Y�I�Q�T�k����x���������������������������������>�H��������������e{�r^�����������������������������������������������������������������������������������������������������������������������~��������������������������������������������������\�L�,u*����T[����������c��eg��������������ov��������������������������������������������������������������������������������������������������������������������������������������������������������������������������ʿ��������������������������������������T�R�&�N�"�������u���R���)w��8(��8���~��]�1�:e#�>gd�����������������������������UT������������������������������������������������������������������������������������������������������������������������������������������������������������������������������a{z�*}F�&�����������Aj�'^2�%6�'V�t�p�Gz�@n�Xe��������������������������:���:��*:��{���������������������������������������������������������������������������������������������������������������������������������������������������������������������������*^/�2dD�����������SVS�x�z�{�^��\���������������~�����������������)���,��(��0���������������������������������������������������������������������������������������������������̷�z�M�����������������������������������������������������������������<T>�6S+���������
����������Z�3��`�����76��EL��\|`�O���Y���jz��F}��h��+��+��(������������������������������������������������������������������������������������������������������z�O�����������������������������������������������������������������mu��3FR���������%��-$��C5��SL��Bd*�HY6���������UX��G]N�2z��0\��.��1��1��,��,��+������������������������������������������������������������������������������������������������������������������������������������������������������������������������������3<������������������������������������������??g�:Oi�3s��>��)��*��*��*��)��'=��������������������������������������������������������������������������������������������������gZ��UE��UF��UF��UF��UF��RC��������������������������������������������������qy��������������������������rl��s����Lj���r�1DR�!E`� Ks�/��2��.��*��*��'��O`������������������������������������������������������������������������������������������������������������������������������������������������������������������������������R��������������������}��B7�� ��Hqq�����V�3�Q�<�Pw}�;��(��>��8��*��*��/��}��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������vp��bY��ME��pn��������p�����jt��>��K��3��F��0��-��0��BR��|{��������������������������������������������������������������������������������������������������UF��WI��WH��WI��VH��ma������{p������������������������������������������]g��hi����������e}����������qv��������O���K���C���<�Zw�� ���9��[F\�iAK�%,��*��(��1@������������������������������������������������������������������������������������������������������������������������������������������������������������������������������;2��q������Ny��J���d���)8��{���ȳ)������F������8����$Y���M ��I,�1+��*��*��)������������������������������������������������������������������������������������������������������������������������������������������~~����������������������������������77��*w��ff��xcm�t{X�a|x�.:��x�e�Ʈ���3�U�����&����?c��-I��I,�nCG�,+��+��+��,��u|��������������������������������������������������������������������������������������������������rr��������������������������ZZ��~~����������������������������������pp��+��pa���c���^&�W:�)0��S[��pgc���(���P���&�^X|�.4��.3��B5��11��&.��-��$-��(0�������������������������������������������������������������������������������������������������� ����mm������vv����>>����������@@��pp��������������������������������������da������z���^@k�}6?�|5B�|5A�~:>��w�����U�{4C�|5C�|6A�|5B�|6C�z5B�w4@�CU���������������������������������������������������������������������������������������������������������pp������""����������������RR����������������������������������·�����������Ƽ����;"��:��:��:��:��<��=��9��:��:��:��:��:��:��8��Y+���������ʚ��Ц�����������������������������������������������������������������������tv���������b]��
����rr��������DD����������������������������������������������������������mx�����������D��;��<��<��<��;��;��<��<��<��<��<��<��<��;��C��{]�ȥ��–��Ҳ���������������������������������������������������������������������������[]��~��tp�� ����rr����������������������������������u]������������������������������F{������ɨ���V)��9��8��8��8��8��8��8��8��8��8��8��8��8��8��8��6��J��R$��N�Ʒ��������������������������������������������������������������ű��ͻ���tv���������BA����oo������[[�� ��BB����������PP������������������������������������������������K��qJ���d��sQ��e:��j@��j?��e;��j?��j?��j?��j?��j?��j?��j?��j?��j?��j?��j@��j?��h=��pO�����������������������������������������������������������������������������q^��TF��C9��+)��}}����������??��uu����������SS��xx�������������������������������������������vK���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������UU��������������hh��������������ya���n������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������fK��+��rW������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������XX��������������|d��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������OO��qq����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������(0` $��������������������������������������������������u���k���j���j���j���j���g���i���g���g���g���g���h�ş�ɩ��ʫ��ȧ��Ǥ��™w���i���h���j���j���i�Ûz�����������������������������������������������������������������������������������������Ҷ��ÃO��z9��{8��{9��{8�ɂF�̗k�Υ��͞w�Кl�؟o�ءt�ۨ}��Ȯ���������������������ᷕ�ҐY��};��{9��{8�ʆL��ƺ�������������������������������������������������������������������������������������̞y�ȁG�ɁE�ʅK��|=�ψM�ھ��������������������������������������������������������������ۤv��|;��}<��~?�ϓb��;����������������������������������������������������������������������������������������������ʼ�ټ���ʶ�������������������������������������������������������������濠�ԐX��|9��|:��|:��{9�̇O����������������������������������������������������������������������������������������������������������ɹ���������������������������������������������������������Иi�͏[�̉R�͌W�͋T�̋U�ڳ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Ь��������������Ĵ�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������..��}}���������������������������������������������������������������������������������ܸ��̸���ʥ�����������������������������������y�Ģ�������������������������������������������vv��[[��ll����!!���������������������������������������������������������������������������������ة|���X��Z���������������������������������[�V���Y������������������������������������������wz�� �� ��
���̚������������������������������������������������������������������������������֧}���v�a�r���������������������������������{z��jv�����������������������������������������������4r��Fi��#)���ɐ��������������������������������������������������������������������������������Q��sz�B�p��Ƃ�����������������������������z^}�Pc���������������������������������������������������[��� ��!!�ݽ������������������������������������������������������������������������������(���J\K�Qq`�Kǚ�����������������������������dL5�@h�ao����������������������������������������������V7�����88������������������������������������������������������������������������������������aS;�c}k�3�������������������������������-� k?�EZV��������������������������������������������������LM�Ǔ����������������������������������������������������������������������������������#u���sW�^p�*Ĥ�����������������������������&7Y�Pd(�Zj3��Գ���������������������������������������������ֵ����������������������������������������������������������������������������������v�f�)�[�a]E�Fw_�.�5��җ�������������������������X>���v�fw7�������������������������������������������������������������������������������������������������������������������������������������x���3��,���+�k�T�)�����������������������������jT���|H�@}:�������������������������������������������������������������������������������������������������������������������������������������]j{�;� �'�V�[�q����������������������������������pY�M]��/er�������������������������������������������������������������������������������������������������������������������������������������pO6�@cB�F�2��Ȧ�����������������������������q����xC�wdk�=���r����������������������������������������������������������������������������������������������������������������������������������?���]NO�������������������������������������c���c�z�szW�2Q}�_Q����������������������������������������������������������������������������������������������������������������������������������D���_�������������������������������L�|�d�m����Jv��OB`�0m��}�������������������������������������������þ����������������������������������������������������������������������������������������������������������������������>�z�-���R�T�g�M�$j��IWK�\z^���p��������������ֵ��ʟ���������w_����������������������������������������������������������������������������������������������������������������������������������;�>�"���N�����1p���������������������������Ϫ��ɡ���������������������������������������������������������������������������������������������������������������������������������������������7{=�&���z���t���4w��=/��fQ��o�Y�8_=�������������������������yz�����������������������������������������������������������������������������������Ŷ���������������������������������������������BtY�-�}�����Yq��A0�#&>�YZm�]�3�Rv;���������������������3���1��\k���������������������������������������������������������������������������ɯ�������������������������������������������������ct{�4Y/�����MLK��~�����v��]�����hj��n�}���������t���!k��(��-����������������������������������������������������������������������������������������������������������������������������������:LW�����NH��*#v�\Q��Ufh�Xq>�����kk��H^^�5|��/L��=��7��+��-����������������������������������������������������������������������������������þ��ý������������������������������������������VZ����������������������������������.Bb�*a��/��)��*��)��-C��������������������������������������������������������������������������re��`R��aS��aS��^P��������������������������������������y�������������������XN��Rk���r�R�?�2Yc�=��0��6��*��(��Vf����������������������������������������������������������������������������������������������������������������������������������8���������������um��OF��`d��������m�t���B��<��>��0��,��DT������������������������������������������������������������������������������bT��dV��cU��gZ������������������������������������������qt������k����������xz����K���E���8�O��� k��TCk�^>a�*��(��GT����������������������������������������������������������������������������������Ŀ����������������������������������������������;E��d���fo��W���?f��en��ű���T���5���A� h��rLD�mAN�!*��*��'7�������������������������������������������������������������������������� ��mn����������������������ss��������������������������QZ��AO���e���Z8�C9��QX����?���I���8�k`m�/8��K9��=4��#-��!,��:A����������������������������������������������������������������������������XX������((��FF����������kk��������������������������������������o>P��65��66��C*��r��V��66��67��67��68��55��FM���������ȣ��������������������������������������������������������������~|����ZZ�������������������������������������������������������������?��;��;��;��:��:��;��;��;��;��:��N�۾��پ��Ϩ�������������������������������������������������������qr��~��ZW����YY��ii�� ����������������������������������������������d��������O��8��8��8��8��8��8��8��8��8��8��8��A��a8��d=�������������������������������������������������Ϳ����������������UU������II��>>����������ww����������������������������������~U������c�Ƅb�ăa�ńb�Ɉf�Ɉf�Ɉf�Ɉf�Ɉf�Ɉf�Ɉf�džc�ńa���k�������������������������������������������������������������sh���~����������uu��||�������������������������������������������ʾ�ĵ������������������������������������������������������������������������������������������������������������������������������������������������������������������I'��iL����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������jj����������Ż��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������( @ ����������������������������̴����c�ÈV�ĈW�ÈX�e�Ñh�ŏb�Ɛc�ʚq�׼���¯�׼��ϩ��Ɛb�ÈW�ÈV�˦����������������������������������������������������������ո��ɆN�˃G��@�Ԣx��������������������������������������ӽ�ӏW��{8�͊R��¯��������������������������������������������������������������������������������������������������������������è�ψN��}=��|;�Ϗ[������������������������������������������������������������������������������������������������������������������κ��̶��˵�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ӫ�����������������������������������������������������������î��Ѷ����������������������ʶ�����������������������������ٴ��Ƌ���44��ii�����������������������������������������������������ԩ{���i�����������������������������������������������������ͣ���-����22�������������������������������������������������������q�d�s��޻���������������������e|�������������������������������j���"9��ED�����������������������������������������������������6���RkW�}�������������������[[H�4ao����������������������������������+N��}{�����������������������������������������������������<u��ew`�dк�����������������BUc�:]/���������������������������������Ш����������������������������������������������������������;�R�E|Z�[�T�����������������{b���p-�����������������������������������������������������������������������������������������t���4�.�C�r��ۮ������������������xu�Tgp�����������������������������������������������������������������������������������������x�}�HfB�������������������������~�i�Z`k�g_������������������Ŀ������������������������������������������������������������������j���~�������������������l���v�|�Z���GXn�`z�����������������������������������������������������������������������������������������������������������Ÿ�-�y�Z�i�B|x�h|~��������������Χ���������������������������������������������������������������������Ľ��������������������������*���q���L���_[��|���s�����������������������������������������������������������������������������������������������������������;ye�����(>C�ILb�j�R�o�{�������������-h��AQ��������������������������������������������������������������������������������������Zjo�����60h�mo��n�\�����Tg��M���<\��=��0��������������������������������������������������������������������������������������������������������������?Yf�G��+��(��4I��������������������������������������������������������������������������������������~�����������xp��Y^����n�g�x�B��:��-��:L�������������������������������������������������������|���~������������������������������x���{���x���ry����I���D�H���CO��L8��(��ju��������������������������������������������������wv����������������������������������M[��oh��e`q�SU����;���?�dhu�K@��E4��*��bi����������������������������������������������ba��??������ZZ�����������������������������������?8��7)��M��V��9)��7+��6,��GC�˼��ؾ����������������������������������ô������IF��;;��LL��mm�����������������������������������J��:��:��9��:��;��:��@��nG���b�����������������������������������������g`��YX������SS��������������������������������y�̩��Ρ��Π��ש��ت��ש��֨��է��С��ʤ����������������������������������������������������������������������|d������������������������������������������������������������������������������������������������������������������������������Ǿ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������(  ����������������ɑb�͖h�غ��ܽ��������������ʇP�ְ����������������������������������������������������������ݭ��޶��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������̘��ݿ�����������������������������������������������������������9U�˓��������������������������R�~�������������w���������������á������������������������������I�[���������������}���������������������������������������������������������}���iu������������������������������������������������������w���P���l|����������������������������������������������������������`l��fsx�����x���B_������������������������������������������������������m���B��-A����������������������������������������������z���pq����P�U\�:5��������������������������ZX��rr�������������������L1��P��D#��I7�š�����������������������������������������������ô��ô��Ƿ��ó��ȼ�������������������������������������������������������������������������
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<div id="map"></div>
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="//d3js.org/d3.geo.projection.v0.min.js" charset="utf-8"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src="//d3js.org/queue.v1.min.js"></script>
<style>
body {
background: #fcfcfa;
}
.stroke {
fill: none;
stroke: #000;
stroke-width: 3px;
}
.fill {
fill: #d6fefa;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #000;
}
.image.country {
stroke: #000;
stroke-width: 0.5px;
}
.boundary {
fill: none;
stroke: #000;
stroke-width: 0.5px;
}
</style>
<script>
var wflags = "https://gist.githubusercontent.com/espinielli/5107491/raw/world-country-flags.tsv",
w110 = "https://gist.githubusercontent.com/mbostock/4090846/raw/world-110m.json",
wnames = "https://gist.githubusercontent.com/mbostock/4090846/raw/world-country-names.tsv";
var width = 1200,
height = 700;
//
var projection = d3.geo.robinson()
.scale(180)
.translate([width / 2, height / 2])
.precision(.1);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var defs = svg.append("defs");
defs.append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
var q = queue()
.defer(d3.json, w110)
.defer(d3.tsv, wnames)
.defer(d3.tsv, wflags)
.await(ready);
function ready(error, world, names, flags) {
if (error) {
alert('error: ' + error);
return;
}
flags.forEach(function (d) { d.id = +d.id;});
flags.sort(function(a,b) {
return +a.id < +b.id ? -1 : +a.id > +b.id ? +1 : 0;
});
var countries = topojson.feature(world, world.objects.countries).features,
land = topojson.feature(world, world.objects.land);
countries = countries.filter(function(d) {
return names.some(function(n) {
if (d.id == n.id) {
return d.name = n.name;
}
});
});
countries = countries.filter(function(d) {
return flags.some(function(n) {
if (d.id == n.id) {
var bounds = path.bounds(d);
if (bounds[0][0] < 0) bounds[0][0] = 0;
if (bounds[1][0] > width) bounds[1][0] = width;
if (bounds[0][1] < 0) bounds[0][1] = 0;
if (bounds[1][1] < 0) bounds[1][1] = height;
d.bounds = bounds;
return d.url = n.url;
}
});
});
defs.selectAll("mask")
.data(countries)
.enter()
.append("clipPath")
.attr("class", "mask")
.attr("id", function(d) {return "iso-" + d.id})
.append("path")
.attr("d", path);
svg.selectAll("country")
.data(countries)
.enter()
.insert("image", ".graticule")
.attr("class", "country")
.attr("xlink:href", function (d){return d.url;})
.attr("x", function (d) {return d.bounds[0][0];})
.attr("y", function (d) {return d.bounds[0][1];})
.attr("width", function (d) {return d.bounds[1][0] - d.bounds[0][0];})
.attr("height", function (d) {return d.bounds[1][1] - d.bounds[0][1];})
.attr("preserveAspectRatio", "none")
.attr("clip-path", function(d) {
return "url(#iso-" + d.id + ")";
});
// interior boundaries
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("clip-path", "url(#sphere)")
.attr("d", path);
// exterior boundaries
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a === b}))
.attr("d", path)
.attr("class", "boundary");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment