libgd-gis 0.3.1 → 0.3.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gd/gis/layer_points.rb +92 -10
- data/lib/gd/gis/map.rb +10 -6
- data/lib/test.rb +1 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ae0d79550ce61b3bebaa90e48f7b57c5dd1f1fca8be67d857e41fd8fec69e75c
|
|
4
|
+
data.tar.gz: b37ff43e8f0a0dd9112ad256c46e3aa1154975ca737544eae761bec9d074ee32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6272498890dd101132b00edcd65d63b023721afa2d18a77bb17919b53d6220927ff5d532803d1c24e726799ac3d7671b648d2979c38725880403d5cd5dc966be
|
|
7
|
+
data.tar.gz: 65464584707bb1c54bb8401c847a395ba646f94846d5897fe5e6b099c97d812616035d35770d3106860819ce0d318b8980b56c7e067ace39c683ed6a5fa18273
|
data/lib/gd/gis/layer_points.rb
CHANGED
|
@@ -38,17 +38,25 @@ module GD
|
|
|
38
38
|
label: nil,
|
|
39
39
|
font: nil,
|
|
40
40
|
size: 12,
|
|
41
|
-
color: [0, 0, 0]
|
|
41
|
+
color: [0, 0, 0],
|
|
42
|
+
font_color: nil,
|
|
43
|
+
count: 0
|
|
42
44
|
)
|
|
43
45
|
@data = data
|
|
44
46
|
@lon = lon
|
|
45
47
|
@lat = lat
|
|
48
|
+
@color = color
|
|
46
49
|
|
|
47
50
|
if icon.is_a?(Array) || icon.nil?
|
|
48
51
|
fill, stroke = icon || [GD::GIS::ColorHelpers.random_rgb, GD::GIS::ColorHelpers.random_rgb]
|
|
49
52
|
@icon = build_default_marker(fill, stroke)
|
|
53
|
+
elsif %w[numeric alphabetic].include?(icon)
|
|
54
|
+
@icon = icon
|
|
55
|
+
@font_color = font_color
|
|
50
56
|
else
|
|
51
57
|
@icon = GD::Image.open(icon)
|
|
58
|
+
@icon.alpha_blending = true
|
|
59
|
+
@icon.save_alpha = true
|
|
52
60
|
end
|
|
53
61
|
|
|
54
62
|
@label = label
|
|
@@ -56,9 +64,7 @@ module GD
|
|
|
56
64
|
@size = size
|
|
57
65
|
@r, @g, @b, @a = color
|
|
58
66
|
@a = 0 if @a.nil?
|
|
59
|
-
|
|
60
|
-
@icon.alpha_blending = true
|
|
61
|
-
@icon.save_alpha = true
|
|
67
|
+
@count = count
|
|
62
68
|
end
|
|
63
69
|
|
|
64
70
|
# Builds a default circular marker icon.
|
|
@@ -93,8 +99,21 @@ module GD
|
|
|
93
99
|
#
|
|
94
100
|
# @return [void]
|
|
95
101
|
def render!(img, projector)
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
value = case @icon
|
|
103
|
+
when "numeric"
|
|
104
|
+
@count
|
|
105
|
+
when "alphabetic"
|
|
106
|
+
(@count + 96).chr
|
|
107
|
+
else
|
|
108
|
+
"*"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
if @icon.is_a?(GD::Image)
|
|
112
|
+
w = @icon.width
|
|
113
|
+
h = @icon.height
|
|
114
|
+
else
|
|
115
|
+
w = radius_from_text(img, value, font: @font, size: @size) * 2
|
|
116
|
+
end
|
|
98
117
|
|
|
99
118
|
@data.each do |row|
|
|
100
119
|
lon = @lon.call(row)
|
|
@@ -102,10 +121,6 @@ module GD
|
|
|
102
121
|
|
|
103
122
|
x, y = projector.call(lon, lat)
|
|
104
123
|
|
|
105
|
-
# icono
|
|
106
|
-
img.copy(@icon, x - (w / 2), y - (h / 2), 0, 0, w, h)
|
|
107
|
-
|
|
108
|
-
# etiqueta opcional
|
|
109
124
|
next unless @label && @font
|
|
110
125
|
|
|
111
126
|
text = @label.call(row)
|
|
@@ -113,6 +128,22 @@ module GD
|
|
|
113
128
|
|
|
114
129
|
font_h = @size * 1.1
|
|
115
130
|
|
|
131
|
+
if @icon == "numeric" || @icon == "alphabetic"
|
|
132
|
+
|
|
133
|
+
draw_symbol_circle!(
|
|
134
|
+
img: img,
|
|
135
|
+
x: x,
|
|
136
|
+
y: y,
|
|
137
|
+
symbol: value,
|
|
138
|
+
bg_color: @color,
|
|
139
|
+
font_color: @font_color,
|
|
140
|
+
font: @font,
|
|
141
|
+
font_size: @size
|
|
142
|
+
)
|
|
143
|
+
else
|
|
144
|
+
img.copy(@icon, x - (w / 2), y - (h / 2), 0, 0, w, h)
|
|
145
|
+
end
|
|
146
|
+
|
|
116
147
|
img.text(text,
|
|
117
148
|
x: x + (w / 2) + 4,
|
|
118
149
|
y: y + (font_h / 2),
|
|
@@ -121,6 +152,57 @@ module GD
|
|
|
121
152
|
font: @font)
|
|
122
153
|
end
|
|
123
154
|
end
|
|
155
|
+
|
|
156
|
+
# Draws a filled circle (bullet) with a centered numeric label.
|
|
157
|
+
#
|
|
158
|
+
# - x, y: circle center in pixels
|
|
159
|
+
# - y for text() is BASELINE (not top). We compute baseline to center the text.
|
|
160
|
+
def draw_symbol_circle!(img:, x:, y:, symbol:, bg_color:, font_color:, font:, font_size:, angle: 0.0)
|
|
161
|
+
diameter = radius_from_text(img, symbol, font: font, size: font_size) * 2
|
|
162
|
+
|
|
163
|
+
# 1) Bullet background
|
|
164
|
+
img.filled_ellipse(x, y, diameter, diameter, bg_color)
|
|
165
|
+
|
|
166
|
+
# 2) Measure text in pixels (matches rendering)
|
|
167
|
+
text = symbol.to_s
|
|
168
|
+
w, h = img.text_bbox(text, font: font, size: font_size, angle: angle)
|
|
169
|
+
|
|
170
|
+
# 3) Compute centered position:
|
|
171
|
+
# text() uses baseline Y, so:
|
|
172
|
+
# top_y = y - h/2
|
|
173
|
+
# baseline = top_y + h = y + h/2
|
|
174
|
+
text_x = (x - (w / 2.0)).round
|
|
175
|
+
text_y = (y + (h / 2.0)).round
|
|
176
|
+
|
|
177
|
+
# 4) Draw number
|
|
178
|
+
img.text(
|
|
179
|
+
text,
|
|
180
|
+
x: text_x,
|
|
181
|
+
y: text_y,
|
|
182
|
+
font: font,
|
|
183
|
+
size: font_size,
|
|
184
|
+
color: font_color
|
|
185
|
+
)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Calculates a circle radius that fully contains the rendered text.
|
|
189
|
+
#
|
|
190
|
+
# img : GD::Image
|
|
191
|
+
# text : String (number, letters, etc.)
|
|
192
|
+
# font : path to .ttf
|
|
193
|
+
# size : font size in points
|
|
194
|
+
# padding : extra pixels around text (visual breathing room)
|
|
195
|
+
#
|
|
196
|
+
def radius_from_text(img, text, font:, size:, padding: 4)
|
|
197
|
+
w, h = img.text_bbox(
|
|
198
|
+
text.to_s,
|
|
199
|
+
font: font,
|
|
200
|
+
size: size
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
# Use the larger dimension to ensure the text fits
|
|
204
|
+
([w, h].max / 2.0).ceil + padding
|
|
205
|
+
end
|
|
124
206
|
end
|
|
125
207
|
end
|
|
126
208
|
end
|
data/lib/gd/gis/map.rb
CHANGED
|
@@ -133,6 +133,7 @@ module GD
|
|
|
133
133
|
|
|
134
134
|
@debug = false
|
|
135
135
|
@used_labels = {}
|
|
136
|
+
@count = 1
|
|
136
137
|
end
|
|
137
138
|
|
|
138
139
|
# Returns all features belonging to a given semantic layer.
|
|
@@ -258,20 +259,20 @@ module GD
|
|
|
258
259
|
warn "Style error: missing 'points' section"
|
|
259
260
|
end
|
|
260
261
|
|
|
261
|
-
font =
|
|
262
|
+
font = @style.points[:font] || begin
|
|
262
263
|
warn "[libgd-gis] points.font not defined in style, using random system font"
|
|
263
264
|
GD::GIS::FontHelper.random
|
|
264
265
|
end
|
|
265
266
|
|
|
266
|
-
size =
|
|
267
|
+
size = @style.points[:size] || begin
|
|
267
268
|
warn "[libgd-gis] points.font size not defined in style, using random system font size"
|
|
268
269
|
(6..14).to_a.sample
|
|
269
270
|
end
|
|
270
271
|
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
color = @style.points[:color] ? @style.normalize_color(@style.points[:color]) : GD::GIS::ColorHelpers.random_vivid
|
|
273
|
+
font_color = @style.points[:font_color] ? @style.normalize_color(@style.points[:font_color]) : [250, 250, 250, 0]
|
|
273
274
|
|
|
274
|
-
icon = if
|
|
275
|
+
icon = if @style.points.key?(:icon_fill) && @style.points.key?(:icon_stroke)
|
|
275
276
|
[points_style[:icon_stroke],
|
|
276
277
|
points_style[:icon_stroke]]
|
|
277
278
|
end
|
|
@@ -285,8 +286,11 @@ module GD
|
|
|
285
286
|
label: ->(f) { f.properties["name"] },
|
|
286
287
|
font: font,
|
|
287
288
|
size: size,
|
|
288
|
-
color: color
|
|
289
|
+
color: color,
|
|
290
|
+
font_color: font_color,
|
|
291
|
+
count: @count
|
|
289
292
|
)
|
|
293
|
+
@count += 1
|
|
290
294
|
elsif LINE_GEOMS.include?(geom_type)
|
|
291
295
|
@layers[:minor] << feature
|
|
292
296
|
end
|
data/lib/test.rb
CHANGED