locked
Moving an asset in the Virtual Earth map control

    Question

  • Hi,

    My requirement is to move an asset ( a pushpin with a custom icon ) on the virtual earth map control. I would ideally like to have a context menu to pop up when the user right clicks on the pushpin and when he selects to move this pushpin, the shape of the cursor and the pushpin is modified. When he clicks again on some point in the map, the asset should be relocated to that position.
    Is it possible to acheive this in Virtual Earth?
    Thanks in advance

    -v

    Thursday, August 02, 2007 12:49 PM

Answers

  • I made my pin dragable like this (could easily modify to move the specific pin but i only had one):

    var mode = 0;

    var pin;

     

    Add these events:

        map.AttachEvent("onmousemove", onMapMouseMove);
        map.AttachEvent("onmousedown", onMapMouseDown);
        map.AttachEvent("onmouseup", onMapMouseUp);

     

    and then these functions:

     

    function onMapMouseDown(e) {
        if (e.leftMouseButton && e.elementID) {
            mode=1;
            map.vemapcontrol.EnableGeoCommunity(true);
        }
    }

    function onMapMouseMove(e) {
        var loc = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));  
        if (mode==1) {
            pin.SetPoints(loc);
        }
    }

    function onMapMouseUp(e) {
        if (mode==1 && e.leftMouseButton) {
            map.vemapcontrol.EnableGeoCommunity(false);
            mode=0;
            var loc = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));
            pin.SetPoints(loc);
        }
    }

     

    Sunday, August 05, 2007 7:04 PM
    Moderator

All replies

  • Absolutely do-able...Version 5 of the VE api is much richer with event handling.  I would start here, and research the available map events and what properties are exposed (such as obtaining the VEShape ID of the item that was clicked).  As far as repositioning the pushpin is concerned, you're probably going to end up deleting the first reference and then recreating it on the destination click-point. 

    Thursday, August 02, 2007 2:30 PM
  • I made my pin dragable like this (could easily modify to move the specific pin but i only had one):

    var mode = 0;

    var pin;

     

    Add these events:

        map.AttachEvent("onmousemove", onMapMouseMove);
        map.AttachEvent("onmousedown", onMapMouseDown);
        map.AttachEvent("onmouseup", onMapMouseUp);

     

    and then these functions:

     

    function onMapMouseDown(e) {
        if (e.leftMouseButton && e.elementID) {
            mode=1;
            map.vemapcontrol.EnableGeoCommunity(true);
        }
    }

    function onMapMouseMove(e) {
        var loc = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));  
        if (mode==1) {
            pin.SetPoints(loc);
        }
    }

    function onMapMouseUp(e) {
        if (mode==1 && e.leftMouseButton) {
            map.vemapcontrol.EnableGeoCommunity(false);
            mode=0;
            var loc = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));
            pin.SetPoints(loc);
        }
    }

     

    Sunday, August 05, 2007 7:04 PM
    Moderator