Get nearest point on polyline when mousemove (gMaps v3) - google-maps-api-3

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.

Related

MapsUI polygon blocks mapClick

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);

Converting given Geometry into a PointCollection in ArcGIS

I'm working on JavaFX desktop application and using the ArcGIS SDK v100.7.0. There is a scenario in my code, where i need to create a Polyline from a Geometry object. I'm getting this geometry from the SketchEditor using sketchEditor.getGeometry(). I actually want to add a Point to the sketchEditor geometry when in Polyline creation mode using the point Lat Long inserted by the user and not by mouse click on map. How do i get the sketch geometry into a PointCollecion, add my new Point into the collection, create Polygon from this collection and then pass this polygon back to the sketchEditor.start() method. How do i achieve this?
I solved my problem after going through the classes and documentation, i figured out how i can get a Polyline from a Geometry object. The approach was:
PointCollection pc = new PointCollection(SpatialReferences.getWgs84());
PolylineBuilder pb = new PolylineBuilder(pc, SpatialReferences.getWgs84());
pb.replaceGeometry(sketchEditor.getGeometry());
pb.addPoint(new Point(Double.parseDouble(longField.getText()),Double.parseDouble(latField.getText()), SpatialReferences.getWgs84()));
sketchEditor.start(pb.toGeometry(), SketchCreationMode.POLYLINE);
I created a new PointCollection object, passed it into a new PolylineBuilder object. To pass the given Geometry into the PointBuilder, i used its replaceGeometry() method so that it can have the updated geometry. Now i was able to manipulate it and add Point to it, which is what i was trying to do.

DrawManager Draw Polygon, where is the polygon stored?

When using the "draw polygon" tool from DrawManager, where is the polygon stored once the drawing is completed and it is displayed on the map?
For example, how can I delete this just drawn polygon from the map without creating my own overlay layer and inserting such polygon?
The objects created by the DrawingManager aren't stored somewhere where you may access them.
The only way to access them is the {overlay}complete-event of the DrawingManager.
e.g. for a polygon:
google.maps.event.addListener(drawingManager, 'polygoncomplete', function(event) {
//event.overlay
//is a reference to the polygon,
//store it somewhere
});

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);

Resources