map.Find() without adding pushpins

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



Answer this question

map.Find() without adding pushpins

  • Beast Forever

    Thanks for getting back to me, i have tried putting in the full path to the image in the pushpin creation however it will still appear as the default red pin. Iv included the code i am using based upon what was posted above but with slight modification as i found the long lad did not work.

    //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

    make sure you are passing a URL and not just a file name. for instance "image.gif" will not work even if "image.gif" is in the same directory as your page, and will instead display the default red pushpin. However, "http://www.yoursite.com/image.gif" will work.
  • 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

    Iv tried this code in my site but wanted to pass a different pin icon however no matter what i pass instead of the null value, it comes up as the default red flag. Has anyone got any idea what i can do to correct this.

  • ACHawk

    I'm looking for this same idea as well. I current;y have to do it with the whole remove then add idea. If someone knows of someway to do this it would be awsome.

  • 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

    Thanks for that link. I was trying to intergate the above function into an asp.net site which used ajax to put a set of push pins then show some more information using the find function. However i was having problems getting it to work. With the hack/work around shown in the link above i was able to get this to work a treat.

    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

    There is another thread that answers this question here:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=752722&SiteID=1

  • map.Find() without adding pushpins