Answer the question
In order to leave comments, you need to log in
How to make a selection on a map with QuadKey?
You need to do clustering on the label server from the map. I'm trying to do as described here https://habr.com/en/post/268621/.
Quadkeys with zoom 23 are generated in the database and stored in the decimal system
Yandex returns when zooming and when moving around the map the parameters - bbox=55.5587,36.9141,56.0537,38.4961&zoom=7
I find the middle of them
public function map()
{
$bbox = explode(',', $_GET['bbox']);
$zoom = $_GET['zoom'];
$lat = $bbox[0] + ($bbox[2] - $bbox[0]) / 2;
$long = $bbox[1] + ($bbox[3] - $bbox[1]) / 2;
//и quadkey этих данных
$quad_key = TileSystem::latLongToQuadKeyDec($lat, $long, $zoom);
$this->getClusters($quad_key, $zoom);
}
public function getClusters( $quad_key, $zoom)
{
$q1 = $quad_key . str_repeat("0", TileSystem::MaxZoom - $zoom);
$q2 = $quad_key . str_repeat("3", TileSystem::MaxZoom - $zoom);
$mask = $q1;
$mask_plus = 1;
$mask = $quad_key . str_repeat("3", $mask_plus);
$mask = $mask . str_repeat("0", TileSystem::MaxZoom - $zoom - $mask_plus);
$q1 = TileSystem::quadKey4ToDec( $q1);
$q2 = TileSystem::quadKey4ToDec( $q2);
$mask = TileSystem::quadKey4ToDec( $mask);
return $this-> findBetweenQuadKeys( $q1, $q2, $mask);
}
public function findBetweenQuadKeys( $quad_key_l, $quad_key_r, $mask)
{
$entities = [];
$sql = "SELECT `quadkey`, MIN(id) AS id, COUNT(id) AS count, AVG(longitude) AS longitude, AVG(latitude) AS latitude ";
$sql .= "FROM `table ` ";
$sql .= "WHERE `quadkey` BETWEEN $quad_key_l AND $quad_key_r ";
$sql .= "GROUP BY (`quadkey` & $mask) ";
if( $stmt = $this->_connection->query( $sql))
{
foreach( $stmt as $row)
$entities[] = $this->_createEntityFromRow( $row);
}
return $entities;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question