From 753333d7f2801a5f86a3dd5e169e49d113cb5a90 Mon Sep 17 00:00:00 2001 From: n1rwana Date: Fri, 4 Aug 2023 00:18:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=B0=D1=80=D1=82=D0=B0=20=D0=B1=D0=BB?= =?UTF-8?q?=D0=B8=D0=B6=D0=B0=D0=B9=D1=88=D0=B8=D1=85=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/Models/sql/get-nearest-posts.tsql | 3 +- Web/static/js/al_wall.js | 53 +++++++++++++++++++++------ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Web/Models/sql/get-nearest-posts.tsql b/Web/Models/sql/get-nearest-posts.tsql index d844a3ac..5da7faa8 100644 --- a/Web/Models/sql/get-nearest-posts.tsql +++ b/Web/Models/sql/get-nearest-posts.tsql @@ -3,8 +3,9 @@ SELECT *, POW(69.1 * (? - geo_lat), 2) + POW(69.1 * (? - geo_lon) * COS(RADIANS(geo_lat)), 2) ) AS distance -FROM Posts +FROM posts WHERE id <> ? +AND FROM_UNIXTIME(created) >= DATE_SUB(NOW(), INTERVAL 1 MONTH) HAVING distance < 1 AND distance IS NOT NULL ORDER BY distance LIMIT 25; diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index f28bd997..418b89c9 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -275,7 +275,7 @@ async function initGeo(tid) { $(`#post-buttons${tid} .post-has-geo`).text(`${tr("geotag")}: ${marker.name}`); $(`#post-buttons${tid} .post-has-geo`).show(); }), Function.noop]); - + const element = document.getElementById('osm-map'); element.style = 'height: 600px;'; @@ -378,12 +378,8 @@ function getNearPosts(owner_id, virtual_id) { }); } -function openNearPosts(posts) { - console.log(posts); - let MsgBody = ""; - - posts.posts.forEach((post) => { - MsgBody += ` +function getPostPopup(post) { + return ` @@ -416,9 +412,44 @@ function openNearPosts(posts) {
`; - }); +} - if (posts.need_count) MsgBody += "

Показаны первые 25 постов
" +function openNearPosts(posts) { + if (posts.posts.length > 0) { + let MsgTxt = "
"; + MsgTxt += "

Показано последние 25 постов за месяц
"; - MessageBox("Ближайшие посты", MsgBody, ["OK"], [Function.noop]); -} \ No newline at end of file + MessageBox("Ближайшие посты", MsgTxt, ["OK"], [Function.noop]); + + let element = document.getElementById('osm-map'); + element.style = 'height: 600px;'; + + let markerLayers = L.layerGroup(); + let map = L.map(element, {attributionControl: false}); + + markerLayers.addTo(map); + + let markersBounds = []; + + posts.posts.forEach((post) => { + let marker = L.marker(L.latLng(post.geo.lat, post.geo.lng)).addTo(map); + marker.bindPopup(getPostPopup(post)); + markerLayers.addLayer(marker); + markersBounds.push(marker.getLatLng()); + }) + + let bounds = L.latLngBounds(markersBounds); + map.fitBounds(bounds); + + L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors' + }).addTo(map); + + $(".ovk-diag-cont").width('50%'); + setTimeout(function () { + map.invalidateSize() + }, 100); + } else { + MessageBox("Ближайшие посты", "
Нет ближайших постов :(
", ["OK"], [Function.noop]); + } +}