The following adds identifying capabilities to your application. On mouse click on a property the property will be outlined. To get a handle to the APN on identify look at the IdentifyObserver success method.
function load()
{
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 17);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
}
var divObj = document.getElementById("map");
divObj.onclick = MouseHandler;
}//load
function MouseHandler(event){
var x, y;
// for IE
if (event==null)
{
event = window.event;
x = event.x;
y = event.y;
}
// for Firefox
else
{
x = event.clientX - event.currentTarget.offsetLeft;
y = event.clientY - event.currentTarget.offsetTop;
}
// converts screen coordinate to map latitude longitude
var latLng = map.fromContainerPixelToLatLng(new GPoint(x, y));
// create query control object and point it to the query api url.
var queryControl = new DMCQueryControl();
// create a geometry to use in query.
var geo = new DMCPoint(latLng.lng(), latLng.lat());
queryControl.setGeometryFilter(geo);
// execute query.
queryControl.execute(new IdentifyObserver(),"success", "failure", "ID");
}
// observer to handle the idenitfy response.
function IdentifyObserver()
{
this.success = function(recordSet)
{
var record = recordSet.getByIndex(0);
if(record != null)
{
var apn = record.getByName("APN");
var fips = record.getByName("FIPS");
document.getElementById("output").innerText = "APN:" + apn + " FIPS:" + fips;
var geometry = record.getByName("GEOMETRY");
drawPolygon(geometry);
}
}
this.failure = function(err)
{
//alert("Could not identify parcel at this location.");
}
}
var identifyLayer = null;
// draws the identified shape on the map.
function drawPolygon(dmcPolygon){
if(map == null || dmcPolygon == null) return;
if(identifyLayer != null)
map.removeOverlay(identifyLayer);
var color= "#FF0000";
var weight = 3;
var opacity = 1;
var fillColor = "#FF0000";
var fillOpacity = 0.3;
identifyLayer = DMCtoGoogGeometry( dmcPolygon, color, weight, opacity, fillColor, fillOpacity);
map.addOverlay(identifyLayer);
}
The following example performs a geometry query using the map extent, returning all parcels visible on the map, up to a maximum of 200.
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 17);
map.addControl(newGSmallMapControl());
map.addControl(new GMapTypeControl());
}
GEvent.bind(map, "moveend", this, QueryMapExtent);
QueryMapExtent();
}//load
function QueryMapExtent()
{
var mapBounds = map.getBounds();
var sw = mapBounds.getSouthWest();
var ne = mapBounds.getNorthEast();
var geoPoints = [new DMCPoint(sw.lng(), ne.lat()), new DMCPoint(ne.lng(), ne.lat()), new DMCPoint(ne.lng(), sw.lat()), new DMCPoint(sw.lng(), sw.lat()), new DMCPoint(sw.lng(), ne.lat())];
var geo = new DMCPolygon(geoPoints);
// create query control object and point it to the query api url.
var queryControl = new DMCQueryControl();
queryControl.setGeometryFilter(geo);
queryControl.setMaxOutputRecords(200);
//Set the queryControl object to return the centroids of the parcels
queryControl.setReturnGeometryType(3);
// execute query.
queryControl.execute(new IdentifyObserver(),"success", "failure", "ID");
progressBar.style.visibility = "visible";
}
var identifyLayers = new Array();
// observer to handle the idenitfy response.
function IdentifyObserver()
{
this.success = function(recordSet)
{
for(var i = 0; i < identifyLayers.length; i++)
map.removeOverlay(identifyLayers[i]);
identifyLayers = new Array();
var record;
var geometry;
var length = recordSet.getCount();
for(var i = 0; i < length; i++)
{
record = recordSet.getByIndex(i);
if(record != null)
{
geometry = record.getByName("GEOMETRY");
drawPoint(geometry);
}
}
progressBar.style.visibility = "hidden";
}
this.failure = function(err)
{
//alert("Could not identify parcel at this location.");
}
}
// draws the identified shape on the map.
function drawPoint(dmcPolygon){
if(map == null || dmcPolygon == null) return;
var identifyLayer = new GMarker(DMCtoGoogGeometry(dmcPolygon));
identifyLayers.push(identifyLayer);
map.addOverlay(identifyLayer);
}