Class: NSWTopo::Labels::Label
- Inherits:
-
ConvexHulls
- Object
- GeoJSON::MultiLineString
- ConvexHulls
- NSWTopo::Labels::Label
- Defined in:
- lib/nswtopo/layer/labels/label.rb
Constant Summary
Constants included from StraightSkeleton
StraightSkeleton::DEFAULT_ROUNDING_ANGLE
Instance Attribute Summary collapse
-
#along ⇒ Object
readonly
Returns the value of attribute along.
-
#barrier_count ⇒ Object
readonly
Returns the value of attribute barrier_count.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#dual ⇒ Object
readonly
Returns the value of attribute dual.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#feature_index ⇒ Object
readonly
Returns the value of attribute feature_index.
-
#fixed ⇒ Object
readonly
Returns the value of attribute fixed.
-
#hull ⇒ Object
readonly
Returns the value of attribute hull.
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
-
#label_index ⇒ Object
readonly
Returns the value of attribute label_index.
-
#layer_name ⇒ Object
readonly
Returns the value of attribute layer_name.
-
#ordinal ⇒ Object
readonly
Returns the value of attribute ordinal.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#separation ⇒ Object
readonly
Returns the value of attribute separation.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #barriers? ⇒ Boolean
- #coexists_with?(other) ⇒ Boolean
-
#initialize(baselines, feature, priority, elements, along: nil, fixed: nil, &block) ⇒ Label
constructor
A new instance of Label.
- #optional? ⇒ Boolean
- #point? ⇒ Boolean
Methods inherited from ConvexHulls
Methods inherited from GeoJSON::MultiLineString
#buffer, #dissolve_points, #freeze!, #nodes, #offset, #path_length, #samples, #smooth, #subdivide, #to_multipolygon, #to_polygon, #trim
Constructor Details
#initialize(baselines, feature, priority, elements, along: nil, fixed: nil, &block) ⇒ Label
Returns a new instance of Label.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/nswtopo/layer/labels/label.rb', line 8 def initialize(baselines, feature, priority, elements, along: nil, fixed: nil, &block) super baselines, 0.5 * feature["font-size"] do @categories, @text, @dual, @layer_name, @label_index, @feature_index = feature.values_at(:categories, :text, :dual, :layer_name, :label_index, :feature_index) @indices = [@label_index, @feature_index] @priority, @elements, @along, @fixed = priority, elements, along, fixed @hull = dissolve_points.convex_hull @optional, @coexist, knockout = feature.values_at("optional", "coexist", "knockout") @barrier_count = each.with_object(Label.knockout(knockout)).map(&block).inject(&:merge).size @ordinal = [@barrier_count, @priority] @separation = feature.fetch("separation", {}) end end |
Instance Attribute Details
#along ⇒ Object (readonly)
Returns the value of attribute along.
22 23 24 |
# File 'lib/nswtopo/layer/labels/label.rb', line 22 def along @along end |
#barrier_count ⇒ Object (readonly)
Returns the value of attribute barrier_count.
22 23 24 |
# File 'lib/nswtopo/layer/labels/label.rb', line 22 def @barrier_count end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
21 22 23 |
# File 'lib/nswtopo/layer/labels/label.rb', line 21 def categories @categories end |
#dual ⇒ Object (readonly)
Returns the value of attribute dual.
21 22 23 |
# File 'lib/nswtopo/layer/labels/label.rb', line 21 def dual @dual end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
22 23 24 |
# File 'lib/nswtopo/layer/labels/label.rb', line 22 def elements @elements end |
#feature_index ⇒ Object (readonly)
Returns the value of attribute feature_index.
21 22 23 |
# File 'lib/nswtopo/layer/labels/label.rb', line 21 def feature_index @feature_index end |
#fixed ⇒ Object (readonly)
Returns the value of attribute fixed.
22 23 24 |
# File 'lib/nswtopo/layer/labels/label.rb', line 22 def fixed @fixed end |
#hull ⇒ Object (readonly)
Returns the value of attribute hull.
22 23 24 |
# File 'lib/nswtopo/layer/labels/label.rb', line 22 def hull @hull end |
#indices ⇒ Object (readonly)
Returns the value of attribute indices.
21 22 23 |
# File 'lib/nswtopo/layer/labels/label.rb', line 21 def indices @indices end |
#label_index ⇒ Object (readonly)
Returns the value of attribute label_index.
21 22 23 |
# File 'lib/nswtopo/layer/labels/label.rb', line 21 def label_index @label_index end |
#layer_name ⇒ Object (readonly)
Returns the value of attribute layer_name.
21 22 23 |
# File 'lib/nswtopo/layer/labels/label.rb', line 21 def layer_name @layer_name end |
#ordinal ⇒ Object (readonly)
Returns the value of attribute ordinal.
22 23 24 |
# File 'lib/nswtopo/layer/labels/label.rb', line 22 def ordinal @ordinal end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
22 23 24 |
# File 'lib/nswtopo/layer/labels/label.rb', line 22 def priority @priority end |
#separation ⇒ Object (readonly)
Returns the value of attribute separation.
22 23 24 |
# File 'lib/nswtopo/layer/labels/label.rb', line 22 def separation @separation end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
21 22 23 |
# File 'lib/nswtopo/layer/labels/label.rb', line 21 def text @text end |
Class Method Details
.knockout(value) ⇒ Object
4 5 6 |
# File 'lib/nswtopo/layer/labels/label.rb', line 4 def self.knockout(value) Float(Numeric === value ? value : value ? Config.fetch("knockout", 0.3) : 0) end |
.overlaps(labels, group = labels, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nswtopo/layer/labels/label.rb', line 44 def self.overlaps(labels, group = labels, &block) return Set[] unless group.any?(&block) index = RTree.load(labels.flat_map(&:explode), &:bounds) group.each.with_object Set[] do |label, overlaps| next unless buffer = yield(label) index.search(label.bounds, buffer).each do |other| next if label == other.source next if overlaps === [label, other.source] next if overlaps === [other.source, label] next unless label.length < 3 || ConvexHulls.overlap?(label.hull, other, buffer) next unless label.any? do |hull| ConvexHulls.overlap?(hull, other, buffer) end overlaps << [label, other.source] end end end |
Instance Method Details
#<=>(other) ⇒ Object
40 41 42 |
# File 'lib/nswtopo/layer/labels/label.rb', line 40 def <=>(other) self.ordinal <=> other.ordinal end |
#barriers? ⇒ Boolean
28 29 30 |
# File 'lib/nswtopo/layer/labels/label.rb', line 28 def @barrier_count > 0 end |
#coexists_with?(other) ⇒ Boolean
36 37 38 |
# File 'lib/nswtopo/layer/labels/label.rb', line 36 def coexists_with?(other) Array(@coexist).include? other.layer_name end |
#optional? ⇒ Boolean
32 33 34 |
# File 'lib/nswtopo/layer/labels/label.rb', line 32 def optional? @optional end |
#point? ⇒ Boolean
24 25 26 |
# File 'lib/nswtopo/layer/labels/label.rb', line 24 def point? @along.nil? end |