PageRenderTime 14ms CodeModel.GetById 69ms app.highlight 68ms RepoModel.GetById 2ms app.codeStats 0ms

/examples/MarkerManagerDemo/bin-release/srcview/source/com/google/maps/examples/MarkerManager.as.html

http://gmaps-utility-library-flash.googlecode.com/
HTML | 727 lines | 643 code | 83 blank | 1 comment | 0 complexity | f9b25b2c778f7d42552e7fa30b6dfba8 MD5 | raw file
  1<!-- saved from url=(0014)about:internet -->
  2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3<html xmlns="http://www.w3.org/1999/xhtml">
  4<head>
  5<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6<title>MarkerManager.as</title>
  7<link rel="stylesheet" type="text/css" href="../../../../../SourceStyles.css"/>
  8</head>
  9
 10<body><pre><span class="ActionScriptComment">/* 
 11 * MarkerManager, v1.0
 12 * Copyright (c) 2007 Google Inc.
 13 * Author: Doug Ricket, others
 14 *  Ported to AS3 by Pamela Fox 
 15 *
 16 * Licensed under the Apache License, Version 2.0:
 17 *     http://www.apache.org/licenses/LICENSE-2.0
 18 *
 19 * Marker manager is an interface between the map and the user, designed
 20 * to manage adding and removing many points when the viewport changes.
 21 *
 22 * Algorithm: The MM places its markers onto a grid, similar to the map tiles.
 23 * When the user moves the viewport, the MM computes which grid cells have
 24 * entered or left the viewport, and shows or hides all the markers in those
 25 * cells.
 26 * (If the users scrolls the viewport beyond the markers that are loaded,
 27 * no markers will be visible until the EVENT_moveend triggers an update.)
 28 *
 29 * In practical consequences, this allows 10,000 markers to be distributed over
 30 * a large area, and as long as only 100-200 are visible in any given viewport,
 31 * the user will see good performance corresponding to the 100 visible markers,
 32 * rather than poor performance corresponding to the total 10,000 markers.
 33 *
 34 * Note that some code is optimized for speed over space,
 35 * with the goal of accommodating thousands of markers.
 36 *
 37 */</span>
 38<span class="ActionScriptpackage">package</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">examples</span> <span class="ActionScriptBracket/Brace">{</span>
 39<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">events</span>.<span class="ActionScriptDefault_Text">Event</span>;
 40<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">events</span>.<span class="ActionScriptDefault_Text">MouseEvent</span>;
 41<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">geom</span>.<span class="ActionScriptDefault_Text">Point</span>;
 42<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">display</span>.<span class="ActionScriptDefault_Text">DisplayObject</span>;
 43<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">display</span>.<span class="ActionScriptDefault_Text">Sprite</span>;
 44<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">display</span>.<span class="ActionScriptDefault_Text">Shape</span>;
 45<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">text</span>.<span class="ActionScriptDefault_Text">TextField</span>;
 46<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">text</span>.<span class="ActionScriptDefault_Text">TextFieldAutoSize</span>;
 47<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">text</span>.<span class="ActionScriptDefault_Text">TextFormat</span>;
 48<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">MapEvent</span>;
 49<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">MapMoveEvent</span>;
 50<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">Map</span>;
 51<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">LatLng</span>;
 52<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">LatLngBounds</span>;
 53<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">examples</span>.<span class="ActionScriptDefault_Text">GridBounds</span>;
 54<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">overlays</span>.<span class="ActionScriptDefault_Text">Marker</span>;
 55<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">interfaces</span>.<span class="ActionScriptDefault_Text">IMap</span>;
 56<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">google</span>.<span class="ActionScriptDefault_Text">maps</span>.<span class="ActionScriptDefault_Text">interfaces</span>.<span class="ActionScriptDefault_Text">IProjection</span>;
 57
 58<span class="ActionScriptReserved">public</span> <span class="ActionScriptclass">class</span> <span class="ActionScriptDefault_Text">MarkerManager</span> <span class="ActionScriptBracket/Brace">{</span>
 59     
 60<span class="ActionScriptComment">// Static constants:
 61</span><span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptReserved">const</span> <span class="ActionScriptDefault_Text">DEFAULT_TILE_SIZE</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> 1024;
 62<span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptReserved">const</span> <span class="ActionScriptDefault_Text">DEFAULT_MAX_ZOOM</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> 17;
 63<span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptReserved">const</span> <span class="ActionScriptDefault_Text">DEFAULT_BORDER_PADDING</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> 100;
 64<span class="ActionScriptReserved">public</span> <span class="ActionScriptReserved">static</span> <span class="ActionScriptReserved">const</span> <span class="ActionScriptDefault_Text">MERCATOR_ZOOM_LEVEL_ZERO_RANGE</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> 256;
 65
 66<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">map_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">IMap</span>;
 67<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">mapZoom_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>;
 68<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxZoom_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>;
 69<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">projection_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">IProjection</span>;
 70<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">trackMarkers_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span>;
 71<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">swPadding_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span>;
 72<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">nePadding_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span>;
 73<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">borderPadding_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>;
 74<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridWidth_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span>;
 75<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">grid_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span>;
 76<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">numMarkers_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span>;
 77<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">shownBounds_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span>;
 78<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">shownMarkers_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>;
 79<span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">tileSize_</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>;
 80
 81<span class="ActionScriptASDoc">/**
 82 * Creates a new MarkerManager that will show/hide markers on a map.
 83 *
 84 * @constructor
 85 * @param {Map} map The map to manage.
 86 * @param {Object} opt_opts A container for optional arguments:
 87 *   {Number} maxZoom The maximum zoom level for which to create tiles.
 88 *   {Number} borderPadding The width in pixels beyond the map border,
 89 *                   where markers should be display.
 90 *   {Boolean} trackMarkers Whether or not this manager should track marker
 91 *                   movements.
 92 */</span>
 93<span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">MarkerManager</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">map</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">IMap</span>, <span class="ActionScriptDefault_Text">opt_opts</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Object</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
 94  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">map_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">map</span>;
 95  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mapZoom_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">map</span>.<span class="ActionScriptDefault_Text">getZoom</span><span class="ActionScriptBracket/Brace">()</span>;
 96  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">projection_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">map</span>.<span class="ActionScriptDefault_Text">getCurrentMapType</span><span class="ActionScriptBracket/Brace">()</span>.<span class="ActionScriptDefault_Text">getProjection</span><span class="ActionScriptBracket/Brace">()</span>;
 97
 98  <span class="ActionScriptDefault_Text">opt_opts</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">opt_opts</span> <span class="ActionScriptOperator">||</span> <span class="ActionScriptBracket/Brace">{}</span>;
 99  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">tileSize_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">DEFAULT_TILE_SIZE</span>;
100  
101  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">DEFAULT_MAX_ZOOM</span>;
102  <span class="ActionScriptReserved">if</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">opt_opts</span>.<span class="ActionScriptDefault_Text">maxZoom</span> <span class="ActionScriptOperator">!=</span> <span class="ActionScriptReserved">undefined</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
103    <span class="ActionScriptDefault_Text">maxZoom</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">opt_opts</span>.<span class="ActionScriptDefault_Text">maxZoom</span>;
104  <span class="ActionScriptBracket/Brace">}</span>
105  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">maxZoom_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">maxZoom</span>;
106
107  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">trackMarkers_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">opt_opts</span>.<span class="ActionScriptDefault_Text">trackMarkers</span>;
108
109  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">padding</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>;
110  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">opt_opts</span>.<span class="ActionScriptDefault_Text">borderPadding</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
111    <span class="ActionScriptDefault_Text">padding</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">opt_opts</span>.<span class="ActionScriptDefault_Text">borderPadding</span>;
112  <span class="ActionScriptBracket/Brace">}</span> <span class="ActionScriptReserved">else</span> <span class="ActionScriptBracket/Brace">{</span>
113    <span class="ActionScriptDefault_Text">padding</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">DEFAULT_BORDER_PADDING</span>;
114  <span class="ActionScriptBracket/Brace">}</span>
115  <span class="ActionScriptComment">// The padding in pixels beyond the viewport, where we will pre-load markers.
116</span>  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">swPadding_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptOperator">-</span><span class="ActionScriptDefault_Text">padding</span>, <span class="ActionScriptDefault_Text">padding</span><span class="ActionScriptBracket/Brace">)</span>;
117  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">nePadding_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">padding</span>, <span class="ActionScriptOperator">-</span><span class="ActionScriptDefault_Text">padding</span><span class="ActionScriptBracket/Brace">)</span>;
118  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">borderPadding_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">padding</span>;
119
120  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">gridWidth_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">()</span>;
121
122  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">grid_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">()</span>;
123  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">grid_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">maxZoom</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">()</span>;
124  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">numMarkers_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">()</span>;
125  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">numMarkers_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">maxZoom</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> 0;
126
127  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">map_</span>.<span class="ActionScriptDefault_Text">addEventListener</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">MapMoveEvent</span>.<span class="ActionScriptDefault_Text">MOVE_END</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">onMapMoveEnd_</span><span class="ActionScriptBracket/Brace">)</span>;
128
129  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">resetManager_</span><span class="ActionScriptBracket/Brace">()</span>;
130  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownMarkers_</span> <span class="ActionScriptOperator">=</span> 0;
131
132  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getMapGridBounds_</span><span class="ActionScriptBracket/Brace">()</span>;
133<span class="ActionScriptBracket/Brace">}</span>;
134
135
136<span class="ActionScriptComment">// NOTE: These two closures provide easy access to the map.
137</span><span class="ActionScriptComment">// They are used as callbacks, not as methods.
138</span><span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">removeOverlay_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Marker</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
139  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">map_</span>.<span class="ActionScriptDefault_Text">removeOverlay</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
140  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownMarkers_</span><span class="ActionScriptOperator">--</span>;
141<span class="ActionScriptBracket/Brace">}</span>
142
143<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">addOverlay_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Marker</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
144  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">map_</span>.<span class="ActionScriptDefault_Text">addOverlay</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
145  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownMarkers_</span><span class="ActionScriptOperator">++</span>;
146<span class="ActionScriptBracket/Brace">}</span>
147
148<span class="ActionScriptASDoc">/**
149 * Initializes MarkerManager arrays for all zoom levels
150 * Called by constructor and by clearAllMarkers
151 */</span> 
152<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">resetManager_</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
153  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">mapWidth</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">MERCATOR_ZOOM_LEVEL_ZERO_RANGE</span>;
154  <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">zoom</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">maxZoom_</span>; <span class="ActionScriptOperator">++</span><span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
155    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">grid_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">()</span>;
156    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">numMarkers_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> 0;
157    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">gridWidth_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">ceil</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">mapWidth</span><span class="ActionScriptOperator">/</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">tileSize_</span><span class="ActionScriptBracket/Brace">)</span>;
158    <span class="ActionScriptDefault_Text">mapWidth</span> <span class="ActionScriptOperator">&lt;&lt;=</span> 1;
159  <span class="ActionScriptBracket/Brace">}</span>
160<span class="ActionScriptBracket/Brace">}</span>
161
162<span class="ActionScriptASDoc">/**
163 * Removes all currently displayed markers
164 * and calls resetManager to clear arrays
165 */</span>
166<span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">clearMarkers</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
167  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">processAll_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeOverlay_</span><span class="ActionScriptBracket/Brace">)</span>;
168  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">resetManager_</span><span class="ActionScriptBracket/Brace">()</span>;
169<span class="ActionScriptBracket/Brace">}</span>
170
171
172<span class="ActionScriptASDoc">/**
173 * Gets the tile coordinate for a given latlng point.
174 *
175 * @param {LatLng} latlng The geographical point.
176 * @param {Number} zoom The zoom level.
177 * @param {GSize} padding The padding used to shift the pixel coordinate.
178 *               Used for expanding a bounds to include an extra padding
179 *               of pixels surrounding the bounds.
180 * @return {GPoint} The point in tile coordinates.
181 *
182 */</span>
183<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getTilePoint_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">latlng</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">LatLng</span>, <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">padding</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptBracket/Brace">{</span>
184  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">pixelPoint</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">projection_</span>.<span class="ActionScriptDefault_Text">fromLatLngToPixel</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">latlng</span>, <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">)</span>;
185  <span class="ActionScriptReserved">return</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">(</span>
186      <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">floor</span><span class="ActionScriptBracket/Brace">((</span><span class="ActionScriptDefault_Text">pixelPoint</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">+</span> <span class="ActionScriptDefault_Text">padding</span>.<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptOperator">/</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">tileSize_</span><span class="ActionScriptBracket/Brace">)</span>,
187      <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">floor</span><span class="ActionScriptBracket/Brace">((</span><span class="ActionScriptDefault_Text">pixelPoint</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">+</span> <span class="ActionScriptDefault_Text">padding</span>.<span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptOperator">/</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">tileSize_</span><span class="ActionScriptBracket/Brace">))</span>;
188<span class="ActionScriptBracket/Brace">}</span>;
189
190
191<span class="ActionScriptASDoc">/**
192 * Finds the appropriate place to add the marker to the grid.
193 * Optimized for speed; does not actually add the marker to the map.
194 * Designed for batch-processing thousands of markers.
195 *
196 * @param {Marker} marker The marker to add.
197 * @param {Number} minZoom The minimum zoom for displaying the marker.
198 * @param {Number} maxZoom The maximum zoom for displaying the marker.
199 */</span>
200<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">addMarkerBatch_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Marker</span>, <span class="ActionScriptDefault_Text">minZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">maxZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
201  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">mPoint</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">LatLng</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">marker</span>.<span class="ActionScriptDefault_Text">getLatLng</span><span class="ActionScriptBracket/Brace">()</span>;
202  <span class="ActionScriptComment">// Tracking markers is expensive, so we do this only if the
203</span>  <span class="ActionScriptComment">// user explicitly requested it when creating marker manager.
204</span>  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">trackMarkers_</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
205    <span class="ActionScriptDefault_Text">marker</span>.<span class="ActionScriptDefault_Text">addEventListener</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptString">&quot;changed&quot;</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">onMarkerMoved_</span><span class="ActionScriptBracket/Brace">)</span>;
206  <span class="ActionScriptBracket/Brace">}</span>
207
208  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridPoint</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getTilePoint_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">mPoint</span>, <span class="ActionScriptDefault_Text">maxZoom</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">(</span>0, 0<span class="ActionScriptBracket/Brace">))</span>;
209
210  <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">maxZoom</span>; <span class="ActionScriptDefault_Text">zoom</span> <span class="ActionScriptOperator">&gt;=</span> <span class="ActionScriptDefault_Text">minZoom</span>; <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptOperator">--</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
211    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">cell</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getGridCellCreate_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">gridPoint</span>.<span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">gridPoint</span>.<span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">)</span>;
212    <span class="ActionScriptDefault_Text">cell</span>.<span class="ActionScriptDefault_Text">push</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
213
214    <span class="ActionScriptDefault_Text">gridPoint</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">gridPoint</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;&gt;</span> 1;
215    <span class="ActionScriptDefault_Text">gridPoint</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">gridPoint</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&gt;&gt;</span> 1;
216  <span class="ActionScriptBracket/Brace">}</span>
217<span class="ActionScriptBracket/Brace">}</span>;
218
219
220<span class="ActionScriptASDoc">/**
221 * Returns whether or not the given point is visible in the shown bounds. This
222 * is a helper method that takes care of the corner case, when shownBounds have
223 * negative minX value.
224 *
225 * @param {Point} point a point on a grid.
226 * @return {Boolean} Whether or not the given point is visible in the currently
227 * shown bounds.
228 */</span>
229<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">isGridPointVisible_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">point</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptBracket/Brace">{</span>
230  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">vertical</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">minY</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">point</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&amp;&amp;</span>
231      <span class="ActionScriptDefault_Text">point</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">maxY</span>;
232  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">minX</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">minX</span>;
233  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">horizontal</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">minX</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">point</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">point</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">maxX</span>;
234  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(!</span><span class="ActionScriptDefault_Text">horizontal</span> <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">minX</span> <span class="ActionScriptOperator">&lt;</span> 0<span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
235    <span class="ActionScriptComment">// Shifts the negative part of the rectangle. As point.x is always less
236</span>    <span class="ActionScriptComment">// than grid width, only test shifted minX .. 0 part of the shown bounds.
237</span>    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">width</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">gridWidth_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">]</span>;
238    <span class="ActionScriptDefault_Text">horizontal</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">minX</span> <span class="ActionScriptOperator">+</span> <span class="ActionScriptDefault_Text">width</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">point</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">point</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">width</span> <span class="ActionScriptOperator">-</span> 1;
239  <span class="ActionScriptBracket/Brace">}</span>
240  <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">vertical</span> <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">horizontal</span>;
241<span class="ActionScriptBracket/Brace">}</span>
242
243
244<span class="ActionScriptASDoc">/**
245 * Reacts to a notification from a marker that it has moved to a new location.
246 * It scans the grid all all zoom levels and moves the marker from the old grid
247 * location to a new grid location.
248 *
249 * @param {Marker} marker The marker that moved.
250 * @param {LatLng} oldLatLng The old position of the marker.
251 * @param {LatLng} newLatLng The new position of the marker.
252 */</span>
253<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">onMarkerMoved_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Marker</span>, <span class="ActionScriptDefault_Text">oldLatLng</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">LatLng</span>, <span class="ActionScriptDefault_Text">newLatLng</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">LatLng</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
254  <span class="ActionScriptComment">// NOTE: We do not know the minimum or maximum zoom the marker was
255</span>  <span class="ActionScriptComment">// added at, so we start at the absolute maximum. Whenever we successfully
256</span>  <span class="ActionScriptComment">// remove a marker at a given zoom, we add it at the new grid coordinates.
257</span>  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">maxZoom_</span>;
258  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">changed</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
259  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">oldGrid</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getTilePoint_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">oldLatLng</span>, <span class="ActionScriptDefault_Text">zoom</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">(</span>0, 0<span class="ActionScriptBracket/Brace">))</span>;
260  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">newGrid</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getTilePoint_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">newLatLng</span>, <span class="ActionScriptDefault_Text">zoom</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">(</span>0, 0<span class="ActionScriptBracket/Brace">))</span>;
261  <span class="ActionScriptReserved">while</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">zoom</span> <span class="ActionScriptOperator">&gt;=</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">oldGrid</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">!=</span> <span class="ActionScriptDefault_Text">newGrid</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">||</span> <span class="ActionScriptDefault_Text">oldGrid</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">!=</span> <span class="ActionScriptDefault_Text">newGrid</span>.<span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">))</span> <span class="ActionScriptBracket/Brace">{</span>
262    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">cell</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getGridCellNoCreate_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">oldGrid</span>.<span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">oldGrid</span>.<span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">)</span>;
263    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">cell</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
264      <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeFromArray</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">cell</span>, <span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">))</span> <span class="ActionScriptBracket/Brace">{</span>
265        <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getGridCellCreate_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">newGrid</span>.<span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">newGrid</span>.<span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">push</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
266      <span class="ActionScriptBracket/Brace">}</span>
267    <span class="ActionScriptBracket/Brace">}</span>
268    <span class="ActionScriptComment">// For the current zoom we also need to update the map. Markers that no
269</span>    <span class="ActionScriptComment">// longer are visible are removed from the map. Markers that moved into
270</span>    <span class="ActionScriptComment">// the shown bounds are added to the map. This also lets us keep the count
271</span>    <span class="ActionScriptComment">// of visible markers up to date.
272</span>    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">zoom</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mapZoom_</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
273      <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">isGridPointVisible_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">oldGrid</span><span class="ActionScriptBracket/Brace">))</span> <span class="ActionScriptBracket/Brace">{</span>
274        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(!</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">isGridPointVisible_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">newGrid</span><span class="ActionScriptBracket/Brace">))</span> <span class="ActionScriptBracket/Brace">{</span>
275          <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeOverlay_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
276          <span class="ActionScriptDefault_Text">changed</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
277        <span class="ActionScriptBracket/Brace">}</span>
278      <span class="ActionScriptBracket/Brace">}</span> <span class="ActionScriptReserved">else</span> <span class="ActionScriptBracket/Brace">{</span>
279        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">isGridPointVisible_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">newGrid</span><span class="ActionScriptBracket/Brace">))</span> <span class="ActionScriptBracket/Brace">{</span>
280          <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">addOverlay_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
281          <span class="ActionScriptDefault_Text">changed</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
282        <span class="ActionScriptBracket/Brace">}</span>
283      <span class="ActionScriptBracket/Brace">}</span>
284    <span class="ActionScriptBracket/Brace">}</span>
285    <span class="ActionScriptDefault_Text">oldGrid</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">oldGrid</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;&gt;</span> 1;
286    <span class="ActionScriptDefault_Text">oldGrid</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">oldGrid</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&gt;&gt;</span> 1;
287    <span class="ActionScriptDefault_Text">newGrid</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">newGrid</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;&gt;</span> 1;
288    <span class="ActionScriptDefault_Text">newGrid</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">newGrid</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&gt;&gt;</span> 1;
289    <span class="ActionScriptOperator">--</span><span class="ActionScriptDefault_Text">zoom</span>;
290  <span class="ActionScriptBracket/Brace">}</span>
291  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">changed</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
292    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">notifyListeners_</span><span class="ActionScriptBracket/Brace">()</span>;
293  <span class="ActionScriptBracket/Brace">}</span>
294<span class="ActionScriptBracket/Brace">}</span>;
295
296
297<span class="ActionScriptASDoc">/**
298 * Searches at every zoom level to find grid cell
299 * that marker would be in, removes from that array if found.
300 * Also removes marker with removeOverlay if visible.
301 * @param {GMarker} marker The marker to delete.
302 */</span>
303<span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">removeMarker</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Marker</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
304  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">maxZoom_</span>;
305  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">changed</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
306  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">point</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">LatLng</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">marker</span>.<span class="ActionScriptDefault_Text">getLatLng</span><span class="ActionScriptBracket/Brace">()</span>;
307  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">grid</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getTilePoint_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">point</span>, <span class="ActionScriptDefault_Text">zoom</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">(</span>0, 0<span class="ActionScriptBracket/Brace">))</span>;
308  <span class="ActionScriptReserved">while</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">zoom</span> <span class="ActionScriptOperator">&gt;=</span> 0<span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
309    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">cell</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getGridCellNoCreate_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">grid</span>.<span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">grid</span>.<span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">)</span>;
310
311    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">cell</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
312      <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeFromArray</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">cell</span>, <span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
313    <span class="ActionScriptBracket/Brace">}</span>
314    <span class="ActionScriptComment">// For the current zoom we also need to update the map. Markers that no
315</span>    <span class="ActionScriptComment">// longer are visible are removed from the map. This also lets us keep the count
316</span>    <span class="ActionScriptComment">// of visible markers up to date.
317</span>    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">zoom</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mapZoom_</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
318      <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">isGridPointVisible_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">grid</span><span class="ActionScriptBracket/Brace">))</span> <span class="ActionScriptBracket/Brace">{</span>
319          <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeOverlay_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
320          <span class="ActionScriptDefault_Text">changed</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
321      <span class="ActionScriptBracket/Brace">}</span> 
322    <span class="ActionScriptBracket/Brace">}</span>
323    <span class="ActionScriptDefault_Text">grid</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">grid</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;&gt;</span> 1;
324    <span class="ActionScriptDefault_Text">grid</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">grid</span>.<span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&gt;&gt;</span> 1;
325    <span class="ActionScriptOperator">--</span><span class="ActionScriptDefault_Text">zoom</span>;
326  <span class="ActionScriptBracket/Brace">}</span>
327  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">changed</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
328    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">notifyListeners_</span><span class="ActionScriptBracket/Brace">()</span>;
329  <span class="ActionScriptBracket/Brace">}</span>
330<span class="ActionScriptBracket/Brace">}</span>
331
332
333<span class="ActionScriptASDoc">/**
334 * Add many markers at once.
335 * Does not actually update the map, just the internal grid.
336 *
337 * @param {Array of Marker} markers The markers to add.
338 * @param {Number} minZoom The minimum zoom level to display the markers.
339 * @param {Number} opt_maxZoom The maximum zoom level to display the markers.
340 */</span>
341<span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">addMarkers</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">markers</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span>, <span class="ActionScriptDefault_Text">minZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">opt_maxZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Infinity</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
342  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getOptMaxZoom_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">opt_maxZoom</span><span class="ActionScriptBracket/Brace">)</span>;
343  <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">markers</span>.<span class="ActionScriptDefault_Text">length</span> <span class="ActionScriptOperator">-</span> 1; <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">&gt;=</span> 0; <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">--</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
344    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">addMarkerBatch_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">markers</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">]</span>, <span class="ActionScriptDefault_Text">minZoom</span>, <span class="ActionScriptDefault_Text">maxZoom</span><span class="ActionScriptBracket/Brace">)</span>;
345  <span class="ActionScriptBracket/Brace">}</span>
346
347  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">numMarkers_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">minZoom</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">+=</span> <span class="ActionScriptDefault_Text">markers</span>.<span class="ActionScriptDefault_Text">length</span>;
348<span class="ActionScriptBracket/Brace">}</span>
349
350
351<span class="ActionScriptASDoc">/**
352 * Returns the value of the optional maximum zoom. This method is defined so
353 * that we have just one place where optional maximum zoom is calculated.
354 *
355 * @param {Number} opt_maxZoom The optinal maximum zoom.
356 * @return The maximum zoom.
357 */</span>
358<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getOptMaxZoom_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">opt_maxZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptBracket/Brace">{</span>
359  <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">opt_maxZoom</span> <span class="ActionScriptOperator">!=</span> <span class="ActionScriptDefault_Text">Infinity</span> <span class="ActionScriptOperator">?</span> <span class="ActionScriptDefault_Text">opt_maxZoom</span> <span class="ActionScriptOperator">:</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">maxZoom_</span>;
360<span class="ActionScriptBracket/Brace">}</span>
361
362
363<span class="ActionScriptASDoc">/**
364 * Calculates the total number of markers potentially visible at a given
365 * zoom level.
366 *
367 * @param {Number} zoom The zoom level to check.
368 * @return {Number}
369 */</span>
370<span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getMarkerCount</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptBracket/Brace">{</span>
371  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">total</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> 0;
372  <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">z</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">z</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">zoom</span>; <span class="ActionScriptDefault_Text">z</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
373    <span class="ActionScriptDefault_Text">total</span> <span class="ActionScriptOperator">+=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">numMarkers_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">]</span>;
374  <span class="ActionScriptBracket/Brace">}</span>
375  <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">total</span>;
376<span class="ActionScriptBracket/Brace">}</span>;
377
378
379<span class="ActionScriptASDoc">/**
380 * Add a single marker to the map.
381 *
382 * @param {Marker} marker The marker to add.
383 * @param {Number} minZoom The minimum zoom level to display the marker.
384 * @param {Number} opt_maxZoom The maximum zoom level to display the marker.
385 */</span>
386<span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">addMarker</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Marker</span>, <span class="ActionScriptDefault_Text">minZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">opt_maxZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
387  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxZoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getOptMaxZoom_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">opt_maxZoom</span><span class="ActionScriptBracket/Brace">)</span>;
388  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">addMarkerBatch_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span>, <span class="ActionScriptDefault_Text">minZoom</span>, <span class="ActionScriptDefault_Text">maxZoom</span><span class="ActionScriptBracket/Brace">)</span>;
389  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridPoint</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getTilePoint_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span>.<span class="ActionScriptDefault_Text">getLatLng</span><span class="ActionScriptBracket/Brace">()</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mapZoom_</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">(</span>0, 0<span class="ActionScriptBracket/Brace">))</span>;
390  <span class="ActionScriptReserved">if</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">isGridPointVisible_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">gridPoint</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptOperator">&amp;&amp;</span> 
391    <span class="ActionScriptDefault_Text">minZoom</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">z</span> <span class="ActionScriptOperator">&amp;&amp;</span>
392    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">z</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">maxZoom</span> <span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
393    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">addOverlay_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">marker</span><span class="ActionScriptBracket/Brace">)</span>;
394    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">notifyListeners_</span><span class="ActionScriptBracket/Brace">()</span>;
395  <span class="ActionScriptBracket/Brace">}</span>
396  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">numMarkers_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">minZoom</span><span class="ActionScriptBracket/Brace">]</span><span class="ActionScriptOperator">++</span>;
397<span class="ActionScriptBracket/Brace">}</span>;
398
399
400<span class="ActionScriptASDoc">/**
401 * Get a cell in the grid, creating it first if necessary.
402 *
403 * Optimization candidate
404 *
405 * @param {Number} x The x coordinate of the cell.
406 * @param {Number} y The y coordinate of the cell.
407 * @param {Number} z The z coordinate of the cell.
408 * @return {Array} The cell in the array.
409 */</span>
410<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getGridCellCreate_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">z</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptBracket/Brace">{</span>
411  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">grid</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">grid_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">]</span>;
412  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;</span> 0<span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
413    <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">+=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">gridWidth_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">]</span>;
414  <span class="ActionScriptBracket/Brace">}</span>
415  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridCol</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">grid</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span>;
416  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(!</span><span class="ActionScriptDefault_Text">gridCol</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
417    <span class="ActionScriptDefault_Text">gridCol</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">grid</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">[]</span>;
418    <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">gridCol</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">[]</span>;
419  <span class="ActionScriptBracket/Brace">}</span>
420  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridCell</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">gridCol</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">]</span>;
421  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(!</span><span class="ActionScriptDefault_Text">gridCell</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
422    <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">gridCol</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">[]</span>;
423  <span class="ActionScriptBracket/Brace">}</span>
424  <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">gridCell</span>;
425<span class="ActionScriptBracket/Brace">}</span>
426
427
428<span class="ActionScriptASDoc">/**
429 * Get a cell in the grid, returning undefined if it does not exist.
430 *
431 * NOTE: Optimized for speed -- otherwise could combine with getGridCellCreate_.
432 *
433 * @param {Number} x The x coordinate of the cell.
434 * @param {Number} y The y coordinate of the cell.
435 * @param {Number} z The z coordinate of the cell.
436 * @return {Array} The cell in the array.
437 */</span>
438<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getGridCellNoCreate_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">z</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptBracket/Brace">{</span>
439  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">grid</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">grid_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">]</span>;
440  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;</span> 0<span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
441    <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">+=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">gridWidth_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">]</span>;
442  <span class="ActionScriptBracket/Brace">}</span>
443  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridCol</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">grid</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span>;
444  <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">gridCol</span> <span class="ActionScriptOperator">?</span> <span class="ActionScriptDefault_Text">gridCol</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">:</span> <span class="ActionScriptReserved">undefined</span>;
445<span class="ActionScriptBracket/Brace">}</span>;
446
447
448<span class="ActionScriptASDoc">/**
449 * Turns at geographical bounds into a grid-space bounds.
450 *
451 * @param {LatLngBounds} bounds The geographical bounds.
452 * @param {Number} zoom The zoom level of the bounds.
453 * @param {GSize} swPadding The padding in pixels to extend beyond the
454 * given bounds.
455 * @param {GSize} nePadding The padding in pixels to extend beyond the
456 * given bounds.
457 * @return {GBounds} The bounds in grid space.
458 */</span>
459<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getGridBounds_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">bounds</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">LatLngBounds</span>, <span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">swPadding</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span>, <span class="ActionScriptDefault_Text">nePadding</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span> <span class="ActionScriptBracket/Brace">{</span>
460  <span class="ActionScriptDefault_Text">zoom</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">min</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">zoom</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">maxZoom_</span><span class="ActionScriptBracket/Brace">)</span>;
461  
462  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">bl</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">LatLng</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds</span>.<span class="ActionScriptDefault_Text">getSouthWest</span><span class="ActionScriptBracket/Brace">()</span>;
463  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">tr</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">LatLng</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds</span>.<span class="ActionScriptDefault_Text">getNorthEast</span><span class="ActionScriptBracket/Brace">()</span>;
464  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sw</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getTilePoint_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">bl</span>, <span class="ActionScriptDefault_Text">zoom</span>, <span class="ActionScriptDefault_Text">swPadding</span><span class="ActionScriptBracket/Brace">)</span>;
465  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">ne</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Point</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getTilePoint_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">tr</span>, <span class="ActionScriptDefault_Text">zoom</span>, <span class="ActionScriptDefault_Text">nePadding</span><span class="ActionScriptBracket/Brace">)</span>;
466  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gw</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">gridWidth_</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">zoom</span><span class="ActionScriptBracket/Brace">]</span>;
467  
468  <span class="ActionScriptComment">// Crossing the prime meridian requires correction of bounds.
469</span>  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">tr</span>.<span class="ActionScriptDefault_Text">lng</span><span class="ActionScriptBracket/Brace">()</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">bl</span>.<span class="ActionScriptDefault_Text">lng</span><span class="ActionScriptBracket/Brace">()</span> <span class="ActionScriptOperator">||</span> <span class="ActionScriptDefault_Text">ne</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">sw</span>.<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
470    <span class="ActionScriptDefault_Text">sw</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">-=</span> <span class="ActionScriptDefault_Text">gw</span>;
471  <span class="ActionScriptBracket/Brace">}</span>
472  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">ne</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">-</span> <span class="ActionScriptDefault_Text">sw</span>.<span class="ActionScriptDefault_Text">x</span>  <span class="ActionScriptOperator">+</span> 1 <span class="ActionScriptOperator">&gt;=</span> <span class="ActionScriptDefault_Text">gw</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
473    <span class="ActionScriptComment">// Computed grid bounds are larger than the world; truncate.
474</span>    <span class="ActionScriptDefault_Text">sw</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> 0;
475    <span class="ActionScriptDefault_Text">ne</span>.<span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">gw</span> <span class="ActionScriptOperator">-</span> 1;
476  <span class="ActionScriptBracket/Brace">}</span>
477  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridBounds</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">GridBounds</span><span class="ActionScriptBracket/Brace">([</span><span class="ActionScriptDefault_Text">sw</span>, <span class="ActionScriptDefault_Text">ne</span><span class="ActionScriptBracket/Brace">])</span>;
478  <span class="ActionScriptDefault_Text">gridBounds</span>.<span class="ActionScriptDefault_Text">z</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">zoom</span>;
479  <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">gridBounds</span>;
480<span class="ActionScriptBracket/Brace">}</span>
481
482
483<span class="ActionScriptASDoc">/**
484 * Gets the grid-space bounds for the current map viewport.
485 *
486 * @return {Bounds} The bounds in grid space.
487 */</span>
488<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">getMapGridBounds_</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span> <span class="ActionScriptBracket/Brace">{</span>
489  <span class="ActionScriptReserved">return</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getGridBounds_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">map_</span>.<span class="ActionScriptDefault_Text">getLatLngBounds</span><span class="ActionScriptBracket/Brace">()</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mapZoom_</span>,
490                           <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">swPadding_</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">nePadding_</span><span class="ActionScriptBracket/Brace">)</span>;
491<span class="ActionScriptBracket/Brace">}</span>
492
493
494<span class="ActionScriptASDoc">/**
495 * Event listener for map:movend.
496 * NOTE: Use a timeout so that the user is not blocked
497 * from moving the map.
498 *
499 */</span>
500<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">onMapMoveEnd_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">event</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">MapMoveEvent</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
501  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">updateMarkers_</span><span class="ActionScriptBracket/Brace">()</span>;
502  <span class="ActionScriptComment">//this.objectSetTimeout_(this, this.updateMarkers_, 0);
503</span><span class="ActionScriptBracket/Brace">}</span>
504
505
506<span class="ActionScriptASDoc">/**
507 * Call a function or evaluate an expression after a specified number of
508 * milliseconds.
509 *
510 * Equivalent to the standard window.setTimeout function, but the given
511 * function executes as a method of this instance. So the function passed to
512 * objectSetTimeout can contain references to this.
513 *    objectSetTimeout(this, function() { alert(this.x) }, 1000);
514 *
515 * @param {Object} object  The target object.
516 * @param {Function} command  The command to run.
517 * @param {Number} milliseconds  The delay.
518 * @return {Boolean}  Success.
519 */</span>
520<span class="ActionScriptComment">/*
521MarkerManager.prototype.objectSetTimeout_ = function(object, command, milliseconds) {
522  return window.setTimeout(function() {
523    command.call(object);
524  }, milliseconds);
525};
526*/</span>
527
528<span class="ActionScriptASDoc">/**
529 * Refresh forces the marker-manager into a good state.
530 * If never before initialized, shows all the markers.
531 * If previously initialized, removes and re-adds all markers.
532 */</span>
533<span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">refresh</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
534  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownMarkers_</span> <span class="ActionScriptOperator">&gt;</span> 0<span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
535    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">processAll_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeOverlay_</span><span class="ActionScriptBracket/Brace">)</span>;
536  <span class="ActionScriptBracket/Brace">}</span>
537  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">processAll_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">addOverlay_</span><span class="ActionScriptBracket/Brace">)</span>;
538  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">notifyListeners_</span><span class="ActionScriptBracket/Brace">()</span>;
539<span class="ActionScriptBracket/Brace">}</span>;
540
541
542<span class="ActionScriptASDoc">/**
543 * After the viewport may have changed, add or remove markers as needed.
544 */</span>
545<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">updateMarkers_</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
546  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mapZoom_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">map_</span>.<span class="ActionScriptDefault_Text">getZoom</span><span class="ActionScriptBracket/Brace">()</span>;
547  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">newBounds</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getMapGridBounds_</span><span class="ActionScriptBracket/Brace">()</span>;
548  
549  <span class="ActionScriptComment">// If the move does not include new grid sections,
550</span>  <span class="ActionScriptComment">// we have no work to do:
551</span>  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">newBounds</span>.<span class="ActionScriptDefault_Text">equals</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">newBounds</span>.<span class="ActionScriptDefault_Text">z</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
552    <span class="ActionScriptReserved">return</span>;
553  <span class="ActionScriptBracket/Brace">}</span>
554
555  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">newBounds</span>.<span class="ActionScriptDefault_Text">z</span> <span class="ActionScriptOperator">!=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>.<span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
556    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">processAll_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeOverlay_</span><span class="ActionScriptBracket/Brace">)</span>;
557    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">processAll_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">newBounds</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">addOverlay_</span><span class="ActionScriptBracket/Brace">)</span>;
558  <span class="ActionScriptBracket/Brace">}</span> <span class="ActionScriptReserved">else</span> <span class="ActionScriptBracket/Brace">{</span>
559    <span class="ActionScriptComment">// Remove markers:
560</span>    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">rectangleDiff_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>, <span class="ActionScriptDefault_Text">newBounds</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeCellMarkers_</span><span class="ActionScriptBracket/Brace">)</span>;
561
562    <span class="ActionScriptComment">// Add markers:
563</span>    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">rectangleDiff_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">newBounds</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">addCellMarkers_</span><span class="ActionScriptBracket/Brace">)</span>;
564  <span class="ActionScriptBracket/Brace">}</span>
565  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">shownBounds_</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">newBounds</span>;
566
567  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">notifyListeners_</span><span class="ActionScriptBracket/Brace">()</span>;
568<span class="ActionScriptBracket/Brace">}</span>;
569
570
571<span class="ActionScriptASDoc">/**
572 * Notify listeners when the state of what is displayed changes.
573 */</span>
574<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">notifyListeners_</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
575  <span class="ActionScriptComment">//this.dispatchEvent(new Event(&quot;changed&quot;), this.shownBounds_, this.shownMarkers_);
576</span><span class="ActionScriptBracket/Brace">}</span>
577
578
579<span class="ActionScriptASDoc">/**
580 * Process all markers in the bounds provided, using a callback.
581 *
582 * @param {Bounds} bounds The bounds in grid space.
583 * @param {Function} callback The function to call for each marker.
584 */</span>
585<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">processAll_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">bounds</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span>, <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Function</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
586  <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds</span>.<span class="ActionScriptDefault_Text">minX</span>; <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">bounds</span>.<span class="ActionScriptDefault_Text">maxX</span>; <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
587    <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds</span>.<span class="ActionScriptDefault_Text">minY</span>; <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">bounds</span>.<span class="ActionScriptDefault_Text">maxY</span>; <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
588      <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">processCellMarkers_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span>,  <span class="ActionScriptDefault_Text">bounds</span>.<span class="ActionScriptDefault_Text">z</span>, <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptBracket/Brace">)</span>;
589    <span class="ActionScriptBracket/Brace">}</span>
590  <span class="ActionScriptBracket/Brace">}</span>
591<span class="ActionScriptBracket/Brace">}</span>
592
593
594<span class="ActionScriptASDoc">/**
595 * Process all markers in the grid cell, using a callback.
596 *
597 * @param {Number} x The x coordinate of the cell.
598 * @param {Number} y The y coordinate of the cell.
599 * @param {Number} z The z coordinate of the cell.
600 * @param {Function} callback The function to call for each marker.
601 */</span>
602<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">processCellMarkers_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">z</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Function</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
603  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">cell</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">getGridCellNoCreate_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">)</span>;
604  <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">cell</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
605    <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">cell</span>.<span class="ActionScriptDefault_Text">length</span> <span class="ActionScriptOperator">-</span> 1; <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">&gt;=</span> 0; <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">--</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
606      <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">cell</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">])</span>;
607    <span class="ActionScriptBracket/Brace">}</span>
608  <span class="ActionScriptBracket/Brace">}</span>
609<span class="ActionScriptBracket/Brace">}</span>;
610
611
612<span class="ActionScriptASDoc">/**
613 * Remove all markers in a grid cell.
614 *
615 * @param {Number} x The x coordinate of the cell.
616 * @param {Number} y The y coordinate of the cell.
617 * @param {Number} z The z coordinate of the cell.
618 */</span>
619<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">removeCellMarkers_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">z</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
620  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">processCellMarkers_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">z</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">removeOverlay_</span><span class="ActionScriptBracket/Brace">)</span>;
621<span class="ActionScriptBracket/Brace">}</span>;
622
623
624<span class="ActionScriptASDoc">/**
625 * Add all markers in a grid cell.
626 *
627 * @param {Number} x The x coordinate of the cell.
628 * @param {Number} y The y coordinate of the cell.
629 * @param {Number} z The z coordinate of the cell.
630 */</span>
631<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">addCellMarkers_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">z</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
632  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">processCellMarkers_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">z</span>, <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">addOverlay_</span><span class="ActionScriptBracket/Brace">)</span>;
633<span class="ActionScriptBracket/Brace">}</span>;
634
635
636<span class="ActionScriptASDoc">/**
637 * Use the rectangleDiffCoords function to process all grid cells
638 * that are in bounds1 but not bounds2, using a callback, and using
639 * the current MarkerManager object as the instance.
640 *
641 * Pass the z parameter to the callback in addition to x and y.
642 *
643 * @param {Bounds} bounds1 The bounds of all points we may process.
644 * @param {Bounds} bounds2 The bounds of points to exclude.
645 * @param {Function} callback The callback function to call
646 *                   for each grid coordinate (x, y, z).
647 */</span>
648<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">rectangleDiff_</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">bounds1</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span>, <span class="ActionScriptDefault_Text">bounds2</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span>, <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Function</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
649  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">me</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">MarkerManager</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">this</span>;
650  <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">rectangleDiffCoords</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">bounds1</span>, <span class="ActionScriptDefault_Text">bounds2</span>, <span class="ActionScriptfunction">function</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
651    <span class="ActionScriptDefault_Text">callback</span>.<span class="ActionScriptDefault_Text">apply</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">me</span>, <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">bounds1</span>.<span class="ActionScriptDefault_Text">z</span><span class="ActionScriptBracket/Brace">])</span>;
652  <span class="ActionScriptBracket/Brace">})</span>;
653<span class="ActionScriptBracket/Brace">}</span>;
654
655
656<span class="ActionScriptASDoc">/**
657 * Calls the function for all points in bounds1, not in bounds2
658 *
659 * @param {Bounds} bounds1 The bounds of all points we may process.
660 * @param {Bounds} bounds2 The bounds of points to exclude.
661 * @param {Function} callback The callback function to call
662 *                   for each grid coordinate.
663 */</span>
664<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">rectangleDiffCoords</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">bounds1</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span>, <span class="ActionScriptDefault_Text">bounds2</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">GridBounds</span>, <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Function</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> <span class="ActionScriptBracket/Brace">{</span>
665  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">minX1</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds1</span>.<span class="ActionScriptDefault_Text">minX</span>;
666  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">minY1</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds1</span>.<span class="ActionScriptDefault_Text">minY</span>;
667  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxX1</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds1</span>.<span class="ActionScriptDefault_Text">maxX</span>;
668  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxY1</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds1</span>.<span class="ActionScriptDefault_Text">maxY</span>;
669  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">minX2</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds2</span>.<span class="ActionScriptDefault_Text">minX</span>;
670  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">minY2</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds2</span>.<span class="ActionScriptDefault_Text">minY</span>;
671  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxX2</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds2</span>.<span class="ActionScriptDefault_Text">maxX</span>;
672  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxY2</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">bounds2</span>.<span class="ActionScriptDefault_Text">maxY</span>;
673
674  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
675  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
676
677  <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">minX1</span>; <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">maxX1</span>; <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>  <span class="ActionScriptComment">// All x in R1
678</span>    <span class="ActionScriptComment">// All above:
679</span>    <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">minY1</span>; <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">maxY1</span> <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">minY2</span>; <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>  <span class="ActionScriptComment">// y in R1 above R2
680</span>      <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">)</span>;
681    <span class="ActionScriptBracket/Brace">}</span>
682    <span class="ActionScriptComment">// All below:
683</span>    <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">max</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">maxY2</span> <span class="ActionScriptOperator">+</span> 1, <span class="ActionScriptDefault_Text">minY1</span><span class="ActionScriptBracket/Brace">)</span>;  <span class="ActionScriptComment">// y in R1 below R2
684</span>         <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">maxY1</span>; <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
685      <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">)</span>;
686    <span class="ActionScriptBracket/Brace">}</span>
687  <span class="ActionScriptBracket/Brace">}</span>
688
689  <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">max</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">minY1</span>, <span class="ActionScriptDefault_Text">minY2</span><span class="ActionScriptBracket/Brace">)</span>;
690       <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">min</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">maxY1</span>, <span class="ActionScriptDefault_Text">maxY2</span><span class="ActionScriptBracket/Brace">)</span>; <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>  <span class="ActionScriptComment">// All y in R2 and in R1
691</span>    <span class="ActionScriptComment">// Strictly left:
692</span>    <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">min</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">maxX1</span> <span class="ActionScriptOperator">+</span> 1, <span class="ActionScriptDefault_Text">minX2</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptOperator">-</span> 1;
693         <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;=</span> <span class="ActionScriptDefault_Text">minX1</span>; <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">--</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>  <span class="ActionScriptComment">// x in R1 left of R2
694</span>      <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">)</span>;
695    <span class="ActionScriptBracket/Brace">}</span>
696    <span class="ActionScriptComment">// Strictly right:
697</span>    <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">max</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">minX1</span>, <span class="ActionScriptDefault_Text">maxX2</span> <span class="ActionScriptOperator">+</span> 1<span class="ActionScriptBracket/Brace">)</span>;  <span class="ActionScriptComment">// x in R1 right of R2
698</span>         <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;=</span> <span class="ActionScriptDefault_Text">maxX1</span>; <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
699      <span class="ActionScriptDefault_Text">callback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">)</span>;
700    <span class="ActionScriptBracket/Brace">}</span>
701  <span class="ActionScriptBracket/Brace">}</span>
702<span class="ActionScriptBracket/Brace">}</span>
703
704
705<span class="ActionScriptASDoc">/**
706 * Removes value from array. O(N).
707 *
708 * @param {Array} array  The array to modify.
709 * @param {any} value  The value to remove.
710 * @param {Boolean} opt_notype  Flag to disable type checking in equality.
711 * @return {Number}  The number of instances of value that were removed.
712 */</span>
713<span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">removeFromArray</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">array</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span>, <span class="ActionScriptDefault_Text">value</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Object</span>, <span class="ActionScriptDefault_Text">opt_notype</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Number</span> <span class="ActionScriptBracket/Brace">{</span>
714  <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">shift</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> 0;
715  <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">array</span>.<span class="ActionScriptDefault_Text">length</span>; <span class="ActionScriptOperator">++</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">)</span> <span class="ActionScriptBracket/Brace">{</span>
716    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">array</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">===</span> <span class="ActionScriptDefault_Text">value</span> <span class="ActionScriptOperator">||</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">opt_notype</span> <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">array</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptDefault_Text">value</span><span class="ActionScriptBracket/Brace">))</span> <span class="ActionScriptBracket/Brace">{</span>
717      <span class="ActionScriptDefault_Text">array</span>.<span class="ActionScriptDefault_Text">splice</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">--</span>, 1<span class="ActionScriptBracket/Brace">)</span>;
718      <span class="ActionScriptDefault_Text">shift</span><span class="ActionScriptOperator">++</span>;
719    <span class="ActionScriptBracket/Brace">}</span>
720  <span class="ActionScriptBracket/Brace">}</span>
721  <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">shift</span>;
722<span class="ActionScriptBracket/Brace">}</span>
723
724<span class="ActionScriptBracket/Brace">}</span>
725<span class="ActionScriptBracket/Brace">}</span>
726</pre></body>
727</html>