Jump to content
  • Zoom to data or reset the extent of any map in Spotfire using IronPython


    In Spotfire is to zoom a map to the data displayed, or filtered to. This is particularly useful when the data has been filtered and you want to zoom to only the points shown on the map currently.

    Introduction

    A common task in Spotfire is to zoom a map to the data displayed, or filtered to. This is particularly useful when the data has been filtered and you want to zoom to only the points shown on the map currently. It also enables you to automatically zoom your map to points of interest when a user selects a value from a drop down or user control in a text area, and you use this selected value to filter data for example. Often people write scripts which find a particular map on a page, or send the map visual as a property into the script. However, a more generic and easy way is to use this completely generic script that will zoom/reset the extent of any map.

    Spotfire version: note that in Spotfire 7, this is called reset the extent of a map. In Spotfire 10, a more meaningful description is used, which is zoom to filtered items. 

    What does resetting the extent of map mean?

    A map's extent in Spotfire is defined by the data contained in each of its layers. Each map chart has a layers and you can create many different types and combinations of layers on one map. See a video tutorial on this. Each layer has its own extent i.e. the coordinates it covers, or in other words where it is positioned in the world if you are using typical geographical layers. To make this data usable you want to zoom to points of interest. Spotfire has a button on maps to instantly do this which resets/zooms the map:

    1.png.d5e986188eab58342152163be95e8ed0.png

    When you click this the map chooses the optimal extent to view all the relevant layer's data at. By default all layers are considered for this but you may only want certain layers to be taken into account when resetting the extent/zooming to data. To do this you go to the properties of the layer and change the zoom to filtered items (Spotfire 10) / reset extent option (Spotfire 7) in the Appearance section:

    2.png.e27bdcaa2f34e5cb38b37772f301136b.png

    Script and Output Summary

    The script to make a map zoom to filtered items (or indeed all items), is very simple and only takes a few lines of code. It will zoom any map on any page, so is completely generic. The script is below:

     # Copyright (c) 2017-2019 TIBCO Software Inc. All Rights Reserved.
     
     ## reset map extents when switching tabs
     
     from Spotfire.Dxp.Application.Visuals import *
     from Spotfire.Dxp.Application.Visuals.Maps import *
     
     ## Loop over visuals and find maps
     for visualization in Document.ActivePageReference.Visuals:
         if visualization.TypeId == VisualTypeIdentifiers.MapChart2:
             map = visualization.As[MapChart]();
             map.ResetViewExtent();
     

    Using this script you can now trigger this from a button/link in an action control for example, or attach it to a document property so it runs every time the document property changes.

    Other similar articles on controlling map zoom extents can be found here: https://community.spotfire.com/articles/spotfire/how-zoom-pre-defined-map-location-spotfire-using-ironpython-scripting/

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...