Skip to content
This repository was archived by the owner on Nov 7, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,3 @@ DEPENDENCIES
sass
stretchy
unicorn

BUNDLED WITH
1.10.5
4 changes: 4 additions & 0 deletions app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class App < Padrino::Application
}
end

get :map do
render :map, layout: true
end

get :endpoints do
content_type :json
endpoints = DataMagic.config.api_endpoints.keys.map { |key|
Expand Down
12 changes: 10 additions & 2 deletions app/views/home.liquid
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<div id="map-container">
<div id="map-background"></div>
<div id="map"></div>
</div>

<h1>{{ title }}</h1>

<h2>API endpoints</h2>

<ul>
<ul class="endpoints-list">
{% for name in endpoints %}
<li><a href="/{{ name }}">{{ name }}</a></li>
<li>
<a href="/{{ name }}">{{ name }}</a>
<a href="javascript:void(0)" class="map-link" data-map-category="{{ name }}">map</a>
</li>
{% endfor %}
</ul>

Expand Down
66 changes: 66 additions & 0 deletions app/views/layouts/application.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,74 @@
<head>
<link rel="stylesheet" type="text/css" href="application.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js" type="text/javascript"></script>
</head>
<body>
<%== yield %>

<script type="text/javascript">
$(".endpoints-list").on("click", ".map-link", function(e) {
e.preventDefault();
$("#map-container").children().toggleClass("active");

var mapCategory = $(e.currentTarget).data("map-category");
var mapOptions = {
zoom: 3,
center: new google.maps.LatLng(39.0997, -94.5783),
mapTypeId: google.maps.MapTypeId.DEFAULT
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);

$.ajax({
url: "/" + mapCategory,
data: { per_page: 100 },
success: function(resp) {
markerMaker(resp.results);
}
})

function markerMaker(cities) {
var bounds = new google.maps.LatLngBounds();
cities.forEach(function(city) {
var latlng = new google.maps.LatLng(
city.location.lat,
city.location.lon
);
bounds.extend(latlng);

var contentString = '<div id="content">' +
'<h3>City</h3>' +
'<p>' + city.name + '</p>' +
'<h3>State</h3>' +
'<p>' + city.state + '</p>' +
'<h3>Population</h3>' +
'<p>' + city.population + '</p>' +
'<h3>Land Area</h3>' +
'<p>' + city.land_area + '</p>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});

var marker = new google.maps.Marker({
position: latlng,
map: map,
title: city.name
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
})

map.fitBounds(bounds);
}

});

$("#map-background").on("click", function(e) {
e.preventDefault();
$("#map-container").children().toggleClass("active").empty();
});
</script>
</body>
</html>
67 changes: 67 additions & 0 deletions app/views/map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
</head>
<body>
<div id="map" style="height: 100vh"></div>

<script>
var kansasCity = new google.maps.LatLng(39.0997, -94.5783);
var mapOptions = {
zoom: 3,
center: kansasCity,
mapTypeId: google.maps.MapTypeId.DEFAULT
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);

$.get(
"/cities",
{
per_page: 100
},
function(resp) {
markerMaker(resp.results);
}
)

var bounds = new google.maps.LatLngBounds();
function markerMaker(cities) {
cities.forEach(function(city) {
var lat = city.location.lat;
var lon = city.location.lon;

var contentString = '<div id="content">' +
'<h3>City</h3>' +
'<p>' + city.name + '</p>' +
'<h3>State</h3>' +
'<p>' + city.state + '</p>' +
'<h3>Population</h3>' +
'<p>' + city.population + '</p>' +
'<h3>Land Area</h3>' +
'<p>' + city.land_area + '</p>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});

var latlng = new google.maps.LatLng(lat, lon);
bounds.extend(latlng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: city.name
});

marker.addListener('click', function() {
infowindow.open(map, marker);
});
})
}

map.fitBounds(bounds);
</script>
</body>
</html>
31 changes: 31 additions & 0 deletions public/application.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
body {
}

#map-background {
display: none;
}

#map {
display: none;
}

#map-background.active {
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100vh;
background-color: black;
opacity: 0.8;
}

#map.active {
display: block;
position: absolute;
width: 80%;
height: 80%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) !important;
-ms-transform: translate(-50%, -50%) !important;
-webkit-transform: translate(-50%, -50%) !important;
}