VE Team's profileVirtual Earth / Live Map...PhotosBlogListsMore Tools Help

Blog


    March 13

    The 10 Minute Map, Part 2 - Adding Custom Icons

    Last week I showed you how to add a map with a custom data layer to your website in 10 minutes and without the need to be a developer. One reader used the 10 minute tutorial to add a map to their website for Rushworth Community House, and asked in the follow up comments how to customize the pushpin icon that appears for each location. This is really easy to do if inserting an additional line of code into the web page doesn't frighten you. The icon that appears on the map for each item in your Collection is simply a gif image. You can specify a custom gif image by setting the IconURL for your Collection. Lets say you want each pushpin to be a heart instead of the default pin like this:

    You can try it out here. If you view the source of the page you will notice the only change from the original version is the addition of this line:

         veLayerSpec.IconUrl ="http://www.sininlinen.com/mapstar.gif";

    Of course, you can substitute any image you want in there.

    With a little more effort you can have a different icon for each item in your Collection. Perhaps you want to number the icons. Or maybe you want to draw a different symbol for different types of things in the Collection. Here is a version of the page that draws a numbered circle for each item:

    Again, view the source to see the code. Her eyou will see that we are iterating over the array of pushpins and specifying a new icon for each like this:

    points[cnt].Iconurl = "http://maps.live.com/i/bin/1.3.1204222815.33/pins/RedCircle" + (cnt+1) + ".gif";

    After each icon has had an icon assigned, you tell VE to refresh the layer on the map by hiding it and re-displaying it like this:

         map.HideLayer("MYLAYER");
         map.ShowLayer("MYLAYER");

    That's it! if you've added these extra features to your web page, you should still be under 15 minutes total :-) In part three I'll show you how to add a text field to the page so that the user can enter a city or address they want to jump to. Best of all, it will only add about 4 lines to your application.

    As always, if you want to poke around to find some more chrome for your app, visit the VE developer documentation site. If you see something you like, just hit the 'Source code' tab on the page and copy and paste the snippet into your application.

    Comments (13)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    VE Team has turned off comments on this page.
    July 23
    July 23
    July 23
    July 23
    July 23
    Picture of Anonymous
    yagin wrote:
    販売管理システム
    顧客管理システム
    seo
    sem
    SEOサービスは費用対効果抜群です。
    PPC広告(Overture、AdWords)を中心に、広告の投資対効果を徹底します。
    June 16
    May 11
    Picture of Anonymous
    Apr. 14
    彦强wrote:
    China Tour Select is a China travel agency providing  China toursBeijing Tours, Tibet Tours, Great Wall Tour and Yangtze river cruises. We specialize in "Tailor-Made" and "Customized" private and group tours to China. We'll try our best to offer you China tours with super value and most considerate service.     
    Apr. 4
    No namewrote:
    This is great, thanks.  Is there a way to set the default view to hybrid or aeril for example?
    Mar. 31
    Feb. 14
    May 26
    Picture of Anonymous
    sevenUP wrote:
    check out the map here and get the code to make your map work in firefox too
    here is the code:
    <script text/javascript>
                var ffv = 0;
                var ffn = "Firefox/";
                var ffp = navigator.userAgent.indexOf(ffn);
                if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
                // If we are using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
                if (ffv >= 1.5) {
                    Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
                }
        </script>
    add it right after the <script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script> line
    Apr. 2

    Trackbacks (5)

    The trackback URL for this entry is:
    http://virtualearth.spaces.live.com/blog/cns!2BBC66E99FDCDB98!8258.trak
    Weblogs that reference this entry