The code below is animating the vehicle actions on the map. But I tryed to add popup for each point when animation is showing each point (points are showed as arrow gifs). There is no problem when adding popups for each point but problem is that it opens popup window directly, however I want to open popup window when the mouse is over object.
How can I do that ?
////////////////////////////////////////////////////////////////////////////////////////// ON PAGE LOAD //////////////////////////////////////////////////////////////////////////////
if (staticDt.Rows.Count > 0)
{
currentFleet = Convert.ToInt32(staticDt.Rows[0]["FLEETID"]);
double firstX = 0;
double firstY = 0;
double xCoord = 0;
double yCoord = 0;
StringBuilder script = new StringBuilder();
script.Append("var Objects={aractip:")
.Append(staticDt.Rows[0]["ARACTIPID"].ToString())
.Append(",coords:new Array(");
StringBuilder jsString = new StringBuilder();
List<string></string> jsArray = new List<string></string>();
for (int i = 0; i < staticDt.Rows.Count; i++)
{
jsString.Length = 0;
xCoord = 0;
yCoord = 0;
double.TryParse(staticDt.Rows["X"].ToString(), out xCoord);
double.TryParse(staticDt.Rows["Y"].ToString(), out yCoord);
ConvertCoords(ref xCoord, ref yCoord);
if (i == 0)
{
firstX = xCoord;
firstY = yCoord;
}
int kontak = 0;
int.TryParse(staticDt.Rows["CONTAC"].ToString(), out kontak);
int aractip = 0;
double aci = 0;
double.TryParse(staticDt.Rows["DIRECTION"].ToString(), out aci);
int.TryParse(staticDt.Rows["ARACTIPID"].ToString(), out aractip);
bool rolanti = (bool)staticDt.Rows["ROLANTI"];
bool status = Convert.ToInt32(staticDt.Rows["STATUS"]) != 0;
DateTime InsertDate = Convert.ToDateTime(staticDt.Rows["INSERTDATE"].ToString());
int iStatus = 0;
TimeSpan tm = DateTime.Now - InsertDate;
if ((!status) && (tm.TotalMinutes >= 60))
{
iStatus = 4;
}
else
{
if (kontak == 1 && !rolanti) iStatus = 1;
else if (kontak == 1 && rolanti) iStatus = 2;
else if (kontak == 0) iStatus = 3;
}
jsString.Append("{")
.Append("'x':")
.Append(jsDouble(xCoord))
.Append(",")
.Append("'y':")
.Append(jsDouble(yCoord))
.Append(",")
.Append("'iDegree':")
.Append(Math.Round(aci).ToString())
.Append(",")
.Append("'iStatus':")
.Append(iStatus.ToString())
.Append("}");
jsArray.Add(jsString.ToString());
}
script.Append(String.Join(",", jsArray.ToArray()));
script.Append(")};");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "rastgele", script.ToString(), true);
PointShape point = new PointShape(firstX, firstY);
Map1.ZoomTo(point, Map1.ClientZoomLevelScales[7]);
}
/////////////////////////////////////////////////////////////////////////////////////// END PAGE LOAD ///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////// SCRIPT ///////////////////////////////////////////////////////////////////////////////////////////////////////
function OnMapCreating(map) {
OpenLayers.Layer.Google = OpenLayers.Class(OpenLayers.Layer.Google, {
MIN_ZOOM_LEVEL: 5,
MAX_ZOOM_LEVEL: 17
});
}
function initPage() {
if (Objects)
{
recalcStatic();
parserMap1.map.events.register('movestart', parserMap1.map, function(evt) { mapWait(); });
parserMap1.map.events.register('moveend', parserMap1.map, function(evt) { mapDrawEnd(); });
}
else
{
document.getElementById('startinput').disabled = true;
document.getElementById('stopinput').disabled = true;
alert("Konum bilgisi yok. Ltfen tarih kriterlerini kontrol ediniz.");
}
}
var waitForMap = false;
function mapWait() {
if (isAnimBegin) {
if (animHandler != null) {
window.clearTimeout(animHandler);
animHandler = null;
waitForMap = true;
//buttonCase(false);
}
}
}
function mapDrawEnd() {
if (isAnimBegin) {
beginAnimHandler();
//buttonCase(true);
}
}
function recalcStatic() {
userSinir=(Objects.coords.length < 10) ? 10 : Objects.coords.length
}
var startFrom = 0;
var animHandler = null;
var lastMarker = null;
var markersObj = null;
var tempVehicleMarker = null;
function putMarker(aractip,iStatus,x,y,stat,aci,durum) {
var marker;
//var markers = parserMap1.map.getLayersByName('vehicleLayer')[0];
var degAci = aci || 0;
var degDurum = durum || 1;
var size = new OpenLayers.Size(20, 20);
var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
var imagePath =(!stat)?'images/vTypes/{0}/{1}.gif'.format(aractip, iStatus.toString().padLeft(3)): 'rotate.aspx?aci=' + aci + '&durum=' + durum;
var icon = new OpenLayers.Icon(imagePath);
var LonLat = new OpenLayers.LonLat(x, y);
marker = new OpenLayers.Marker(LonLat, icon);
parserMap1.map.panTo(LonLat);
markerLayer.addMarker(marker);
markersObj.push(marker);
//Add vehicle marker
if (tempVehicleMarker!=null)
{
markerLayer.removeMarker(tempVehicleMarker);
}
var imagePath ='images/vTypes/{0}/{1}.gif'.format(aractip, iStatus.toString().padLeft(3));
var icon = new OpenLayers.Icon(imagePath);
marker = new OpenLayers.Marker(LonLat, icon);
parserMap1.map.panTo(LonLat);
markerLayer.addMarker(marker);
tempVehicleMarker = marker;
}
function showNextMarker() {
if (startFrom + 1 > Objects.coords.length) {
stopAnim();
return;
}
var aci;
var durum;
if (markersObj == null) markersObj = new Array();
else {
var mrk = markersObj[startFrom - 1];
if (mrk.icon != null) {
var img = mrk.icon.imageDiv.getElementsByTagName('IMG');
//img[0].src = 'rotate.aspx?aci=' + Objects.coords[startFrom - 1]['iDegree'].toString() + '&durum=' + Objects.coords[startFrom - 1]['iStatus'].toString();
//isrc = 'rotate.aspx?aci=' + Objects.coords[startFrom - 1]['iDegree'].toString() + '&durum=' + Objects.coords[startFrom - 1]['iStatus'].toString();
aci = Objects.coords[startFrom - 1]['iDegree'].toString();
durum = Objects.coords[startFrom - 1]['iStatus'].toString();
}
}
document.getElementById('siraYaz').innerHTML = startFrom + 1;
var iStatus = Objects.coords[startFrom]['iStatus'].toString().padLeft(3);
var x = Objects.coords[startFrom]['x'];
var y = Objects.coords[startFrom]['y'];
------------------------------- I am trying to add popup here. the code below is working but open popup window directly, however I want to open popup window when the mouse is over object.
// var popup = new OpenLayers.Popup("example",
// new OpenLayers.LonLat(x,y),
// new OpenLayers.Size(200,200),
// "example popup",
// false);
// var map = Map1.GetOpenLayersMap();
// map.addPopup(popup);
-------------------------------------------------------------------------------------------------------------------------------------------
putMarker(Objects.aractip,iStatus,x,y,true, aci, durum);
startFrom++;
beginAnimHandler();
}
function beginAnimHandler() {
var Interval = 500;
if (!isNaN(document.getElementById('numerator').value)) {
Interval = document.getElementById('numerator').value * 100;
}
else {
document.getElementById('numerator').value = 5;
}
animHandler = window.setTimeout(showNextMarker, Interval);
}
function stopAnim() {
if (animHandler != null)
window.clearTimeout(animHandler);
startFrom = 0;
animHandler = lastMarker = markersObj = null;
isAnimBegin = false;
buttonCase(false);
}
function buttonCase(state) {
document.getElementById('startinput').disabled = state;
document.getElementById('stopinput').disabled = !state;
}
function startAnim() {
if (animHandler != null) {
stopAnim();
}
if (markerLayer == null) {
markerLayer = new OpenLayers.Layer.Markers('vehicleLayer');
parserMap1.map.addLayer(markerLayer);
}
buttonCase(true);
isAnimBegin = true;
markerLayer.clearMarkers();
showNextMarker();
}