From 2ce7da72e2d4fe2850271ae440b8ea5b85d90fb4 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Sat, 28 May 2022 19:35:27 +0200 Subject: [PATCH] custom kml layer function --- html/layers.js | 16 +++++++--------- html/script.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/html/layers.js b/html/layers.js index 03429e8..16b11a5 100644 --- a/html/layers.js +++ b/html/layers.js @@ -21,10 +21,10 @@ function createBaseLayers() { let world = new ol.Collection(); let us = new ol.Collection(); let europe = new ol.Collection(); - let custom = new ol.Collection(); + custom_layers = new ol.Collection(); if (loStore['customTiles'] != undefined) { - custom.push(new ol.layer.Tile({ + custom_layers.push(new ol.layer.Tile({ source: new ol.source.OSM({ "url" : loStore['customTiles'], maxZoom: 15, @@ -516,13 +516,11 @@ function createBaseLayers() { } } - if (custom.getLength() > 0) { - layers.push(new ol.layer.Group({ - name: 'custom', - title: 'Custom', - layers: new ol.Collection(custom.getArray().reverse()), - })); - } + layers.push(new ol.layer.Group({ + name: 'custom', + title: 'Custom', + layers: custom_layers, + })); if (europe.getLength() > 0) { layers.push(new ol.layer.Group({ diff --git a/html/script.js b/html/script.js index c095704..d8e1e3d 100644 --- a/html/script.js +++ b/html/script.js @@ -156,6 +156,7 @@ let MessageRate = 0; let layers; let layers_group; +let custom_layers; const nullStyle = new ol.style.Style({}); @@ -7720,5 +7721,20 @@ if (adsbexchange && window.location.hostname.startsWith('inaccurate')) { jQuery('#inaccurate_warning').removeClass('hidden'); } +function add_kml_overlay(url, name, opacity) { + custom_layers.push(new ol.layer.Vector({ + source: new ol.source.Vector({ + url: url, + format: new ol.format.KML(), + }), + name: name, + title: 'custom_' + name, + type: 'overlay', + opacity: opacity, + visible: true, + zIndex: 99, + })); +} + parseURLIcaos(); initialize();