0

I have a Google Fusion Table containing a land parcels layer. Each parcel is assigned an ARN number. I am trying to create a search box where one can type in the ARN number and it will select and hopefully zoom to that parcel. I'm new to java script and am unsure as to why my search box is not working. The Fusion table has a 'geometry' column containing the spatial information and 'ARN' column is a 'number' field containing the ARN numbers. Here is my code.

 function changeMapl0() {
    var searchString = document.getElementById('search-string-l').value.replace(/'/g,  "\\'");
    layer.setOptions({
       query: {
         select: 'geometry',
         from: 'tableID',
         where: "'ARN' CONTAINS IGNORING CASE '" + searchString + "'"
         }
     });
  }


 <body>
    <div style="margin-top: 10px;">
        <label>Enter Roll Number</label><input type="text" id="search-string-l">
        <input type="button" onclick="changeMapl0()" value="Search">
     </div>
 </body>

Any help would be appreciated.

Thanks;

Matt

1 Answers1

0

You would probably want to do something like this, you will have to call a zoom2query function. You will want to probably want to calculate the lat and long of the centroid of parcel for zoom functionality, make sure to call you geometry column column on the map so you don't have the points.

function changeMap() {
                var searchString = document.getElementById('search').value.replace("'", "\\'");
                if(searchString == "") {
                    var query="SELECT 'Lat' FROM " + tableid;
                }
                else {
                    var query="SELECT 'Lat' FROM " + tableid + " WHERE 'PARCEL_ID' = '" + searchString + "'";
                }
                // layer.setQuery(query);
                if(searchString == "") {
                    var query="SELECT 'Lat','Long' FROM " + tableid;
                }
                else {
                    var query="SELECT 'Lat','Long' FROM " + tableid + " WHERE 'ARN' = '" + searchString + "'";
                }
                zoom2query(query);
            }
            var infowindow = new google.maps.InfoWindow();
            function zoom2query(query) {
                // zoom and center map on query results
                //set the query using the parameter
document.getElementById("query").innerHTML = query;
                var queryText = encodeURIComponent(query);
                var query = new google.visualization.Query('https://www.google.com/fusiontables/gvizdata?tq='  + queryText);
                //set the callback function
                query.send(zoomTo);
            }
            function zoomTo(response) {
                if (!response) {
                    alert('no response');
                    return;
                }
                if (response.isError()) {
                    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
                    return;
                } 
                numRows = response.getDataTable().getNumberOfRows();
                numCols = response.getDataTable().getNumberOfColumns();
                var lat = response.getDataTable().getValue(0,0);
                var lng = response.getDataTable().getValue(0,1);
                var zoom_level = 19;
                var location = new google.maps.LatLng(lat,lng);
                map.setCenter(location);
                map.setZoom(zoom_level);
            }

Here is an example of what I have done, we have RP numbers but mine zooms to the parcel https://googledrive.com/host/0B0J_A50xWBAqNHZqVlUxSkNUbWs/Shoshone.html

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Kevin
  • 1