Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_site
js/data.js
node_modules
.grunt
14 changes: 14 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = function(grunt) {

grunt.initConfig({
'gh-pages': {
options: {
base: '_site'
},
src: ['**']
}
});

grunt.loadNpmTasks('grunt-gh-pages');

};
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude: ["geojson", "node_modules", "script", "Gruntfile.js", "package.json"]
17 changes: 17 additions & 0 deletions _plugins/geojson.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Geojson
class Generator < Jekyll::Generator
def generate(site)
data = File.join "js", "data.js";
File.open data, "w" do |file|
file.puts "var data = ["

Dir.glob('geojson/*.geojson') do |geojson|
json = File.read(geojson) + ","
file.puts json
end

file.puts "];"
end
end
end
end
65 changes: 2 additions & 63 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,8 @@
</head>
<body>
<div id='map'></div>

<script src='https://code.jquery.com/jquery-1.11.0.min.js'></script>
<script>
var url = 'https://api.github.com/repos/ResourceDataInc/last-mile/contents/geojson?ref=gh-pages';

var map = L.mapbox.map('map', 'examples.map-h67hf2ic')
.setView([61.189100,-149.873723], 12);

var pickColor = (function() {
var colors = ['#AD0101', '#0D7215', '#4E0963', '#0071CA'];
var colorIndex = Math.floor((Math.random() * colors.length) + 1);

return function() {
colorIndex++;
if (colorIndex >= colors.length) colorIndex = 0;
return colors[colorIndex];
};
})();

function load() {
// Fetch just the contents of a .geojson file from GitHub by passing
// `application/vnd.github.v3.raw` to the Accept header
// As with any other AJAX request, this technique is subject to the Same Origin Policy:
// http://en.wikipedia.org/wiki/Same_origin_policy the server delivering the request should support CORS.
$.ajax({
headers: {
'Accept': 'application/vnd.github.v3.raw'
},
dataType: 'json',
url: url,
success: function(files) {
$.each(files, function (index, file){
if (file.name.split('.').pop().toLowerCase() == 'geojson') {
$.ajax({
headers: {
'Accept': 'application/vnd.github.v3.raw'
},
dataType: 'json',
url: file._links.self,
success: function(geojson) {
$.each(geojson.features, function(index, value) {
$.extend(geojson.features[index].properties, {
'stroke': pickColor(),
'stroke-opacity': 0.5,
'stroke-width': 5
});
});

L.mapbox.featureLayer(geojson)
.eachLayer(function(layer) {
if(layer.feature.properties && layer.feature.properties.desc) {
layer.bindPopup(layer.feature.properties.desc);
}
}).addTo(map);
}
});
}
});
}
});
}

$(load);
</script>
<script src='js/data.js'></script>
<script src='js/app.js'></script>
</body>
</html>
35 changes: 35 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var map = L.mapbox.map('map', 'examples.map-h67hf2ic')
.setView([61.189100,-149.873723], 12);

var pickColor = (function() {
var colors = ['#AD0101', '#0D7215', '#4E0963', '#0071CA'];
var colorIndex = Math.floor((Math.random() * colors.length) + 1);

return function() {
colorIndex++;
if (colorIndex >= colors.length) colorIndex = 0;
return colors[colorIndex];
};
})();

function load() {
// Iterate the geojson objects from the data found in data.js.
$.each(data, function(index, geojson) {
$.each(geojson.features, function(index, value) {
$.extend(geojson.features[index].properties, {
'stroke': pickColor(),
'stroke-opacity': 0.5,
'stroke-width': 5
});
});

L.mapbox.featureLayer(geojson)
.eachLayer(function(layer) {
if(layer.feature.properties && layer.feature.properties.desc) {
layer.bindPopup(layer.feature.properties.desc);
}
}).addTo(map);
})
}

$(load);
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"devDependencies": {
"grunt": "^0.4.5",
"grunt-gh-pages": "^0.9.1"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [View The Map](http://resourcedatainc.github.io/last-mile/)
# [View The Map](http://gregoryjscott.github.io/last-mile/)

[![Build Status][build_png]][travis]

Expand Down