VE Map object as a user control
Hi,
I had created the VE Map object as a user control and had 2 instances running in the same page, the pushpins i created i had done it with unique ids
( var pin = new VEPushpin('<%=myMap.ClientID %>' + k, new VELatLong(lat, lng),imgPath,'', ((html))); )
still when i do the mouse hover on 1 map object both the objects refresh has anyone encountered this problem? is there a fix?
ram
[426 byte] By [
RamV] at [2007-12-27]
Hello Derek,
Below is the code i used for creating the webpart map user control,when we have 2 instances of the usercontrol on a page both the map usercontrols stops working..
<%
@ Control Language="C#" AutoEventWireup="true" CodeFile="AAEVirtualEarthWP.ascx.cs" Inherits="AAEVirtualEarthWP" %><
link rev="stylesheet" media="all" href="../Styles.css" type="text/css" rel="stylesheet" /><
script language="JavaScript" type="text/javascript">var
<%=myMap.ClientID %>map=null;var
footer = null; var
<%=myMap.ClientID %>locationCollection = new Array();function
<%=myMap.ClientID %>mapLoad() {var bCanDisplay ='<%=CanDisplay %>' ;if(bCanDisplay=='True'){
<%=myMap.ClientID %>map =
new VEMap('<%=myMap.ClientID %>');<%=myMap.ClientID %>map.LoadMap();
<%=myMap.ClientID %>XMLHttp.<%=myMap.ClientID %>fetchXML(<%=myMap.ClientID %>XMLHttp.<%=myMap.ClientID %>create(),
"locations-lease01.xml",<%=myMap.ClientID %>finishMap);var <%=myMap.ClientID %>blnNUllLatitude;var <%=myMap.ClientID %>blnNullLongitude; <%=myMap.ClientID %>blnNUllLatitude=
'<%=IsNUllLatitude %>' ;<%=myMap.ClientID %>blnNullLongitude=
'<%=IsNUllLongitude %>' ;if((<%=myMap.ClientID %>blnNUllLatitude == 'False') && ( <%=myMap.ClientID %>blnNullLongitude=='False')){
var ilat= '<%=Latitude %>' ;var ilng='<%=Longitude %>'; if(ilat.length == 0 || ilng.length== 0 ) {}else { //<%=myMap.ClientID %>map.AttachEvent('onclick', <%=myMap.ClientID %>SetCtr);//////? setTimeout(<%=myMap.ClientID %>SetCtr,1);}
}
//<%=myMap.ClientID %>map.onLoadMap = function(){ alert('The map has loaded.') };}
}
function
<%=myMap.ClientID %>SetCtr(){
var ilat= '<%=Latitude %>' ;var ilng='<%=Longitude %>'; // <%=myMap.ClientID %>map.SetCenterAndZoom(new VELatLong(ilat,ilng), 8); if(<%=myMap.ClientID %>locationCollection.length > 0){
//<%=myMap.ClientID %>map.SetMapView(<%=myMap.ClientID %>locationCollection);}
<%=myMap.ClientID %>map.SetCenter(
new VELatLong(ilat,ilng)); }
function
<%=myMap.ClientID %>finishMap(xml) {<%=myMap.ClientID %>processLocations(xml);
if(<%=myMap.ClientID %>locationCollection.length > 0){
<%=myMap.ClientID %>map.SetMapView(<%=myMap.ClientID %>locationCollection);
}
}
window.attachEvent(
'onload',<%=myMap.ClientID %>mapLoad);window.onresize= <%=myMap.ClientID %>mapLoad;
//window.attachEvent('onResize',<%=myMap.ClientID %>mapLoad);
//<%=myMap.ClientID %>map.AttachEvent('onresize', <%=myMap.ClientID %>mapLoad());
var
<%=myMap.ClientID %>XMLHttp = {<%=myMap.ClientID %>create :
function () {var xmlhttp;try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }catch (e) {try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch (e) {xmlhttp =
false;}
}
return xmlhttp;},
<%=myMap.ClientID %>fetchXML :
function(request,url,callbackFn) {request.open(
"GET", url, true);request.onreadystatechange =
function() {if (request.readyState == 4) {var <%=myMap.ClientID %>xml = request.responseXML;callbackFn(<%=myMap.ClientID %>xml);
}
}
request.send(
null);}
}
function
<%=myMap.ClientID %>processLocations(xmlDoc){
var strXML = '<%=GetXMLLocations()%>'; var ilat; var ilng; var <%=myMap.ClientID %>blnNUllLatitude;var <%=myMap.ClientID %>blnNullLongitude; <%=myMap.ClientID %>map.Clear();
if (strXML.length > 6){
xmlDoc.loadXML(strXML);
var locations = xmlDoc.documentElement.getElementsByTagName("Location");for (var i = 0; i < locations.length; i++){
var k;k= i+1;
if((locations
.getAttribute("Lat").length > 0) && (locations
.getAttribute("Lng").length > 0)){
var lat = parseFloat(locations
.getAttribute("Lat"));var lng = parseFloat(locations
.getAttribute("Lng"));var img=locations
.getAttribute("Image");var imgPath;if(img ==''){ imgPath=
'../images/icons/flag_blue.gif';}
else{ imgPath=
'../images/icons/'+img ;}
var html = <%=myMap.ClientID %>createLocationInfoWindow(locations
);<%=myMap.ClientID %>locationCollection.push(
new VELatLong(lat, lng)); // var pin = new VEPushpin(k, new VELatLong(lat, lng),'../images/icons/flag_blue.png','', html); //var pin = new VEPushpin(k, new VELatLong(lat, lng)); var pin = new VEPushpin('<%=myMap.ClientID %>'+k, new VELatLong(lat, lng),imgPath,'', ((html))); // VEPushpin.ShowDetailOnMouseOver = false;/// map.AddPushpin(pin);<%=myMap.ClientID %>map.AddPushpin(pin);
}
}
}
}
function
<%=myMap.ClientID %>createLocationInfoWindow(myLocation){
var strChildNode;var strChildNodexml;var strSubstrMsg;strChildNode =myLocation.childNodes[0] ;
//strChildNodexml=strChildNode.xml;strChildNodexml=strChildNode.text;
var html =(strChildNodexml) ;//alert(html);return html;}
//-->
</
script><
div id="DivContainer" runat="server" style="OVERFLOW:hidden;position:relative;"><
div id="myMap" runat="server" style="WIDTH:100%;HEIGHT:98%;OVERFLOW:hidden;position:relative;"></div></
div>Another question:
1) Are you trying to put up two user controls, and within each user control exists one instance of VE?
2) What do you mean, "it stops working"?
3) What exactly do you mean by: "both objects refresh when I hover over it"? Both maps reload and populate themselves with pushpins?
Derek,
Are you trying to put up two user controls, and within each user control exists one instance of VE?
Thast true, i am loading 2 instances of the VE user control in a page
What do you mean, "it stops working"? when there is only 1 instance of the VE user control in the page the pins are loaded correctly refresh happens, but when there are 2 instances trying to reload 1 instance refreshes the second instance too andthe page goes into this infinite loading cycle
What exactly do you mean by: "both objects refresh when I hover over it"? Both maps reload and populate themselves with pushpins?
Both maps objects try to reload but they dont populate with pushpins..
Ram,
Here is what I suspect:
When you reload the VE map, you are dynamically creating VE by parsing your xml locations into HTML. This causes a page refresh which causes the other VE map to reload itself and in turn dynamically populates its own pushpins. Then in turn, the second VE map causes a page refresh which causes the first VE map to reload its pushpins. Thus you get your infinite cycle and nothing happens as both are constantly populating their pins.
First of all having two VE instances on the same map is not recommended as it causes a huge hit on cpu performance and as a workaround find a way to separate the controls on two different pages.