Skip to content

Commit

Permalink
geocoder settings: add testing map #71
Browse files Browse the repository at this point in the history
  • Loading branch information
mcguffin committed Dec 28, 2024
1 parent 52096b0 commit df42dc9
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 92 deletions.
15 changes: 13 additions & 2 deletions include/ACFFieldOpenstreetmap/Core/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,20 @@ public function register_assets() {
],
'providers' => $leaflet_providers->get_providers( $provider_filters ),
];
$geocoders = $leaflet_geocoders->get_geocoders();
$osm_settings = [
'options' => [
'layer_config' => $leaflet_providers->get_layer_config(), // settings only
],
'geocoders' => array_combine(
array_keys( $geocoders ),
array_map(
function( $geocoder ) use ( $leaflet_geocoders ) {
return $leaflet_geocoders->get_options( $geocoder );
},
array_keys( $geocoders )
),
),
];

/**
Expand Down Expand Up @@ -196,12 +206,13 @@ public function register_assets() {


// settings js
wp_register_script( 'acf-osm-settings', $this->get_asset_url( 'assets/js/acf-osm-settings.js' ), [], $this->get_version() );
wp_register_script( 'acf-osm-settings', $this->get_asset_url( 'assets/js/acf-osm-settings.js' ), ['wp-backbone'], $this->get_version() );
wp_localize_script( 'acf-osm-settings', 'acf_osm', $osm_l10n );
wp_localize_script( 'acf-osm-settings', 'acf_osm_settings', $osm_settings );
wp_localize_script( 'acf-osm-settings', 'acf_osm_admin', $osm_admin );

// settings css
wp_register_style( 'acf-osm-settings', $this->get_asset_url( 'assets/css/acf-osm-settings.css' ), ['leaflet'], $this->get_version() );
wp_register_style( 'acf-osm-settings', $this->get_asset_url( 'assets/css/acf-osm-settings.css' ), ['leaflet', 'acf-input-osm'], $this->get_version() );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion include/ACFFieldOpenstreetmap/Core/LeafletGeocoders.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function get_options($geocoder_name) {

// merge with settings
$geocoder_settings = (array) get_option('acf_osm_geocoder');

$options['scale'] = $geocoder_settings['scale'];
if ( isset( $geocoder_settings[$geocoder_name] ) && is_array( $geocoder_settings[$geocoder_name] ) ) {
$options = wp_parse_args( $geocoder_settings[$geocoder_name], $options );
}
Expand Down
28 changes: 26 additions & 2 deletions include/ACFFieldOpenstreetmap/Settings/SettingsOpenStreetMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function settings_page() {
<?php esc_html_e('Geocoder', 'acf-openstreetmap-field') ?>
</label>
</h2>
<?php /*
<?php // Future
/*
<div class="tab-content acf-osm-tab-1">
<h3><?php esc_html_e('Plugin Options', 'acf-openstreetmap-field') ?></h3>
<div class="acf-osm-plugin-settings">
Expand Down Expand Up @@ -143,11 +144,12 @@ public function settings_page() {
<div class="acf-osm-test-map-container">
<div class="acf-osm-test-map">
<div
data-test="providers"
data-map="leaflet"
data-map-lat="53.55064"
data-map-lng="10.00065"
data-map-zoom="12"
data-map-layers="<?php esc_attr_e( json_encode(['OpenStreetMap']) ); ?>"
data-map-layers="<?php esc_attr_e( json_encode(['OpenStreetMap.Mapnik']) ); ?>"
>
</div>
</div>
Expand All @@ -158,9 +160,31 @@ public function settings_page() {
<div class="tab-content acf-osm-tab-3">
<h3><?php esc_html_e('Geocoder Options', 'acf-openstreetmap-field') ?></h3>
<div class="acf-osm-geocoder-settings">

<table class="form-table" role="presentation"><?php
do_settings_fields( $this->optionset, 'geocoder' )
?></table>

<div class="acf-osm-test-map-container">
<div class="acf-osm-test-map">
<div
class="leaflet-map"
data-test="geocoders"
data-map="leaflet"
data-map-lat="53.55064"
data-map-lng="10.00065"
data-map-zoom="9"
data-map-layers="<?php esc_attr_e( json_encode(['OpenStreetMap.Mapnik']) ); ?>"
>
</div>
</div>
<p class="description">
<?php esc_html_e('Use search to geocode.','acf-openstreetmap-field'); ?><br />
<?php esc_html_e('Click on the map for reverse geocode.','acf-openstreetmap-field'); ?>
</p>
<h3><?php esc_html_e('Geocoder response', 'acf-openstreetmap-field'); ?></h3>
<pre class="acf-osm-geocode-response code card"></pre>
</div>
</div>
</div>

Expand Down
Loading

0 comments on commit df42dc9

Please sign in to comment.