diff --git a/modules/farm/farm_map/farm_map.default_openlayers_controls.inc b/modules/farm/farm_map/farm_map.default_openlayers_controls.inc index 02c71d43..fdbcb225 100644 --- a/modules/farm/farm_map/farm_map.default_openlayers_controls.inc +++ b/modules/farm/farm_map/farm_map.default_openlayers_controls.inc @@ -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; diff --git a/modules/farm/farm_map/farm_map.default_openlayers_maps.inc b/modules/farm/farm_map/farm_map.default_openlayers_maps.inc index 67ce4909..8955431b 100644 --- a/modules/farm/farm_map/farm_map.default_openlayers_maps.inc +++ b/modules/farm/farm_map/farm_map.default_openlayers_maps.inc @@ -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', diff --git a/modules/farm/farm_map/farm_map.info b/modules/farm/farm_map/farm_map.info index 6ce21bf9..bfeb52b0 100644 --- a/modules/farm/farm_map/farm_map.info +++ b/modules/farm/farm_map/farm_map.info @@ -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 diff --git a/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/OLGeocoder.php b/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/OLGeocoder.php new file mode 100644 index 00000000..334e0164 --- /dev/null +++ b/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/OLGeocoder.php @@ -0,0 +1,34 @@ + '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); + } +} diff --git a/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/css/OLGeocoder.css b/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/css/OLGeocoder.css new file mode 100644 index 00000000..091b6741 --- /dev/null +++ b/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/css/OLGeocoder.css @@ -0,0 +1,3 @@ +.ol-geocoder ul.gcd-gl-result>li { + line-height: normal !important; +} diff --git a/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/js/OLGeocoder.js b/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/js/OLGeocoder.js new file mode 100644 index 00000000..7ac1d1f4 --- /dev/null +++ b/modules/farm/farm_map/src/Plugin/Control/OLGeocoder/js/OLGeocoder.js @@ -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); + } + } +});