100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/overture_maps/mcp_server.rb', line 100
def self.call(theme:, type: nil, category: nil, limit: nil, server_context: nil, **bbox_args)
bbox = Helpers.resolve_bbox(bbox_args)
limit = [(limit || 20).to_i.clamp(1, MAX_FEATURES), MAX_FEATURES].min
wanted = category&.split(",")&.map(&:strip)
features = []
Query.new(theme: theme, type: type, bbox: bbox, limit: limit * 5).each do |record|
if wanted
cats = record["categories"]
primary = cats.is_a?(Hash) ? cats["primary"] : record["basic_category"]
next unless wanted.include?(primary) ||
(cats.is_a?(Hash) && (Array(cats["alternate"]) & wanted).any?)
end
geometry = record.delete("geometry")
properties = record.except("bbox", "names", "sources")
properties["name"] = record.dig("names", "primary")
features << {
type: "Feature",
geometry: geometry && RGeo::GeoJSON.encode(geometry),
properties: properties
}
break if features.length >= limit
end
Helpers.text_response({ type: "FeatureCollection", features: features })
rescue OvertureMaps::Error, ArgumentError => e
Helpers.error_response(e.message)
end
|