public function MapaelMapConfig()
 {
     $cfg = MapaelMap::MapaelConfigArray();
     $holder = null;
     $selected_country_page = null;
     $page = $this->getMapaelPage();
     if (strstr(MapaelMap::getAllowedCountries(), $page->CountryCode)) {
         $holder = $page->CountryHolderPage();
         $selected_country_page = $page;
     } else {
         $holder = $page;
     }
     $default_config = json_decode(file_get_contents(SS_MAPAEL_FOLDER_PATH . '/json/default_config.json'), true);
     if (!isset($cfg['areas'])) {
         $cfg['areas'] = array();
     }
     foreach ($holder->CountryPages() as $country_page) {
         /** @var Page|MapaelCountryPageExtension $country_page */
         if ($country_page->canView()) {
             $cfg['areas'][$country_page->CountryCode]['attrs'] = $default_config['map']['hasLinkArea']['attrs'];
             if ($selected_country_page && $selected_country_page->ID == $country_page->ID) {
                 $cfg['areas'][$country_page->CountryCode]['attrs'] = array_merge($cfg['areas'][$country_page->CountryCode]['attrs'], $default_config['map']['selectedArea']['attrs']);
             }
             $cfg['areas'][$country_page->CountryCode]['href'] = $country_page->Link();
             if ($country_page->Target) {
                 $cfg['areas'][$country_page->CountryCode]['target'] = $country_page->Target;
             }
             foreach ($country_page->MapaelCities() as $city) {
                 /** @var MapaelCity $city */
                 $cid = 'city_' . $city->ID;
                 $cfg['plots'][$cid]['latitude'] = $city->Lat;
                 $cfg['plots'][$cid]['longitude'] = $city->Lng;
                 $cfg['plots'][$cid]['href'] = $city->Link();
                 if ($city->Target) {
                     $cfg['plots'][$cid]['target'] = $city->Target;
                 }
                 $cfg['plots'][$cid]['tooltip']['content'] = $city->Name;
                 if ($city->HidePlot) {
                     $cfg['plots'][$cid]['size'] = 0;
                     $cfg['plots'][$cid]['attrs']['stroke-width'] = 0;
                 }
                 foreach ($city->LinkedToCities() as $linkedCity) {
                     $lcid = 'city_' . $linkedCity->ID;
                     /** @var MapaelCity $linkedCity */
                     $lc_link = $cid . '_' . $lcid;
                     $cfg['links'][$lc_link] = array('factor' => "-0.3", 'between' => array($cid, $lcid), 'attrs' => array("stroke-width" => 2), 'tooltip' => array('content' => $linkedCity->LinkTooltipContent));
                     if ($linkedCity->LinkHref) {
                         $cfg['links'][$lc_link]['href'] = $linkedCity->LinkHref;
                         if ($linkedCity->LinkTarget) {
                             $cfg['links'][$lc_link]['target'] = $linkedCity->LinkTarget;
                         }
                     }
                 }
             }
         }
     }
     return json_encode($cfg);
 }
 public function updateCMSFields(FieldList $fields)
 {
     /** @var Page|MapaelCountryPageExtension $page */
     $page = $this->getOwner();
     $labels = $page->fieldLabels();
     $name = MapaelCountryPage::create()->i18n_singular_name();
     $tab = $fields->findOrMakeTab('Root.CountryPageTab', $name);
     $tab->push(new TabSet('CountryPageTabSet', $main = new Tab('CountryPageMain', _t('CMSMain.TabContent', 'Content')), $cities = new Tab('CountryPageCities', $page->fieldLabel('MapaelCities'))));
     $arr = array();
     foreach (MapaelMap::getAreasArray() as $code => $attrs) {
         $arr[$code] = $attrs['tooltip']['content'];
     }
     $main->push($dd = new CountryDropdownField('CountryCode', $page->fieldLabel('CountryCode'), $arr, $page->CountryCode));
     $dd->setEmptyString(_t(__CLASS__ . '.CountryCodeNone', 'None'));
     $main->push($tf = self::getTooltipContentField($page));
     $tf->setDescription(MapaelMap::getCountryName($page->CountryCode));
     $main->push(self::getTargetField($page));
     $main->push(self::getHrefField($page));
     if ($page->CountryHolderPageID) {
         $main->push(new ReadonlyField('CountryHolderPageReadonly', $page->fieldLabel('CountryHolderPage'), $page->CountryHolderPage()->Title));
     }
     $cities->push(GridField::create('MapaelCities', $page->fieldLabel('MapaelCities'), $page->MapaelCities(), GridFieldConfig_RelationEditor::create()));
 }