mirror of
https://github.com/openvk/openvk
synced 2025-01-11 02:19:39 +03:00
Better geo points
This commit is contained in:
parent
92690767a1
commit
5a7c99be74
4 changed files with 62 additions and 15 deletions
|
@ -117,7 +117,7 @@ final class Wall extends VKAPIRequestHandler
|
|||
$geoarray = $post->getGeo();
|
||||
|
||||
$geo = [
|
||||
"coordinates" => $geoarray["lat"] . " " . $geoarray["lng"],
|
||||
"coordinates" => $geoarray->lat . " " . $geoarray->lng,
|
||||
"showmap" => 1,
|
||||
"type" => "point"
|
||||
];
|
||||
|
@ -392,7 +392,7 @@ final class Wall extends VKAPIRequestHandler
|
|||
];
|
||||
}
|
||||
|
||||
function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = "", float $latitude, float $longitude): object
|
||||
function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = "", ?float $latitude = NULL, ?float $longitude = NULL, ?string $geo_name = NULL): object
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
@ -433,11 +433,40 @@ final class Wall extends VKAPIRequestHandler
|
|||
if(empty($message) && empty($attachments))
|
||||
$this->fail(100, "Required parameter 'message' missing.");
|
||||
|
||||
$geo = array(
|
||||
"name" => null,
|
||||
"lat" => $latitude,
|
||||
"lng" => $longitude,
|
||||
);
|
||||
$geo = NULL;
|
||||
|
||||
if ($latitude && $longitude) {
|
||||
$geo = array(
|
||||
"name" => null,
|
||||
"lat" => $latitude,
|
||||
"lng" => $longitude,
|
||||
);
|
||||
|
||||
if ($latitude > 90 || $latitude < -90 || $longitude > 180 || $longitude < -180) {
|
||||
$this->fail(100, "Invalid latitude or longitude");
|
||||
}
|
||||
|
||||
if (strlen(trim($geo_name))) {
|
||||
$geo["name"] = $geo_name;
|
||||
} else {
|
||||
$info = file_get_contents("https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2", false, stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => implode("\r\n", [
|
||||
'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2',
|
||||
"Referer: https://$_SERVER[SERVER_NAME]/"
|
||||
])
|
||||
]
|
||||
]));
|
||||
|
||||
if ($info) {
|
||||
$info = json_decode($info, true, JSON_UNESCAPED_UNICODE);
|
||||
if (key_exists("place_id", $info)) {
|
||||
$geo["name"] = $info["name"] ?? $info["display_name"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$post = new Post;
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
<div n:if="$post->getGeo()" class="post-signature">
|
||||
<a onclick="javascript:openGeo({$post->getGeo()}, {$post->getOwner()->getId()}, {$post->getVirtualId()})">
|
||||
<img src="/assets/packages/static/openvk/img/geo.svg">
|
||||
<b>{_geotag}</b>: {$post->getGeo()->name}
|
||||
<b>{_geotag}</b>: {$post->getGeo()->name ?? tr("admin_open")}
|
||||
</a>
|
||||
</div>
|
||||
<div n:if="$post->isAd()" style="color:grey;">
|
||||
|
|
|
@ -69,7 +69,9 @@
|
|||
</div>
|
||||
<div n:if="$post->getGeo()" style="padding: 4px;">
|
||||
<div style="border-bottom: #ECECEC solid 1px;" />
|
||||
<div style="cursor: pointer; padding: 4px;" onclick="javascript:openGeo({$post->getGeo()}, {$post->getOwner()->getId()}, {$post->getVirtualId()})"><b>{_geotag}</b>: {$post->getGeo()->name}</div>
|
||||
<div style="cursor: pointer; padding: 4px;" onclick="javascript:openGeo({$post->getGeo()}, {$post->getOwner()->getId()}, {$post->getVirtualId()})">
|
||||
<b>{_geotag}</b>: <a>{$post->getGeo()->name ?? tr("admin_open")}</a>
|
||||
</div>
|
||||
</div>
|
||||
<div n:if="$post->isAd()" style="color:grey;">
|
||||
<br/>
|
||||
|
|
|
@ -353,8 +353,9 @@ function openGeo(data, owner_id, virtual_id) {
|
|||
let map = L.map(element, {attributionControl: false});
|
||||
let target = L.latLng(data.lat, data.lng);
|
||||
map.setView(target, 15);
|
||||
|
||||
let marker = L.marker(target).addTo(map);
|
||||
marker.bindPopup(data.name).openPopup();
|
||||
marker.bindPopup(data.name ?? tr("geotag")).openPopup();
|
||||
|
||||
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||
|
@ -404,7 +405,7 @@ function getPostPopup(post) {
|
|||
</div>
|
||||
<div style="padding: 4px;">
|
||||
<div style="border-bottom: #ECECEC solid 1px;"></div>
|
||||
<div style="cursor: pointer; padding: 4px;"><b>${tr("geotag")}</b>: ${post.geo.name}</div>
|
||||
<div style="cursor: pointer; padding: 4px;"><b>${tr("geotag")}</b>: ${post.geo.name ?? tr("admin_open")}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -430,12 +431,27 @@ function openNearPosts(posts) {
|
|||
markerLayers.addTo(map);
|
||||
|
||||
let markersBounds = [];
|
||||
let coords = [];
|
||||
|
||||
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());
|
||||
if (coords.includes(`${post.geo.lat} ${post.geo.lng}`)) {
|
||||
markerLayers.getLayers().forEach((marker) => {
|
||||
if (marker.getLatLng().lat === post.geo.lat && marker.getLatLng().lng === post.geo.lng) {
|
||||
let content = marker.getPopup()._content += getPostPopup(post);
|
||||
if (!content.startsWith(`<div style="max-height: 300px; overflow-y: auto;">`))
|
||||
content = `<div style="max-height: 300px; overflow-y: auto;">${content}`;
|
||||
|
||||
marker.getPopup().setContent(content);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
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());
|
||||
}
|
||||
|
||||
coords.push(`${post.geo.lat} ${post.geo.lng}`);
|
||||
})
|
||||
|
||||
let bounds = L.latLngBounds(markersBounds);
|
||||
|
|
Loading…
Reference in a new issue