locked
Add new pushpin in V5 RRS feed

  • Question

  • Newbie Alert

     

     In V4  I use  VEMap.AttachEvent(“onclick”, function); to pass the latlong values through to the function and generate a pushpin for every click from which I can read off accurate latitudes and longitudes. In V5 the lat longs don’t appear to get passed through to the function. Reading the literature it says “The latLong coordinates of the clicked location.... This only works in 3D mode. For 2D, you can convert mapX and mapY to a latLong using the VEMap.PixelToLatLong Method method.” I’m stuck here. I tried various things including this based on a previous thread

     

            mapXPixel = event.clientX - map.GetLeft();

            mapYPixel = event.clientY - map.GetTop();

            latLong = map.PixelToLatLong(mapXPixel,mapYPixel);

            alert('Latitude=' + latLong.Latitude + ', Longitude=' + latLong.Latitude);

            var shape = new VEShape(VEShapeType.Pushpin, latLong);

            shape.SetTitle('My pushpin');

            map.AddShape(shape);

     

    in the function but to no avail. Could anyone point me in the right direction.

     

    Thanx.

    Friday, May 4, 2007 2:46 PM

Answers

  • Actually, in V5 you need to instantiate a new VEPixel object before passing to the PixelToLatLong.  Something like:

    mapXPixel = event.clientX - map.GetLeft();

    mapYPixel = event.clientY - map.GetTop();

    latLong = map.PixelToLatLong(new VEPixel(mapXPixel,mapYPixel));

    VE5 PixeltoLatLong method:
    http://msdn2.microsoft.com/en-us/library/bb429564.aspx

    Hope that helps,

    Friday, May 4, 2007 2:55 PM

All replies

  • Actually, in V5 you need to instantiate a new VEPixel object before passing to the PixelToLatLong.  Something like:

    mapXPixel = event.clientX - map.GetLeft();

    mapYPixel = event.clientY - map.GetTop();

    latLong = map.PixelToLatLong(new VEPixel(mapXPixel,mapYPixel));

    VE5 PixeltoLatLong method:
    http://msdn2.microsoft.com/en-us/library/bb429564.aspx

    Hope that helps,

    Friday, May 4, 2007 2:55 PM
  • Brilliant. It works perfectly. Many thanx.
    Friday, May 4, 2007 3:01 PM