sfYandexMapPlugin - 1.0.2

An easy, object-oriented, PHP abstraction of the Yandex Maps API

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfYandexMapPlugin

The sfYandexMap plugin provides helpers and an objet-oriented PHP abstraction to the Yandex Maps API to ease the process of adding a Yandex Map and customising it in your symfony projects.

The sfYandexMap plugin is based on the sfEasyGMap plugin. You can reffer to sfEasyGMap documentation if something is missed here.

Installation

  • Install the plugin

    $ symfony plugin:install sfYandexMapPlugin (Not tested)
    
    or in your plugins directory :
    
    $ svn co http://svn.symfony-project.com/plugins/sfYandexMapPlugin sfYandexMapPlugin 
    
  • Get some Yandex Maps API keys for your production and development environments (requires registration)

    http://api.yandex.ru/maps/form.xml
    
  • Put the keys in your app.yml file

     all:
       yandex_maps_api:
         keys: 
           dev.acobby.com:          'AJ0hFUoBAAAA4xyPBgMA9FlAnrkT1tvl_TDpg8LVnl-3MRUAAAAAAAAAAADFVEROOs0UTPbbcVz7bCOmN-BrDw==' 
           default:                 'AJ0hFUoBAAAA4xyPBgMA9FlAnrkT1tvl_TDpg8LVnl-3MRUAAAAAAAAAAADFVEROOs0UTPbbcVz7bCOmN-BrDw=='
           127.0.0.1:               'AMUhFUoBAAAAXjroMQQAhoR9XwEb6xzd8nV9ox_GLrpYGBYAAAAAAAAAAACkgTGHXjMIjkshSozi76gBwVeiNg=='
    
  • Optional: enable the sample module in your settings.yml: sfYandexMapPlugin

        [php]
        all:
          .settings:
            enabled_modules:      [default, sfYandexMapPlugin]
    
  • Clear your cache

    $ php symfony cc
    

Examples

All samples are available in the sfYandexMapPlugin module of the plugin

IMPORTANT ! The javascript in the samples will not work unless you put the js files in your web directory.

    $ ln -s ../plugins/sfYandexMapPlugin/web web/sfYandexMapPlugin

or

    $ php symfony plugin:publish-assets
  • Sample 1

    Add some markers on a map, using longitudes and latitudes

    • In the action:

      $this->yMap = new YMap();
      $this->yMap->addMarker(new YMapMarker(30.45,50.42));
      $this->yMap->addMarker(new YMapMarker(30.44,50.43));
      
    • In the template:

      <?php use_helper('Javascript','YMap') ?>
      
      <?php include_map($yMap,array('width'=>'512px','height'=>'400px')); ?>
      
      <!-- Javascript included at the bottom of the page -->
      <?php include_map_javascript($yMap); ?>
      
  • Sample 2

    Geocode some addresses and open an info window if the user clicks on a marker

    • In the action:

      $this->yMap = new YMap();
      
      // some places in the world
      $addresses = array(
        'Киев, Хрещатик',
        'Киев, пр. Победы 69'
      );
      
      foreach ($addresses as $address)
      {
        $geocoded_address = $this->yMap->geocodeXml($address);
        $yMapMarker = new YMapMarker($geocoded_address->getLng(),$geocoded_address->getLat());
        $yMapMarker->addHtmlInfoWindow('<b>Address:</b><br />'.$address); 
        $this->yMap->addMarker($yMapMarker);
      }
      
    • In the template:

      <?php use_helper('Javascript','YMap') ?>
      
      <?php include_map($yMap,array('width'=>'512px','height'=>'400px')); ?>
      
      <!-- Javascript included at the bottom of the page -->
      <?php include_map_javascript($yMap); ?>
      
  • Sample 3

    • change the map center location and the zoom level

    • change the zoom and movement controls used

    • store the markers' javascript objects in a javascript array

    • use a custom icon for the markers

    • bind event listeners to the markers linked to custom javascript functions

    • add custom property to the markers' javascript objects

    • In the action:

      // parameters: zoom level, lat, lng, options
      $this->yMap = new YMap(
        array(
          'zoom'=>14,
          'center_lat'=>30.5,
          'center_lng'=>50.5,
          'control'=>array('new YMaps.TypeControl()', 'new YMaps.ToolBar()', 'new YMaps.Zoom()')
          )
        );
      
      // some places in the world
      $coordinates = array(
        array(30.499,50.491),
        array(30.498,50.492),
        array(30.497,50.493),
        array(30.496,50.494),
        array(30.495,50.495)
      );
      
      // adds a variable "markers" defined on the global level
      $this->yMap->addGlobalVariable('markers','new Array()');
      
      // creates a custom icon for markers
      $yMapIcon = new YMapIcon(
        'nice_icon',
        '../sfYandexMapPlugin/images/nice_icon.png',
        array(
          'width'=>18,
          'height'=>25,
          'info_window_anchor_x'=>9,
          'info_window_anchor_y'=>25
        )
      );
      
      // creates two custom event listeners 
      $yMapEvent1 = new YMapEvent(
        'MouseOver',
        "document.getElementById('console_div').innerHTML = 'Mouse over marker number '+this.name;"
      );
      $yMapEvent2 = new YMapEvent(
        'MouseOut',
        "document.getElementById('console_div').innerHTML = 'Mouse over marker number '+this.name;"
      );
      
      foreach ($coordinates as $key=>$coordinate)
      {
        $yMapMarker = new YMapMarker($coordinate[0],$coordinate[1],'markers['.$key.']',$yMapIcon);
        $yMapMarker->addHtmlInfoWindow('<b>Coordinates:</b><br />'.implode(', ',$coordinate));
        $yMapMarker->setCustomProperty('name',$key);
        $yMapMarker->addEvent($yMapEvent1);
        $yMapMarker->addEvent($yMapEvent2);
      
        $this->yMap->addMarker($yMapMarker);
      }
      
    • In the template:

      <?php use_helper('Javascript','YMap') ?>
      
      <?php include_map($yMap,array('width'=>'512px','height'=>'400px')); ?>
      
      <!-- Javascript included at the bottom of the page -->
      <?php include_map_javascript($yMap); ?>
      
  • Sample 5

    • change the map center location and the zoom level

    • change the zoom and movement controls used

    • Add Events listeners to update map when it is changed,

    • In the action:

      $this->yMap = new YMap(
        array(
          'zoom'=>14,
          'center_lat'=>30.5,
          'center_lng'=>50.5,
          'control'=>array('new YMaps.TypeControl()', 'new YMaps.ToolBar()', 'new YMaps.Zoom()')
        )
      );
      
      
      $yMapEvent1 = new YMapEvent('Update','update_map(\''.$this->getController()->genUrl('sfYandexMapPlugin/dataJson').'\',\''.sfConfig::get('app_yandex_maps_api_icons_path').'\', map);');
      $yMapEvent2 = new YMapEvent('MoveEnd','update_map(\''.$this->getController()->genUrl('sfYandexMapPlugin/dataJson').'\',\''.sfConfig::get('app_yandex_maps_api_icons_path').'\', map);');
      $this->yMap->addEvent($yMapEvent1);
      $this->yMap->addEvent($yMapEvent2);
      
    • In the template:

      <?php use_helper('Javascript','YMap') ?>
      
      <?php include_map($yMap,array('width'=>'512px','height'=>'400px')); ?>
      
      <!-- Javascript included at the bottom of the page -->
      <?php include_map_javascript($yMap); ?>