Reimers.dk

.NET, AJAX and Google APIs brought together
Welcome to Reimers.dk Sign in | Join | Help
in Search

No client side map objects accessible after a callback

Last post 08-04-2010, 3:46 by jarobert. 12 replies.
Sort Posts: Previous Next
  •  02-02-2010, 16:49 2985

    No client side map objects accessible after a callback

    I have renamed this post as it is not specific to the GEvent.trigger event I was trying to fire.

    It would seem that no overlay objects are accessible in any javascript functions on the .aspx page after any kind of call back.

    Someone must have hit a similar problem? 

  •  02-02-2010, 19:49 2986 in reply to 2985

    More info

    Ok, finally, an explanation but no cure.

    If I do not clear the overlays then this works ok, so this is something defintely to do with clearing the overlay. Not quite sure what though?

  •  02-03-2010, 22:04 2987 in reply to 2986

    Re: More info

    I think you will need to explain in a little more detail.

    You can access any overlay currently on the client by checking reimers.map.[mapID].Overlays. This is the array that holds the overlays. Each overlay has an ID property. This ID is not the same as the serverside ID. It is a specially generated clientside ID, which you can get by calling the ClientSideID(Map) on the server.

    If you are using Firebug you can see the array in your DOM inspector. Here you should see all the overlays managed by the control.

  •  07-20-2010, 6:08 3174 in reply to 2987

    Re: More info

    I am experiencing the exact problem described above.

    In order to open an infowindow after clicking a row in a grid view I have the following which works perfectly until any call back occurs. After that the javascript function is called but the infowindow does not open.

    If I comment out the line  mapcommand = GMap.ClearOverlays(true); from the callback everything works fine but obviously that is not a long term solution.

            //Add javascript to handle the row click event
            ClientScript.RegisterStartupScript(this.GetType(),"markerclick",
            "<script language=javascript>" +
            "function myclick(id){" +
            "id = 'GMapmarker' + id;" +
            "marker = reimers.map.GMap.getOverlay(id);" +
            "GEvent.trigger(marker, 'click');" +
            "}</script>");

            //Add click event to gridview rows

            if (GridView1.Rows.Count > 0)
             {
                    int i;
                    for (i = 0; i < GridView1.Rows.Count; i++)
                    {
                        GridView1.Rows[i].Attributes.Add("onclick", GMap.CreateMapCallback("this.rowIndex", true));
                    }
             }

           //Handle the Callback

           void GMap_ExternalCallback(string argument, ref string MapCommand)
           {
                 string mapcommand = null;
            
                 if (argument == "filter")
                 {
                     //Get extents of the new viewport
                     double minx = (double)(Session["minx"]);
                     double miny = (double)(Session["miny"]);
                     double maxx = (double)(Session["maxx"]);
                     double maxy = (double)(Session["maxy"]);

                     createMarkers(minx, miny, maxx, maxy, ref mapcommand);
                 }
                 else
                 {
                     dt = Session["transactionlist"] as DataTable;
                     int recid = Convert.ToInt32(argument)-1;
                     recid = Convert.ToInt32(dt.Rows[recid]["transactionid"]);
                     mapcommand = "myclick('" + recid + "');";
                 }

                 MapCommand = mapcommand;

             }
  •  07-20-2010, 20:53 3176 in reply to 3174

    Re: More info

    I'm going to have to do some checking on this to see what may be happening here.
  •  07-21-2010, 2:04 3177 in reply to 3176

    Re: More info

    Thank you. Much appreciated. I've tried many things to no avail.
  •  07-22-2010, 15:25 3178 in reply to 3177

    Re: More info

    Hi Jacob. Have you had a chance to look into this? I simply cannot find a cause or solution.
  •  07-23-2010, 20:11 3180 in reply to 3178

    Re: More info

    I'm going to have a look at it in the weekend when I have some free time.
  •  07-25-2010, 17:44 3184 in reply to 3180

    Re: More info

    I had a careful look at this and I think it is not so much related to the map control as to your grid. When you use the ClearOverlays method, you are generating a script to remove all overlays. This also destroys all clientside references to them, which explains why they are not available in the collection. What you need to do is to remove the corresponding rows from your grid since there is no longer an overlay associated with that row.

    If what you really want to do is hide the overlay, then you need to recursively go through all the overlays and generate a hide command for it using the Hide helper method. 

    How are you keeping it synchronized with the overlay collection?

    I hope this helps. 

  •  07-26-2010, 2:23 3185 in reply to 3184

    Re: More info

    I don't think that this is the problem.

    The clearOverlays method is called as the first line of a procedure that regenerates the markers anytime the map extent changes or a filter parameter is changed.

    The database is then re-queried, a new dataset created and put in session, the markers regenerated (by looping through the dataset)  and then sent back to the client via:

                    mapcommand += GMap.AddOverlay(m1);

     Also sent back to the client is the following to force the gridview. Its in an update panel.

                    mapcommand += "__doPostBack('pnlResults', '');";

     In the page_load the following code gets the latest dataset from sesson and rebinds the grid to the new dataset:

     if (Page.IsPostBack)
            {           

                dt = Session["transactionlist"] as DataTable;
                bindGridView();

            }

    The markers are obviously reference by the client. They display in the map and the infowindows work properly - just not when executed via the javascript above after the first callback.

  •  08-03-2010, 5:18 3192 in reply to 3185

    Re: More info

    Hello,

     Have you had an opportunity to investigate this issue further.

     To be clear the issue is caused by line mapcommand = GMap.ClearOverlays(true);

    Despite the fact that the markers are immediately recreated and sent to the client via the same procedure,  the following line of javascript stops working:

    "GEvent.trigger(marker, 'click');" +

     Thanks Again.

  •  08-03-2010, 21:23 3193 in reply to 3192

    Re: More info

    I have to admit that you were right. There was a bug in the control that meant that in cases like yours when markers where being overwritten with new ones with the same ID, then there was a loss of reference. I checked in a fixed script to the trunk. 

    If you want to have a compiled version please let me know.

    Thank you for your persistence in this matter. 

  •  08-04-2010, 3:46 3194 in reply to 3193

    Re: More info

    A compiled version would be very helpful.

    Thank you for taking the time to investigate and resolve the problem.


View as RSS news feed in XML