Last active
November 10, 2016 00:18
-
-
Save dotspencer/114ffe3f80b619cd3c88 to your computer and use it in GitHub Desktop.
Current Projects Map Shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$json = file_get_contents('./api/research.json'); | |
$research = json_decode($json, true); | |
$thematicProjects = array(); | |
$count = 0; | |
foreach ($research as $project) | |
{ | |
if(intval($project[lat]) < -40 && intval($project[lat]) > -55 && intval($project[lng]) > -30 && intval($project[lng]) < 30) | |
{ | |
array_push($thematicProjects, $project); | |
$count++; | |
} | |
} | |
$otherCount = 0; | |
//$break1 = intval(($count)/3); original | |
//$break1 = intval($count/3) + 1; | |
$break1 = intval(($count+2)/3); | |
$break2 = $break1 * 2; | |
echo('<div id="thematic-research" class="opened"> | |
<h3 style="text-align:center; margin-bottom:5px;margin-top:8px;"> Multi-Region & Thematic Studies</h3><div id="close"></div>'); | |
foreach ($thematicProjects as $project) | |
{ | |
if($otherCount == 0 || $otherCount == $break1 || $otherCount == $break2) | |
{ | |
if($otherCount == $break1 || $otherCount == $break2) | |
{ | |
echo('</ul>'); | |
echo( '</div></div>'); | |
} | |
echo('<div class="vc_span3 wpb_column column_container" style="margin-left:10px;"><div class="wpb_wrapper">'); | |
echo('<ul style="display:inline;">'); | |
} | |
echo('<a href="/research/current-projects/'); | |
echo($project[id]); | |
echo('">'); | |
echo('<img class="tick" '); | |
if($project[status] == 'Completed') | |
echo('src="/wp-content/uploads/2014/05/complete-without.png"'); | |
if($project[status] == 'In Progress') | |
echo('src="/wp-content/uploads/2014/05/in-progress-without.png"'); | |
if($project[status] == "In Development") | |
echo('src="/wp-content/uploads/2014/05/in-development-without.png"'); | |
echo('>'); | |
echo('<li class="'); | |
if($project[status] == 'Completed') | |
echo('completed'); | |
if($project[status] == 'In Progress') | |
echo('in-progress'); | |
if($project[status] == "In Development") | |
echo('in-development'); | |
echo('">'); | |
echo(str_replace("Phase", "Ph.", $project[title])); | |
echo('</li></a>'); | |
$otherCount++; | |
} | |
echo('</ul>'); | |
echo( '</div></div>'); | |
echo('<div style="clear:both"></div></div><div id="mini">Thematic Projects</div>'); //<h3 style="text-align:center; margin-bottom:5px;">▲ Collapse ▲</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery('#close').click(function() { | |
jQuery('#thematic-research').toggle(); | |
jQuery('.gm-style').height(770); | |
}); | |
jQuery('#mini').click(function() { | |
jQuery('#thematic-research').toggle(); | |
jQuery('.gm-style').height(850); | |
}); | |
window.onload = function() { | |
setTimeout(function() { | |
jQuery('.gm-style').height(850); | |
}, 100); | |
}; | |
function initialize() { | |
var clicked = false; | |
function TxtOverlay(left, right, id, font, txt, cls, map) { | |
// Now initialize all properties. | |
var leftlng = left.lng(); | |
var rightlng = right.lng(); | |
this.pos = new google.maps.LatLng(left.lat(), (leftlng - (leftlng - rightlng) / 2)); | |
this.txt_ = txt; | |
this.id_ = id; | |
this.font_ = font; | |
this.cls_ = cls; | |
this.map_ = map; | |
// We define a property to hold the image's | |
// div. We'll actually create this div | |
// upon receipt of the add() method so we'll | |
// leave it null for now. | |
this.div_ = null; | |
// Explicitly call setMap() on this overlay | |
this.setMap(map); | |
} | |
TxtOverlay.prototype = new google.maps.OverlayView(); | |
TxtOverlay.prototype.onAdd = function() { | |
// Note: an overlay's receipt of onAdd() indicates that | |
// the map's panes are now available for attaching | |
// the overlay to the map via the DOM. | |
// Create the DIV and set some basic attributes. | |
var div = document.createElement('DIV'); | |
div.className = this.cls_; | |
div.id = this.id_; | |
div.innerHTML = this.txt_; | |
var zoom = this.getMap().getZoom(); | |
var fontSize = this.font_ * 2 ^ (zoom - 2); | |
// Set the overlay's div_ property to this DIV | |
this.div_ = div; | |
var overlayProjection = this.getProjection(); | |
var position = overlayProjection.fromLatLngToDivPixel(this.pos); | |
div.style.left = (position.x - htmlWidth / 2) + 'px'; | |
div.style.top = position.y + 'px'; | |
div.style.fontSize = fontSize + 'px'; | |
div.style['zIndex'] = 1000; | |
// We add an overlay to a map via one of the map's panes. | |
var panes = this.getPanes(); | |
panes.overlayLayer.appendChild(div); | |
var htmlWidth = jQuery('#' + div.id).width(); | |
div.style.left = (position.x - htmlWidth / 2) + 'px'; | |
panes.overlayLayer.removeChild(div); | |
panes.overlayLayer.appendChild(div); | |
} | |
TxtOverlay.prototype.draw = function() { | |
var overlayProjection = this.getProjection(); | |
var zoom = this.getMap().getZoom(); | |
var fontSize = this.font_ * Math.pow(2, zoom - 1); | |
// Retrieve the southwest and northeast coordinates of this overlay | |
// in latlngs and convert them to pixels coordinates. | |
// We'll use these coordinates to resize the DIV. | |
var position = overlayProjection.fromLatLngToDivPixel(this.pos); | |
var div = this.div_; | |
div.style.fontSize = fontSize + 'px'; | |
var htmlWidth = jQuery('#' + div.id).width(); | |
div.style.left = (position.x - htmlWidth / 2) + 'px'; | |
div.style.top = position.y + 'px'; | |
} | |
var mapOptions = { | |
center: new google.maps.LatLng(0, 6), //center: new google.maps.LatLng(38, 6), | |
zoom: 2, | |
mapTypeId: google.maps.MapTypeId.HYBRID, //mapTypeId: google.maps.MapTypeId.HYBRID, | |
mapTypeControl: false, | |
minZoom: 2, | |
streetViewControl: false | |
}; | |
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); | |
function HomeControl(controlDiv, map) { | |
// Set CSS styles for the DIV containing the control | |
// Setting padding to 5 px will offset the control | |
// from the edge of the map | |
controlDiv.style.padding = '0px'; //'5px'; | |
// Set CSS for the control border | |
var controlUI = document.createElement('div'); | |
controlUI.style.backgroundColor = 'rgba(0,0,0,0)'; | |
controlUI.style.borderStyle = 'solid'; | |
controlUI.style.borderWidth = '0px'; //'2px'; | |
controlUI.style.borderColor = 'rgba(0,0,0,0)'; | |
controlUI.style.cursor = 'pointer'; | |
controlUI.style.textAlign = 'center'; | |
controlUI.title = 'Legend'; | |
controlDiv.appendChild(controlUI); | |
// Set CSS for the control interior | |
var controlText = document.createElement('div'); | |
controlText.style.fontFamily = 'Arial,sans-serif'; | |
controlText.style.fontSize = '12px'; | |
controlText.style.paddingLeft = '0px'; //'4px'; | |
controlText.style.paddingRight = '0px'; //'4px'; | |
controlText.innerHTML = '<img style="width:170px;" src="/wp-content/uploads/2014/05/legend_web.png"/>'; | |
controlUI.appendChild(controlText); | |
} | |
var homeControlDiv = document.createElement('div'); | |
var homeControl = new HomeControl(homeControlDiv, map); | |
homeControlDiv.index = 1000001; | |
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv); | |
var allowedBounds = new google.maps.LatLngBounds( | |
new google.maps.LatLng(-85, -180), | |
new google.maps.LatLng(85, 180) | |
); | |
var lastValidCenter = map.getCenter(); | |
jQuery.getJSON("/api/research.json", function(json) { | |
//jQuery.getJSON( "/wp-content/uploads/2014/05/Research.json", function( json ) { | |
var markerArray = new Array(); | |
var infoArray = new Array(); | |
var overlayArray = new Array(); | |
var idArray = new Array(); | |
var thematicIdArray = new Array(); | |
jQuery.each(json, function(index) { | |
var superBounds = new google.maps.LatLngBounds(new google.maps.LatLng(-55, -30), new google.maps.LatLng(-40, 30)); | |
if (superBounds.contains(new google.maps.LatLng(json[index].lat, json[index].lon))) { | |
thematicIdArray.push(json[index].id.toLowerCase()); | |
return; | |
} | |
var overlays = new Array(); | |
if (typeof json[index].layover != 'undefined') { | |
jQuery.each(json[index].layover, function(coord) { | |
var overlayCoords = new Array(); | |
jQuery.each(json[index].layover[coord], function(othercoord) { | |
overlayCoords.push(new google.maps.LatLng(json[index].layover[coord][othercoord][1], json[index].layover[coord][othercoord][0])); | |
}); | |
var polygon = new google.maps.Polygon({ | |
paths: overlayCoords, | |
geodesic: true, | |
fillColor: '#c01230', | |
fillOpacity: 0.45, | |
strokeColor: '#c01230', | |
strokeOpacity: 0.8, | |
strokeWeight: 0.0 | |
}); | |
polygon.setMap(null); | |
overlays.push(polygon); | |
}); | |
} | |
var contentString1 = '<div id="content" style="width:400px;">' + | |
'<div id="siteNotice">' + | |
'</div>' + | |
'<h1 id="firstHeading" class="firstHeading" style="margin: 0 0 10px 0; padding: 0 0 0 0; line-height:30px"><a style="font-size:inherit !important; font-weight:inherit !important;" href="/research/current-projects/' + json[index].id + '/">'; | |
var contentString2 = ''; | |
if (json[index].status == 'Completed') { | |
contentString2 = '</a></h1>' + '<h2 style="margin-bottom:10px;">Completed | Immediate Delivery</h2>' + '<h3>Contact(s): ' + json[index].contact + '</h3>' + | |
'<div id="bodyContent">' + | |
'<p style="margin-bottom:5px;">View more information about this project here:<br/>'; | |
} else { | |
contentString2 = '</h1>' + '<h2 style="margin-bottom:10px;">' + json[index].status + '</h2>' + '<h3>Contact: ' + json[index].contact + '</h3>' + | |
'<div id="bodyContent">' + | |
'<p style="margin-bottom:5px;">View more information about this project here:<br/>'; | |
} | |
var contentString3 = ', <a href="/research/current-projects/'; | |
var contentString4 = '/"><strong>' + 'Project Page</a></strong></p>' + | |
'</div>' + | |
'</div>'; | |
var latlong = new google.maps.LatLng(json[index].lat, json[index].lon); | |
var latlong = new google.maps.LatLng(json[index].lat,json[index].lon); | |
var image = { | |
url: "", | |
size: new google.maps.Size(30, 30), | |
origin: new google.maps.Point(0, 0), | |
anchor: new google.maps.Point(15, 15) | |
}; | |
switch (json[index].status) { | |
case 'Completed': | |
image.url = '/wp-content/uploads/2014/05/complete-small.png'; | |
break; | |
case 'In Progress': | |
image.url = '/wp-content/uploads/2014/05/in-progress-small.png'; | |
break; | |
case 'In Development': | |
image.url = '/wp-content/uploads/2014/05/in-development-small.png'; | |
break; | |
default: | |
image.url = '/wp-content/uploads/2014/05/complete-small.png'; | |
} | |
var info = new google.maps.InfoWindow({ | |
content: contentString1 + json[index].title + contentString2 + json[index].id.substring(0, 1) + " " + json[index].id.substring(1, json[index].id.length) + contentString3 + json[index].id + contentString4 | |
}); | |
var marker = new google.maps.Marker({ | |
position: latlong, | |
map: map, | |
animation: google.maps.Animation.DROP, | |
title: json[index].title, | |
icon: image | |
}); | |
markerArray.push(marker); | |
infoArray.push(info); | |
overlayArray.push(overlays); | |
idArray.push(json[index].id.toLowerCase()); | |
}); | |
function closeAllBoxes() { | |
jQuery.each(infoArray, function(index) { | |
if (infoArray[index]) { | |
infoArray[index].close(); | |
} | |
if (overlayArray[index]) { | |
jQuery.each(overlayArray[index], function(overlayIndex) { | |
overlayArray[index][overlayIndex].setMap(null); | |
}); | |
} | |
}); | |
} | |
jQuery.each(infoArray, function(index) { | |
google.maps.event.addListener(markerArray[index], 'click', function() { | |
closeAllBoxes(); | |
infoArray[index].open(map, markerArray[index]); | |
if (overlayArray[index]) { | |
jQuery.each(overlayArray[index], function(overlayIndex) { | |
overlayArray[index][overlayIndex].setMap(map); | |
}); | |
} | |
}); | |
if (document.getElementById(idArray[index]) != null) { | |
google.maps.event.addDomListener(document.getElementById(idArray[index]), 'click', function() { | |
map.panTo(markerArray[index].position); | |
closeAllBoxes(); | |
jQuery("html, body").animate({ | |
scrollTop: 0 | |
}, "slow"); | |
infoArray[index].open(map, markerArray[index]); | |
if (overlayArray[index]) { | |
jQuery.each(overlayArray[index], function(overlayIndex) { | |
overlayArray[index][overlayIndex].setMap(map); | |
}); | |
} | |
return false; | |
}); | |
} | |
}); | |
jQuery.each(thematicIdArray, function(index) { | |
google.maps.event.addDomListener(document.getElementById(thematicIdArray[index]), 'click', function() { | |
closeAllBoxes(); | |
jQuery("html, body").animate({ | |
scrollTop: jQuery('#thematic-research').offset().top - 65 | |
}, "1000"); | |
if (clicked) { | |
clicked = false; | |
jQuery('#thematic-research').animate({ | |
height: 25 | |
}, 200); | |
//Get Current Height | |
var currentHeight = jQuery('#thematic-research').css("height"); | |
//Set height to auto | |
jQuery('#thematic-research').css("height", "auto"); | |
//Store auto height | |
var animateHeight = jQuery('#thematic-research').css("height"); | |
//Put height back | |
jQuery('#thematic-research').css("height", currentHeight); | |
//Do animation with animateHeight | |
jQuery('#thematic-research').animate({ | |
height: animateHeight | |
}, 500); | |
} | |
setTimeout(function() { | |
window.location.href = "/research/current-projects/" + thematicIdArray[index].toUpperCase(); | |
}, 800); | |
}); | |
}); | |
google.maps.event.addListener(map, 'click', function() { | |
closeAllBoxes(); | |
}); | |
/*google.maps.event.addDomListener(document.getElementById('ui-id-7'), 'click', function() { | |
map.setZoom(4); | |
map.panTo(new google.maps.LatLng(-47, 0)); | |
jQuery("html, body").animate({ scrollTop: 0 }, "slow"); | |
closeAllBoxes(); | |
});*/ | |
google.maps.event.addDomListener(document.getElementById('ui-id-1'), 'click', function() { | |
map.setZoom(3); | |
map.panTo(new google.maps.LatLng(30, -100)); //50, -100)); | |
jQuery("html, body").animate({ | |
scrollTop: 0 | |
}, "slow"); | |
closeAllBoxes(); | |
}); | |
google.maps.event.addDomListener(document.getElementById('ui-id-2'), 'click', function() { | |
map.setZoom(3); | |
map.panTo(new google.maps.LatLng(-30, -58)); | |
jQuery("html, body").animate({ | |
scrollTop: 0 | |
}, "slow"); | |
closeAllBoxes(); | |
}); | |
google.maps.event.addDomListener(document.getElementById('ui-id-3'), 'click', function() { | |
map.setZoom(3); | |
map.panTo(new google.maps.LatLng(-12, 19)); | |
jQuery("html, body").animate({ | |
scrollTop: 0 | |
}, "slow"); | |
closeAllBoxes(); | |
}); | |
google.maps.event.addDomListener(document.getElementById('ui-id-4'), 'click', function() { | |
map.setZoom(3); | |
map.panTo(new google.maps.LatLng(32, 14)); | |
jQuery("html, body").animate({ | |
scrollTop: 0 | |
}, "slow"); | |
closeAllBoxes(); | |
}); | |
google.maps.event.addDomListener(document.getElementById('ui-id-5'), 'click', function() { | |
map.setZoom(3); | |
map.panTo(new google.maps.LatLng(15, 104)); | |
jQuery("html, body").animate({ | |
scrollTop: 0 | |
}, "slow"); | |
closeAllBoxes(); | |
}); | |
google.maps.event.addDomListener(document.getElementById('ui-id-6'), 'click', function() { | |
map.setZoom(4); | |
map.panTo(new google.maps.LatLng(-32, 133)); | |
jQuery("html, body").animate({ | |
scrollTop: 0 | |
}, "slow"); | |
closeAllBoxes(); | |
}); | |
google.maps.event.addDomListener(document.getElementById('ui-id-8'), 'click', function() { | |
map.setZoom(1); | |
map.panTo(new google.maps.LatLng(17.682109, 5.325463)); //37.682109, 5.325463)); | |
jQuery("html, body").animate({ | |
scrollTop: 0 | |
}, "slow"); | |
closeAllBoxes(); | |
}); | |
}); | |
/* | |
var txt = new TxtOverlay(new google.maps.LatLng(-42, -30), new google.maps.LatLng(-42, 30),'map_label', 4,"<div>Thematic</div>","customBox",map ); | |
var rectangle = new google.maps.Rectangle({ | |
strokeColor: '#000000', | |
strokeOpacity: 0.8, | |
strokeWeight: 1, | |
fillColor: '#000000', | |
fillOpacity: 0.35, | |
map: map, | |
bounds: new google.maps.LatLngBounds( | |
new google.maps.LatLng(-40, -30), | |
new google.maps.LatLng(-55, 30)) | |
});*/ | |
google.maps.event.addListener(map, 'center_changed', function() { | |
if (allowedBounds.contains(map.getCenter()) || allowedBounds.contains(new google.maps.LatLng(map.getCenter().lat(), 100))) { | |
// still within valid bounds, so save the last valid position | |
lastValidCenter = map.getCenter(); | |
return; | |
} | |
// not valid anymore => return to last valid position | |
map.panTo(lastValidCenter); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map-canvas{ | |
height:770px; | |
} | |
#mini{ | |
position: absolute; | |
margin-top: -42px; | |
background-color: white; | |
padding: 5px; | |
padding-right: 30px; | |
padding-left: 30px; | |
font-size: 16.5px; | |
cursor: pointer; | |
left: calc(50% - 100px); | |
border: 1px solid rgb(150, 150, 150); | |
border:1px solid rgba(0, 0, 0, 0.38); | |
background-image: -webkit-linear-gradient(top,#f5f5f5,#E8E8E8); | |
border-radius: 2px; | |
} | |
#mini:hover{ | |
background-image: -webkit-linear-gradient(top,#f5f5f5,#E8E8E8); | |
border: 1px solid gray; | |
box-shadow: 0 1px 1px rgba(0,0,0,0.1); | |
} | |
#close{ | |
width: 13px; | |
height: 13px; | |
float: right; | |
/* background-color: deeppink; */ | |
background: url('https://maps.gstatic.com/mapfiles/api-3/images/mapcnt3.png'); | |
background-position: 0 -335px; | |
margin-top: -23px; | |
margin-right: 15px; | |
cursor:pointer; | |
opacity:.6; | |
} | |
#close:hover{ | |
opacity:1; | |
} | |
.tick{ | |
width: 30px; | |
//height: 22px; | |
float: left; | |
//border-radius: 14px; | |
//margin-top: 4px; | |
//margin-right: 8px; | |
} | |
.prog{ | |
//background-color: coral; | |
} | |
.dev{ | |
//background-color: deepskyblue; | |
} | |
.comp{ | |
//background-color: limegreen; | |
} | |
#thematic-research | |
{ | |
display: inline-block; | |
overflow: hidden; | |
background-color: white; | |
width: 100%; | |
height: 190px; | |
width: calc(100% - 20px); | |
margin-left: 10px; | |
margin-top: -200px; | |
z-index: 10; | |
position: absolute; | |
border-radius: 2px; | |
} | |
#thematic-research a{ | |
font-weight:400; | |
display: table; | |
} | |
#thematic-research li | |
{ | |
color:black; | |
} | |
#thematic-research h3 | |
{ | |
color:black; | |
} | |
#thematic-research li:hover | |
{ | |
color:black; | |
} | |
#thematic-research li.in-progress | |
{ | |
//background-image: url(/wp-content/uploads/2014/05/in-progress-new.png); | |
line-height: 30px; | |
background-repeat: no-repeat; | |
padding-left: 30px; | |
} | |
#thematic-research li.completed | |
{ | |
line-height: 30px; | |
background-repeat: no-repeat; | |
padding-left: 30px; | |
//background-image: url(/wp-content/uploads/2014/05/complete-new-light.png) Edit the map buttons in Javascript | |
} | |
#thematic-research li.in-development | |
{ | |
line-height: 30px; | |
background-repeat: no-repeat; | |
padding-left: 30px; | |
//background-image: url(/wp-content/uploads/2014/05/in-development-new.png); | |
} | |
#thematic-research.closed | |
{ | |
height:25px; | |
} | |
#thematic-research.opened | |
{ | |
} | |
@media (max-width: 1100px){ | |
#thematic-research{ | |
height: 280px; | |
margin-top: -290px; | |
} | |
#map-canvas{ | |
height:625px; | |
} | |
} | |
@media (max-width: 767px){ | |
#thematic-research{ | |
width: inherit; | |
height: inherit; | |
margin-top: 0px; | |
position: relative; | |
padding-bottom: 15px; | |
border-bottom: 1px solid darkgray; | |
white-space: nowrap; | |
margin-left: -30px; | |
display:block !important; | |
} | |
#map-canvas{ | |
height:330px; | |
padding:0px; | |
} | |
.gm-style{ | |
height:330px !important; | |
} | |
#mini{ | |
display:none; | |
} | |
#close{ | |
display:none; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script></script> | |
<style> | |
.customBox { | |
background: transparent; | |
border: 0px solid black; | |
position: absolute; | |
color: white; | |
z-index:-10; | |
} | |
</style> | |
<!-- Advanced shortcode, suppress content filters --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment