Skip to content

Commit

Permalink
Version 1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilyas Ronef committed Feb 2, 2018
2 parents f46a31f + 79ac7db commit 80033d8
Showing 1 changed file with 78 additions and 36 deletions.
114 changes: 78 additions & 36 deletions ddYMap.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
<?php
/**
* ddYMap
* @version 1.6 (2017-11-28)
* @version 1.6.1 (2018-02-02)
*
* @desc A snippet that allows Yandex.Maps to be rendered on a page in a simple way.
*
* @uses The library modx.ddTools 0.12.
* @uses PHP >= 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];
}

//Где должны быть подключены скрипты
Expand All @@ -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);
//если задано сделает относительно положения по умолчанию
Expand All @@ -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.'"';}
//Масштаб карты по умолчанию
Expand All @@ -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('<script type="text/javascript">'.$inlineScript.'</script>', array('plaintext' => true));
$modx->regClientStartupScript(
'<script type="text/javascript">'.$inlineScript.'</script>',
['plaintext' => true]
);
}else{
//Подключаем библиотеку карт
$modx->regClientScript("<script defer type='text/javascript' src='//api-maps.yandex.ru/2.1/?lang=" . $lang . "'></script>", array('name' => 'api-maps.yandex.ru', 'version' => '2.1'));
$modx->regClientScript(
'<script defer type="text/javascript" src="//api-maps.yandex.ru/2.1/?lang='.$lang.'"></script>',
[
'name' => 'api-maps.yandex.ru',
'version' => '2.1'
]
);
//Подключаем $.ddYMap
$modx->regClientScript("<script defer type='text/javascript' src='" . $modx->getConfig('site_url') . "assets/js/jquery.ddYMap-1.4.min.js'></script>", array('name' => '$.ddYMap', 'version' => '1.4'));
$modx->regClientScript(
'<script defer type="text/javascript" src="'.$modx->getConfig('site_url').'assets/js/jquery.ddYMap-1.4.min.js"></script>',
[
'name' => '$.ddYMap',
'version' => '1.4'
]
);
//Подключаем инлайн-скрипт с инициализацией
$modx->regClientScript("<script defer type='text/javascript'>".$inlineScript."</script>", array('plaintext' => true));
$modx->regClientScript(
'<script defer type="text/javascript">'.$inlineScript.'</script>',
['plaintext' => true]
);
}
}
?>
?>

0 comments on commit 80033d8

Please sign in to comment.