libgd-gis 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e54f40ea70b79fc866db311f7ac994ca267483f62de518b2f6f4f5989957f5e6
4
- data.tar.gz: c8825bd11685f5a0254bd5fdaa5b654cee53dff608a990ac91bc4bacfcba4f31
3
+ metadata.gz: 853349ea776badb5542429302596948e10214ccd5dd3eb75c31e075bfde0e45e
4
+ data.tar.gz: 51a6d88d8f49e6e14a363c68fbd9a0837aae91aef028b456f4df20865831fce8
5
5
  SHA512:
6
- metadata.gz: 7bf12c61f036e85b93aa1b7617fb2aa63f9c0fb788f3ad53e1bf313259b5847658e3c1c1cf2682227fdc9d542cabf86489cb94d9a79c5cf15949519dfe08be69
7
- data.tar.gz: bdc13c7e7aa1e99f4328c3ea69699b4e8f548ea5aeb975b317a81fe136d8dc94b1e64655987f51a0fcf4db0af030ffd8e5a125ae8cd3191a34c8814575cffa0e
6
+ metadata.gz: e3430de5b4a01574ccb741d0948de4458b07cae11e196835282c71c88edf2e69f3f6a53f5d35cdaa3195423f0e9bf845324919b233f3aeec68af5719da752173
7
+ data.tar.gz: e2a9b4e8149839b5b9d7b834757e304979a81e3879a4332f97159e75236be79ea4c4e179a54ed3efd94231c24d290edc83812793b2962ffdbd40ae12549bf40a
@@ -40,19 +40,19 @@ module GD
40
40
  size: 12,
41
41
  color: [0, 0, 0],
42
42
  font_color: nil,
43
- count: 0
43
+ symbol: 0
44
44
  )
45
45
  @data = data
46
46
  @lon = lon
47
47
  @lat = lat
48
48
  @color = color
49
+ @font_color = font_color
49
50
 
50
51
  if icon.is_a?(Array) || icon.nil?
51
52
  fill, stroke = icon || [GD::GIS::ColorHelpers.random_rgb, GD::GIS::ColorHelpers.random_rgb]
52
53
  @icon = build_default_marker(fill, stroke)
53
- elsif icon == "numeric" || icon == "alphabetic"
54
+ elsif %w[numeric alphabetic symbol].include?(icon)
54
55
  @icon = icon
55
- @font_color = font_color
56
56
  else
57
57
  @icon = GD::Image.open(icon)
58
58
  @icon.alpha_blending = true
@@ -62,10 +62,11 @@ module GD
62
62
  @label = label
63
63
  @font = font
64
64
  @size = size
65
+
65
66
  @r, @g, @b, @a = color
66
67
  @a = 0 if @a.nil?
67
- @count = count
68
68
 
69
+ @symbol = symbol
69
70
  end
70
71
 
71
72
  # Builds a default circular marker icon.
@@ -100,18 +101,19 @@ module GD
100
101
  #
101
102
  # @return [void]
102
103
  def render!(img, projector)
103
-
104
- case @icon
105
- when "numeric"
106
- value = @count
107
- when "alphabetic"
108
- value = (@count + 96).chr
109
- else
110
- value = "*"
111
- end
104
+ value = case @icon
105
+ when "numeric"
106
+ @symbol
107
+ when "alphabetic"
108
+ (@symbol + 96).chr
109
+ when "symbol"
110
+ @symbol
111
+ else
112
+ @icon
113
+ end
112
114
 
113
115
  if @icon.is_a?(GD::Image)
114
- w = @icon.width
116
+ w = @icon.width
115
117
  h = @icon.height
116
118
  else
117
119
  w = radius_from_text(img, value, font: @font, size: @size) * 2
@@ -127,31 +129,30 @@ module GD
127
129
 
128
130
  text = @label.call(row)
129
131
  next if text.nil? || text.strip.empty?
130
- font_h = @size * 1.1
131
132
 
132
- if @icon == "numeric" || @icon == "alphabetic"
133
+ font_h = @size * 1.1
133
134
 
135
+ if @icon == "numeric" || @icon == "alphabetic" || @icon == "symbol"
134
136
  draw_symbol_circle!(
135
- img: img,
136
- x: x,
137
- y: y,
138
- symbol: value,
139
- radius: 12,
140
- bg_color: @color,
141
- font_color: @font_color,
142
- font: @font,
143
- font_size: @size
144
- )
137
+ img: img,
138
+ x: x,
139
+ y: y,
140
+ symbol: value,
141
+ bg_color: @color,
142
+ font_color: @font_color,
143
+ font: @font,
144
+ font_size: @size
145
+ )
145
146
  else
146
147
  img.copy(@icon, x - (w / 2), y - (h / 2), 0, 0, w, h)
147
148
  end
148
149
 
149
150
  img.text(text,
150
- x: x + (w / 2) + 4,
151
- y: y + (font_h / 2),
152
- size: @size,
153
- color: GD::Color.rgba(@r, @g, @b, @a),
154
- font: @font)
151
+ x: x + (w / 2) + 4,
152
+ y: y + (font_h / 2),
153
+ size: @size,
154
+ color: @font_color,
155
+ font: @font)
155
156
  end
156
157
  end
157
158
 
@@ -159,7 +160,7 @@ module GD
159
160
  #
160
161
  # - x, y: circle center in pixels
161
162
  # - y for text() is BASELINE (not top). We compute baseline to center the text.
162
- def draw_symbol_circle!(img:, x:, y:, symbol:, radius:, bg_color:, font_color:, font:, font_size:, angle: 0.0)
163
+ def draw_symbol_circle!(img:, x:, y:, symbol:, bg_color:, font_color:, font:, font_size:, angle: 0.0)
163
164
  diameter = radius_from_text(img, symbol, font: font, size: font_size) * 2
164
165
 
165
166
  # 1) Bullet background
@@ -175,7 +176,7 @@ module GD
175
176
  # baseline = top_y + h = y + h/2
176
177
  text_x = (x - (w / 2.0)).round
177
178
  text_y = (y + (h / 2.0)).round
178
-
179
+
179
180
  # 4) Draw number
180
181
  img.text(
181
182
  text,
@@ -203,9 +204,8 @@ module GD
203
204
  )
204
205
 
205
206
  # Use the larger dimension to ensure the text fits
206
- (([w, h].max / 2.0).ceil) + padding
207
+ ([w, h].max / 2.0).ceil + padding
207
208
  end
208
-
209
209
  end
210
210
  end
211
211
  end
data/lib/gd/gis/map.rb CHANGED
@@ -288,7 +288,7 @@ module GD
288
288
  size: size,
289
289
  color: color,
290
290
  font_color: font_color,
291
- count: @count
291
+ symbol: @count
292
292
  )
293
293
  @count += 1
294
294
  elsif LINE_GEOMS.include?(geom_type)
@@ -298,6 +298,96 @@ module GD
298
298
  end
299
299
  end
300
300
 
301
+ # Adds a single point (marker) to the map.
302
+ #
303
+ # This is a convenience helper for the most common use case: rendering
304
+ # one point with an optional label and icon, without having to build
305
+ # a full collection or manually configure a PointsLayer.
306
+ #
307
+ # Internally, this method wraps the given coordinates into a one-element
308
+ # data collection and delegates rendering to {GD::GIS::PointsLayer},
309
+ # preserving the same rendering behavior and options.
310
+ #
311
+ # This method is intended for annotations, markers, alerts, cities,
312
+ # or any scenario where only one point needs to be rendered.
313
+ #
314
+ # @param lon [Numeric]
315
+ # Longitude of the point.
316
+ # @param lat [Numeric]
317
+ # Latitude of the point.
318
+ # @param label [String, nil]
319
+ # Optional text label rendered next to the point.
320
+ # @param icon [String, Array<GD::Color>, nil]
321
+ # Marker representation. Can be:
322
+ # - a path to an image file
323
+ # - :numeric or :alphabetic symbol styles
324
+ # - an array of [fill, stroke] colors
325
+ # - nil to generate a default marker
326
+ # @param font [String, nil]
327
+ # Font path used to render the label or symbol.
328
+ # @param size [Integer]
329
+ # Font size in pixels (default: 12).
330
+ # @param color [Array<Integer>]
331
+ # Label or symbol background color as an RGB(A) array.
332
+ # @param font_color [GD::Color, nil]
333
+ # Text color for numeric or alphabetic symbols.
334
+ #
335
+ # @return [void]
336
+ #
337
+ # @example Render a simple point
338
+ # map.add_point(
339
+ # lon: -58.3816,
340
+ # lat: -34.6037
341
+ # )
342
+ #
343
+ # @example Point with label
344
+ # map.add_point(
345
+ # lon: -58.3816,
346
+ # lat: -34.6037,
347
+ # label: "Buenos Aires"
348
+ # )
349
+ #
350
+ # @example Point with numeric marker
351
+ # map.add_point(
352
+ # lon: -58.3816,
353
+ # lat: -34.6037,
354
+ # icon: "numeric",
355
+ # label: "1",
356
+ # font: "/usr/share/fonts/DejaVuSans.ttf"
357
+ # )
358
+ #
359
+
360
+ def add_point(
361
+ lon:,
362
+ lat:,
363
+ label: nil,
364
+ icon: nil,
365
+ font: nil,
366
+ size: nil,
367
+ color: nil,
368
+ font_color: nil,
369
+ symbol: nil
370
+ )
371
+ row = {
372
+ lon: lon,
373
+ lat: lat,
374
+ label: label
375
+ }
376
+
377
+ @points_layers << GD::GIS::PointsLayer.new(
378
+ [row],
379
+ lon: -> r { r[:lon] },
380
+ lat: -> r { r[:lat] },
381
+ icon: icon || @style.point[:icon],
382
+ label: label ? -> r { r[:label] } : nil,
383
+ font: font || @style.point[:font],
384
+ size: size || @style.point[:size],
385
+ color: color || @style.point[:color],
386
+ font_color: font_color || @style.point[:font_color],
387
+ symbol: symbol
388
+ )
389
+ end
390
+
301
391
  # Adds a generic points overlay layer.
302
392
  #
303
393
  # @param data [Enumerable]
data/lib/gd/gis/style.rb CHANGED
@@ -17,6 +17,9 @@ module GD
17
17
  # @return [Hash] global styling rules
18
18
  attr_reader :global
19
19
 
20
+ # @return [Hash] point styling rules
21
+ attr_reader :point
22
+
20
23
  # @return [Hash] road styling rules
21
24
  attr_reader :roads
22
25
 
@@ -45,6 +48,7 @@ module GD
45
48
  # :global, :roads, :rails, :water, :parks, :points, :order, :track
46
49
  def initialize(definition)
47
50
  @global = definition[:global] || {}
51
+ @point = definition[:point] || {}
48
52
  @roads = definition[:roads] || {}
49
53
  @rails = definition[:rails] || {}
50
54
  @water = definition[:water] || {}
@@ -79,6 +83,7 @@ module GD
79
83
 
80
84
  new(
81
85
  global: data[:global],
86
+ point: data[:point],
82
87
  roads: data[:roads],
83
88
  rails: data[:rail] || data[:rails],
84
89
  track: data[:track],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libgd-gis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Germán Alberto Giménez Silva
@@ -57,7 +57,6 @@ files:
57
57
  - lib/gd/gis/projection.rb
58
58
  - lib/gd/gis/style.rb
59
59
  - lib/libgd_gis.rb
60
- - lib/test.rb
61
60
  homepage: https://github.com/ggerman/libgd-gis
62
61
  licenses:
63
62
  - MIT
@@ -77,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
76
  - !ruby/object:Gem::Version
78
77
  version: '0'
79
78
  requirements: []
80
- rubygems_version: 4.0.4
79
+ rubygems_version: 4.0.5
81
80
  specification_version: 4
82
81
  summary: Geospatial raster rendering for Ruby using libgd
83
82
  test_files: []
data/lib/test.rb DELETED
@@ -1,4 +0,0 @@
1
- def foo
2
- end
3
-
4
- foo(1, 2)