/** * Returns json * @return string */ public function getJson() { $data = ['type' => $this->type, 'coordinates' => []]; if (!count($this->points) && ($map = Api::getCurrentMap())) { $data['coordinates'] = new JsExpression($map->getId() . '.getCenter()'); } elseif (count($this->points) === 1) { $data['coordinates'] = $this->points[0]->getCoordinates(); } else { foreach ($this->points as $point) { $data['coordinates'][] = $point->getCoordinates(); } } return Json::encode($data); }
/** * Register scripts for map control */ private function registerScripts() { Api::registerApiFile($this->map); $js = "\nymaps.ready(function() {\n" . (string) $this->map . "\n});"; \Yii::$app->view->registerJs($js, View::POS_READY); }