简体   繁体   English

刷新后,Gmap释放GListener

[英]Gmap looses GListener after refresh

I have a Gmap Control where i add lots of points(markers) via c# code. 我有一个Gmap控件,我在其中通过c#代码添加了很多点(标记)。 Directly after i add the marker i add a GListener to all the markers. 在添加标记后,我立即向所有标记添加GListener。

Now i have a few buttons on the web page that when a user clicks one of them the map gets refreshed to show only relative markers. 现在,我在网页上有几个按钮,当用户单击其中的一个按钮时,地图将刷新以仅显示相关标记。 Everything works fine when the user clicks the first button but when the user clicks on any other button the Glistener just doesnt work but the markers does change accordingly. 当用户单击第一个按钮时,一切工作正常,但是当用户单击任何其他按钮时,闪烁器将不起作用,但标记会相应地更改。

Here is some code where i add the markers and listeners. 这是一些我在其中添加标记和侦听器的代码。

marker = new GMarker(new GLatLng(lat, lng), new GIcon(Gicon));                 
clicklistener = new GListener(marker.ID, GListener.Event.click, string.Format(@"function(){{var w=new google.maps.InfoWindow();w.setContent('<center><b>{0}</b></center></br><center>{3}</center></br><center>{4}</center></br><center>{5}</center></br><center>{6}</center>');w.open({1}, {2});}}", SName + " , " + FacType, GMap1.GMap_Id, marker.ID, "Printer Status: " + PrinterStatus.ToString() + ", Battery: " + Sbat + "V  Signal: " + SSignal + "%", "Scanner Status: " + ScannerStatus.ToString(), "SMS Received: " + Sreceived + " , SMS Sent: " + Ssent, "Last SMS Date: " + SsmsDate.ToString() + " , Last Comms Date: " + ScommsDate.ToString()));

The Marker and clicklistener is globally defined and gets added to the map via gmap1.add(marker) and gmap1.add(clicklistener) any ideas? Marker和clicklistener是全局定义的,可以通过gmap1.add(marker)和gmap1.add(clicklistener)添加到地图上吗?

Regards Patrick 问候帕特里克

Sorted. 排序。

All that needed to be done is a complete reset of the whole map like so: GMap1.reset(); 需要做的就是完全重置整个地图,如下所示:GMap1.reset(); and then just add the new markers and listeners as necessary :) 然后根据需要添加新的标记和侦听器:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM