Is it possible to do a map.Find() and not have the pushpins automatically added I would like to have a callback on the Find() but I would like to add my own pushpins. Do I have to manually go through and remove all the pushpins it automatically entered then re-add them Or is there a parameter or property I am missing
Thanks,
Jason

map.Find() without adding pushpins
Beast Forever
//define a global bool check variable
var map = null;
var doIReturnPushpin = true;
var idCounter = 1;
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.ShowDisambiguationDialog(false);
map.Clear();
map.HideDashboard();
}
function FindBars(){
returnPushpin = false;
map.Find('bars','nashville,tn',1,onFindBars);
}
function onFindBars(findResults){
var curLatLong;
if(findResults != null){
for (r=0; r < findResults.length; r++){
try{
idCounter ++;
curLatLong = new VELatLong(findResults[r].Lat,
findResults[r].Lon);
var Pushpin = new VEPushpin(
idCounter,
curLatLong,
"http://forums.microsoft.com/MSDN/emoticons/PostAttributeIMG/CommentIcon.gif",
findResults[r].Name,
findResults[r].Description + '<br>' + findResults[r].Phone
);
doIReturnPushpin = true;
map.AddPushpin(Pushpin);
doIReturnPushpin = false;
}catch(e){
// on error do nothing
}
}
}
doIReturnPushpin = false;
}
VEPushpin.prototype.GetContent = function()
{
var pinId=this.ID+"_"+this.m_vemap.GUID;
var content="<img onload='onPinLoad(this)' class='"+this.IconStyle+"' src='"+this.Iconurl+"' id='"+pinId+"' ";
var isTitleValid=this.Title!=null&&this.Title!="undefined"&&this.Title.length>0;
var isDetailsValid=this.Details!=null&&this.Details!="undefined"&&this.Details.length>0;
if(isTitleValid||isDetailsValid){
content+=" onmouseout='VEPushpin.Hide();' onmousedown='VEPushpin.Hide(true);' onmouseover='VEPushpin.Show(\""
+this.m_vemap.GUID
+"\",\""
+this.ID
+"\","
+this.LatLong.Latitude
+","+this.LatLong.Longitude;
if(isTitleValid)content+=", \""+escape(this.Title)+"\"";
else content+=",\"\"";
if(isDetailsValid)content+=", \""+escape(this.Details)+"\"";
else content+=",\"\"";
content+=",\""+this.TitleStyle+"\"";
content+=",\""+this.DetailsStyle+"\"";
content+=");' ";
alert('pin contents: ' + content);
}
//this adds the click event
content += " onclick='PinClick(" + this.ID + ")'";
content+=" />";
// see if we return a pushpin or not
if(doIReturnPushpin == false){
//alert('return nothing');
return '';
}else{
//alert('return something');
return content;
}
}
Andijk
HelderPinto79
this code works because everytime a pushpin is added it uses teh VEPushpin.prototype.GetContent you define here. if you have your check variable set to false then the function returns an empty string and there for nothing gets put on the map. when you call your own onFindResults function you set the check variable to true just before you put your pin on the map and to false right afterward. check this example:
//define a global bool check variable
var doIReturnPushpin = true;
GetMapFunction(){
//Include this inside your map initialization function
VEPushpin.prototype.GetContent = function()
{
var pinId=this.ID+"_"+this.m_vemap.GUID;
var content="<img class='"+this.IconStyle+"' src='"+this.Iconurl+"' id='"+pinId+"' ";
var isTitleValid=this.Title!=null&&this.Title!="undefined"&&this.Title.length>0;
var isDetailsValid=this.Details!=null&&this.Details!="undefined"&&this.Details.length>0;
if(isTitleValid||isDetailsValid)
{
content+=" onmouseout='VEPushpin.Hide();' onmousedown='VEPushpin.Hide(true);' onmouseover='VEPushpin.Show(\""
+this.m_vemap.GUID
+"\",\""
+this.ID
+"\","
+this.LatLong.Latitude
+","+this.LatLong.Longitude;
if(isTitleValid)content+=", \""+escape(this.Title)+"\"";
else content+=",\"\"";
if(isDetailsValid)content+=", \""+escape(this.Details)+"\"";
else content+=",\"\"";
content+=",\""+this.TitleStyle+"\"";
content+=",\""+this.DetailsStyle+"\"";
content+=");' ";
//this adds the click event to a pushpin
content += " onclick='PinOnClick(" + this.ID + ")'";
content+=" />";
}
// see if we return a pushpin or not
if(doIReturnPushpin == false){
return '';
}else{
return content;
}
}
map = new VEMap('MAP');
map.LoadMap();
map.ShowDisambiguationDialog(false);
map.Clear();
map.HideDashboard();
}
function FindBars(){
returnPushpin = false;
map.Find('bars','nashville,tn',1,onFindBars);
}
function onFindBars(findResults){
if(findResults != null){
for (r=0; r < findResults.length; r++){
try{
var Pushpin = new VEPushpin(idCounter,findResults[r].LatLong,null,findResults[r].Name,findResults[r].Description + '<br>' + findResults[r].Phone);
doIReturnPushpin = true;
map.AddPushpin(Pushpin);
doIReturnPushpin = false;
}catch(e){
// on error do nothing
}
}
}
doIReturnPushpin = false;
}
Lawrex
ACHawk
CFleming
sorry i cut and pasted the code and didnt bother to check if the code would stand on its own outside of my site. this updated code works, i double checked it.
only a couple things changed, i had some variables that were not defined in the original code. enjoy.
var map = null;
var doIReturnPushpin = true;
var idCounter = 1;
function GetMap()
{
VEPushpin.prototype.GetContent = function(){
var pinId=this.ID+"_"+this.m_vemap.GUID;
var content="<img class='"+this.IconStyle+"' src='"+this.Iconurl+"' id='"+pinId+"' ";
var isTitleValid=this.Title!=null&&this.Title!="undefined"&&this.Title.length>0;
var isDetailsValid=this.Details!=null&&this.Details!="undefined"&&this.Details.length>0;
if(isTitleValid||isDetailsValid)
{
content+=" onmouseout='VEPushpin.Hide();' onmousedown='VEPushpin.Hide(true);' onmouseover='VEPushpin.Show(\""
+this.m_vemap.GUID
+"\",\""
+this.ID
+"\","
+this.LatLong.Latitude
+","+this.LatLong.Longitude;
if(isTitleValid)content+=", \""+escape(this.Title)+"\"";
else content+=",\"\"";
if(isDetailsValid)content+=", \""+escape(this.Details)+"\"";
else content+=",\"\"";
content+=",\""+this.TitleStyle+"\"";
content+=",\""+this.DetailsStyle+"\"";
content+=");' ";
//this adds the click event
content += " onclick='PinOnClick(" + this.ID + ")'";
content+=" />";
}
if(doIReturnPushpin == false){
return '';
}else{
return content;
}
}
map = new VEMap('myMap');
map.LoadMap();
map.ShowDisambiguationDialog(false);
map.Clear();
map.HideDashboard();
}
function FindBars(){
doIReturnPushpin = false;
map.Find('bars','nashville,tn',1,onFindBars);
}
function onFindBars(findResults){
if(findResults != null){
alert('test');
for (r=0; r < findResults.length; r++){
try{
var Pushpin = new VEPushpin(idCounter,findResults[r].LatLong,'http://forums.microsoft.com/MSDN/emoticons/PostAttributeIMG/CommentIcon.gif',findResults[r].Name,findResults[r].Description + '<br>' + findResults[r].Phone);
doIReturnPushpin = true;
map.AddPushpin(Pushpin);
doIReturnPushpin = false;
idCounter ++;
}catch(e){
// on error do nothing
}
}
}
doIReturnPushpin = false;
}
Sai A
It would be nice if the Virtual Earth guys could include some extra params on the find that you can say if you dont want the default pins to be added, also the radius of the find you want to perform.
Thanks again
kewlbuddy
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=752722&SiteID=1