-
Notifications
You must be signed in to change notification settings - Fork 22
WordPress Filters
Jörn Lund edited this page Dec 23, 2024
·
3 revisions
Filter init options for leaflet geocoder (JS).
add_filter('acf_osm_geocoder_options', function( $geocoder_options ) {
// Maps and borders have a colonial connotation. Using 19th century language seems more than appropriate.
$geocoder_options['errorMessage'] = __('Sapperlot, es ist entzwei!');
return $geocoder_options;
});
Filter init options for nominatim geocoder.
add_filter('acf_osm_nominatim_options', function( $nominatim_options ) {
// most people on earth speak chinese
$nominatim_options['geocoderQueryParams']['accept-language'] = 'zh';
$nominatim_options['reverseQueryParams']['accept-language'] = 'zh';
return $nominatim_options;
});
Filter available map layers. Please refer to the Leaflet Providers source.
add_filter('acf_osm_leaflet_providers', function( $providers ) {
$providers[ 'WorldDominationMap' ] = array(
'url' => 'https://{s}.dr-evil-maps.luna/{x}/{y}/{z}.png',
'options' => array(
'attribution' => '© Me and my Mini-Me, 2001',
),
);
return $providers;
});
add_filter('acf_osm_leaflet_providers', function( $providers ) {
$providers[ 'WorldDominationMap' ] = array(
'url' => 'https://{s}.dr-evil-maps.luna/{x}/{y}/{z}.png?access_token={access_token}',
'options' => array(
'attribution' => '© Me and my Mini-Me, 2001',
'access_token' => 'sdjfw46rxcnw46rw47rxw476n4w7rfn47',
// replace with your own api key.
),
);
return $providers;
});
add_filter('acf_osm_leaflet_providers', function( $providers ) {
$providers[ 'WorldDominationMap' ] = array(
'url' => 'https://{s}.dr-evil-maps.luna/{x}/{y}/{z}.png?access_token={access_token}',
'options' => array(
'attribution' => '© Me and my Mini-Me, 2001',
'access_token' => '<Insert Access Token Here>',
),
);
return $providers;
});
Force proxy mode for all tile providers. (@see Map Proxy)
add_filter( 'acf_osm_force_proxy', '__return_true' );
Filters the markers class name.
add_filter( 'acf_osm_marker_classname', function( $classname ) {
return classname . ' my-marker-classname';
});
Override marker HTML.
add_filter('acf_osm_marker_html', function( $html ){
return '<div class="my-marker"></div>';
});
Draw a small red Circle:
.my-marker {
display:block;
width:20px;
height:20px;
border-radius:10px;
border:2px solid #f00;
margin-top:-4px;
margin-left:-4px;
}
Leaflet marker has a margin top/left of -6px from the map position. We have to subtract another 4px to match the center of the circle with the map position.
Should return the arguments passed to L.icon
.
add_filter('acf_osm_marker_icon', function( $icon ) {
return array(
'iconUrl' => 'http://example.com/img/map-marker.svg',
'iconSize' => [ 40, 60 ],
'iconAnchor' => [ 20, 50 ],
);
});
Anchor position is relative to the top left corner: