Skip to content

Commit

Permalink
Version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilyas Ronef committed Mar 16, 2014
2 parents d275d94 + d6b0ed3 commit fc1803e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
17 changes: 0 additions & 17 deletions assets/js/jquery.ddYMap-1.0.min.js

This file was deleted.

24 changes: 24 additions & 0 deletions assets/js/jquery.ddYMap-1.1.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* jQuery ddYMap Plugin
* @version 1.1 (2014-03-16)
*
* @desc A jQuery library that allows Yandex.Maps to be rendered on a page in a simple way.
*
* @uses jQuery 1.10.2.
* @uses Yandex.Maps 2.0-stable.
*
* Parameters of the “$.fn.ddYMap” method (transferred as plain object).
* @param latLng {array} - Comma separated longitude and latitude. @required
* @param zoom {integer} - Default map zoom. Default: 15.
* @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 scrollZoom {boolean} - Allow zoom while scrolling. Default: false.
* @param placemarkOptions {plain object} - Placemark options. Default: {}.
*
* @link http://code.divandesign.biz/jquery/ddymap/1.1
*
* @copyright 2014, DivanDesign
* http://www.DivanDesign.biz
*/

(function(b){b.extend(!0,{ddYMap:{defaults:{latLng:[],element:"map",zoom:15,defaultType:"map",scrollZoom:!1,placemarkOptions:{}},init:function(a){a=b.extend({},this.defaults,a);b.isArray(a.latLng)&&2==a.latLng.length&&ymaps.ready(function(){var b=new ymaps.Map(a.element,{center:a.latLng,zoom:a.zoom,type:"yandex#"+a.defaultType});b.controls.add("zoomControl").add("typeSelector").add("scaleLine").add("mapTools");a.scrollZoom&&b.behaviors.enable("scrollZoom");b.geoObjects.add(new ymaps.Placemark(a.latLng,
{},a.placemarkOptions))})}}});b.fn.ddYMap=function(a){var c=b.ddYMap;return b(this).each(function(){c.init(b.extend(a,{element:b(this).get(0)}))})}})(jQuery);
39 changes: 23 additions & 16 deletions ddYMap.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
<?php
/**
* ddYMap.php
* @version 1.1.1 (2013-10-02)
*
* @version 1.2 (2014-03-16)
*
* @desc A snippet that allows Yandex.Maps to be rendered on a page in a simple way.
*
* @uses The snippet ddGetDocumentField 2.4 (if position getting from another field is required, see $geoPos).
* @uses The library modx.ddTools 0.11 (if position getting from another field is required, see “$getField” and “$getId”).
*
* @note Attention! The jQuery library should be included on the page.
* @note From the pair of field/getField parameters one is required.
* @note From the pair of “$field” / “$getField parameters one is required.
*
* @param $geoPos {comma separated string} - Comma separated longitude and latitude. @required
* @param $getField {string} - A field name with position that is required to be got.
* @param $getId {integer} - Document ID with a field value needed to be received. Default: current document.
* @param $mapElementId {string} - Container ID which the map is required to be embed in. Default: 'map'.
* @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.
*
* @link http://code.divandesign.biz/modx/ddymap/1.1.1
*
* @copyright 2013, DivanDesign
* @link http://code.divandesign.biz/modx/ddymap/1.2
*
* @copyright 2014, DivanDesign
* http://www.DivanDesign.biz
*/

//Если задано имя поля, которое необходимо получить
if (isset($getField)){
$geoPos = $modx->runSnippet('ddGetDocumentField', array(
'id' => $getId,
'field' => $getField
));
//Подключаем modx.ddTools
require_once $modx->getConfig('base_path').'assets/snippets/ddTools/modx.ddtools.class.php';

$geoPos = ddTools::getTemplateVarOutput(array($getField), $getId);
$geoPos = $string[$getField];
}

//Если координаты заданы и не пустые
if (!empty($geoPos)){
$mapElementId = isset($mapElementId) ? $mapElementId : 'map';
$mapElement = isset($mapElement) ? $mapElement : '#map';

//Подключаем библиотеку карт
$modx->regClientStartupScript('http://api-maps.yandex.ru/2.0-stable/?load=package.standard&amp;lang=ru-RU', array('name' => 'api-maps.yandex.ru', 'version' => '2.0-stable'));
//Подключаем $.ddYMap
$modx->regClientStartupScript('assets/js/jquery.ddYMap-1.0.min.js', array('name' => '$.ddYMap', 'version' => '1.0'));
$modx->regClientStartupScript($modx->getConfig('site_url').'assets/js/jquery.ddYMap-1.1.min.js', array('name' => '$.ddYMap', 'version' => '1.1'));

//Инлайн-скрипт инициализации
$inlineScript = '(function($){$(function(){$.ddYMap.init({elementId: "'.$mapElementId.'", latLng: new Array('.$geoPos.')';
$inlineScript = '(function($){$(function(){$("'.$mapElement.'").ddYMap({latLng: new Array('.$geoPos.')';

//Если иконка задана
if (!empty($icon)){
Expand All @@ -68,7 +71,7 @@
$inlineScript .= ', placemarkOptions: {
iconImageHref: "'.$icon.'",
iconImageSize: ['.$iconSize[0].', '.$iconSize[1].'],
iconImageOffset: ['.$resultIconOffset[0].', '.$resultIconOffset[1].']
iconImageOffset: ['.round($resultIconOffset[0]).', '.round($resultIconOffset[1]).']
}';

fclose($iconHandle);
Expand All @@ -77,6 +80,10 @@

//Если нужен скролл колесом мыши, упомянем об этом
if (isset($scrollZoom) && $scrollZoom == 1){$inlineScript .= ', scrollZoom: true';}
//Тип карты по умолчанию
if (!empty($defaultType)){$inlineScript .= ', defaultType: "'.$defaultType.'"';}
//Масштаб карты по умолчанию
if (!empty($defaultZoom)){$inlineScript .= ', zoom: '.$defaultZoom;}

$inlineScript .= '});});})(jQuery);';

Expand Down

0 comments on commit fc1803e

Please sign in to comment.