{"id":2809,"date":"2022-12-12T08:56:00","date_gmt":"2022-12-12T08:56:00","guid":{"rendered":"https:\/\/mindfusion.eu\/blog\/?p=2809"},"modified":"2022-12-12T10:36:38","modified_gmt":"2022-12-12T10:36:38","slug":"fifa-championship-map","status":"publish","type":"post","link":"https:\/\/mindfusion.dev\/blog\/fifa-championship-map\/","title":{"rendered":"An Interactive Map with All FIFA World Cup Hosts and Winners"},"content":{"rendered":"<p>In this article we are looking at the steps you need to make to build this beautiful, interactive map:<\/p>\n<p><a href=\"https:\/\/mindfusion.dev\/javascript-demo.html?sample=FIFA\" title=\"FIFA World Map\"><img decoding=\"async\" src=\"https:\/\/mindfusion.dev\/samples\/javascript\/mapping\/fifa_map.png\" title=\"FIFA World Championship Map\"><\/a><\/p>\n<p>The map has several layers and markers in the cities that hosted the football world cup tournament. Optionally, users can show info labels that describe the tournament year and the winner.<br \/>\n<!--more--><br \/>\n<strong>I. General Setup<\/strong><\/p>\n<p>In order to use MindFusion mapping library for JavaScript, we need to reference its script files. We need the following files:<\/p>\n<pre>&lt;script src=\"Scripts\/drawing.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;script src=\"Scripts\/controls.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;script src=\"Scripts\/common.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;script src=\"Scripts\/common-collections.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;script src=\"Scripts\/mapping.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n<\/pre>\n<p>We add them at the end of our web page, right before the closing BODY tag. We also need to add a DIV element that represents the map: the mapping library will use it to render itself into it. It is important that we give the DIV element an id:<\/p>\n<pre>&lt;div id=\"content\" style=\"top: 5px; bottom: 24px;\"&gt;\n\t&lt;div style=\"position: absolute; width: 100%; height: 100%;\"&gt;\n\t\t&lt;div id=\"mapView\" style=\"height: 100%; width: 100%;\"&gt;\n\t\t&lt;\/div&gt;\n\t&lt;\/div&gt;\n&lt;\/div&gt;\n<\/pre>\n<p><strong>II. Creating the Map<\/strong><\/p>\n<p>We create the map by using the DIV element we&#8217;ve initialzed in the web page. The map is represented by a <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Mapping_MapView.htm\" title=\"MindFusion Mapping for JavaScript: MapView\">MapView<\/a> object. The decorations and different maps are layers to the  <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?The_MapView_Control.htm\" title=\"MindFusion Mapping for JavaScript: MapView\">MapView<\/a> .The map loads images as tiles provided by a TMS (tile map service) server. We use for the sample <a href=\"http:\/\/maps.stamen.com\" title=\"Stamen maps\">Stamen maps<\/a>, but you can use any other.<\/p>\n<pre>var view = new m.MapView(document.getElementById(\"mapView\"));\n\/\/ add a map layer\nvar l = new m.MapLayer(\"Map\");\nl.urlTemplate = \"https:\/\/stamen-tiles.a.ssl.fastly.net\/terrain\/{z}\/{x}\/{y}.jpg\";\nl.attribution = 'Map tiles by &lt;a href=\"http:\/\/stamen.com\"&gt;Stamen Design&lt;\/a&gt;, under &lt;a href=\"http:\/\/creativecommons.org\/licenses\/by\/3.0\"&gt;CC BY 3.0&lt;\/a&gt;. Data by &lt;a href=\"http:\/\/openstreetmap.org\"&gt;OpenStreetMap&lt;\/a&gt;, under &lt;a href=\"http:\/\/www.openstreetmap.org\/copyright\"&gt;ODbL&lt;\/a&gt;.';\nview.layers.add(l);\n<\/pre>\n<p>The MapView control supports themes, which mostly differ in the color of the zoom control and the location themes. In order to use a theme, you need to set the <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?P_MindFusion_Common_Control_theme_0.htm\" title=\"MindFusion Mapping for JavaScript: theme\">theme<\/a> property of the class to the name of the theme:<\/p>\n<pre>view.theme = \"standard\";<\/pre>\n<p>The library includes a list of predefined themes, which you need to reference as CSS files first. You can use them as a base to create your own themes.<\/p>\n<p><strong>II. Location Pins<\/strong><\/p>\n<p>The layer with map pins that mark the locations of world cup tournaments is an instance of the <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Mapping_DecorationLayer_Members.htm\" title=\"MindFusion Mapping for JavaScript: DecorationLayer\">DecorationLayer<\/a> class. We create <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Mapping_Marker_Members.htm\" title=\"MindFusion Mapping for JavaScript: Marker\">Marker<\/a> objects and add it to the <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?P_MindFusion_Mapping_MapView_decorations_0.htm\" title=\"MindFusion Mapping for JavaScript: decorations\">decorations<\/a> list of the layer. The locations are <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Mapping_LatLong_Members.htm\" title=\"MindFusion Mapping for JavaScript: LatLong\">LatLong<\/a> instances, that specify the latitude and longitude of each location. We keep them in JavaScript object, together with the city name, the year and who the winner was:<\/p>\n<pre>var worldCupLocations = [\n\t { location: new m.LatLong(47.751076, -120.740135), city: \"Washington\", year: 2026, winner: \"unknown\" },\n\t { location: new m.LatLong(45.424721, -75.695000), city: \"Ottawa\", year: 2026, winner: \"unknown\" },\n\t { location: new m.LatLong(19.432608, -99.133209), city: \"Mexico City\", year: 2026, winner: \"unknown\" },\n\t { location: new m.LatLong(25.285446, 51.531040), city: \"Doha\", year: 2022, winner: \"unknown\" },\n...........................\n...........................\n}];<\/pre>\n<p>We create the markers in a foreach loop:<\/p>\n<pre>\/\/ create some markers with default css styling\nworldCupLocations.forEach(\n\tfunction (tournamentHost){\n\t\tthis.decorations.add(new m.Marker(tournamentHost.location));\n\t}, pins);\n<\/pre>\n<p>We also make the later visible and add it to the <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?P_MindFusion_Mapping_MapView_layers_0.htm\" title=\"MindFusion Mapping for JavaScript: layers\">layers<\/a> collection of the <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Mapping_MapView_Members.htm\" title=\"MindFusion Mapping for JavaScript: MapView\">MapView<\/a><\/p>\n<pre>\/\/ add a decoration layer for world cup images\nvar markers = new m.DecorationLayer(\"World Cup Markers\");\nmarkers.visible = true;\nview.layers.add(markers);\n<\/pre>\n<p>When you create any type of layer, you can specify its label in the constructor. The label appears as a map legend. Here is how the map looks with the pins:<br \/>\n<img decoding=\"async\" src=\"https:\/\/mindfusion.dev\/samples\/javascript\/mapping\/map_pins.png\" title=\"FIFA World Championship Map - Location Pins\"><br \/>\n<strong>III. The Captions<\/strong><br \/>\nFor the captions we need a new <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Mapping_DecorationLayer_Members.htm\" title=\"MindFusion Mapping for JavaScript: DecorationLayer\">DecorationLayer<\/a> It will hold <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Mapping_Bubble_Members.htm\" title=\"MindFusion Mapping for JavaScript: Bubble\">Bubble<\/a> instances, whose <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?P_MindFusion_Mapping_Decoration_text_0.htm\" title=\"MindFusion Mapping for JavaScript: text\">text<\/a> property will render the text. The <a href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?P_MindFusion_Mapping_Decoration_text_0.htm\" title=\"MindFusion Mapping for JavaScript: text\">text<\/a> property supports styled text and we can use HTML formatting tags to make our bubble beautiful.<\/p>\n<pre>var bubble = new m.Bubble(tournamentHost.location);\nbubble.text = \"&gt;div align=\"\\\"center\\\"\"&lt;&gt;strong&lt;Location:&gt;\/strong&lt; \"  + tournamentHost.city + \t\t\"\n&gt;strong&lt;Year:&gt;\/strong&lt; \"+ tournamentHost.year + \"\n&gt;strong&lt;Winner:&gt;\/strong&lt; \" + tournamentHost.winner + \"&gt;\/div&lt;\";\nbubbles.decorations.add(bubble);\n<\/pre>\n<p>We use the array with data to take the right info for each bubble. Be default this layer is also not visible but users can show it from the map legend.<\/p>\n<p>And that was the last feature we had to add to our web application. You can download the sample together with all libraries used from the following link:<\/p>\n<p align=\"center\"><a href=\"https:\/\/mindfusion.dev\/samples\/javascript\/mapping\/FIFA_Map.zip\" title=\"FIFA World Championship Map\">FIFA World Championship Map<\/a><\/p>\n<p>Technical support is available on <a href=\"https:\/\/mindfusion.dev\/Forum\/YaBB.pl\" title=\"MindFusion Discussion Board\">MindFusion forums<\/a> at the <a href=\"https:\/\/mindfusion.dev\/HelpDesk\/index.php?pid=login\" title=\"MindFusion HelpDesk\">Help Desk<\/a> or per email support@mindfusion.dev.<\/p>\n<p><i>About Mapping for JavaScript:<\/i> The library enables any type of web application to render an interactive map through its preferred Tiled Map Service. A special property allows the developer to credit the map service, if necessary. The library boasts a layer and a zoom control. Multiple layers are supported, which can hold pins, decorations or info bubbles. The labels support HTML formatted text. The various events allow you to respond to user actions in a way that&#8217;s most suitable to your application. Learn more about Mapping for JavaScript at <a href=\"https:\/\/mindfusion.dev\/javascript-map.html\" title=\"Mapping for JavaScript\">https:\/\/mindfusion.dev\/javascript-map.html<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we are looking at the steps you need to make to build this beautiful, interactive map: The map has several layers and markers in the cities that hosted the football world cup tournament. Optionally, users can show &hellip; <a href=\"https:\/\/mindfusion.dev\/blog\/fifa-championship-map\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[513,73],"tags":[],"class_list":["post-2809","post","type-post","status-publish","format-standard","hentry","category-javascript","category-mapping"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3RlKs-Jj","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/comments?post=2809"}],"version-history":[{"count":6,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2809\/revisions"}],"predecessor-version":[{"id":2817,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2809\/revisions\/2817"}],"wp:attachment":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/media?parent=2809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/categories?post=2809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/tags?post=2809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}