// TO CACHE THIS RH - comment, remove or set isStatic=1
//request.element.isStatic = 0;
application.ADF.scripts.loadResources("JQuery");
application.ADF.scripts.loadResources("MaplaceJS");
application.ADF.scripts.loadResources("cswMapBasicGoogleCSS");
/* Load Custom CSS Resource */
Application.ADF.widgets.loadCustomWidgetCSS("cswMapBasicGoogleCSS","TERTIARY","_custom");
// exit if all we're doing is detecting required resources
if ( Request.RenderState.RenderMode EQ "getResources" )
exit;
if ( NOT structKeyExists(attributes,'elementinfo') )
exit;
// Set the element ID
elementID = request.element.id;
// Get Records from the ElementData structure
elementData = Attributes.ElementInfo.ElementData;
items = ArrayNew(1);
// Get Records from the Element as an Array of Structures
if ( StructKeyExists(elementData, 'PropertyValues') AND ArrayLen(elementData.PropertyValues) )
items = elementData.PropertyValues;
totalItems = ArrayLen(items);
// Get the RenderHandler MetaData
rhMetadata = Attributes.ElementInfo.RenderHandlerMetaData;
widgetData = StructNew();
requireInitialWidgetData = true;
// Set the Field Names for Render Handler Metadata to WidgetData conversion
mdOptionsFieldName = "WidgetOptions,APIkey";
mapAPIkey = "";
/* Verify the Widget Custom Medadata Form and Render Handler Binding */
/* Look at the ElementInfo struct and the Caller Struct verify the metadata form is bound and we have some saved data */
mdBindingIsValid = Application.ADF.widgets.verifyRenderHandlerMetadata(rhCaller=Variables.Caller,metadataFields=mdOptionsFieldName,rhElementInfo=Attributes.ElementInfo,requireMetadata=requireInitialWidgetData);
if ( mdBindingIsValid )
{
// Get the widgetData from the bound Metadata Form with a "WidgetOptions" field
widgetData = Application.ADF.widgets.getWidgetConfigData(customMetdata=rhMetadata,configFieldName=mdOptionsFieldName);
// Also, make sure we have a Google Maps API key
if ( !StructKeyExists(widgetData,"APIkey") OR LEN(TRIM(widgetData.APIkey)) EQ 0 )
{
WriteOutput("Please open the Custom Properties for this Render Handler and add a Google Maps API key!
");
}
else
mapAPIkey = widgetData.APIkey;
}
/* PARSE [Theme] */
themeClass = "";
if ( StructKeyExists(widgetData,"Theme") )
themeClass = TRIM(widgetData.Theme);
/* PARSE [zoom] */
zoomValue = "";
if ( StructKeyExists(widgetData,"zoom") )
zoomValue = INT(widgetData.zoom);
/* PARSE [width] */
widthStr = "";
if ( StructKeyExists(widgetData,"width") AND LEN(TRIM(widgetData.width)) )
widthStr = widgetData.width;
/* PARSE [height] */
heightStr = "";
if ( StructKeyExists(widgetData,"height") AND LEN(TRIM(widgetData.height)) )
heightStr = widgetData.height;
// Open the MarkerSet
markerSet = "";
markerSetOpen = "var markerLocs_#elementID# = [";
markerSetClose = "]";
currTitle = "";
currHTML = "";
animatedState = "";
iconURL = "";
// Custom Element data coming from CS render mode filter so unescaping is needed before applying jsstringformat()
currTitle = "";
if ( StructKeyExists(items[itm].values,'title') AND LEN(TRIM(items[itm].values.title)) )
currTitle = items[itm].values.title;
currTitle = server.commonspot.udf.html.unescape(currTitle);
currTitle = jsstringformat(currTitle);
currHTML = "";
if ( StructKeyExists(items[itm].values,'infoWindowHTML') AND LEN(TRIM(items[itm].values.infoWindowHTML)) )
currHTML = items[itm].values.infoWindowHTML;
currHTML = server.commonspot.udf.html.unescape(trim(currHTML));
currHTML = jsstringformat(currHTML);
// Build the Marker Options
animatedState = "";
if ( StructKeyExists(items[itm].values,'animated') AND items[itm].values.animated EQ 1 )
animatedState = ",animation: google.maps.Animation.DROP";
iconURL = "";
if ( StructKeyExists(items[itm].values,'icon') AND isStruct(items[itm].values.icon) AND StructKeyExists(items[itm].values.icon,"resolvedURL") AND StructKeyExists(items[itm].values.icon.resolvedURL,"serverRelative") )
{
// assume CommonSpot icon field is used and structure is passed
iconURL = items[itm].values.icon.ResolvedURL.ServerRelative;
}
else
{
// assume icon url string is passed
iconURL = items[itm].values.icon;
}
markerSet = markerSet & "
{
lat: #items[itm].values.latitude#,
lon: #items[itm].values.longitude#,
title: '#currTitle#',
html: '#currHTML#',
icon: '#iconURL#'
#animatedState#
}
";
if ( itm LT totalItems )
markerSet = markerSet & ",";
var fieldMappingArray = ArrayNew(1);
var fieldDetailsStruct = StructNew();
fieldDetailsStruct = StructNew();
fieldDetailsStruct.FieldName = 'id';
fieldDetailsStruct.Description = 'Unique identifier for this marker.';
fieldDetailsStruct.Required = 1;
arrayAppend(fieldMappingArray, fieldDetailsStruct);
fieldDetailsStruct = StructNew();
fieldDetailsStruct.FieldName = 'Name';
fieldDetailsStruct.Description = 'The internal name for the marker.';
fieldDetailsStruct.Required = 1;
arrayAppend(fieldMappingArray, fieldDetailsStruct);
fieldDetailsStruct = StructNew();
fieldDetailsStruct.FieldName = 'Longitude';
fieldDetailsStruct.Description = "Starting location for this map. Specifies the east-west position of a point on the Earth's surface.";
fieldDetailsStruct.Required = 1;
arrayAppend(fieldMappingArray, fieldDetailsStruct);
fieldDetailsStruct = StructNew();
fieldDetailsStruct.FieldName = 'Latitude';
fieldDetailsStruct.Description = "Starting location for this map. Specifies the north-south position of a point on the Earth's surface.";
fieldDetailsStruct.Required = 1;
arrayAppend(fieldMappingArray, fieldDetailsStruct);
fieldDetailsStruct = StructNew();
fieldDetailsStruct.FieldName = 'Title';
fieldDetailsStruct.Description = 'The title for the marker.';
fieldDetailsStruct.Required = 0;
arrayAppend(fieldMappingArray, fieldDetailsStruct);
fieldDetailsStruct = StructNew();
fieldDetailsStruct.FieldName = 'infoWindowHTML';
fieldDetailsStruct.Description = 'An info window can be created for each marker using specified HTML.';
fieldDetailsStruct.Required = 0;
arrayAppend(fieldMappingArray, fieldDetailsStruct);
fieldDetailsStruct = StructNew();
fieldDetailsStruct.FieldName = 'icon';
fieldDetailsStruct.Description = 'Typically a pointer-type icon is used like you would see on Google Maps.';
fieldDetailsStruct.Required = 0;
arrayAppend(fieldMappingArray, fieldDetailsStruct);
fieldDetailsStruct = StructNew();
fieldDetailsStruct.FieldName = 'animated';
fieldDetailsStruct.Description = 'Checking this box will cause the marker to drop from the top of the map down to its location when created.';
fieldDetailsStruct.Required = 0;
arrayAppend(fieldMappingArray, fieldDetailsStruct);
return fieldMappingArray;