6

Is there a way to get marker clustering (ie makerclusterer) to work with a Fusion Table layer? It seems that you have to assign markers to markerclusterer yet when using a fusion table layer, Google is handling the markers/infowindows? Still trying to figure this fusion table thing out.

Basically looking for a way to cluster large amounts of markers being provided via a Fusion Table

RonnieT
  • 2,193
  • 4
  • 32
  • 43

4 Answers4

5

Fusion Table Layers render an additional png image for each tile that gets overlaid on top of the map tile, containing the data points for that tile, this is the server side rendering part. So it's multiple data points per tile that contains data points.

MapsIt.png map tile with data points already positioned on the layer

Generating your own markers from data, which is necessary for MarkerClusterer, doesn't overlay an image per tile, it creates an individual Marker on the map for each data point and overlays a sprite image on to that.

Marker Sprite image used for each data point

Based on this, it is not possible to use MarkerClusterer and a FusionTablesLayer.

Freddy
  • 442
  • 1
  • 6
  • 13
  • Ran across this post researching this for myself. Thought I'd leave a comment that yes, it is possible according to Google Fusion Tables Team. [https://groups.google.com/d/msg/fusion-tables-users-group/eW-der8-diM/UnaqHkpgeDcJ] – danagerous Apr 14 '15 at 19:30
  • @danagerous There's a big difference between doing it on a FusionTablesLayer and using the data from a Fusion Table like the post you mentioned references. It is possible to do it using data from a Fusion Table, it is still not possible to do it using a FusionTablesLayer which is rendered server-side. They would have to create a Layer of the grouped items at each zoom level on the server side. – Freddy Apr 14 '15 at 20:38
  • @danagerous your link appears to be broken. Do you have an alternate one? – tentaclenorm Apr 29 '15 at 04:41
  • 1
    @tentaclenorm I just tested the URL. It worked. It should bring you to the Google Fusion Table API Users Group. Failing that search for **Multiple Items with same geolocation do not display** in the Google groups forum. – danagerous Apr 29 '15 at 22:31
  • 1
    @danagerous I just noticed that there is a bracket being appended at the end of the url when I click it. It does work once I remove that bracket. Cheers and thanks. – tentaclenorm May 01 '15 at 02:19
  • 1
    I couldn't edit. Apparently there is only a 5 minute window. Here is the URL again. https://groups.google.com/d/msg/fusion-tables-users-group/eW-der8-diM/UnaqHkpgeDcJ – danagerous Jan 27 '17 at 19:21
5

This is my own code. I was trying the technique in the earlier link but it didn't work for me. So this is how i did it.

First i queried the fusion table with the regular chart api query

function initialize() {
    mapMain = new google.maps.Map(document.getElementById('map-canvas'), {
        center: new google.maps.LatLng(37.4, -100.1),
        zoom: 3,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    mc = new MarkerClusterer(mapMain);
    var queryText = encodeURIComponent("select wikipedia_article, xy from "+tableid);
    var query = new google.visualization.Query("https://www.google.com/fusiontables/gvizdata?tq="+queryText);
    query.send(handleQueryResponse);
}

Next, in my handleQueryResponse, I dynamically created markers and added it to the Mapclusterer

function handleQueryResponse(response){
     dataTable = response.getDataTable();

    for(var i=0; i< dataTable.getNumberOfRows();i++){           
        var hrefval = dataTable.getValue(i,0).toString();

        var arr = dataTable.getValue(i,1).toString().split(" ");            
        var latlng = new google.maps.LatLng(arr[0], arr[1]);

        var marker = new google.maps.Marker({
            position: latlng,
            map:mapMain
        });
        fn = markerClick(i, marker);
        google.maps.event.addListener(marker,'click', fn);          
        markers.push(marker);
    }
    mc.addMarkers(markers);
}

In this case, the main map, the array of markers (mc in the code below) are global variables. You can see the full working example here.

Ash Catchem
  • 911
  • 11
  • 13
1

I don't think you will get it work with a fusion table. IMO the fusion table is lacking the support for a spatial index. A si helps reduce the 2d complexity to a 1d complexity. It's uses in a lot of applications like heatmaps, treemaps, post code search, maps application. You want to look for Nick's hilbert curve spatial index quadtree blog.

Micromega
  • 12,486
  • 7
  • 35
  • 72
0

Fusion Tables allows you to view thousands of points at once by using server side rendering (from the google servers). Marker Clusterer solves the problem by building a set of clusters from nearest points (from the clients browser). I wouldn't necessarily use them both at the same time, but it might work for your use case it's up to you.

You can read more information about how they work here:

http://code.google.com/apis/maps/articles/toomanymarkers.html

If you really wanted too you could use the Fusion Tables API to feed the data from Fusion Tables to the Marker Clusterer.

Hope this helps.

MattT
  • 157
  • 5