mikejuniper.com

August 8, 2008

My first Virtual Earth post

Filed under: Virtual Earth — mike @ 1:43 pm

So I’ve got a page with a virtual earth map into which I load a bunch of shapes. When the user mouses over a shape, I wanted the fill color to change and the infobox to popup. My initial plan was to use onmouseover and onmouseout but I found that when you mouse over the infobox, the onmouseout event fires. So instead of using the onmouseover and onmouseout events, I handled everything in onmousemove and keep track of my ‘current’ shape (_currentWatershed). I also check to see whether the shape the mouse is over is the same as the _currentWatershed and if so, I don’t do anything.

function mouseMoveHandler(e)
{
    if (e.elementID == null)
    {   //if we moused off all features
        //and there was a _currentWatershed set
        if (_currentWatershed != null)
        {
            _currentWatershed.SetFillColor(_watershedsFillColor);
            _map.HideInfoBox(_currentWatershed);
            _currentWatershed = null;
        }
    }
    else
    {
        var shape = _map.GetShapeByID(e.elementID);
        if (shape != null &&
            shape.GetShapeLayer() == _watershedsLayer &&
                shape != _currentWatershed)
        {
            if (_currentWatershed != null)
                _currentWatershed.SetFillColor(_watershedsFillColor);

            _currentWatershed = shape;
            _currentWatershed.SetFillColor(_watershedsHoverFillColor);
            _map.HideInfoBox();

            //shows the infobox at the mouse position when this event fires
            _map.ShowInfoBox(_currentWatershed, new VEPixel(e.mapX, e.mapY));
        }
    }
}

3 Comments

  1. Ahhhhh Mike! Indent your code! Just playing ;-)

    Looks great! Perfect start for your blog, something simple.

    Congratz!

    Comment by Max — August 8, 2008 @ 2:34 pm

  2. Yeah, I know. I wasn’t sure how to get Wordpress to do that. Just figured it out though: the html

     tag seems to work.

    Comment by mike — August 16, 2008 @ 8:56 am

  3. Mike, if you are interested in creating a tile overlay map for your simple VE app, please take a look at MapDotNet UX.

    You can try our parcel overlay map now just by adding the following code…

    function GetTiles()
    {
    var bounds = [new VELatLongRectangle(new VELatLong(32,-85),new VELatLong(30,-83))];
    var tileSourceSpec = new VETileSourceSpecification(”parcels”, “http://services.parcelatlas.com/MapTileHandler.ashx?qkey=%4&contractid=D3342484-32CD-DD11-AF04-0003FF70C8AE”);

    tileSourceSpec.NumServers = 1;
    tileSourceSpec.Bounds = bounds;
    tileSourceSpec.MinZoomLevel = 1;
    tileSourceSpec.MaxZoomLevel = 20;
    tileSourceSpec.Opacity = 1.0;
    tileSourceSpec.ZIndex = 100;
    map.AddTileLayer(tileSourceSpec, true);
    }

    Comment by Mark Alexander — February 16, 2009 @ 11:44 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress