}
function updateButton() {
- const disabled = OSM.LAYERS_WITH_MAP_KEY.indexOf(map.getMapBaseLayerId()) === -1;
+ const disabled = !map.getMapBaseLayer().options.hasLegend;
button
.toggleClass("disabled", disabled)
.attr("data-bs-original-title",
DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
- LAYER_DEFINITIONS: <%= MapLayers::full_definitions("config/layers.yml").to_json %>,
- LAYERS_WITH_MAP_KEY: <%= YAML.load_file(Rails.root.join("config/key.yml")).keys.to_json %>,
+ LAYER_DEFINITIONS: <%= MapLayers::full_definitions("config/layers.yml", :legends => "config/key.yml").to_json %>,
MARKER_BLUE: <%= image_path("marker-blue.png").to_json %>,
MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,
module MapLayers
- def self.full_definitions(layers_filename)
+ def self.full_definitions(layers_filename, legends: nil)
+ legended_layers = YAML.load_file(Rails.root.join(legends)).keys if legends
YAML.load_file(Rails.root.join(layers_filename))
.reject { |layer| layer["apiKeyId"] && !Settings[layer["apiKeyId"]] }
.map do |layer|
layer["apikey"] = Settings[layer["apiKeyId"]]
layer.delete "apiKeyId"
end
+ layer["hasLegend"] = true if legended_layers&.include?(layer["layerId"])
layer
end
end