none
V8 - get a point when click. RRS feed

  • Question

  • I have a working site with V7. Now I tryed to test V8 and got into some trouble.

    I am trying : when a user click on the map get the Point and do something.......

    eg.

    Microsoft.Maps.Events.addHandler(map, 'click', displayLatLong);

    function displayLatLong(e) {
        if (e.targetType === "map") {
            var point = new Microsoft.Maps.Point(e.getX(), e.getY());
            var loc = e.target.tryPixelToLocation(point);
            var lat = loc.latitude.toString();
            var lat = lat.replace(".", ",");
            var long = loc.longitude.toString();
            var long = long.replace(".", ",");
           
            document.getElementById("Latitude").value = lat;
            document.getElementById("Longitude").value = long;
        }

    This works fine in V7 but I cant work it out in V8.

    The tip in this page (bottom) sound like it shoud be similar in V8

    https://msdn.microsoft.com/en-us/library/mt712677.aspx

    Jan

    ps. If you use the Bootstrap css some conflicts exist  (label) ds. 

    Wednesday, April 6, 2016 2:23 PM

Answers

  • The getX/getY methods of the event are not yet exposed in the API. We plan to add this in before taking V8 out of preview.

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Thursday, April 7, 2016 12:18 AM
    • Marked as answer by Jan_Olsmar Thursday, April 7, 2016 8:01 AM
    Thursday, April 7, 2016 12:18 AM
  • Took a closer look at this. Currently V8 returns an object and not a class, thus the reason why there is no getX/getY functions. However, the object returned by V8 now contains "point" and "location" properties. As such, you no longer need to manually convert the pixel coordinate to a map location. Here is a modified version of your code:

    function displayLatLong(e) {
         if (e.targetType === "map") {
             var loc = e.location;
    
            var lat = loc.latitude.toString();
             var lat = lat.replace(".", ",");
             var long = loc.longitude.toString();
             var long = long.replace(".", ",");
             
             document.getElementById("Latitude").value = lat;
             document.getElementById("Longitude").value = long;
         }

    We will still plan to add the functions in the future, but in the mean time this should help you move your project forward. Logged as Bug 283856


    http://rbrundritt.wordpress.com




    Monday, April 11, 2016 7:15 PM
  • Update: getX/getY is now supported by the mouseEventArgs object. They also have a target and targetType property.

    [Blog] [twitter] [LinkedIn]


    Wednesday, April 27, 2016 11:56 PM

All replies

  • The getX/getY methods of the event are not yet exposed in the API. We plan to add this in before taking V8 out of preview.

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Thursday, April 7, 2016 12:18 AM
    • Marked as answer by Jan_Olsmar Thursday, April 7, 2016 8:01 AM
    Thursday, April 7, 2016 12:18 AM
  • O, thanks. It was a bad tip then. At this Point......
    Thursday, April 7, 2016 8:01 AM
  • Took a closer look at this. Currently V8 returns an object and not a class, thus the reason why there is no getX/getY functions. However, the object returned by V8 now contains "point" and "location" properties. As such, you no longer need to manually convert the pixel coordinate to a map location. Here is a modified version of your code:

    function displayLatLong(e) {
         if (e.targetType === "map") {
             var loc = e.location;
    
            var lat = loc.latitude.toString();
             var lat = lat.replace(".", ",");
             var long = loc.longitude.toString();
             var long = long.replace(".", ",");
             
             document.getElementById("Latitude").value = lat;
             document.getElementById("Longitude").value = long;
         }

    We will still plan to add the functions in the future, but in the mean time this should help you move your project forward. Logged as Bug 283856


    http://rbrundritt.wordpress.com




    Monday, April 11, 2016 7:15 PM
  • Thanks, had to remove the test on targetType too. But then it worked.
    Tuesday, April 12, 2016 4:25 AM
  • I believe there are plans to add that back in.

    For my reference I have logged this as Bug 284039. 


    [Blog] [LinkedIn]

    Tuesday, April 12, 2016 7:30 PM
  • Update: getX/getY is now supported by the mouseEventArgs object. They also have a target and targetType property.

    [Blog] [twitter] [LinkedIn]


    Wednesday, April 27, 2016 11:56 PM