libgd-gis 0.3.21 → 0.4.0

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: ae0d79550ce61b3bebaa90e48f7b57c5dd1f1fca8be67d857e41fd8fec69e75c
4
- data.tar.gz: b37ff43e8f0a0dd9112ad256c46e3aa1154975ca737544eae761bec9d074ee32
3
+ metadata.gz: 74dd1161f2cc225b81f304e90a5e60c2bf249da1606c7a84798367f3d1d1c4bb
4
+ data.tar.gz: 51a6d88d8f49e6e14a363c68fbd9a0837aae91aef028b456f4df20865831fce8
5
5
  SHA512:
6
- metadata.gz: 6272498890dd101132b00edcd65d63b023721afa2d18a77bb17919b53d6220927ff5d532803d1c24e726799ac3d7671b648d2979c38725880403d5cd5dc966be
7
- data.tar.gz: 65464584707bb1c54bb8401c847a395ba646f94846d5897fe5e6b099c97d812616035d35770d3106860819ce0d318b8980b56c7e067ace39c683ed6a5fa18273
6
+ metadata.gz: 78987b17ccf96eb35607632956a97add64353d9500a5ec9b208028a7064a11501ee5d0b19ce0b1134e41062dd35387b891eb1d67316737a0f7c83279223d1e2c
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 %w[numeric alphabetic].include?(icon)
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,9 +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
+
69
+ @symbol = symbol
68
70
  end
69
71
 
70
72
  # Builds a default circular marker icon.
@@ -101,11 +103,13 @@ module GD
101
103
  def render!(img, projector)
102
104
  value = case @icon
103
105
  when "numeric"
104
- @count
106
+ @symbol
105
107
  when "alphabetic"
106
- (@count + 96).chr
108
+ (@symbol + 96).chr
109
+ when "symbol"
110
+ @symbol
107
111
  else
108
- "*"
112
+ @icon
109
113
  end
110
114
 
111
115
  if @icon.is_a?(GD::Image)
@@ -128,8 +132,7 @@ module GD
128
132
 
129
133
  font_h = @size * 1.1
130
134
 
131
- if @icon == "numeric" || @icon == "alphabetic"
132
-
135
+ if @icon == "numeric" || @icon == "alphabetic" || @icon == "symbol"
133
136
  draw_symbol_circle!(
134
137
  img: img,
135
138
  x: x,
@@ -148,7 +151,7 @@ module GD
148
151
  x: x + (w / 2) + 4,
149
152
  y: y + (font_h / 2),
150
153
  size: @size,
151
- color: GD::Color.rgba(@r, @g, @b, @a),
154
+ color: @font_color,
152
155
  font: @font)
153
156
  end
154
157
  end
@@ -173,7 +176,7 @@ module GD
173
176
  # baseline = top_y + h = y + h/2
174
177
  text_x = (x - (w / 2.0)).round
175
178
  text_y = (y + (h / 2.0)).round
176
-
179
+
177
180
  # 4) Draw number
178
181
  img.text(
179
182
  text,
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.21
4
+ version: 0.4.0
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,3 +0,0 @@
1
- def foo; end
2
-
3
- foo(1, 2)