How To Use Blazing Charts Pluging To Customize Google Maps

Blazing Charts plugin for WordPress can be used for many things other than charts. In this example, I customize Google Maps using its API to show how Yemen is divided between various factions:


The above map is added to the post by using the following shortcode:

[BlazingChart source="google-maps-api-test"]

As you see, none of the charting libraries are loaded. So this shortcode only inserts the scripts saved in a Chart Snippet post, with a slug of “google-maps-api-test”.

In that snippet the following code, draws the map and all the polygons, icons, and legend on top of that:

 

<div id="map-canvas" style="width:100%; height: 400px;"></div>
<div id="map-legend" style="background: white; padding: 10px;"></div>

<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

<script type="text/javascript">
window.onload = function () {
  // map options
  var options = {
    center: {
      lat: 15.829214,
      lng: 47.618805
    },
    zoom: 7,
    disableDefaultUI: true,
    scrollwheel: true,
    draggable: true,
    mapTypeId: google.maps.MapTypeId.HYBRID,
    maxZoom: 11,
    minZoom: 6,
    zoomControlOptions: {
      position: google.maps.ControlPosition.BOTTOM_RIGHT,
      style: google.maps.ZoomControlStyle.DEFAULT
    },
    panControlOptions: {
      position: google.maps.ControlPosition.LEFT_BOTTOM
    }
  },
  element = document.getElementById('map-canvas'),
  // map
  map = new google.maps.Map(element, options);

var icons = [
		[		// Group 0
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/fighterjet_green.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/ship_green.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/soldier_green.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/tank_green.png'
		],
		[	// Group 1
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/fighterjet_red.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/ship_red.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/soldier_red.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/tank_red.png'
		],
		[	// Group 2
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/fighterjet.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/ship.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/soldier.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/tank.png'
		],
		[	// Group 3
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/fighterjet_orange.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/ship_orange.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/soldier_orange.png',
			'//blazingspider.com/wp-demo/wp-content/uploads/mapicons/tank_orange.png'
		]
	];

// legend
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(  document.getElementById('map-legend'));
var legend = document.getElementById('map-legend');
var div = document.createElement('div');
div.innerHTML = '<img src="' + icons[0][2] + '"> ' + 'Houthis';
legend.appendChild(div);
div = document.createElement('div');
div.innerHTML = '<img src="' + icons[1][2] + '"> ' + 'Former President';
legend.appendChild(div);
div = document.createElement('div');
div.innerHTML = '<img src="' + icons[2][2] + '"> ' + 'Alqaeda';
legend.appendChild(div);

var polygons = [
	[0, [
		{lat: 17.240497931237368, lng: 46.2799072265625},
		{lat: 16.70986293320658, lng: 46.2139892578125},
		{lat: 15.929638243169176, lng: 45.7745361328125},
		{lat: 15.44309082346371, lng: 45.37353515625},
		{lat: 14.711134758870658, lng: 45.5108642578125},
		{lat: 14.716447783648709, lng: 46.3787841796875},
		{lat: 14.104612543423306, lng: 46.3787841796875},
		{lat: 14.131248778377437, lng: 44.6868896484375},
		{lat: 14.022020463599421, lng: 44.53582763671875},
		{lat: 13.573911442504556, lng: 44.4012451171875},
		{lat: 13.435038009690732, lng: 44.30511474609375},
		{lat: 13.402978840988796, lng: 43.93707275390625},
		{lat: 13.52584902223084, lng: 43.81622314453125},
		{lat: 12.881424937623558, lng: 43.4619140625},
		{lat: 13.223903512667825, lng: 43.253173828125},
		{lat: 13.645986814875332, lng: 43.2806396484375},
		{lat: 14.077973196671598, lng: 43.13232421875},
		{lat: 14.599531422729912, lng: 43.00048828125},
		{lat: 15.141066893509299, lng: 42.8302001953125},
		{lat: 15.728813770533964, lng: 42.6983642578125},
		{lat: 16.388661170759384, lng: 42.7862548828125},
		{lat: 16.662506225634584, lng: 43.17626953125},
		{lat: 17.23000493050636, lng: 43.154296875},
		{lat: 17.555009243667573, lng: 43.35205078125},
		{lat: 17.382094947877505, lng: 43.6761474609375},
		{lat: 17.4187874493387, lng: 44.1595458984375},
		{lat: 17.444991866993263, lng: 44.71435546875},
		{lat: 17.429269667952468, lng: 45.263671875},
		{lat: 17.324420443290116, lng: 45.4229736328125},
		{lat: 17.23525150539053, lng: 46.263427734375}
	]],

	[1, [
		{lat: 17.240497931237368, lng: 46.2799072265625},
		{lat: 16.70986293320658, lng: 46.2139892578125},
		{lat: 15.929638243169176, lng: 45.7745361328125},
		{lat: 15.44309082346371, lng: 45.37353515625},
		{lat: 14.711134758870658, lng: 45.5108642578125},
		{lat: 14.716447783648709, lng: 46.3787841796875},
		{lat: 14.104612543423306, lng: 46.3787841796875},
		{lat: 14.131248778377437, lng: 44.6868896484375},
		{lat: 14.022020463599421, lng: 44.53582763671875},
		{lat: 13.573911442504556, lng: 44.4012451171875},
		{lat: 13.435038009690732, lng: 44.30511474609375},
		{lat: 13.402978840988796, lng: 43.93707275390625},
		{lat: 13.52584902223084, lng: 43.81622314453125},
		{lat: 12.881424937623558, lng: 43.4619140625},
		{lat: 12.819835795356386, lng: 43.5003662109375},
		{lat: 12.683214911818654, lng: 43.466033935546875},
		{lat: 12.740818976502307, lng: 43.589630126953125},
		{lat: 12.637658279835078, lng: 43.90960693359375},
		{lat: 12.597454504832017, lng: 44.0386962890625},
		{lat: 12.637658279835078, lng: 44.300994873046875},
		{lat: 12.75153456902064, lng: 44.493255615234375},
		{lat: 12.815818588006746, lng: 44.630584716796875},
		{lat: 12.760910340467493, lng: 44.732208251953125},
		{lat: 12.760910340467493, lng: 45.034332275390625},
		{lat: 12.987162237749496, lng: 45.12908935546875},
		{lat: 13.064763536135816, lng: 45.388641357421875},
		{lat: 13.330830095126228, lng: 45.6427001953125},
		{lat: 13.410994034321702, lng: 46.1810302734375},
		{lat: 13.43236657581376, lng: 46.73583984375},
		{lat: 13.678013256725489, lng: 47.43896484375},
		{lat: 14.083301314706791, lng: 48.021240234375},
		{lat: 14.083301314706791, lng: 48.603515625},
		{lat: 14.626108798876851, lng: 48.394775390625},
		{lat: 14.955399325942619, lng: 48.515625},
		{lat: 15.453680224345833, lng: 49.735107421875},
		{lat: 15.42191039994707, lng: 50.086669921875},
		{lat: 15.008463695004872, lng: 50.394287109375},
		{lat: 15.178180945596376, lng: 51.075439453125},
		{lat: 15.665354182093274, lng: 52.22900390625},
		{lat: 16.29905101458183, lng: 52.239990234375},
		{lat: 16.70986293320658, lng: 53.10791015625},
		{lat: 18.999802829053262, lng: 52.03125},
		{lat: 18.80231812168813, lng: 50.943603515625},
		{lat: 18.6670631919266, lng: 49.5263671875},
		{lat: 18.239785970838884, lng: 49.658203125},
		{lat: 17.151288449816732, lng: 50.020751953125},
		{lat: 16.688816956180833, lng: 49.85595703125},
		{lat: 16.246319993438693, lng: 49.306640625},
		{lat: 15.855673509998681, lng: 47.021484375},
		{lat: 16.214674588248556, lng: 47.13134765625},
		{lat: 16.941214960202657, lng: 47.197265625},
		{lat: 16.97274101999902, lng: 47.021484375},
		{lat: 17.29819876772391, lng: 46.768798828125},
		{lat: 17.240497931237368, lng: 46.2799072265625}
	]],

	[2, [
		{lat: 14.083301314706791, lng: 48.603515625},
		{lat: 14.626108798876851, lng: 48.394775390625},
		{lat: 14.955399325942619, lng: 48.515625},
		{lat: 15.453680224345833, lng: 49.735107421875},
		{lat: 15.42191039994707, lng: 50.086669921875},
		{lat: 15.008463695004872, lng: 50.394287109375},
		{lat: 14.820025850795036, lng: 50.05096435546875},
		{lat: 14.764259178591587, lng: 49.69390869140625},
		{lat: 14.498508149446229, lng: 49.06494140625},
		{lat: 14.155218724792237, lng: 48.81500244140625},
		{lat: 14.083301314706791, lng: 48.603515625}
	]],

	[2, [
		{lat: 18.6670631919266, lng: 49.5263671875},
		{lat: 18.59939520219874, lng: 49.130859375},
		{lat: 18.18238775108558, lng: 48.2080078125},
		{lat: 17.429269667952468, lng: 47.581787109375},
		{lat: 17.104042525557904, lng: 47.4664306640625},
		{lat: 16.941214960202657, lng: 47.197265625},
		{lat: 16.214674588248556, lng: 47.13134765625},
		{lat: 15.855673509998681, lng: 47.021484375},
		{lat: 16.246319993438693, lng: 49.306640625},
		{lat: 16.688816956180833, lng: 49.85595703125},
		{lat: 17.151288449816732, lng: 50.020751953125},
		{lat: 18.239785970838884, lng: 49.658203125},
		{lat: 18.6670631919266, lng: 49.5263671875}
	]],

	[2, [
		{lat: 14.213801273022412, lng: 47.26318359375},
		{lat: 14.243086862716888, lng: 46.9775390625},
		{lat: 14.112603740893713, lng: 46.8182373046875},
		{lat: 14.080637271223901, lng: 46.72760009765625},
		{lat: 14.00336651694593, lng: 46.7138671875},
		{lat: 14.046001880594353, lng: 46.94732666015625},
		{lat: 14.093957177836236, lng: 47.1368408203125},
		{lat: 14.125921780589302, lng: 47.2686767578125},
		{lat: 14.213801273022412, lng: 47.26318359375}
	]]
	];
var factions = [
	{
		strokeColor: '#00FF00',
		strokeOpacity: 0.5,
		strokeWeight: 2,
		fillColor: '#00FF00',
		fillOpacity: 0.15
	},
	{
		strokeColor: '#FF0000',
		strokeOpacity: 0.5,
		strokeWeight: 2,
		fillColor: '#FF0000',
		fillOpacity: 0.15
	},
	{
		strokeColor: '#555555',
		strokeOpacity: 0.5,
		strokeWeight: 2,
		fillColor: '#555555',
		fillOpacity: 0.45
	}
	];
	// Construct the polygon.
	for (i = 0, len = polygons.length; i < len; i++) {
		var bermudaTriangle = new google.maps.Polygon({
			paths: polygons[i][1],
			strokeColor: factions[polygons[i][0]].strokeColor,
			strokeOpacity: factions[polygons[i][0]].strokeOpacity,
			strokeWeight: factions[polygons[i][0]].strokeWeight,
			fillColor: factions[polygons[i][0]].fillColor,
			fillOpacity: factions[polygons[i][0]].fillOpacity
		});
		bermudaTriangle.setMap(map);
	}
var marks = [
	{
		group: 1,
		type:  2,
		position: {
			lat: 16.794023610508034,
			lng: 50.504150390625
        },
    },
	{
		group: 1,
		type:  2,
		position: {
			lat: 14.849231237914223,
			lng: 47.779541015625
        },
    },
	{
		group: 1,
		type:  2,
		position: {
			lat: 15.69708644541173,
			lng: 46.439208984375
        },
    },
	{
		group: 1,
		type:  2,
		position: {
			lat: 15.114552871944102,
			lng: 45.736083984375
        },
    },
	{
		group: 1,
		type:  2,
		position: {
			lat: 13.81674404684894,
			lng: 45.560302734375
        },
    },
	{
		group: 2,
		type:  2,
		position: {
			lat: 14.902321826141808,
			lng: 49.130859375
        },
    },
	{
		group: 2,
		type:  2,
		position: {
			lat: 17.26672782352052,
			lng: 48.702392578125
        },
    },
	{
		group: 2,
		type:  2,
		position: {
			lat: 17.340151652399435,
			lng: 48.043212890625
        },
    },
	{
		group: 2,
		type:  2,
		position: {
			lat: 15.633616989544775,
			lng: 51.21826171875
        },
    },
	{
		group: 2,
		type:  2,
		position: {
			lat: 14.189837515179644,
			lng: 47.04620361328125
        },
    },
	{
		group: 0,
		type:  2,
		position: {
			lat: 17.18277905643184,
			lng: 44.725341796875
        },
    },
	{
		group: 0,
		type:  2,
		position: {
			lat: 16.99375545289456,
			lng: 43.9892578125
        },
    },
	{
		group: 0,
		type:  2,
		position: {
			lat: 15.358356179450597,
			lng: 43.2421875
        },
    },
	{
		group: 0,
		type:  2,
		position: {
			lat: 14.67925389520471,
			lng: 43.143310546875
        },
    },
	{
		group: 1,
		type:  3,
		position: {
			lat: 16.872890378907783,
			lng: 46.702880859375
        },
    },
	{
		group: 1,
		type:  3,
		position: {
			lat: 15.458974721921685,
			lng: 47.61474609375
        },
    },
	{
		group: 1,
		type:  3,
		position: {
			lat: 13.838079936422474,
			lng: 46.3018798828125
        },
    },
	{
		group: 0,
		type:  3,
		position: {
			lat: 16.899171994430837,
			lng: 45.538330078125
        },
    },
	{
		group: 0,
		type:  3,
		position: {
			lat: 15.14636929963884,
			lng: 44.4122314453125
        },
    },
	{
		group: 0,
		type:  3,
		position: {
			lat: 14.43468021529728,
			lng: 43.494873046875
        },
    },
	];

	// Construct the polygon.
	for (i = 0, len = marks.length; i < len; i++) {
        var opts = {
          position: marks[i].position,
          draggable: false,
          map: map,
          icon: icons[marks[i].group][marks[i].type]
        };
		new google.maps.Marker(opts);
	}

}
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.