SplunkMapView

The SplunkMap view

Description

The SplunkMap view binds a map to a search that interprets geographic data and displays it on a map. Data with lat and lon fields are used to populate map markers according to location. This view works best with the geostats search command, which provides clustering and spatial statistics in the Splunk search language.

Library path

Simple XML wrapper

Properties

Name

Default value

Description

id Required. The unique ID for this control.
data"preview"The type of data to retrieve from the search results
results | preview | events | summary | timeline ).
drilldowntrue
"all"
Indicates whether to enable a drilldown action when this view is clicked. Can be a Boolean or a String (true or "all" to enable drilldown, or false or "none" to disable it.)
drilldownRedirecttrueIndicates whether to redirect to a search page when clicked. When true, a refined search corresponding to the point that was clicked is displayed in the search app. When false, you must create a click event handler to define a drilldown action. You can also use the preventDefault method in the click event handler to bypass the default redirect to search.
height400
"400px"
The height of the view, in pixels. Can be a Number or a String.
manageridnullThe ID of the search manager to bind this control to.
mapping.type"marker"The type of map to render ( marker | choropleth ).
mapping.*Simple XML map properties. For a list of mapping properties, see the map and Choropleth map options in the Dashboards and Visualizations manual.
maxZoomAn integer that indicates the maximum zoom level of the tileset.
resizablefalseIndicates whether the view can be resized.
settingsThe properties of the view. See the methods below to get and set values.
tileSource"splunk"The tiles to use in map rendering ( openStreetMap | splunk ).
Note  The "splunk" tile set is only supported for Splunk Web apps.

Methods

Name

Description

renderDraws the control to the screen. Called only when you create the view manually.
settings.get( property )Returns the value of property for the current component.
settings.set( propertyvalue )Sets the value of property to the specified value for the current component.

Events

Name

Description

clickFired when a marker is clicked.
click:markerFired when a marker is clicked.

Example

This example uses search results from a sample earthquakes lookup table, and includes lat and lng fields in the search query. To try it for yourself, download earthquakes.csv to a /lookups directory under $SPLUNK_HOME/etc/apps/your_app_name.

require([
    "splunkjs/mvc/searchmanager",
    "splunkjs/mvc/splunkmapview",
    "splunkjs/mvc/simplexml/ready!"
], function(SearchManager, SplunkMapView) {

    // Create managers
    new SearchManager({
        id: "example-search",
        search: "| inputlookup earthquakes.csv | search  Region=Washington | rename Lat as lat, Lon as lon | geostats count" 
    });

    // Instantiate components
    mysplunkmap = new SplunkMapView({
        id: "example-splunkmap",
        managerid: "example-search",
        drilldown: true,
        drilldownRedirect: true,
        tileSource: "splunk",
        "mapping.map.zoom": 6, // Place complex property names within quotes
        "mapping.map.center": "(47.5,-120)", // Center on Washington state
        "mapping.markerLayer.markerOpacity": 0.6,
        "mapping.markerLayer.markerMinSize": 15,
        el: $("#mysplunkmapview")
    }).render();

    // Create an on-click event handler to change the default drilldown behavior 
    mysplunkmap.on("click:marker", function(e) {
        e.preventDefault();
        alert(e.data.count + " earthquakes near (" + e.data.latitude + ", " + e.data.longitude + ")");
        console.log(e.data); // Displays data to the console
    });

});