Reputation: 10547
I'm trying to create a concave polygon by getting user clicks on a map. I can create convex polygons just fine. But when I attempt to create the concave polygon I have to click on the polygon itself giving me the following error:
e.target.tryPixelToLocation is not a function
Allow me to elaborate further. The user clicks on the map and a pin is placed on the map to show where they just clicked. They click two more time and they now have a triangle drawn on the map. When they attempt to click inside that triangle to draw the fourth point, creating a concave polygon, they get the above error.
The code I am using is below
function GetMap(sender, args) {
map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {
credentials: "XXXXX",
enableSearchLogo: false,
enableClickableLogo: false,
disableBirdseye: true
});
map.setView({
zoom: 17,
center: new Microsoft.Maps.Location($('#startLatitude').val(), $('#startLongitude').val()),
mapTypeId: Microsoft.Maps.MapTypeId.aerial,
labelOverlay: Microsoft.Maps.LabelOverlay.visible
});
Microsoft.Maps.Events.addHandler(map, 'click', getUserClick);
}
function getUserClick(e) {
alert(e.targetType); // <--- When this is 'Polygon' we get the error
if (e.mouseMoved === false && e.isPrimary === true) {
var p = new Microsoft.Maps.Point(e.getX(), e.getY());
var t = e.target.tryPixelToLocation(p);
var l = new Microsoft.Maps.Location(t.latitude, t.longitude);
// Clear and draw polygon with new point //
}
}
How can I get the latitude/longitude of the click when the targetType
is Polygon?
Upvotes: 0
Views: 660
Reputation: 17954
When the click event is on a Polygon class use map.tryPixelToLocation as the polygon class doesn't have that function.
Upvotes: 1