protected function LeafletDemoForm::outputDemoMaps in Leaflet More Maps 8
Same name and namespace in other branches
- 2.1.x leaflet_demo/src/Form/LeafletDemoForm.php \Drupal\leaflet_demo\Form\LeafletDemoForm::outputDemoMaps()
Outputs the HTML for available Leaflet maps, centered on supplied coords.
Parameters
float $latitude: The latitude, -90..90 degrees.
float $longitude: The longitude, -180..180 degrees.
int $zoom: The zoom level, typically 0..18.
Return value
array An array of maps as renderable arrays.
1 call to LeafletDemoForm::outputDemoMaps()
- LeafletDemoForm::buildForm in leaflet_demo/
src/ Form/ LeafletDemoForm.php - Form constructor.
File
- leaflet_demo/
src/ Form/ LeafletDemoForm.php, line 151
Class
- LeafletDemoForm
- Class LeafletDemoForm.
Namespace
Drupal\leaflet_demo\FormCode
protected function outputDemoMaps($latitude = LeafletDemoForm::LEAFLET_DEMO_DEFAULT_LAT, $longitude = LeafletDemoForm::LEAFLET_DEMO_DEFAULT_LNG, $zoom = LeafletDemoForm::LEAFLET_DEMO_DEFAULT_ZOOM) {
if (!is_numeric($latitude) || !is_numeric($longitude) || !is_numeric($zoom)) {
return [];
}
$center = [
'lat' => $latitude,
'lon' => $longitude,
];
$feature = [
'type' => 'point',
'lat' => $latitude,
'lon' => $longitude,
'popup' => $this
->t('Location as entered above'),
];
$demo_maps = [];
$map_info = leaflet_map_get_info();
foreach ($map_info as $map_id => $map) {
$map['id'] = $feature['leaflet_id'] = str_replace(' ', '-', $map_id);
$map['settings']['map_position'] = $center;
$map['settings']['zoom'] = $zoom;
$render_object = $this->leafletService
->leafletRenderMap($map, [
$feature,
], '350px');
$demo_maps[$map_id] = [
'#type' => 'item',
'#title' => $map_info[$map_id]['label'],
'#markup' => $this->renderer
->render($render_object),
'#attributes' => [
'class' => [
'leaflet-gallery-map',
],
],
];
}
return $demo_maps;
}