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
});
Related
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.
I need to pan and zoom map using map.fitBounds() with a bounds object of a GeoJSON multipolygon without first adding it to the map.
I can determine a mapped feature's bounds by using map.data.addGeoson() to add geoJSON multipolygon to map, then grabbing feature w/ map.data.getFeatureById() and using processPoints() from this example https://developers.google.com/maps/documentation/javascript/examples/layer-data-dragndrop.
But, like I said, I want to pan and zoom to the multipolygon without first mapping it. I'm trying to frame markers contained within the multipolygon to provide user with more context without immediately pan/zoom to the marker bounds, which could be to a zoom level that does not provide a user enough context. See http://brookfieldlogisticsproperties.com/available-properties. Compare using select filters to drill into state of Utah vs. drilling through the map.
One approach would be to iterate over a GeoJSON MultiPolygon coordinates with the constructors for google.maps.Data.MultiPolygon, google.maps.Data.Polygon, etc. This seems rather unpleasant.
A Data-layer must not be drawn on a map.
map.data is a built-in Data-layer that will be drawn on a map, to create a Data-Layer without drawing anything simply use
new google.maps.Data()
So the workflow would be:
var
//create a map
map = new google.maps.Map(someNode,options),
//create bounds
bounds = new google.maps.LatLngBounds(),
//create data-layer
data = new google.maps.Data();
//add geoJson to the data-layer
data.addGeoJson(yourGeoJson);
//process the points via the linked function
processPoints(data.getFeatureById('idOfTheFeature').getGeometry(),
bounds.extend,
bounds);
//set the bounds of the map
map.fitBounds(bounds);
I'm am trying to use a maps engine layer in google maps api v3 and am running into issues with events and opacity (accepted enhancement) for raster layers.
The issue is that raster type data does not allow any events as far as I can tell.
var layer2 = new google.maps.visualization.MapsEngineLayer({
layerId: '15658084116283052074-13711557424617485464',
map: map,
clickable: true,
suppressInfoWindows: false
});
google.maps.event.addListener(layer2, 'click', function (event) {
alert('click');
});
Demo (jsbin) with vector maps engine layer and raster layer here. Is there something I'm missing or is it simply not implemented?
Documentation:Maps Engine Layers
Edit: I would like to get the pixel value of the raster.
The click event in a DMEL is fired when a feature is clicked. In Maps Engine, a feature is the same as defined in GeoJSON. That is: a single geometry, or table row in your data set.
As raster layers are not attached to a tabular data source, they don't contain individual features like points and shapes.
Raster layers are much like the base layer in the map however, so you can grab a click event at the map level. e.g.
google.maps.event.addListener(map, 'click', function (event) {
alert(event.latLng);
});
I'm not sure what your intention is beyond just a lat/lng pair though. If you wish to interrogate pixel data you may be better off putting the raw data into a table.
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.
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.