0

I have been making a script using a fusion table's layer in google maps.

I am using geocoder and get the coordinates of a point that I need.

I put a script that changes the style of a polygon from the fusion table when you click on it, using the google.maps.event.addListener(layer, "click", function(e) {});

I would like to use the same function that I call in the case of a click on the layer, but this time with a click with the coordinates that I got.

I have tried google.maps.event.trigger(map, 'click', {latLng: new google.maps.LatLng(42.701487,26.772308)});

As well as the example here > Google Fusion Table Double Click (dblClick)

I have tried changing map with layer...

I am sorry if my question is quite stupid, but I have tried many options.

P.S. I have seen many post about getting the info from the table, but I do not need that. I want to change the style of the KML element in the selected row, so I do not see it happening by a query.

Here is the model of my script:

        function initialize() 
        {
        geocoder = new google.maps.Geocoder();

        map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

        layer = new google.maps.FusionTablesLayer({
            suppressInfoWindows:true,
            map : map,
                query : {
                    select: 'Местоположение',
                from: '12ZoroPjIfBR4J-XwM6Rex7LmfhzCDJc9_vyG5SM'
                }
            });

            google.maps.event.addListener(layer, "click", function(e) {
            SmeniStilRaionni(layer,e);
                marker.setMap(null);
            });

            }

    function SmeniStilRaionni(layer,e)
            {
                ...
            }

    function showAddress(address) 
        {
        geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                  var point = results[0].geometry.location;
                  //IMITATE THE CLICK
                  }
            });
        }

In response to geocodezip

This way you hide all the other elements... I do not wish that. It is like if I want to change the border of the selected element. And I do not wish for a new layer. In the function that I use now I push the style of the options of the layer and then set the option. I use the e from google.maps.event.addListener(layer, "click", function(e)); by inserting e.row['Name'].value inside the where rule.

I would like to ask you if there is any info on the e variable in google.maps.event.addListener(layer, "click", function(e));

I found out how to get the results I wanted:

For my query after I get the point I use this:

var queryText ="SELECT 'Районен съд','Окръжен съд','Апелативен съд','Местоположение'  FROM "+FusionTableID+" WHERE ST_INTERSECTS(\'Местоположение\', CIRCLE(LATLNG(" + point.toUrlValue(6) + "),0.5));";
queryText = encodeURIComponent(queryText);          
document.getElementById("vij query").innerHTML = queryText;
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq='  + queryText);

And then I get these results:

var rsyd = response.getDataTable().getValue(0,0);
var osyd =  response.getDataTable().getValue(0,1);
var apsyd = response.getDataTable().getValue(0,2);

And then, I use the following:

      where: "'Районен съд' = '"+rsyd+"'",

Which is the same as:

      where: "'Районен съд' = '"+e.row['Районен съд'].value+"'",

in the click function.

This is a working solution for my problem.

But still, I cannot find a way to Imitate a Mouse click.

4

1 回答 1

0

The issue is this: the data(row) for the layers will be requested via AJAX when you click on a layer.

In theory it's possible to select a geometry(polygon) by a given LatLng, the geometry-library has a method for this: google.maps.geometry.poly.containsLocation().

Unfortunately the FusionTableAPI does not support such queries(ST_CONTAINS), you cannot select a row by supplying a LatLng and selecting the rows where the geometry contains the LatLng.

So what you can do: create a copy of the table that contains the columns needed to select a row(Община...the distinct value, and Местоположение.... the geometry). This copy may be requested via AJAX, but when the FusionTable will not be modified anymore I would suggest to use a hardcoded copy.

What to do now when you want to simulate the click:

Iterate over all rows of the copy, use the mentioned containsLocation()-method to check if the geometry(Местоположение) contains the LatLng and when it does apply the query by using the value of the distinct column Община .

Of course it would take some time to check all the geometries, but the FusionTable is not very large, it should be a possible approach in your case.

Here is a demo: http://jsfiddle.net/doktormolle/sSwj3/

The size of the stored data is approximately 500kb, you should store the data in an external script, so they may be cached.

You may notice that the highligthning of the selected layer will be much faster when triggered via the links, because there will no data be requested via AJAX. When the highlightning of the selected feature is the only thing you need you may ommit the observation of the layer-click completely and observe the map-click instead. Use the returned LatLng to retrieve the selected row from the data and set the style:

Demo: http://jsfiddle.net/doktormolle/swdX8/

于 2013-10-28T09:51:51.963 回答