Skip to content

Commit

Permalink
Обновлен до последнего состояния разработки
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirocow committed Oct 12, 2014
1 parent 7e66594 commit 547821a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 76 deletions.
56 changes: 28 additions & 28 deletions mirocow/yandexmaps/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class Api extends Component
/** @var string */
public $protocol = 'http';

/** @var string */
public $uri = 'api-maps.yandex.ru';
/** @var string */
public $api_version = '2.0-stable';
/** @var string */
public $uri = 'api-maps.yandex.ru';

/** @var string */
public $api_version = '2.0-stable';

/** @var string */
public $language = 'ru-RU';
Expand Down Expand Up @@ -169,45 +169,45 @@ public function generateMap(Map $map, $var = null)
$jsObj = array();
$objBegin = false;
$objects = '';
$clusterer = "var points = [];\n";
$clusterer = "var points = [];\n";

foreach ($map->objects as $i => $object) {
if (!is_string($object) && !$object instanceof GeoObject) {
if ($objBegin) {
$jsObj[] = $object;
} elseif(is_callable($object)) {
try{
$object = $object->__invoke();
$js .= "\n$object";
} catch(\Exception $e){
//
}
} else {
$js .= "\n$object";
}
try{
$object = $object->__invoke();
$js .= "\n$object";
} catch(\Exception $e){
//
}
} else {
$js .= "\n$object";
}
} else {
$objBegin = true;
// Load only GeoObjects instanceof GeoObject
if ($object instanceof GeoObject) {
$_object = $this->generateObject($object);
// use Clusterer
if($map->use_clusterer && $object instanceof objects\Placemark){
$clusterer .= "points[$i] = $_object;\n";
} else {
$objects .= ".add($_object)\n";
}

// use Clusterer
if($map->use_clusterer && $object instanceof objects\Placemark){
$clusterer .= "points[$i] = $_object;\n";
} else {
$objects .= ".add($_object)\n";
}

} elseif(is_string($_object)) {
$js .= "$_object;\n";
}
}
}
if($map->use_clusterer){
$js .= "$clusterer\nvar clusterer = new ymaps.Clusterer();clusterer.add(points);";
$objects .= ".add(clusterer)";
}

if($map->use_clusterer){
$js .= "$clusterer\nvar clusterer = new ymaps.Clusterer();clusterer.add(points);";
$objects .= ".add(clusterer)";
}

if (!empty($objects)){
$js .= "\nMaps['$id'].geoObjects$objects;\n";
Expand Down
2 changes: 1 addition & 1 deletion mirocow/yandexmaps/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Map extends JavaScript implements Interfaces\GeoObjectCollection, Interfac
/** @var array */
public $options = array();

public $use_clusterer = false;
public $use_clusterer = false;

/** @var string */
private $_id;
Expand Down
71 changes: 24 additions & 47 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,51 +78,28 @@ echo YandexCanvas::widget([

### mirocow\yandexmaps\Clusterer ###

```php

$points = [];

$points[] = new mirocow\yandexmaps\objects\Placemark(
[$point->latitude, $point->longitude],
[
'balloonContentBody' => 'Annonunce text',
'hintContent' => 'next>>>'
],
[
'iconImageHref' => $img_path,
'iconImageSize' => [29, 29],
'balloonIconImageHref' => $img_path,
'balloonIconImageSize' => [29, 29],
'hasBalloon' => true
]
);

$map = new YandexMap('yandex_map_polygon',
[
'center' => ['55.7372', '37.6066'],
'zoom' => 10,
// Enable zoom with mouse scroll
'behaviors' => array('default', 'scrollZoom'),
'type' => "yandex#map",
],
[
//'minZoom' => 9,
//'maxZoom' => 20,
'controls' => [
"new ymaps.control.SmallZoomControl()",
"new ymaps.control.TypeSelector(['yandex#map', 'yandex#satellite'])",
],
'objects' => $points
]
);

$map->use_clusterer = true;

echo YandexCanvas::widget([
'htmlOptions' => [
'style' => 'height: 500px; width: 370px;',
],
'map' => $map,
]);
```js
for (var i in map_point) {
points[i] = new ymaps.GeoObject({
geometry : {
type: 'Point',
coordinates : [map_point[i]['lat'],map_point[i]['lng']]
},
properties : {
balloonContentBody : map_point[i]['body']
// hintContent : 'подробнее'
}
},
{
iconImageHref: '/i/' + map_point[i]['spec']+'.png',
iconImageSize: [29,29],
balloonIconImageHref: '/i/' + map_point[i]['spec']+'.png',
balloonIconImageSize: [29,29],
hasBalloon: true
});
}

var clusterer = new ymaps.Clusterer();
clusterer.add(points);
map.geoObjects.add(clusterer);
```

0 comments on commit 547821a

Please sign in to comment.