Skip to content
Snippets Groups Projects
Commit bd1ab184 authored by Christian Adamski's avatar Christian Adamski
Browse files

Merge branch '3519395-mapcenter-plugin-follow' into '4.x'

Issue #3519395

See merge request !99
parents e1261d0b bd0dde67
No related branches found
No related tags found
No related merge requests found
Pipeline #498470 passed
plugin.plugin_configuration.geolocation.map_center_option.client_location:
type: geolocation.map_center_option_settings
label: 'Client location'
mapping:
settings:
type: mapping
label: 'Settings'
mapping:
initial_latitude:
type: float
label: 'Initial Latitude'
initial_longitude:
type: float
label: 'Initial Longitude'
follow_client:
type: boolean
label: 'Follow Client'
plugin.plugin_configuration.geolocation.map_center_option.fit_bounds:
type: geolocation.map_center_option_settings
label: 'Fit Locations'
......
import { GeolocationMapCenterBase } from "./GeolocationMapCenterBase.js";
import { GeolocationCoordinates } from "../Base/GeolocationCoordinates.js";
/**
* @prop {float} settings.initial_longitude
* @prop {float} settings.initial_latitude
* @prop {boolean} settings.follow_client
*/
export default class ClientLocation extends GeolocationMapCenterBase {
setCenter() {
super.setCenter();
this.map.setCenterByCoordinates(new GeolocationCoordinates(this.settings.initial_latitude, this.settings.initial_longitude));
if (!navigator.geolocation) {
return false;
}
navigator.geolocation.getCurrentPosition((position) => {
this.map.setCenterByCoordinates(new GeolocationCoordinates(position.coords.latitude, position.coords.longitude));
});
if (this.settings.follow_client) {
setInterval(() => {
navigator.geolocation.getCurrentPosition((position) => {
this.map.setCenterByCoordinates(new GeolocationCoordinates(position.coords.latitude, position.coords.longitude));
});
}, 20000);
}
return true;
}
}
......@@ -41,6 +41,6 @@ export default class ClientLocationIndicator extends GeolocationMapFeature {
indicatorCircle = this.map.createCircle(currentCoordinates, parseInt(currentPosition.coords.accuracy.toString()));
}
});
}, 5000);
}, 20000);
}
}
<?php
namespace Drupal\geolocation\Plugin\geolocation\MapCenter;
use Drupal\geolocation\MapCenterBase;
use Drupal\geolocation\MapCenterInterface;
/**
* Fixed boundaries map center.
*
* @MapCenter(
* id = "client_location",
* name = @Translation("Client Location"),
* description = @Translation("If client allows, set location. Optionally follow continously."),
* )
*/
class ClientLocation extends MapCenterBase implements MapCenterInterface {
/**
* {@inheritdoc}
*/
public static function getDefaultSettings(): array {
return [
'initial_latitude' => 0,
'initial_longitude' => 0,
'follow_client' => FALSE,
];
}
/**
* {@inheritdoc}
*/
public function getSettingsForm(?string $option_id = NULL, array $settings = [], array $context = []): array {
$form = parent::getSettingsForm($option_id, $settings, $context);
$settings = $this->getSettings($settings);
$form['initial_latitude'] = [
'#type' => 'textfield',
'#title' => $this->t('Initial Latitude'),
'#default_value' => $settings['initial_latitude'] ?? 0,
'#description' => $this->t('Before client location becomes available, if at all.'),
'#size' => 60,
'#maxlength' => 128,
];
$form['initial_longitude'] = [
'#type' => 'textfield',
'#title' => $this->t('Initial Longitude'),
'#default_value' => $settings['initial_longitude'] ?? 0,
'#description' => $this->t('Before client location becomes available, if at all.'),
'#size' => 60,
'#maxlength' => 128,
];
$form['follow_client'] = [
'#type' => 'checkbox',
'#title' => $this->t('Follow client location'),
'#default_value' => $settings['follow_client'],
'#description' => $this->t('Continuously update center by client location if available.'),
];
return $form;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment