Esempio n. 1
0
 /**
  * Register the script for the map to be rendered according to the configurations on the LeafLet
  * component.
  */
 public function registerScript()
 {
     $view = $this->getView();
     LeafLetAsset::register($view);
     $this->leafLet->getPlugins()->registerAssetBundles($view);
     $id = $this->options['id'];
     $name = $this->leafLet->name;
     $js = $this->leafLet->getJs();
     $clientOptions = $this->leafLet->clientOptions;
     if ($clientOptions !== false) {
         $options = empty($clientOptions) ? '{}' : Json::encode($clientOptions);
         array_unshift($js, "var {$name} = L.map('{$id}', {$options});");
         if ($this->leafLet->getTileLayer() !== null) {
             $js[] = $this->leafLet->getTileLayer()->encode();
         }
     } else {
         return;
     }
     $clientEvents = $this->leafLet->clientEvents;
     if (!empty($clientEvents)) {
         foreach ($clientEvents as $event => $handler) {
             $js[] = "{$name}.on('{$event}', {$handler});";
         }
     }
     $view->registerJs("function {$name}_init(){\n" . implode("\n", $js) . "}\n{$name}_init();");
 }
Esempio n. 2
0
 /**
  * Register the script for the map to be rendered according to the configurations on the LeafLet
  * component.
  */
 public function registerScript()
 {
     $view = $this->getView();
     LeafLetAsset::register($view);
     $this->leafLet->getPlugins()->registerAssetBundles($view);
     $id = $this->options['id'];
     $name = $this->leafLet->name;
     $js = $this->leafLet->getJs();
     $clientOptions = $this->leafLet->clientOptions;
     // for map load event to fire, we have to postpone setting view, until events are bound
     // see https://github.com/Leaflet/Leaflet/issues/3560
     $lateInitClientOptions['center'] = Json::encode($clientOptions['center']);
     $lateInitClientOptions['zoom'] = $clientOptions['zoom'];
     unset($clientOptions['center']);
     unset($clientOptions['zoom']);
     $options = empty($clientOptions) ? '{}' : Json::encode($clientOptions, LeafLet::JSON_OPTIONS);
     array_unshift($js, "var {$name} = L.map('{$id}', {$options});");
     if ($this->leafLet->getTileLayer() !== null) {
         $js[] = $this->leafLet->getTileLayer()->encode();
     }
     $clientEvents = $this->leafLet->clientEvents;
     if (!empty($clientEvents)) {
         foreach ($clientEvents as $event => $handler) {
             $js[] = "{$name}.on('{$event}', {$handler});";
         }
     }
     $js[] = "{$name}.setView({$lateInitClientOptions['center']}, {$lateInitClientOptions['zoom']});";
     $view->registerJs("function {$name}_init(){\n" . implode("\n", $js) . "}\n{$name}_init();");
 }