Geofield Yandex Maps
Component ID
2152937
Component name
Geofield Yandex Maps
Component type
module
Maintenance status
Development status
Component security advisory coverage
covered
Downloads
7849
Component created
Component changed
Component body
Geofield 2.x widget, Geofield formatter, Views handler, Form element and Text filter with Yandex.Maps 2.1
API
Programmaticaly show map with marker
$map = array(
'#theme' => 'geofield_ymap',
'#map_type' => 'yandex#map', // optionaly, default 'yandex#map'
'#map_center' => array(37, 55), // optionaly, default auto centering
'#map_zoom' => 12, // optionaly, default auto zooming
'#map_auto_centering' => TRUE, // optionaly, default TRUE
'#map_objects' => '{"type":"Point","coordinates":[37.62817382812449,55.75485888286848]}', // GeoJSON, optionaly
);
$output = render($map);
Show map with marker via html (without php)
Add to node content:
<div class="geofield-ymap" data-map-objects='{"type":"Point","coordinates":[37,55]}'></div>
Enable setting "Use loader" on module settings page.
Usage form element
$form['location'] = array(
'#type' => 'geofield_ymap',
'#title' => 'Location',
'#description' => 'Select control and click to map for add object on map. Double click on object to remove it.',
'#map_multiple' => TRUE,
'#map_center' => array(55.733835, 37.588227),
'#map_zoom' => 12,
'#map_auto_centering' => TRUE,
'#map_object_types' => array('point', 'line', 'polygon'),
);
#default_value contains geometry in GeoJSON or json array of objects like [{"type":"Point","coordinates":[55,37]},{"type":"Point","coordinates":[37,55]}]
Demo.
Add map with marker from Javascript
ymaps.ready(function () {
// for <div id="my-map" style="width:100%; height:400px;"></div>
var map = Drupal.geofieldYmap.mapInit('my-map', {
objects: '{"type":"Point","coordinates":[37.62,55.75]}',
autoCentering: true,
autoZooming: true
});
});
before that do not forget add library:
drupal_add_library('geofield_ymap', 'geofield_ymap');
