Woody_In_Sheffield


Hi,

I am currently trying to get the Longitude and Latitude co-ordinates whilst in the Birds Eye view mode but it would seem this is not possible even though you are allowed to set pushpins whilst in this mode...

I would have thought if you could set pushpins, you should also be able to retrieve details...

Has anyone managed to get around this issue

Cheers,

Woody.




Re: Getting Long/Lat in Birds Eye view mode

Woody_In_Sheffield


After some more investigation... I know it can be done as the central site is able to do it:

http://local.live.com/

Does anyone have the code I have tried to locate the JS files they use but "needle in a haystack" springs to mind...

Cheers,

Woody.






Re: Getting Long/Lat in Birds Eye view mode

SoulSolutions

It appears that for some reason, maybe the agreement from the data provider, none of the usual functions for retreiving lat and long work in Birdseye.

To make my applications work I found two things:

1) You can get the centre of the map using 'e.view.latlong.latitude' where e is the parameter in a map event like 'onchangeview'. I used this to estimate the overall bounds of the birdseye area to request the data required.

2) You can get the position of the actual pin div by using this:

var element2 = document.getElementByID(ID+ "_" + MapController._map.map.GUID);
var element = document.getElementByID(ID);
x = element.offsetLeft + element.offsetParent.offsetLeft + (element2.offsetLeft + element2.offsetWidth / 2);
y = element.offsetTop + element.offsetParent.offsetTop + (element2.offsetTop + element2.offsetHeight / 2);

I hope that helps in some way.

John.







Re: Getting Long/Lat in Birds Eye view mode

Woody_In_Sheffield

Sounds like a plan to me...

However, I am assuming that "element" is going to link to the DIV that contains the map.

But was is "element2" trying to link to





Re: Getting Long/Lat in Birds Eye view mode

Woody_In_Sheffield

SUCCESS...

Slightly unconventional way but here goes...

Firstly, I capture the point where I right-clicked.
Then I get the height and width of the DIV holding the map (just in case these are dynamic in any way...)
Then I divide them by 2 as I will be working with the centre of the DIV.
Then get the BirdsEyeScene object and get the pixel for the centre which is always the centre of the DIV (which is nice!)
Split the pixel variable into its relevant x/y co-ords.

Now we want to find the pixel at the Top Left corner of the DIV (not the 0, 0 position but the pixel of the actual map image as this is likely to have been moved around...). This is done by taking the x/y co-ords from the LatLongToPixel command of the centre of the map and subtracting the DIV width and height (which is why we halved the values).

We then add the Top Left co-ords to the captured co-ords of the right mouse click (as these are specifically related to the DIV) to give us the x/y co-ords of the map image to translate into the LatLong co-ords for the pushpin (or whatever reason we right-clicked in the first place...).

This may sound conveluted but I have pasted the code below with some alerts so that others may also have the power of the Birds Eye view...

// Get the position of the click
var posx = 0;
var posy = 0;
var e = window.event;

if (e.x || e.y)
{
posx = e.x;
posy = e.y;
}

var mapDiv = document.getElementById("myMap");
var mapDivH = mapDiv.offsetHeight / 2;
var mapDivW = mapDiv.offsetWidth / 2;
alert('DIV: H: ' + mapDivH + ' W: ' + mapDivW);

var be = map.GetBirdseyeScene();
var pixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());
var ppx = pixel.x;
var ppy = pixel.y;

var tlx = ppx - mapDivH;
var tly = ppy - mapDivW;
alert('TL: X: ' + tlx + ' Y: ' + tly);

var newx = posx + tlx;
var newy = posy + tly;

alert('x: ' + newx + ' y: ' + newy);

DoPixelToLL(newx, newy); //This is where I create my pushpin but I'm sure everyone knows that...





Re: Getting Long/Lat in Birds Eye view mode

SoulSolutions

I'm glad you found a work around.

I may have to do something similar to allow for drawing polygons in birdseye mode in the future. It is a bit annoying it doesn't just work exactly like the other modes.

John.






Re: Getting Long/Lat in Birds Eye view mode

Woody_In_Sheffield

Hi,

Just thought I would extend this thread as I have noticed that when I have applied a pushpin and then move to a different orientation, that the pushpins become mis-aligned (I can only guess due to the 30 deg agle that the photo is looking at!)

However, using a real life example (that most people know where to find), I navigated to the Statue of Liberty. One thing I did notice is that on the North view, (in zoomed out) there is a pier to the right which cannot be completely seen (goes off the RH side of the map). However, choosing the South view allows the full pier to be shown (obviously now on the left) but it is all in vision.

Does anyone know whether this is a fault with the mapping and the fact that the Long/Lat are not as precise as we would hope Either this or whether it is known that the misalignment can be accounted for using a particular formula to ensure the pushpins look OK

Woody.





Re: Getting Long/Lat in Birds Eye view mode

duqx

I have tried using the code in this post to create a pushpin in birds eye view and it works great. The trouble I am having is that I am unable to get the lat/long of the pushpin that was created. When I look at the pushpin it has the lat/long as null, is there anyway to get the lat/long of a pushpin created in birds eye view

Thanks!





Re: Getting Long/Lat in Birds Eye view mode

Derek Chan

There's an excellent example of what your looking for on the SDK, check here:

http://dev.live.com/virtualearth/sdk/ref/HTML/P_Namespace_VEPushpin_OnMouseOverCallback.htm

I've modified it slightly to output the lat/longs instead of pixel locations.

<html>
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
      <script>
         var map = null;
         var pinID = 1;
        
         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap();
         }  
        
         function AddPin()
         {  
            var pin = new VEPushpin(
            pinID,
            new VELatLong(47.6, -122.33),
            null,
            'My pushpin',
            'This is pushpin number '+pinID
            );
  
            VEPushpin.ShowDetailOnMouseOver = false;
            VEPushpin.OnMouseOverCallback = function(x, y, title, details)
            {
               alert('your mouse is at : ' + map.PixelToLatLong(x,y) + ','+ x + ', ' + y +
               ' and you can display the details from title: ' + unescape(title) +
               ' and details: ' + unescape(details));
            }
            map.AddPushpin(pin);
            pinID++;
         }  
      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
      <a href="#" onclick="AddPin();">Add a pushpin to the center of the map</a>
   </body>
</html>

Hope that helps,






Re: Getting Long/Lat in Birds Eye view mode

SoulSolutions

Good thought but no it doesn't work for birdseye view.

In this case I founf the best solution is to get the location of the actual pin div itself and place the popup based on its location.

John.






Re: Getting Long/Lat in Birds Eye view mode

Woody_In_Sheffield

In response to duqx question, you are not allowed to retrieve the LatLong value from within Bird's Eye view in the normal sense.

It is suggested by MS that the result is a string that is encrypted (I am assuming maybe for some legal/terrorism reason!):

http://msdn2.microsoft.com/en-us/library/aa973056.aspx

You can use the details in other functions but you can't see the details...

I am also after a way to get this information... and if I figure it out, I will let you know! I was hoping that I would be able to store the data in a database even if it was the encrypted string that I stored (I'm not fussy!!).

Woody.





Re: Getting Long/Lat in Birds Eye view mode

Woody_In_Sheffield

OK. I think I have some kind of answer...

When I first tried this, it didn't work as close as I would have liked but then I tried it on the Statue of Liberty and it seemed to work exactly so it may be a little hit and miss... Suck it and see...

You can store the encrypted string in a JavaScript variable but when you try and view it, you can't do anything with it (this far I assume you have already got to...) apart from using it in other VE functions.

Now use the variable (I will use 'ELatLong') and do the following...

map.SetMapStyle(VEMapStyle.Hybrid);
map.SetCenter(ELatLong);
alert(map.GetCenter().toString());

The alert will give you the LatLong. Now try and use it in a pushpin set of textboxes on your test form and it should put the pushpin where you want it...

Basically, the script above changes the mapstyle so that you ARE able to read the LatLong of the centre of the screen. So as long as you are able to SetCenter() using the coords (which you can as MS HAVE allowed this), then you just set and then get the coords...

Messing about I know and it must be said that it may be hit and miss but try it and see whether it works for you... You may be able to create a hidden DIV with a second map so that you can do the processing in the background in your production system... I wouldn't like to comment on the performance hit though, so TEST TEST TEST...

Woody.





Re: Getting Long/Lat in Birds Eye view mode

SoulSolutions

Woody,

I have been lead to believe that a work around is going to be put in place for the next version of VE for paid subscribers of the system only, it will be a seperate webservice from my understanding.

Is there a way you can work around this issue in the short term, maybe even with some bad performance

For example there is no problems adding pushpins to birdseye view using the normal lat/long, so i currently don't allow adding pushpins or drawing while in birdseye, the users have to go to normal mode to do this in the short term. All my data is stored in a database.

I also looked at a way to simply add the pin to the centre and provide links to move it left,right,up,down - behind the scene this simply modified the lat/long slightly and readded the pin. It was a bit of a pain for the user but it the concept could be turned into a control like the V3 navigation where you hold down the mouse and the pin redraws across the page.

John.






Re: Getting Long/Lat in Birds Eye view mode

Woody_In_Sheffield

SUPPORT RED NOSE DAY 2007 (16th March 2007)...

 

John (and indeed duqx),

Now that I have chance to test, here is a solution that works (without any subscription... although donations to Comic Relief greatly appreciated)...

Using a similar method in my last post, I am able to get the Lat and Long (and all it took was some lateral thinking...).

And actually it can all be done in a couple of lines of code...

map.SetMapStyle(VEMapStyle.Hybrid);

myLatFld.value = map.PixelToLatLong(map.LatLongToPixel(ll, 2).x, map.LatLongToPixel(ll, 2).y).Latitude.toString();

myLongFld.value = map.PixelToLatLong(map.LatLongToPixel(ll, 2).x, map.LatLongToPixel(ll, 2).y).Longitude.toString();

You have to have the map (or at least a map) in a mode other than Birdseye for this to work hence the first piece of code.

The next 2 lines just record the information in a couple of textboxes on my form (that I then use from a hyperlink to set a pushpin) just to tell me what the Lat/Long values are and that I can record them should I wish...

All the code does is get the encrypted LatLong values ("ll") and converts it to an x,y set of coords on the map. Then it just converts them back but because you are no longer in Birdseye view, you can actually access the values. Using these values is a lot better than my previous explanation above and less code.

After you have the Lat/Long, you can then set the SetMapStyle to Birdseye view and if you recorded the information where you were before (such as GetId(), GetCenter() and GetZoomLevel()) you go back to your previous Birdseye view, but there would be a flicker as it changed styles a couple of times. I have tried having a minimap behind the main DIV by using the z-index property to play around with getting the coords... But although the 2 maps were effectively identical, it did produce different results...

So all-in-all, for a production system, the MS dev you suggest would be better but at least for now, it works and I can play with it...

Have fun...

Woody...

 





Re: Getting Long/Lat in Birds Eye view mode

SoulSolutions

Grr, It looks like V5 has removed all ability to get to the lat/long. And we have no sign of the method to retrieve the information from the encypted value.

Looks like I won't be able to support birdseye mode for clustering without some serious hacks Sad

Has anybody be able to retrieve anything to determine the bounds of the birdseye scene so you can dynamically request only data for that area

John.