1/// <reference path="~/JavaScript/jquery.js" /> 2/// <reference path="~/JavaScript/esri/jsapi_vsdoc10_v38.js" /> 3 4// Create the DisplayArea namespace ... 5var DisplayArea = DisplayArea || {}; 6 7// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 8// FUNCTION AttachAreaPopup: Attach the area popup ... 9// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 10DisplayArea.AttachAreaPopup = function AttachAreaPopup(strAreaSpanID, arrAreaUnits, intDefaultAreaUnit, strGroupSeparator, strDecimalSeparator, dblAreaInKm2) { 11 12 // Set the area values and default area unit to be the currently selected area unit ... 13 DisplayArea.c_arrAreaUnits = arrAreaUnits; 14 DisplayArea.c_intAreaUnit = intDefaultAreaUnit; 15 DisplayArea.c_strGroupSeparator = strGroupSeparator; 16 DisplayArea.c_strDecimalSeparator = strDecimalSeparator; 17 DisplayArea.c_dblAreaInKm2 = dblAreaInKm2; 18 19 // When the document is ready ... 20 $(document).ready(function () { 21 22 // Get the area span ... 23 DisplayArea.c_objAreaSpan = $('#' + strAreaSpanID); 24 25 // Update the area span text ... 26 DisplayArea.UpdateAreaSpanText(DisplayArea); 27 28 // Remove all mouse enter and mouse leave event handlers from the area span ... 29 DisplayArea.c_objAreaSpan.parent().unbind('mouseenter'); 30 DisplayArea.c_objAreaSpan.parent().unbind('mouseleave'); 31 32 // When the mouse enters the div arond the area span ... 33 DisplayArea.c_objAreaSpan.parent().mouseover(function () { 34 35 // Set a timer to build the area popup ... 36 DisplayArea.c_intMouseEnterTimer = setTimeout(function () { 37 38 // Apply the hover style to the area span ... 39 DisplayArea.c_objAreaSpan.parent().removeClass('area_item_normal'); 40 DisplayArea.c_objAreaSpan.parent().addClass('area_item_hover'); 41 }); 42 }); 43 44 // When the mouse enters the div around the area span ... 45 DisplayArea.c_objAreaSpan.parent().mouseout(function (e) { 46 47 // When the popup div is not visble ... 48 if (DisplayArea.c_objAreaPopupDiv == null) { 49 50 // Apply the hover style to the area span ... 51 DisplayArea.c_objAreaSpan.parent().removeClass('area_item_hover'); 52 DisplayArea.c_objAreaSpan.parent().addClass('area_item_normal'); 53 54 // Stop the timer ... 55 clearTimeout(DisplayArea.c_intMouseEnterTimer); 56 } 57 }); 58 59 // When the user clicks the area span ... 60 DisplayArea.c_objAreaSpan.parent().click(function () { 61 62 // When the area popup is not already open ... 63 if (DisplayArea.c_objAreaPopupDiv == null) { 64 65 // Build the area popup ... 66 DisplayArea.BuildAreaPopup(strAreaSpanID, arrAreaUnits, intDefaultAreaUnit); 67 68 } else { 69 70 // Close the area popup ... 71 DisplayArea.ClosePopup(); 72 } 73 }); 74 }); 75} 76 77// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 78// FUNCTION UpdateAreaSpanText 79// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 80DisplayArea.UpdateArea = function UpdateArea(dblAreaInKm2) { 81 82 // Set the area in square kilometers ... 83 DisplayArea.c_dblAreaInKm2 = dblAreaInKm2; 84 85 // Update the area span text ... 86 DisplayArea.UpdateAreaSpanText(); 87} 88 89// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 90// FUNCTION UpdateAreaSpanText 91// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 92DisplayArea.UpdateAreaSpanText = function UpdateAreaSpanText() { 93 94 // Set the area value in the span ... 95 DisplayArea.c_objAreaSpan.html(DisplayArea.AreaDisplayText(DisplayArea.c_intAreaUnit)); 96} 97 98// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 99// FUNCTION ClosePopup: Close the popup ... 100// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 101DisplayArea.ClosePopup = function ClosePopup() { 102 103 // When we have a popup open ... 104 if (DisplayArea.c_objAreaPopupDiv) { 105 106 // Apply the hover style to the area span ... 107 DisplayArea.c_objAreaSpan.parent().removeClass('area_item_hover'); 108 DisplayArea.c_objAreaSpan.parent().addClass('area_item_normal'); 109 110 // Remove the popup ... 111 DisplayArea.c_objAreaPopupDiv.remove(); 112 113 // Set to not have a popup open ... 114 DisplayArea.c_objAreaPopupDiv = null; 115 } 116} 117 118// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 119// FUNCTION BuildAreaPopup: Build the area popup ... 120// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 121DisplayArea.BuildAreaPopup = function BuildAreaPopup(strAreaSpanID, arrAreaUnits, intDefaultAreaUnit) { 122 123 // * Build the area popup here ... 124 125 // Create the div ...
126 DisplayArea.c_objAreaPopupDiv = $('<div class="AreaPopupDiv"></div>'); 127 128 // Create the table ... 129 var objTable = $('<table cellpadding="0" cellspacing="0" border="0"></table>'); 130 131 // Append the table to it ... 132 DisplayArea.c_objAreaPopupDiv.append(objTable); 133 134 // Loop through all the area units ... 135 for (var intAreaUnit = 0; intAreaUnit < DisplayArea.c_arrAreaUnits.length; intAreaUnit++) { 136 137 // Get the area unit object ... 138 var objAreaUnit = DisplayArea.c_arrAreaUnits[intAreaUnit]; 139 140 // Build a string with the area, unit abbreviation and unit name in brackets ... 141 var strArea = DisplayArea.AreaDisplayText(intAreaUnit, DisplayArea) + ' (' + objAreaUnit.Unit + ')'; 142 143 // Declare a variable to hold the mark up for the check box if this row is to have a check ... 144 var strCheck = ''; 145 146 // When this is the current area unit ... 147 if (intAreaUnit == DisplayArea.c_intAreaUnit) { 148 149 // Set to add the check image ... 150 //strCheck = '<img src="Images/Check.png"></img>'; 151 strCheck = '<img src="Images/Check.png" style="margin-left:6px;margin-right:6px"></img>'; 152 } 153 154 // Build a table row with 2 columns with an optional check and a span with the area text ... 155 var objTableRow = $('<tr><td style="width:20px" align="center">' + strCheck + '</td><td><span class="AreaPopupText">' + strArea + '</span> </td></tr>'); 156 157 // Add the row to the table ... 158 objTable.append(objTableRow); 159 160 // Attach a mouse enter event handler to the row ... 161 objTableRow.mouseenter(function (e) { 162 163 // Get the row index, this would be the index into the area units array ... 164 var intAreaUnit = $.inArray(this, $(this).parent().find('tr')); 165 166 // When not the currently selected area unit ... 167 if (intAreaUnit != DisplayArea.c_intAreaUnit) { 168 169 // Toggle AreaPopupRowHighlight class on the row ... 170 $(this).toggleClass('AreaPopupRowHighlight', true); 171 }; 172 }); 173 174 // Attach a mouse leave event handler to the row ... 175 objTableRow.mouseleave(function (e) { 176 177 // Toggle AreaPopupRowHighlight class on the row ... 178 $(this).toggleClass('AreaPopupRowHighlight', false); 179 }); 180 181 // Attach a click event handler to the row ... 182 objTableRow.click(function (e) { 183 184 // Get the row index, this would be the index into the area units array ... 185 var intAreaUnit = $.inArray(this, $(this).parent().find('tr')); 186 187 // When not the currently selected area unit ... 188 if (intAreaUnit != DisplayArea.c_intAreaUnit) { 189 190 // Close the Popup ... 191 DisplayArea.ClosePopup(); 192 193 // Select the area unit that the user clicked on ... 194 DisplayArea.c_intAreaUnit = intAreaUnit; 195 196 // Update the area value on the interface ... 197 DisplayArea.c_objAreaSpan.html(DisplayArea.AreaDisplayText(DisplayArea.c_intAreaUnit)); 198 }; 199 }); 200 }; 201 202 // Position the div on top of the area label ... 203 DisplayArea.c_objAreaPopupDiv.css('top', DisplayArea.c_objAreaSpan.parent().position().top + DisplayArea.c_objAreaSpan.parent().outerHeight() - 1); 204 DisplayArea.c_objAreaPopupDiv.css('left', DisplayArea.c_objAreaSpan.position().left - 1); 205 206 // Add the div to the parent of the area text span ... 207 DisplayArea.c_objAreaSpan.offsetParent().append(DisplayArea.c_objAreaPopupDiv); 208 209 // Bring the popup div to the front ... 210 SD.DOM.BringToFront(DisplayArea.c_objAreaPopupDiv); 211 212 // When the mouse leaves the div arond the area span ... 213 DisplayArea.c_objAreaPopupDiv.mouseleave(function (e) { 214 215 // Close the Popup ... 216 DisplayArea.ClosePopup(); 217 }); 218 219 // Trigger the Opened event on the span ... 220 DisplayArea.c_objAreaSpan.trigger('Opened'); 221} 222 223// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 224// FUNCTION AreaDisplayText: Build the area text ... 225// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 226DisplayArea.AreaDisplayText = function AreaDisplayText(intAreaUnit) { 227 228 // Get the area unit object ... 229 var objAreaUnit = DisplayArea.c_arrAreaUnits[intAreaUnit]; 230 231 // Convert the area value to the unit ... 232 var dblAreaValue = DisplayArea.c_dblAreaInKm2 / objAreaUnit.ConversionFactorToKm2; 233 234 // Convert the area value to a string ... 235 var strArea = SD.DisplayValue.FromDouble(dblAreaValue, DisplayArea.c_strGroupSeparator, DisplayArea.c_strDecimalSeparator, objAreaUnit.DecimalPlaces); 236 237 // Append the area unit abbreviation ... 238 strArea += ' ' + objAreaUnit.Abbreviation; 239 240 return strArea; 241} 242 243// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 244// FUNCTION InsidePopup: Tests if the mouse is inside the popup ... 245// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 246DisplayArea.InsidePopup = function InsidePopup(decX, decY) { 247 248 // Return true when witin either the area span or the popup div ... 249 return (DisplayArea.WithinElement(decX, decY, DisplayArea.c_objAreaSpan) || DisplayArea.WithinElement(decX, decY, DisplayArea.c_objAreaPopupDiv)); 250} 251 252// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 253// FUNCTION WithinElement: Tests if the x,y coordinate is inside the element ... 254// O+ -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- -=-=-=-=- +O 255DisplayArea.WithinElement = function WithinElement(decX, decY, objElement) { 256 257 // Get the position of the element rel;ative to the document ... 258 var objPosition = DisplayArea.c_objAreaSpan.offset(); 259 260 // Return true when within the element ... 261 var blnReturn = ((decX >= objPosition.left) && 262 (decY >= objPosition.top) && 263 (decX <= objPosition.left + objElement.outerWidth()) && 264 (decY <= objPosition.top + objElement.outerHeight())); 265 266 return blnReturn; 267}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.