Description
This filter allows you to modify the default map settings used in wpsl-admin.js.
The plugin prints these settings on the Store Locator admin pages as the wpslSettings JavaScript object. They are used by the map on the store edit screen, the maps on the settings pages, Marker Studio, and the onboarding wizard.
The default map location comes from the “Start location” on Store Locator > Settings > Map. See the Map settings. Change the start location there first if you want the same location on the store locator page. Use this filter if you only want a different location or zoom level in the admin.
Parameters
$js_settings - (array) Settings used in wpsl-admin.js.
These are the keys you are most likely to change:
| Key | Default | Description |
|---|---|---|
defaultLatLng | The coordinates of the "Start location" setting, or '37.4220, -122.0840' when there are none | The location the admin maps show when there is no other location to show, for example for a new store without coordinates. |
defaultZoom | 6 | The zoom level the admin maps start with. |
api | The active map provider | An array with the provider (gmaps, mapbox, osm or stadia) and its key, language, region, style and tile layer settings, as set on Store Locator > Settings > API. |
geocodeComponents | Only set when "Country filtering" is set to "Restrict results (hard)" with one country | Google Maps only. Restricts the geocode requests on the store edit screen, and in the geocode test on the settings page, to that country, for example array( 'country' => 'NL' ). |
To see all the keys, open a Store Locator admin page in your browser and type wpslSettings in the console.
Usage
This example changes the default map coordinates and zoom level for the store map preview:
| add_filter( 'wpsl_admin_js_settings', 'custom_admin_js_settings' ); | |
| function custom_admin_js_settings( $js_settings ) { | |
| $js_settings['defaultLatLng'] = '51.507351, -0.127758'; | |
| $js_settings['defaultZoom'] = 8; | |
| return $js_settings; | |
| } |
If you want to change the default map location, but you don’t know the coordinates, then you can use a site like http://www.latlong.net/ to find them.
Changelog
| Version | Description |
|---|---|
| 3.0 | Moved to includes/admin/assets/class-resources.php. Added the api key with the active map provider and its settings. The settings are now also used by Marker Studio and the onboarding wizard. Without a start location, defaultLatLng now falls back to '37.4220, -122.0840' instead of Amsterdam. geocodeComponents is now set by the "Country filtering" setting. |
| 2.0 | Introduced. |
Source File
This filter is located in /includes/admin/assets/class-resources.php.
Placement
The code needs to be placed in the functions.php file inside your active theme folder.