snapa 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/snapa.rb +2 -2
- data/lib/snapa/version.rb +1 -1
- data/public/map.html +19 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b1a3768a78b868e91084f933b59e48436ff6c91
|
4
|
+
data.tar.gz: f44e8582e8efb09956c0bd184c52ed19b1917c3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87d9d709b8338f8a604c06d4ab4bb7b2f600a4d7f3f9ef9974791fafcaa3f918c44d5c97541af51a848ccefe107a798066e8729c5358733dc98ba68d6058989d
|
7
|
+
data.tar.gz: a9b9818d79b03e81dfbbd9e5d6c936281fe47b7a7081308ba136eb74022dd0a1c0fb8b499a3a9cab1a8184684e5b82011754216f8565ef0c589855884a9fc561
|
data/Gemfile.lock
CHANGED
data/lib/snapa.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'snapa/version'
|
2
2
|
require 'rack/file'
|
3
|
-
require 'digest'
|
3
|
+
require 'digest/md5'
|
4
4
|
|
5
5
|
module Snapa
|
6
6
|
class File < Rack::File
|
@@ -22,7 +22,7 @@ module Snapa
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def path(request)
|
25
|
-
@path ||= F.join('/tmp/snapa', ::Digest.
|
25
|
+
@path ||= F.join('/tmp/snapa', ::Digest::MD5.hexdigest(request.query_string) + '.png')
|
26
26
|
end
|
27
27
|
|
28
28
|
def _call(env)
|
data/lib/snapa/version.rb
CHANGED
data/public/map.html
CHANGED
@@ -32,6 +32,14 @@ function getParameterByName(name) {
|
|
32
32
|
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
33
33
|
}
|
34
34
|
|
35
|
+
function mergeGeometry(a, b) {
|
36
|
+
if (b.type === 'MultiPolygon') {
|
37
|
+
a.coordinates = a.coordinates.concat(b.coordinates)
|
38
|
+
} else {
|
39
|
+
a.coordinates.push(b.coordinates)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
35
43
|
var countries = (getParameterByName('c') || 'TZ').toUpperCase().split(','),
|
36
44
|
width = getParameterByName('w') || 400,
|
37
45
|
height = getParameterByName('h') || 230,
|
@@ -51,25 +59,17 @@ var path = d3.geo.path()
|
|
51
59
|
.projection(projection);
|
52
60
|
|
53
61
|
d3.json("countries.json", function(error, world) {
|
54
|
-
var features = topojson.feature(world, world.objects.countries).features
|
62
|
+
var features = topojson.feature(world, world.objects.countries).features,
|
63
|
+
highlight = {type: 'Feature', geometry: {type: 'MultiPolygon', coordinates: []}};
|
55
64
|
|
56
65
|
for (var i = 0; i < features.length; i++) {
|
57
66
|
if (countries.indexOf(features[i].id) !== -1) {
|
58
|
-
|
59
|
-
highlight = JSON.parse(JSON.stringify(features[i]));
|
60
|
-
} else {
|
61
|
-
highlight.geometry.coordinates = d3.merge([highlight.geometry.coordinates, features[i].geometry.coordinates])
|
62
|
-
}
|
67
|
+
mergeGeometry(highlight.geometry, features[i].geometry)
|
63
68
|
}
|
64
69
|
}
|
65
70
|
|
66
|
-
|
67
|
-
|
68
|
-
.scale(50)
|
69
|
-
.translate([width / 2], [height / 2]);
|
70
|
-
|
71
|
-
} else {
|
72
|
-
var centroid = d3.geo.centroid(highlight);
|
71
|
+
var centroid = d3.geo.centroid(highlight);
|
72
|
+
if (!isNaN(centroid[0])) {
|
73
73
|
if (rotation[0] === '') {
|
74
74
|
rotation = [-centroid[0], 0, 0];
|
75
75
|
}
|
@@ -86,6 +86,12 @@ d3.json("countries.json", function(error, world) {
|
|
86
86
|
projection
|
87
87
|
.scale(scale)
|
88
88
|
.translate([width / 2, (height / 2) + centroid[1] * 2.77]);
|
89
|
+
|
90
|
+
} else {
|
91
|
+
|
92
|
+
projection
|
93
|
+
.scale(50)
|
94
|
+
.translate([width / 2, height / 2]);
|
89
95
|
}
|
90
96
|
|
91
97
|
svg.selectAll("path")
|