states/gd/map_data.php

Unless stated otherwise, code available for viewing through this tool is dedicated to the public domain. If you have any questions, drop me a line.

<?php

require('../../../wp-config.php');

// Query fetches each unique code existing in the polygons table,
// and also the extents of the geometry assigned to that code.

$query = 'SELECT code, 
min(latitude_min) as latitude_min,
max(latitude_max) as latitude_max,
min(longitude_min) as longitude_min,
max(longitude_max) as longitude_max
FROM shape_polygons GROUP BY code ORDER BY code ASC';

try {
	$dbh = new PDO('mysql:host=mysql.uwmike.com;dbname=uwmike_maps', DB_USER, DB_PASSWORD);
	$regions = $dbh->query($query);
} catch (PDOException $e) {
	print "Error: " . $e->getMessage();
	die();
}

?>

var regions = [
<?php 
foreach ($regions as $row) {
	echo $joiner;
	extract($row);
	?>
	{
		'title': '<?= str_replace('US.States.', '', $code) ?>',
		'code': '<?= $code ?>',
		'bounds': [<?= $latitude_min ?>, <?= $longitude_min ?>, <?= $latitude_max ?>, <?= $longitude_max ?>]
	}<?
	$joiner = ",\n";
	$count++;
} // foreach;
?>

];

/* Output <?= $count ?> points */