How to programmatically click on a Google Maps Fusion Table layer? - google-maps

I have a google map that uses a fusion table layer for dynamic styling of a large number of Polygons. On top of this layer, I'm also generating a set of markers at specific LatLng positions within the polygons themselves. I'm looking to have the following behavior:
When you click anywhere on a polygon, an infoWindow should pop up, populated by data from the fusion table. This is working.
When you click on a marker, it should pass the click event through to the fusion table layer and create the same popup as if a natural click occurred at the LatLng of the marker. This is what I'm struggling with, and isn't currently working. I'm adding a click listener to each marker, then using that to trigger a click on my fusion table layer, more or less as suggested here:
Here's the code I'm using to add a listener to each marker:
function addMarkerListener(city, LatLng){
google.maps.event.addListener(city, "click", function(e) {
google.maps.event.trigger(layer, 'click', {
latLng: LatLng
});
});
}
In this case, layer is my fusion table layer.
Using this, the click triggers, but I don't actually get any of the data from my fusion table (stored in the row variable of the mouse event object). Instead, my mouse event is passed directly though to my listener on the fusion table layer that would normally handle clicks.
How can I create a click event on the fusion table layer, programmatically, that will pull data from the fusion table as a natural click would?

This is an example of Fusion Table Layer that click markers from sidebar programmatically.
See the entire code from this page.
http://googlemaps.googlermania.com/google_maps_api_v3/en/fusion-tables-sidebar.html

Related

Google Maps V3 > Click event listener not working after adding data.loadGeoJson() [duplicate]

I've implemented a click event on the map using
google.maps.event.addListener(map, 'click', mapclick);
and everything is working fine.
I've also added a geojson layer on map. So, the problem is when I click on the overlay geojson layer (which is a polygon layer actually), the map click event not fired. Hence, my question is what should I do so that map click event also work when I click on an overlay layer on map?
It's not clear what you mean by "geojson layer" , but when you mean a Data-layer there are 2 options:
when you don't need the click-event to be triggered for the feature(e.g. polygon)
set the clickable-option of the layer to false:
map.data.setStyle({clickable:false});
when the click-event should be triggered for both, map and feature
trigger the event for the map programmatically:
map.data.addListener('click',function(e){
google.maps.event.trigger(this.getMap(),'click',e);
});

How to properly hide markers in google maps?

I am trying to add a bunch of markers to a map with show/hide buttons for each category of markers. Adding a marker from stored db data puts them on the map and makes them clickable, but they won't respond to setMap(null) unless that call is through google.event.addListener(marker, ...). Calling it from a standard js button onclick event, or via google.event.addDomListener(marker, ...) doesn't work.
Also maybe helpful to note is that when I call marker.setAnimation(BOUNCE) the marker starts bouncing but it looks like there is a duplicate marker under it. Similarly, if I drag the marker it's as if an unmovable duplicate is created right under it.
Thoughts? This is super frustrating!
Just like this taken from here ? Are you trying to avoid google maps api's google.maps.event.addDomListener? Why? You can use it to listen to your button's click event too. just as in:
var YourButton = document.getElementById('myButton');
function HideMarkers() {
// Hide us
}
google.maps.event.addDomListener(YourButton, 'click', HideMarkers);
customized for you from. For the second part, seeming like double markers I suppose we need some code..
This turned out to be purely user error. I am using firebase to store map data without a server backend and was adding duplicate markers. This explains the "inability to hide" and also the appearance of duplicate markers when dragging or animating.
The reason it was working from a click event on the marker was that both duplicate markers were receiving the click event and so both were being hidden.
setMap appears to be perfectly reliable when used in or out of google event handlers.

Pop up info window on google map given coordinates

I wonder is there a way to automatically pop up the infoWindow of a marker provided a coordinate. I want to click a link on the page from which I will get a geolocation, (and this location has already been marked on the map) With this coordinate, the corresponding infoWindow will pop up just like I clicked it on the map. Does anyone have a clue how to do that?
Thanks.
--
Generally, it's like what you can do with Google Maps, if you have multiple locations on the left, you click one, the corresponding marker on the map will pop up an infoWindow.
It's possible, all you need is a reference to the related marker, then you may trigger a click on the marker, and the infoWindow will open.
How to get the reference to the marker depends on your application(the way you create the markers and the links)

Fusion Table Layer with polygons AND markers

Using Google Maps API v3
I have a map with the countries coloured using polygons from a Fusion Table Layer. When a polygon is clicked it opens the default Fusion Table info window which has been configured in the web interface.
Some of the countries can't be seen at certain zoom levels so I'd like these countries to have a polygon AND marker, which when clicked open the default Fusion Table info window. I did add a standard map marker but there is no way to open the Fusion Table info window when clicked.
I've read through the docs and looked at the examples but can't see how this is achieved. Is this possible?
Managed to get this working.
I created a second Fusion Table layer and instead of selecting the KML column I selected the Longitude column with a WHERE clause specifying the smaller countries. This renders a layer with markers on the smaller countries which sits on top of the polygon layer.
The only downside is that both the polygon and marker are both clickable which could open duplicate default Fusion Table info windows. Not a major problem though.
You can't access the "default FusionTables infowindow" from an external click event. You can query the FusionTable from your page and display an infowindow containing the same information on a click on a Google Maps API marker (or a sidebar entry).
Example (opening infowindow from sidebar click, not a marker, as you didn't provide an example)

GoogleMaps API v3 - Need help with two "click" event scenarios. Need similar functionality to v2 API

In version 2 of the API the map click event returned an Overlay, LatLng, Overlaylatlng.
I used this to create a generic map event that would either retrieve the coordinates of the Map click event, or return the coordinates of a Marker or other type of Overlay.
Now that API v3 doesn't return the Overlay or Overlaylatlng during the map click event, how can I go about creating a generic "click" event for the map that works if the user clicks on a marker or overlay? I really don't want to create a click event for each marker I have on my page as I am creating anywhere from a handful to a couple thousand markers.
Also, I had to create a custom ImageMapType in order to display the StreetViewOverlay like we could do in v2 of the API because I couldn't find anywhere that told me how to add the StreetViewOverlay without the pegman icon. How can I go about retrieving the LatLng coordinates of a click on this overlay type as well?
You will need to add a click listener to each overlay you add. You can do this in a createMarker function to reduce your code overhead.
Clicks on markers do not trigger a click event on the map at all.