From 0d671fafe8480f67c16790300a2a29d3170b5c60 Mon Sep 17 00:00:00 2001 From: hire2gis <160482521+hire2gis@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:26:39 +0700 Subject: [PATCH 1/4] JAM-0: Add OSM map in compare tool --- index.html | 6 ++++++ index.js | 1 + osm.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 osm.js diff --git a/index.html b/index.html index 3c8ef13..350564f 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,9 @@ + + + @@ -46,11 +49,13 @@ position: absolute; top: 10px; right: 10px; + z-index: 1000; } #langSelect { position: absolute; top: 35px; right: 10px; + z-index: 1000; } @@ -69,6 +74,7 @@ + diff --git a/index.js b/index.js index 96ef87a..35dea1f 100644 --- a/index.js +++ b/index.js @@ -57,6 +57,7 @@ mapbox: mapboxApi, here: hereApi, yandex: yandexApi, + osm: osmApi, }; const firstApi = mapglApi; diff --git a/osm.js b/osm.js new file mode 100644 index 0000000..64812f5 --- /dev/null +++ b/osm.js @@ -0,0 +1,63 @@ +const osmApi = { + type: "osm", + + map: undefined, + container: undefined, + + init(elementId) { + if (!window.L) { + return; + } + + if (this.map && this.container) { + this.container.style.display = "block"; + this.update(); + return; + } + + this.container = document.createElement("div"); + this.container.classList.add("map-container"); + + const wrapper = document.getElementById(elementId); + wrapper.appendChild(this.container); + + this.map = new window.L.Map(this.container, { + center: [state.lat, state.lng], + zoom: state.zoom, + attributionControl: false, + }); + window.L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png").addTo( + this.map + ); + + const onMove = () => { + const center = this.map.getCenter(); + + window.updateAnotherMap(this, { + lng: center.lng, + lat: center.lat, + zoom: this.map.getZoom(), + rotation: 0, + pitch: 0, + }); + }; + + this.map.on("zoom", onMove); + this.map.on("move", onMove); + }, + + update() { + if (!this.map) { + return; + } + + this.map.setView([state.lat, state.lng], state.zoom); + }, + + hide() { + if (this.container) { + this.container.style.display = "none"; + } + }, + }; + \ No newline at end of file From dcd6fea7d57c3c46f58f5a2110000ac1ff41333a Mon Sep 17 00:00:00 2001 From: hire2gis <160482521+hire2gis@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:28:24 +0700 Subject: [PATCH 2/4] JAM-0: Add blank line in the end of file --- osm.js | 1 - 1 file changed, 1 deletion(-) diff --git a/osm.js b/osm.js index 64812f5..7b9e2f7 100644 --- a/osm.js +++ b/osm.js @@ -60,4 +60,3 @@ const osmApi = { } }, }; - \ No newline at end of file From 34a8ca65e775895c9528a0a3e2f0b4dc460f2030 Mon Sep 17 00:00:00 2001 From: Michel Beloshitsky Date: Fri, 29 Nov 2024 09:27:27 +0300 Subject: [PATCH 3/4] Update index.html --- index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.html b/index.html index 350564f..6cb3f10 100644 --- a/index.html +++ b/index.html @@ -49,6 +49,8 @@ position: absolute; top: 10px; right: 10px; + // Лефлет накладывает карту с большим z-уровнем + // (зачем - не знаю), поэтому чтобы контролы были видны - делаем так z-index: 1000; } #langSelect { From 37ec45e054f941c0dcb40cb1eb67348946dd165e Mon Sep 17 00:00:00 2001 From: Michel Beloshitsky Date: Fri, 29 Nov 2024 09:27:32 +0300 Subject: [PATCH 4/4] Update index.html --- index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.html b/index.html index 6cb3f10..efbe5cd 100644 --- a/index.html +++ b/index.html @@ -57,6 +57,8 @@ position: absolute; top: 35px; right: 10px; + // Лефлет накладывает карту с большим z-уровнем + // (зачем - не знаю), поэтому чтобы контролы были видны - делаем так z-index: 1000; }