Files
register/marko_unpacked/marko/portal/views/mobile-api/explore-objects-map.php
T
Admin Nasledstvo ac168868ee Initial import
2026-05-01 20:52:04 +03:00

86 lines
2.5 KiB
PHP

<?php
$lat = $_GET['lat'] ?? 42.698334;
$lon = $_GET['lon'] ?? 23.319941;
$dist = $_GET['dist'] ?? 50;
?>
<link rel="stylesheet" href="<?= Yii::$app->params['portal'] ?>/_public/plugins/leafletjs/leaflet.css">
<script src="<?= Yii::$app->params['portal'] ?>/_public/plugins/leafletjs/leaflet.js"></script>
<style>
#map {
width: 100%;
height: 100%;
}
body {
padding: 0;
margin: 0;
}
.leaflet-left {
right: 10px;
left: auto;
}
.leaflet-control-attribution.leaflet-control a {
display: none;
}
.leaflet-control-container {
display: none;
}
</style>
<div id="map"></div>
<script>
let lang = '<?= Yii::$app->language ?>'
let host = '<?= Yii::$app->params['portal'] ?>'
let addedPoints = [];
let mapOptions = {
center: [<?=$lat ?>, <?= $lon ?>],
zoom: 13
}
let map = new L.map('map', mapOptions);
let layer = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
map.addLayer(layer);
let marker = new L.Marker([<?=$lat?>, <?= $lon?>]);
marker.addTo(map);
let icon = L.icon({
iconUrl: '/_public/plugins/leafletjs/images/pin-b.png',
iconSize: [40, 40]
});
let iconBlue = L.icon({
iconUrl: '/_public/plugins/leafletjs/images/point-blue.png',
iconSize: [30, 30]
});
marker.setIcon(icon)
function addPoints() {
const xhr = new XMLHttpRequest()
xhr.open('get', `${host}/${lang}/remote/get-nearest-objects/?lat=<?= $lat ?>&lon=<?= $lon ?>&dist=<?= $dist ?>&explorer=1`)
if(addedPoints.length > 0) {
addedPoints.forEach(pointToDelete => {
map.removeLayer(pointToDelete)
})
}
xhr.responseType = 'json';
xhr.onload = function () {
if (xhr.response) {
const points = xhr.response;
points.forEach(p => {
if (p.latitude !== '<?= $lat?>' && p.longitude !== '<?= $lon?>') {
let point = new L.Marker([p.latitude, p.longitude]);
point.setIcon(iconBlue)
point.addTo(map);
addedPoints.push(point)
point.addEventListener('click', () => {
window.parent.postMessage(JSON.stringify(p), '*');
})
}
})
}
}
xhr.send();
}
setTimeout(function () {
addPoints()
}, 50)
</script>