Timer Update not following new location

Last post 7/10/2008 3:38:36 AM by Chris Pietschmann. 4 replies. << Back to Web.Maps.VE v2.0 General
7/4/2008 1:45:06 PM
nsfranklin

Timer Update not following new location

I have a timer that updates the map and is working very well, except for the issue that the moving point eventually disappears off the map, so the map is not centering on the new location.

Thanks

7/4/2008 1:55:57 PM
nsfranklin

Re:Timer Update not following new location

Further to the above, forgot to mention that I can have any number of moving points and would like the map to keep them all in view. When the map loads I call the javascript maploaded as per a previous forum entry,

 <Simplovation:Map runat="server" ID="Map1" OnClientMapLoaded="mapLoaded" />
<script type="text/javascript">
// This method is run once the map has completed loading on the page
function mapLoaded()
{
    var map = $find("<%=Map1.ClientID%>");
    //This code will center the map on all the shapes that are plotted
    var locations = new Array();
    for(var a = 0; a < map.get_Map().GetShapeLayerCount(); a++)
    {
        for(var b = 0; b < map.get_Map().GetShapeLayerByIndex(a).GetShapeCount(); b++)
        {
            Array.addRange(locations, map.get_Map().GetShapeLayerByIndex(a).GetShapeByIndex(b).GetPoints());
        }
    }
    if (locations.length != 0)
        map.get_Map().SetMapView(locations);
}
</script>

but it doesn't appear to fire after timer fires the updatemap() sub

7/6/2008 1:02:36 PM
Chris Pietschmann

Re:Timer Update not following new location

The JavaScript method defined in the OnClientMapLoaded property only gets fired when the Map has finished loading or initializing on the client. This only happens once when the page is initially loaded, and does not occur on subsequent Asynchronous Postbacks since the Map is already loaded when those occur.
7/6/2008 4:20:28 PM
nsfranklin

Re:Timer Update not following new location

Do you have any suggestions as to how best to set a boundary to display all points after a update.

7/10/2008 3:38:36 AM
Chris Pietschmann

Re:Timer Update not following new location

You can use the ScriptManager.RegisterStartupScript method to execute some JavaScript code on the client once the Asynchronous Postback completes.

Place the following JavaScript method in the page:

<script type="text/javascript">
    function CenterMapOnCurrentShapes()
    {
        var map = $find("<%=Map1.ClientID%>");
        //This code will center the map on all the shapes that are plotted
        var locations = new Array();
        for(var a = 0; a < map.get_Map().GetShapeLayerCount(); a++)
        {
            for(var b = 0; b < map.get_Map().GetShapeLayerByIndex(a).GetShapeCount(); b++)
            {
                Array.addRange(locations, map.get_Map().GetShapeLayerByIndex(a).GetShapeByIndex(b).GetPoints());
            }
        }
        if (locations.length != 0)
            map.get_Map().SetMapView(locations);
    }
</script>

Then call the JavaScript method from in your server-side code using the ScriptManager.RegisterStartupScript method during the Asynchronous Postback, like so:

ScriptManager.RegisterStartupScript(
            this,
            this.GetType(),
            "centerMap",
            "CenterMapOnCurrentShapes();",
            true);