3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Issue #2999087: Map address lookup

This commit is contained in:
Michael Stenta 2018-09-12 20:34:40 -04:00
parent f0cb822d24
commit 461732abe0
6 changed files with 67 additions and 1 deletions

View file

@ -10,6 +10,16 @@
function farm_map_default_openlayers_controls() {
$export = array();
$ol_control = new stdClass();
$ol_control->disabled = FALSE; /* Edit this to true to make a default ol_control disabled initially */
$ol_control->api_version = 1;
$ol_control->machine_name = 'farm_map_control_geocoder';
$ol_control->name = 'Farm Map: Geocoder';
$ol_control->description = '';
$ol_control->factory_service = 'openlayers.Control:OLGeocoder';
$ol_control->options = array();
$export['farm_map_control_geocoder'] = $ol_control;
$ol_control = new stdClass();
$ol_control->disabled = FALSE; /* Edit this to true to make a default ol_control disabled initially */
$ol_control->api_version = 1;

View file

@ -38,11 +38,12 @@ function farm_map_default_openlayers_maps() {
1 => 'openlayers_control_scaleline',
2 => 'farm_map_control_layer_switcher',
3 => 'farm_map_control_geolocate',
4 => 'farm_map_control_geocoder',
/**
* @todo
* https://www.drupal.org/node/2543186
*/
// 4 => 'openlayers_control_fullscreen',
// 5 => 'openlayers_control_fullscreen',
),
'interactions' => array(
0 => 'openlayers_interaction_doubleclickzoom',

View file

@ -37,3 +37,4 @@ features[openlayers_sources][] = farm_map_source_google_hybrid
features[openlayers_sources][] = farm_map_source_google_satellite
features[openlayers_sources][] = farm_map_source_google_terrain
features[openlayers_sources][] = farm_map_source_openstreetmap
registry_autoload[] = PSR-4

View file

@ -0,0 +1,34 @@
<?php
/**
* @file
* Control: OLGeocoder.
*/
namespace Drupal\farm_map\Plugin\Control\OLGeocoder;
use Drupal\openlayers\Types\Control;
use Drupal\openlayers\Types\ObjectInterface;
/**
* Class OLGeocoder.
*
* @OpenlayersPlugin(
* id = "OLGeocoder",
* description = "Geocoder Nominatim for OpenLayers"
* )
*/
class OLGeocoder extends Control {
/**
* {@inheritdoc}
*/
public function preBuild(array &$build, ObjectInterface $context = NULL) {
parent::preBuild($build, $context);
$options = array(
'type' => 'external',
'weight' => 100,
);
drupal_add_js('https://cdn.jsdelivr.net/npm/ol-geocoder', $options);
drupal_add_css('https://cdn.jsdelivr.net/npm/ol-geocoder@latest/dist/ol-geocoder.min.css', $options);
}
}

View file

@ -0,0 +1,3 @@
.ol-geocoder ul.gcd-gl-result>li {
line-height: normal !important;
}

View file

@ -0,0 +1,17 @@
Drupal.openlayers.pluginManager.register({
fs: 'openlayers.Control:OLGeocoder',
init: function(data) {
try {
var geocoder = new Geocoder('nominatim', {
provider: 'osm',
placeholder: 'Search for address...',
limit: 5,
autoComplete: true
});
data.map.addControl(geocoder);
}
catch(err) {
console.log(err.message);
}
}
});