Custom Scripts

Attach a function to get access to the map object and features

Mapster WP Maps is built to allow developers to easily extend and tweak map display and settings. We have a huge number of ways you can hook into specific maps during runtime to execute functions and modify content. Custom Scripts is the simplest way to get developer access.

Custom Scripts are scripts you can write somewhere in the Javascript on your site, and then give to a specific map to call after it's done initializing. This is a simple way to hook into any given map and manipulate displays or controls as you need.

For any particular map, go to the Custom section. Enter the name of a function here. For example, let's call our function "myCustomScript".

Create a global function with that script name. Your script will automatically receive a "map" and a "features" variable. For Maplibre and Mapbox, this will be a map object matching those libraries; for Google Maps, it'll be a map object matching the Google Maps API. As follows:

window.myCustomScript = function(map, features) {

	console.log(map);

	console.log(features);

}

From here, make the modifications you need!

Last updated