Hello,
I have successfully added the tick event runtime but now i want to remove it at runtime but its not working.
Basically what i am trying to give user is that they can start auto refresh and also has the power to stop this auto refresh.
I have modified your "AutoRefreshOverlay" page from sample set and pasted that code below.
Apart from this, i also want to give user the button of "Refresh Now" . Right now i am reloading the whole page page user clicks on it. Is there any javascript so by calling it, it can execute tick event functionality manually?
Looking forward to your as usual prompt reply . :)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AutoRefreshOverlay.aspx.cs" Inherits="CSSamples.AutoRefreshOverlay" %>
<%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="w3.org/1999/xhtml">
<head id="Head1" runat="server">
<link href="~/theme/default/samplepic/style.css" rel="stylesheet" type="text/css" />
<title>MarkerOverlay AutoRefresh</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="Map1_Script" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<cc1:Map ID="Map1" runat="server" Width="100%" Height="100%">
</cc1:Map>
<asp:Button ID="btnStart" runat="server" Text="Start Refresh" OnClick="btnStart_Click" />
</asp:UpdatePanel>
<Description:DescriptionPanel ID="DescPanel" runat="server">
Demonstrate how to use the AutoRefresh functinality.
</Description:DescriptionPanel>
</form>
</body>
</html>
using System;
using System.Web.UI;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
namespace CSSamples
{
public partial class AutoRefreshOverlay : System.Web.UI.Page
{
public SimpleMarkerOverlay MarkerOverlay
{
get { return (Map1.CustomOverlays["Vehicle Markers"] as SimpleMarkerOverlay); }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
Map1.CurrentExtent = new RectangleShape(-95.31105, 38.98184, -95.20359, 38.92185);
Map1.MapUnit = GeographyUnit.DecimalDegree;
WorldMapKitWmsWebOverlay overlay = new WorldMapKitWmsWebOverlay();
Map1.CustomOverlays.Add(overlay);
CreateMarkerOverlay();
SimpleMarkerOverlay markerOverlay = MarkerOverlay;
markerOverlay.AutoRefreshInterval = TimeSpan.FromMilliseconds(3000);
//markerOverlay.Tick += new EventHandler<EventArgs>(markerOverlay_Tick);
markerOverlay.Markers.Add(new Marker(-95.26095, 38.93926, new WebImage(21, 25, -10.5f, -25f)));
markerOverlay.Markers.Add(new Marker(-95.26086, 38.96956, new WebImage(21, 25, -10.5f, -25f)));
markerOverlay.Markers.Add(new Marker(-95.25919, 38.96758, new WebImage(21, 25, -10.5f, -25f)));
markerOverlay.Markers.Add(new Marker(-95.29056, 38.95703, new WebImage(21, 25, -10.5f, -25f)));
markerOverlay.Markers.Add(new Marker(-95.22653, 38.94278, new WebImage(21, 25, -10.5f, -25f)));
markerOverlay.Markers.Add(new Marker(-95.26987, 38.93531, new WebImage(21, 25, -10.5f, -25f)));
}
}
/// <summary>
/// Create Marker overlay
/// </summary>
protected void CreateMarkerOverlay()
{
SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay("Vehicle Markers");
Map1.CustomOverlays.Add(markerOverlay);
}
void markerOverlay_Tick(object sender, EventArgs e)
{
SimpleMarkerOverlay markerOverlay = MarkerOverlay; //(SimpleMarkerOverlay)Map1.CustomOverlays["MarkerOverlay"];
foreach (Marker marker in markerOverlay.Markers)
{
double lon = marker.Position.X + new Random(Guid.NewGuid().GetHashCode()).Next(-12, 20) / 5000.0;
double lat = marker.Position.Y + new Random(Guid.NewGuid().GetHashCode()).Next(-11, 26) / 5000.0;
marker.Position = new PointShape(lon, lat);
}
}
protected void btnStart_Click(object sender, EventArgs e)
{
if (btnStart.Text == "Stop")
{
btnStart.Text = "Start";
SimpleMarkerOverlay markerOverlay = MarkerOverlay;
markerOverlay.AutoRefreshInterval = TimeSpan.FromMilliseconds(3000);
markerOverlay.Tick -= new EventHandler<EventArgs>(markerOverlay_Tick);
markerOverlay.Tick += null;
//Type type = Map1.GetType();
//System.Reflection.EventInfo evInfo = type.GetEvent("Tick");
//evInfo.RemoveEventHandler(Map1, new EventHandler<EventArgs>(markerOverlay_Tick));
}
else
{
btnStart.Text = "Stop";
SimpleMarkerOverlay markerOverlay = MarkerOverlay;
markerOverlay.AutoRefreshInterval = TimeSpan.FromMilliseconds(3000);
markerOverlay.Tick += new EventHandler<EventArgs>(markerOverlay_Tick);
}
}
}
}