Skip to content

Commit 684c420

Browse files
committed
2 parents b19af11 + 1eb9869 commit 684c420

File tree

6 files changed

+313
-49
lines changed

6 files changed

+313
-49
lines changed

Diff for: cgi/simpleMap.cgi

-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ my @markers;
5757

5858
# removing header line
5959
shift @$table;
60-
6160

6261
my $markers = {};
6362

@@ -110,8 +109,6 @@ $pgx->pgx_get_web_geomap();
110109

111110
print <<END;
112111
Content-type: text/html
113-
User-Agent: Mozilla/5.0
114-
115112
116113
117114
<html>

Diff for: config/config.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ map_params:
1717
# extra_JS: 'id: "mapbox.streets",'
1818

1919
plottype: map
20-
plotid: map
21-
canvas_w_px: 794
22-
canvas_h_px: 480
20+
plotid: map-canvas
21+
map_w_px: 794
22+
map_h_px: 480
2323
bubble_stroke_color: '#dd6633'
2424
bubble_stroke_weight: 1
2525
bubble_fill_color: '#cc9966'
@@ -38,3 +38,5 @@ map_params:
3838
<meta charset="utf-8">
3939
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==" crossorigin="" />
4040
41+
42+
plot_params:

Diff for: lib/plotGeomaps.pm

+24-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require Exporter;
88
@EXPORT = qw(
99
new
1010
pgx_get_web_geomap
11-
read_plot_defaults
1211
);
1312

1413
######## #### #### #### #### #### #### #### #### ####
@@ -19,18 +18,24 @@ sub new {
1918

2019
my $class = shift;
2120
my $args = shift;
22-
my $map_params = read_plot_defaults();
21+
22+
my $path_of_this_module = File::Basename::dirname( eval { ( caller() )[1] } );
23+
my $defs = LoadFile($path_of_this_module.'/../config/config.yaml');
2324

2425
foreach my $param (keys %{$args}) {
25-
if (grep{/^$param$/} keys %{$map_params}) {
26+
if (grep{/^$param$/} keys %{ $defs->{plot_params} }) {
2627
my $p_v = $args->{$param};
2728
if ($p_v =~ /\w/) {
28-
$map_params->{$param} = $p_v }
29+
$defs->{plot_params}->{$param} = $p_v }
2930
}
3031
}
3132

33+
foreach (keys %{$defs->{plot_params}}) {
34+
$defs->{map_params}->{$_} = $defs->{plot_params}->{$_};
35+
}
36+
3237
my $self = {
33-
parameters => $map_params,
38+
parameters => $defs->{map_params},
3439
plotid => $map_params->{plotid},
3540
map => q{},
3641
};
@@ -56,10 +61,8 @@ sub _aggregate_geomarkers {
5661
push(@{$markers->{$m_k}->{items}}, $label);
5762
print Dumper($group, $label, $markers->{$m_k}->{size}, $markers->{$m_k}->{items});
5863
}
59-
# print Dumper(%$markers);
6064

6165

62-
# return $markers;
6366
return $pgx->{geomarkers};
6467

6568
}
@@ -99,7 +102,7 @@ sub pgx_get_web_geomap {
99102

100103
if ($m->{type} eq 'marker') {
101104
push @markersJs, qq!
102-
L.marker([$m->{lat}, $m->{lon}]).bindPopup('$title').addTo(map)
105+
L.marker([$m->{lat}, $m->{lon}]).bindPopup('$title')
103106
! }
104107
else {
105108
my $radius = sprintf "%.0f", sqrt($m->{size} / 3.14 * $locsizeF);
@@ -112,27 +115,32 @@ L.circle([$m->{lat}, $m->{lon}], {
112115
fillOpacity: $pgx->{parameters}->{bubble_opacity},
113116
radius: $radius,
114117
count: $m->{size}
115-
}).bindPopup('$title').addTo(map)
118+
}).bindPopup('$title')
116119
!
117120
}
118121
}
119122

120-
my $_markersJs = '' . join(';', @markersJs) . '';
123+
my $_markersJs = join(",\n", @markersJs);
121124

122125
$pgx->{map} = $pgx->{parameters}->{head};
123-
124126
$pgx->{map} .= << "__HTML__";
125127
126128
<!-- map needs to exist before we load leaflet -->
127-
<div id="map-canvas" style="width: $pgx->{parameters}->{canvas_w_px}px; height: $pgx->{parameters}->{canvas_h_px}px;"></div>
129+
<div id="$pgx->{parameters}->{id}" style="width: $pgx->{parameters}->{map_w_px}px; height: $pgx->{parameters}->{map_h_px}px;"></div>
128130
129131
<!-- Make sure you put this AFTER Leaflet's CSS -->
130132
<script src="https://unpkg.com/leaflet\@1.8.0/dist/leaflet.js"
131133
integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
132134
crossorigin=""></script>
133135
<script>
136+
137+
var markers = [
138+
$_markersJs
139+
];
140+
var markersGroup = L.featureGroup(markers);
141+
134142
// Create the map.
135-
var map = L.map('map-canvas', { renderer: L.svg() } ).setView([$pgx->{parameters}->{latitude}, $pgx->{parameters}->{longitude}], $pgx->{parameters}->{zoom});
143+
var map = L.map('$pgx->{parameters}->{id}', { renderer: L.svg() } ).setView([$pgx->{parameters}->{latitude}, $pgx->{parameters}->{longitude}], $pgx->{parameters}->{zoom});
136144
137145
L.tileLayer('$pgx->{parameters}->{tiles_source}', {
138146
minZoom: $pgx->{parameters}->{zoom_min},
@@ -141,23 +149,15 @@ L.circle([$m->{lat}, $m->{lon}], {
141149
attribution: '$pgx->{parameters}->{attribution}'
142150
}).addTo(map);
143151
144-
$_markersJs;
152+
map.addLayer(markersGroup);
153+
map.fitBounds(markersGroup.getBounds().pad(0.05));
154+
145155
</script>
146156
__HTML__
147157

148158
return $pgx;
149159

150160
}
151161

152-
################################################################################
153-
154-
sub read_plot_defaults {
155-
156-
my $path_of_this_module = File::Basename::dirname( eval { ( caller() )[1] } );
157-
my $plotPars = LoadFile($path_of_this_module.'/../config/config.yaml');
158-
return $plotPars->{map_params};
159-
160-
}
161-
162162

163163
1;

Diff for: rsrc/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Map Source & Test data
2+
3+
## Country shapes
4+
5+
The [./geoJSONcountries.json][geoJSONcountries] file is a concatenation of the
6+
GeoJSON country shapes provided by [_digitalki_](https://digitalki.net/2021/03/26/geojson-country-boundaries-data-for-all/)
7+
(all world countries as of 2021). Some attributes were renamed:
8+
9+
* `ADMIN` => `country`
10+
* `ISO_A3` => `ISO3166alpha3`

Diff for: rsrc/geoJSONcountries.json

+254
Large diffs are not rendered by default.

Diff for: rsrc/locationtest.tsv

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
Location Latitude Longitude Count Label Link
2-
Swiss 47 8 50 group 1 http://progenetix.org
3-
Swiss 47 8 60 Group 2 http://lifescienceszurich.ch
4-
Swiss 47 8 100 Group 3 http://uzh.ch
5-
Swiss 47 8 97 Group 4 http://sib.swiss
6-
German (217) 51 10 217
7-
Italian (75) 44 11 75
8-
Austrian (41) 48 15 41
9-
French (33) 47 3 33
10-
Chinese (33) 35 110 33
11-
Polish (25) 52 21 25
12-
Spanish (24) 40 -3 24
13-
British (23) 52 -1 23
14-
Dutch (22) 52 5 22
15-
Greek (19) 39 23 19
16-
American (15) 40 -99 15
17-
Portuguese (12) 40 -8 12
18-
Turkish (11) 39 31 11
19-
Iranian (9) 34 53 9
1+
group_label group_lat group_lon item_size item_label item_link markerType
2+
# Label text, required latitude, required longitude, required size parameter, e.g. count; will be summed up for all members of the same group; default 1 required if > 1 in group optional (http://...)
3+
Swiss 47 8 50 Progenetix http://progenetix.org
4+
Swiss 47 8 60 LSZGS 2 http://lifescienceszurich.ch
5+
Swiss 47 8 100 UZH http://uzh.ch
6+
Swiss 47 8 97 SIB http://sib.swiss
7+
Birthplace of Naima 37.44 -122.14
8+
German 51 10 217
9+
Italian 44 11 75
10+
Austrian 48 15 41
11+
French 47 3 33
12+
Polish 52 21 25
13+
Spanish 40 -3 24
14+
British 52 -1 23
15+
Dutch 52 5 22
16+
Greek 39 23 19
17+
American 40 -99 15
18+
Portuguese 40 -8 12
19+
Turkish 39 31 11
20+
Iranian 34 53 9

0 commit comments

Comments
 (0)