diff --git a/ddYMap.php b/ddYMap.php index 33b77d4..7d75090 100644 --- a/ddYMap.php +++ b/ddYMap.php @@ -1,46 +1,50 @@ = 5.4. + * @uses MODXEvo.libraries.ddTools >= 0.21 {@link http://code.divandesign.biz/modx/ddtools }. * * @note Attention! The jQuery library should be included on the page. - * @note From the pair of “$geoPos” / “$docField” parameters one is required. + * @note From the pair of “$geoPos” / “$geoPos_docField” parameters one is required. * - * @param $geoPos {comma separated string} - Comma separated longitude and latitude. @required - * @param $docField {string} - A field name with position that is required to be got. - * @param $docId {integer} - Document ID with a field value needed to be received. Default: current document. - * @param $mapElement {string} - Container selector which the map is required to be embed in. Default: '#map'. - * @param $defaultType {'map'; 'satellite'; 'hybrid'; 'publicMap'; 'publicMapHybrid'} - Default map type: 'map' — schematic map, 'satellite' — satellite map, 'hybrid' — hybrid map, 'publicMap' — public map, 'publicMapHybrid' - hybrid public map. Default: 'map'. - * @param $defaultZoom {integer} - Default map zoom. Default: 15. - * @param $icon {string} - An icon to use (relative address). Default: without (default icon). - * @param $iconOffset {comma separated string} - An offset of the icon in pixels (x, y).Basic position: the icon is horizontally centered with respect to x and its bottom position is y. Default: '0,0'. - * @param $scrollZoom {0; 1} - Allow zoom while scrolling. Default: 0. - * @param $mapCenterOffset {comma separated string} - Center offset of the map with respect to the center of the map container in pixels. Default: '0,0'. - * @param $lang {'ru_RU'; 'en_US'; 'ru_UA'; 'uk_UA'; 'tr_TR'} - Map language — locale ID. See http://api.yandex.com/maps/doc/jsapi/2.x/dg/concepts/load.xml for more information. Default: 'ru_RU'. - * @param $scriptsLocation {'head'; 'body';} - The tag where jQuery scripts are included. Default: 'head'. + * @param $geoPos {string_commaSeparated} — Comma separated longitude and latitude. @required + * @param $geoPos_docField {string} — A field name with position that is required to be got. + * @param $geoPos_docId {integer} — Document ID with a field value needed to be received. Default: current document. + * @param $mapElement {string} — Container selector which the map is required to be embed in. Default: '#map'. + * @param $defaultType {'map'|'satellite'|'hybrid'|'publicMap'|'publicMapHybrid'} — Default map type: 'map' — schematic map, 'satellite' — satellite map, 'hybrid' — hybrid map, 'publicMap' — public map, 'publicMapHybrid' - hybrid public map. Default: 'map'. + * @param $defaultZoom {integer} — Default map zoom. Default: 15. + * @param $icon {string} — An icon to use (relative address). Default: without (default icon). + * @param $iconOffset {string_commaSeparated} — An offset of the icon in pixels (x, y).Basic position: the icon is horizontally centered with respect to x and its bottom position is y. Default: '0,0'. + * @param $scrollZoom {0|1} — Allow zoom while scrolling. Default: 0. + * @param $mapCenterOffset {string_commaSeparated} — Center offset of the map with respect to the center of the map container in pixels. Default: '0,0'. + * @param $lang {'ru_RU'|'en_US'|'ru_UA'|'uk_UA'|'tr_TR'} — Map language — locale ID. See http://api.yandex.com/maps/doc/jsapi/2.x/dg/concepts/load.xml for more information. Default: 'ru_RU'. + * @param $scriptsLocation {'head'|'body'} — The tag where jQuery scripts are included. Default: 'head'. * - * @link http://code.divandesign.biz/modx/ddymap/1.6 + * @link http://code.divandesign.biz/modx/ddymap/1.6.1 * - * @copyright 2015–2017 DivanDesign {@link http://www.DivanDesign.biz } + * @copyright 2015–2018 DivanDesign {@link http://www.DivanDesign.biz } */ -//Подключаем modx.ddTools -require_once $modx->getConfig('base_path').'assets/snippets/ddTools/modx.ddtools.class.php'; +//Include MODXEvo.libraries.ddTools +require_once $modx->getConfig('base_path').'assets/libs/ddTools/modx.ddtools.class.php'; -//Для обратной совместимости -extract(ddTools::verifyRenamedParams($params, array( - 'docField' => 'getField', - 'docId' => 'getId' -))); +//Backward compatibility +extract(ddTools::verifyRenamedParams($params, [ + 'geoPos_docField' => ['docField', 'getField'], + 'geoPos_docId' => ['docId', 'getId'] +])); //Если задано имя поля, которое необходимо получить -if (isset($docField)){ - $geoPos = ddTools::getTemplateVarOutput(array($docField), $docId); - $geoPos = $geoPos[$docField]; +if (isset($geoPos_docField)){ + $geoPos = ddTools::getTemplateVarOutput( + [$geoPos_docField], + $geoPos_docId + ); + $geoPos = $geoPos[$geoPos_docField]; } //Где должны быть подключены скрипты @@ -67,7 +71,10 @@ $iconSize = getimagesize($icon); //если смещение не задано сделаем над опорной точкой ценруя по ширине - $resultIconOffset = array($iconSize[0] / -2, $iconSize[1] * -1); + $resultIconOffset = [ + $iconSize[0] / -2, + $iconSize[1] * -1 + ]; if (!empty($iconOffset)){ $iconOffset = explode(',', $iconOffset); //если задано сделает относительно положения по умолчанию @@ -87,7 +94,12 @@ } //Если нужен скролл колесом мыши, упомянем об этом - if (isset($scrollZoom) && $scrollZoom == 1){$inlineScript .= ', scrollZoom: true';} + if ( + isset($scrollZoom) && + $scrollZoom == 1 + ){ + $inlineScript .= ', scrollZoom: true'; + } //Тип карты по умолчанию if (!empty($defaultType)){$inlineScript .= ', defaultType: "'.$defaultType.'"';} //Масштаб карты по умолчанию @@ -99,18 +111,48 @@ if ($scriptsLocation == 'head') { //Подключаем библиотеку карт - $modx->regClientStartupScript('//api-maps.yandex.ru/2.1/?lang=' . $lang, array('name' => 'api-maps.yandex.ru', 'version' => '2.1')); + $modx->regClientStartupScript( + '//api-maps.yandex.ru/2.1/?lang='.$lang, + [ + 'name' => 'api-maps.yandex.ru', + 'version' => '2.1' + ] + ); //Подключаем $.ddYMap - $modx->regClientStartupScript($modx->getConfig('site_url') . 'assets/js/jquery.ddYMap-1.4.min.js', array('name' => '$.ddYMap', 'version' => '1.4')); + $modx->regClientStartupScript( + $modx->getConfig('site_url').'assets/js/jquery.ddYMap-1.4.min.js', + [ + 'name' => '$.ddYMap', + 'version' => '1.4' + ] + ); //Подключаем инлайн-скрипт с инициализацией - $modx->regClientStartupScript('', array('plaintext' => true)); + $modx->regClientStartupScript( + '', + ['plaintext' => true] + ); }else{ //Подключаем библиотеку карт - $modx->regClientScript("", array('name' => 'api-maps.yandex.ru', 'version' => '2.1')); + $modx->regClientScript( + '', + [ + 'name' => 'api-maps.yandex.ru', + 'version' => '2.1' + ] + ); //Подключаем $.ddYMap - $modx->regClientScript("", array('name' => '$.ddYMap', 'version' => '1.4')); + $modx->regClientScript( + '', + [ + 'name' => '$.ddYMap', + 'version' => '1.4' + ] + ); //Подключаем инлайн-скрипт с инициализацией - $modx->regClientScript("", array('plaintext' => true)); + $modx->regClientScript( + '', + ['plaintext' => true] + ); } } -?> +?> \ No newline at end of file