mirror of
https://github.com/openvk/openvk
synced 2025-01-26 17:49:58 +03:00
Карта ближайших постов
This commit is contained in:
parent
f909976348
commit
753333d7f2
2 changed files with 44 additions and 12 deletions
|
@ -3,8 +3,9 @@ SELECT *,
|
||||||
POW(69.1 * (? - geo_lat), 2) +
|
POW(69.1 * (? - geo_lat), 2) +
|
||||||
POW(69.1 * (? - geo_lon) * COS(RADIANS(geo_lat)), 2)
|
POW(69.1 * (? - geo_lon) * COS(RADIANS(geo_lat)), 2)
|
||||||
) AS distance
|
) AS distance
|
||||||
FROM Posts
|
FROM posts
|
||||||
WHERE id <> ?
|
WHERE id <> ?
|
||||||
|
AND FROM_UNIXTIME(created) >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
|
||||||
HAVING distance < 1 AND distance IS NOT NULL
|
HAVING distance < 1 AND distance IS NOT NULL
|
||||||
ORDER BY distance
|
ORDER BY distance
|
||||||
LIMIT 25;
|
LIMIT 25;
|
||||||
|
|
|
@ -378,12 +378,8 @@ function getNearPosts(owner_id, virtual_id) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openNearPosts(posts) {
|
function getPostPopup(post) {
|
||||||
console.log(posts);
|
return `<a style="color: inherit; display: block; margin-bottom: 8px;" href="${post.url}" target="_blank">
|
||||||
let MsgBody = "";
|
|
||||||
|
|
||||||
posts.posts.forEach((post) => {
|
|
||||||
MsgBody += `<a style="color: inherit; display: block; margin-bottom: 8px;" href="${post.url}" target="_blank">
|
|
||||||
<table border="0" style="font-size: 11px;" class="post">
|
<table border="0" style="font-size: 11px;" class="post">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -416,9 +412,44 @@ function openNearPosts(posts) {
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</a>`;
|
</a>`;
|
||||||
});
|
}
|
||||||
|
|
||||||
if (posts.need_count) MsgBody += "<br/><br/><center style='color: grey;'>Показаны первые 25 постов</center>"
|
function openNearPosts(posts) {
|
||||||
|
if (posts.posts.length > 0) {
|
||||||
MessageBox("Ближайшие посты", MsgBody, ["OK"], [Function.noop]);
|
let MsgTxt = "<div id=\"osm-map\"></div>";
|
||||||
|
MsgTxt += "<br /><br /><center style='color: grey;'>Показано последние 25 постов за месяц</center>";
|
||||||
|
|
||||||
|
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: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||||
|
}).addTo(map);
|
||||||
|
|
||||||
|
$(".ovk-diag-cont").width('50%');
|
||||||
|
setTimeout(function () {
|
||||||
|
map.invalidateSize()
|
||||||
|
}, 100);
|
||||||
|
} else {
|
||||||
|
MessageBox("Ближайшие посты", "<center style='color: grey;'>Нет ближайших постов :(</center>", ["OK"], [Function.noop]);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue