Advanced map page script

This script is used to display the number of open incidents by location.

This script varies the size of the icon based on the number of open incidents for the location. Using the html parameter, it also displays the location name and number of incidents, as well as a link to the list of related incidents.

//get the instances url so we can link back to it
var uri = gs.getProperty("glide.servlet.uri");
//create an aggregate query on the incident table
var count = new GlideAggregate('incident');
//set condition for active incidents
count.addQuery('active', 'true');
//set aggregate field to location to get count by location
count.addAggregate('COUNT', 'location');
//execute the query
count.query();
 
//loop through the results
while (count.next()) {
 
 //get the current record's location
 var loc = count.location;
 //get the count of incidents for this location
 var locCount = count.getAggregate('COUNT', 'location');
 //only display location is there are active incidents
 if (locCount > 0) {
 //create new new map item for this location
 var item = map.addItem(count);
 //set lat/long from the location record
 item.latitude = loc.latitude;
 item.longitude = loc.longitude;
 //build the link to the list of incidents for the location
 var link = 'href=' + uri + 'incident_list.do?sysparm_query=active%3Dtrue^location%3D' + loc;
 //build the html value to be displayed when you click the map icon
 item.html='<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ')</a>';
 //link to the icon image
 item.icon = "http://maps.google.com/mapfiles/kml/pal3/icon51.png";
 //set the size of the icon based on the number of active incidents
 if (locCount < 5) {
 item.icon_width = "12";
 item.icon_height = "12";
 }
 else if (locCount < 15) {
 item.icon_width = "16";
 item.icon_height = "16";
 }
 else {
 item.icon_width = "32";
 item.icon_height = "32";
 }
 }
}