@@ -8,7 +8,6 @@ require Exporter;
8
8
@EXPORT = qw(
9
9
new
10
10
pgx_get_web_geomap
11
- read_plot_defaults
12
11
) ;
13
12
14
13
# ####### #### #### #### #### #### #### #### #### ####
@@ -19,18 +18,24 @@ sub new {
19
18
20
19
my $class = shift ;
21
20
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' );
23
24
24
25
foreach my $param (keys %{$args }) {
25
- if (grep {/ ^$param $ / } keys %{$map_params }) {
26
+ if (grep {/ ^$param $ / } keys %{ $defs -> { plot_params } }) {
26
27
my $p_v = $args -> {$param };
27
28
if ($p_v =~ / \w / ) {
28
- $map_params -> {$param } = $p_v }
29
+ $defs -> { plot_params } -> {$param } = $p_v }
29
30
}
30
31
}
31
32
33
+ foreach (keys %{$defs -> {plot_params }}) {
34
+ $defs -> {map_params }-> {$_ } = $defs -> {plot_params }-> {$_ };
35
+ }
36
+
32
37
my $self = {
33
- parameters => $map_params ,
38
+ parameters => $defs -> { map_params } ,
34
39
plotid => $map_params -> {plotid },
35
40
map => q{ } ,
36
41
};
@@ -56,10 +61,8 @@ sub _aggregate_geomarkers {
56
61
push (@{$markers -> {$m_k }-> {items }}, $label );
57
62
print Dumper($group , $label , $markers -> {$m_k }-> {size }, $markers -> {$m_k }-> {items });
58
63
}
59
- # print Dumper(%$markers);
60
64
61
65
62
- # return $markers;
63
66
return $pgx -> {geomarkers };
64
67
65
68
}
@@ -99,7 +102,7 @@ sub pgx_get_web_geomap {
99
102
100
103
if ($m -> {type } eq ' marker' ) {
101
104
push @markersJs , qq!
102
- L.marker([$m ->{lat}, $m ->{lon}]).bindPopup('$title ').addTo(map)
105
+ L.marker([$m ->{lat}, $m ->{lon}]).bindPopup('$title ')
103
106
! }
104
107
else {
105
108
my $radius = sprintf " %.0f" , sqrt ($m -> {size } / 3.14 * $locsizeF );
@@ -112,27 +115,32 @@ L.circle([$m->{lat}, $m->{lon}], {
112
115
fillOpacity: $pgx ->{parameters}->{bubble_opacity},
113
116
radius: $radius ,
114
117
count: $m ->{size}
115
- }).bindPopup('$title ').addTo(map)
118
+ }).bindPopup('$title ')
116
119
!
117
120
}
118
121
}
119
122
120
- my $_markersJs = ' ' . join (' ; ' , @markersJs ) . ' ' ;
123
+ my $_markersJs = join (" , \n " , @markersJs );
121
124
122
125
$pgx -> {map } = $pgx -> {parameters }-> {head };
123
-
124
126
$pgx -> {map } .= << "__HTML__" ;
125
127
126
128
<!-- 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>
128
130
129
131
<!-- Make sure you put this AFTER Leaflet's CSS -->
130
132
<script src="https://unpkg.com/leaflet\@ 1.8.0/dist/leaflet.js"
131
133
integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
132
134
crossorigin=""></script>
133
135
<script>
136
+
137
+ var markers = [
138
+ $_markersJs
139
+ ];
140
+ var markersGroup = L.featureGroup(markers);
141
+
134
142
// 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});
136
144
137
145
L.tileLayer('$pgx ->{parameters}->{tiles_source}', {
138
146
minZoom: $pgx ->{parameters}->{zoom_min},
@@ -141,23 +149,15 @@ L.circle([$m->{lat}, $m->{lon}], {
141
149
attribution: '$pgx ->{parameters}->{attribution}'
142
150
}).addTo(map);
143
151
144
- $_markersJs;
152
+ map.addLayer(markersGroup);
153
+ map.fitBounds(markersGroup.getBounds().pad(0.05));
154
+
145
155
</script>
146
156
__HTML__
147
157
148
158
return $pgx ;
149
159
150
160
}
151
161
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
-
162
162
163
163
1;
0 commit comments