MapsUI polygon blocks mapClick - xamarin.forms

I have a layer with a number of polygons, where the layer is marked as NOT being an infolayer
myLayer = new Layer() { IsMapInfoLayer = false...
I also have an eventhandler for clicking the map defined in the xaml
MapClicked="myClickHandler"
This click works well on empty areas, but if I click a polygon, the map click is blocked. Previously I solved this by responding to the info event handler for the polygons and route that to the same code that handled map clicks, but that is not enough now, as I need the lat,lng of the clicked position.
How do I make the polygons not intercept my click?

If a feature is clicked the MapInfo event is called. If not the MapClicked event is called. This is by design. You mention IsMapInfoLayer is set to false. In that case no MapInfo event should be triggered and you should get a MapClicked event. Note, that the MapInfo event could also be triggered from another layer.
A workaround for your problem: The MapInfo event also contains the WorldPosition but it is on SphericalMercator coordinates. You can translate that with:
var latLon = Projection.SphericalMercator.ToLonLat(point.X, point.Y);

Related

Get nearest point on polyline when mousemove (gMaps v3)

I have an application that shows tracking data. With the map, and the track, I have a chart that show the speed of each point of the polilyne. When I move over the chart, the same point in the maps is highlighted.
What I need to do is: when I move the pointer over the polyline on the map, also highlight the point on the chart, for this, I need to get the nearest point from the polyline to the mouse pointer on the map.
I binded the polyline mousemove event, but I can't find any property that helps me.
the point(latLng) is a property of the mouseEvent
google.maps.event.addListener(polylineInstance, 'mousemove',function(e){
console.log(e.latLng)
})
To get the clicked segment of the Polyline, iterate over the path of the Polyline, create a temporarily polyline for each segment and use google.maps.geometry.poly.isLocationOnEdge() to check if the click has been on the current segment.

Flex: How to listen to event in ItemRenderer

I try to make have an EventListener in ItemRenderer but its not working. How to listen to an event inside an ItemRenderer?
----In MainHomeView.mxml----
<fx:Metadata>
[Event(name="myEvent", type="flash.events.Event")]
</fx:Metadata>
protected function btnAdd_clickHandler(event:MouseEvent):void {
var eventObject:Event = new Event("myEvent", true, true);
dispatchEvent(eventObject);
}
----In UserRenderer.mxml (ItemRenderer)---
protected function init(event:FlexEvent):void{ //run in CreationComplete
addEventListener("myEvent", onHandleEvent);
}
protected function onHandleEvent():void {
trace("Event received");
}
This might be a little late, but according to your sample, your ItemRenderer is listening to itself - which is why you'll never get the event. And as for bubbling, remember in both the target and capture phase, things start from the stage and work its way up to dispatching target, then back down again. Since your renderer is a child of the list, it will never receive this event.
If you want the IR to get the event from the list, you'll need a reference to the list - usually owner. In which case, this is owner.addEventListener(). You can also look at the ListData that is assigned to each renderer, and in that composite object is a reference to the list.
Straight from the documentation:
The event target serves as the focal point for how events flow through the display list hierarchy. When an event such as a mouse click or a keypress occurs, Flash Player or the AIR application dispatches an event object into the event flow from the root of the display list. The event object then makes its way through the display list until it reaches the event target, at which point it begins its return trip through the display list. This round-trip journey to the event target is conceptually divided into three phases: the capture phase comprises the journey from the root to the last node before the event target's node, the target phase comprises only the event target node, and the bubbling phase comprises any subsequent nodes encountered on the return trip to the root of the display list
You'll need to be a little careful with this, since the ItemRenderer is part of a ClassFactory creation method each renderer will be assigned this listener - this may or may not be what you want.
I have google and found the solution in gskinner. But by using this method, each item in the ItemRenderer will received an event, so if you have 100 items (in your ItemRenderer) you will rec'd 100 events.

How can I display moving object in google maps api 3

I want to be able to show movement in a google maps just like in this example
http://www.labnol.org/internet/live-flight-tracking-google-maps/12308/
I am starting, and followed an example to load markers from mysql and put them in a map. But this is all static. If I keep track of a moving object in my database, how can I display them in real time?
Thank you
Assuming marker is your Marker instance, you should use some Ajax call to get new coordinates, depending how you return them, lets say your script will return an Object of lat and long and assign it to variable new_location. Now you need to change marker position to new coordinates:
function change_pos(new_location) {
var LatLong = new google.maps.LatLng(new_location.lat, new_location.long);
marker.setPosition(LatLong);
}
Just call this function everytime you got replay from Ajax.
And thats it.

Initiate polygon drawing from custom button

I love the new polygon drawing options and have been playing with them for a couple of days.
On the official documentation I see that it is possible to initiate the drawing of a polygon by clicking on a button external to the map. Does anybody know how to do this?
http://code.google.com/apis/maps/documentation/javascript/overlays.html#updating_the_drawing_tools_control
In other words I would like to be able to create a button similar to the "Delete selected shape", but which will instead start the drawing of the polygon:
http://googlegeodevelopers.blogspot.com/2011/11/make-your-map-interactive-with-shape.html
Use setDrawingMode() function of the google.maps.drawing.DrawingManager object.
In the button click event handler, call:
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
To quit the drawing mode, call:
drawingManager.setDrawingMode(null);

Debug which event is dispatched when I double-click the mouse

I am currently working with a drawing tool for a mapping API, and every time I double-click the mouse a map service will perform a measurement and display the length of the line that I am drawing.
I want to mimic this double-click manually by dispatching a MouseEvent.DOUBLE_CLICK, but the map service is not listening to this default Flex event. I suspect that the API has created a custom MapMouseEvent or something like it that is being dispatched when a user double-clicks the mouse.
Is there a way to determine which event is being dispatched when I double-click the mouse?
The API isn't necessarily dispatching its own event. Even if it is, it has to listen for MouseEvents first. One could detect double-clicks using MouseEvent.DOUBLE_CLICK, or by listening for successive MouseEvent.CLICK or MouseEvent.MOUSE_DOWN events. There's no way (just within Flash) to detect a double click without listening for one or more of those events somewhere.
It's also possible that the Map Service IS listening for the DOUBLE_CLICK event, but you're not dispatching the MouseEvent from the right object. For example, if the map service does this:
mapRoot.mapChild.addEventListener(MouseEvent.DOUBLE_CLICK, performMeasurement);
and you do this:
mapRoot.dispatchEvent(new MouseEvent(MouseEvent.DOUBLE_CLICK));
nothing is going to happen.
There are other possibilities as well:
When you actually perform a double-click with the mouse, you cause several events to be dispatched:
MOUSE_DOWN, MOUSE_UP, CLICK, MOUSE_DOWN, MOUSE_UP, CLICK, DOUBLE_CLICK
It's possible that the map service listens for MOUSE_DOWN, and adds the DOUBLE_CLICK listener inside the MOUSE_DOWN handler, like this:
mapRoot.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDownHandler);
private function _mouseDownHandler(event:MouseEvent):void
{
var targ:InteractiveObject = event.target as InteractiveObject;
targ.addEventListener(MouseEvent.DOUBLE_CLICK, _doubleClickHandler);
}
private function _doubleClickHandler(event:MouseEvent):void
{
var targ:InteractiveObject = event.target as InteractiveObject;
targ.removeEventListener(MouseEVent.DOUBLE_CLICK, doubleClickHandler);
performMeasurement();
}
So you may actually need to dispatch a combination of events to trigger the handler.
You can try the following:
Use DisplayObjectContainer.getObjectsUnderPoint() to get an Array of all the objects that could be responding to the click. Then from each of the objects in that array, try dispatching various sequences of MouseEvents till you come up with the right event(s) from the right object.
Take note though, that if
areInaccessibleObjectsUnderPoint() returns true for the point you test at, then there are some objects you won't be able to get access to, and if those are the ones the map service is listening to, then you're out of luck.
public function cbMouseEvents( e:MouseEvent ):void{
trace( e.type )
}

Resources