| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
function MarkerManager(map, opt_opts) { |
| 75 |
var me = this; |
| 76 |
me.map_ = map; |
| 77 |
me.mapZoom_ = map.getZoom(); |
| 78 |
|
| 79 |
me.projectionHelper_ = new ProjectionHelperOverlay(map); |
| 80 |
google.maps.event.addListener(me.projectionHelper_, 'ready', function () { |
| 81 |
me.projection_ = this.getProjection(); |
| 82 |
me.initialize(map, opt_opts); |
| 83 |
}); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
MarkerManager.prototype.initialize = function (map, opt_opts) { |
| 88 |
var me = this; |
| 89 |
|
| 90 |
opt_opts = opt_opts || {}; |
| 91 |
me.tileSize_ = MarkerManager.DEFAULT_TILE_SIZE_; |
| 92 |
|
| 93 |
var mapTypes = map.mapTypes; |
| 94 |
|
| 95 |
|
| 96 |
var mapMaxZoom = 1; |
| 97 |
for (var sType in mapTypes ) { |
| 98 |
if (typeof map.mapTypes.get(sType) === 'object' && typeof map.mapTypes.get(sType).maxZoom === 'number') { |
| 99 |
var mapTypeMaxZoom = map.mapTypes.get(sType).maxZoom; |
| 100 |
if (mapTypeMaxZoom > mapMaxZoom) { |
| 101 |
mapMaxZoom = mapTypeMaxZoom; |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
me.maxZoom_ = opt_opts.maxZoom || 19; |
| 107 |
|
| 108 |
me.trackMarkers_ = opt_opts.trackMarkers; |
| 109 |
me.show_ = opt_opts.show || true; |
| 110 |
|
| 111 |
var padding; |
| 112 |
if (typeof opt_opts.borderPadding === 'number') { |
| 113 |
padding = opt_opts.borderPadding; |
| 114 |
} else { |
| 115 |
padding = MarkerManager.DEFAULT_BORDER_PADDING_; |
| 116 |
} |
| 117 |
|
| 118 |
me.swPadding_ = new google.maps.Size(-padding, padding); |
| 119 |
me.nePadding_ = new google.maps.Size(padding, -padding); |
| 120 |
me.borderPadding_ = padding; |
| 121 |
|
| 122 |
me.gridWidth_ = {}; |
| 123 |
|
| 124 |
me.grid_ = {}; |
| 125 |
me.grid_[me.maxZoom_] = {}; |
| 126 |
me.numMarkers_ = {}; |
| 127 |
me.numMarkers_[me.maxZoom_] = 0; |
| 128 |
|
| 129 |
|
| 130 |
google.maps.event.addListener(map, 'dragend', function () { |
| 131 |
me.onMapMoveEnd_(); |
| 132 |
}); |
| 133 |
google.maps.event.addListener(map, 'zoom_changed', function () { |
| 134 |
me.onMapMoveEnd_(); |
| 135 |
}); |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
me.removeOverlay_ = function (marker) { |
| 146 |
marker.setMap(null); |
| 147 |
me.shownMarkers_--; |
| 148 |
}; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
me.addOverlay_ = function (marker) { |
| 157 |
if (me.show_) { |
| 158 |
marker.setMap(me.map_); |
| 159 |
me.shownMarkers_++; |
| 160 |
} |
| 161 |
}; |
| 162 |
|
| 163 |
me.resetManager_(); |
| 164 |
me.shownMarkers_ = 0; |
| 165 |
|
| 166 |
me.shownBounds_ = me.getMapGridBounds_(); |
| 167 |
|
| 168 |
google.maps.event.trigger(me, 'loaded'); |
| 169 |
|
| 170 |
}; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
MarkerManager.DEFAULT_TILE_SIZE_ = 1024; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
MarkerManager.DEFAULT_BORDER_PADDING_ = 100; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
MarkerManager.MERCATOR_ZOOM_LEVEL_ZERO_RANGE = 256; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
MarkerManager.prototype.resetManager_ = function () { |
| 194 |
var mapWidth = MarkerManager.MERCATOR_ZOOM_LEVEL_ZERO_RANGE; |
| 195 |
for (var zoom = 0; zoom <= this.maxZoom_; ++zoom) { |
| 196 |
this.grid_[zoom] = {}; |
| 197 |
this.numMarkers_[zoom] = 0; |
| 198 |
this.gridWidth_[zoom] = Math.ceil(mapWidth / this.tileSize_); |
| 199 |
mapWidth <<= 1; |
| 200 |
} |
| 201 |
|
| 202 |
}; |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
MarkerManager.prototype.clearMarkers = function () { |
| 209 |
this.processAll_(this.shownBounds_, this.removeOverlay_); |
| 210 |
this.resetManager_(); |
| 211 |
}; |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
MarkerManager.prototype.getTilePoint_ = function (latlng, zoom, padding) { |
| 226 |
|
| 227 |
var pixelPoint = this.projectionHelper_.LatLngToPixel(latlng, zoom); |
| 228 |
|
| 229 |
var point = new google.maps.Point( |
| 230 |
Math.floor((pixelPoint.x + padding.width) / this.tileSize_), |
| 231 |
Math.floor((pixelPoint.y + padding.height) / this.tileSize_) |
| 232 |
); |
| 233 |
|
| 234 |
return point; |
| 235 |
}; |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
MarkerManager.prototype.addMarkerBatch_ = function (marker, minZoom, maxZoom) { |
| 248 |
var me = this; |
| 249 |
|
| 250 |
var mPoint = marker.getPosition(); |
| 251 |
marker.MarkerManager_minZoom = minZoom; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
if (this.trackMarkers_) { |
| 257 |
google.maps.event.addListener(marker, 'changed', function (a, b, c) { |
| 258 |
me.onMarkerMoved_(a, b, c); |
| 259 |
}); |
| 260 |
} |
| 261 |
|
| 262 |
var gridPoint = this.getTilePoint_(mPoint, maxZoom, new google.maps.Size(0, 0, 0, 0)); |
| 263 |
|
| 264 |
for (var zoom = maxZoom; zoom >= minZoom; zoom--) { |
| 265 |
var cell = this.getGridCellCreate_(gridPoint.x, gridPoint.y, zoom); |
| 266 |
cell.push(marker); |
| 267 |
|
| 268 |
gridPoint.x = gridPoint.x >> 1; |
| 269 |
gridPoint.y = gridPoint.y >> 1; |
| 270 |
} |
| 271 |
}; |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
MarkerManager.prototype.isGridPointVisible_ = function (point) { |
| 284 |
var vertical = this.shownBounds_.minY <= point.y && |
| 285 |
point.y <= this.shownBounds_.maxY; |
| 286 |
var minX = this.shownBounds_.minX; |
| 287 |
var horizontal = minX <= point.x && point.x <= this.shownBounds_.maxX; |
| 288 |
if (!horizontal && minX < 0) { |
| 289 |
|
| 290 |
|
| 291 |
var width = this.gridWidth_[this.shownBounds_.z]; |
| 292 |
horizontal = minX + width <= point.x && point.x <= width - 1; |
| 293 |
} |
| 294 |
return vertical && horizontal; |
| 295 |
}; |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
MarkerManager.prototype.onMarkerMoved_ = function (marker, oldPoint, newPoint) { |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
var zoom = this.maxZoom_; |
| 312 |
var changed = false; |
| 313 |
var oldGrid = this.getTilePoint_(oldPoint, zoom, new google.maps.Size(0, 0, 0, 0)); |
| 314 |
var newGrid = this.getTilePoint_(newPoint, zoom, new google.maps.Size(0, 0, 0, 0)); |
| 315 |
while (zoom >= 0 && (oldGrid.x !== newGrid.x || oldGrid.y !== newGrid.y)) { |
| 316 |
var cell = this.getGridCellNoCreate_(oldGrid.x, oldGrid.y, zoom); |
| 317 |
if (cell) { |
| 318 |
if (this.removeFromArray_(cell, marker)) { |
| 319 |
this.getGridCellCreate_(newGrid.x, newGrid.y, zoom).push(marker); |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
if (zoom === this.mapZoom_) { |
| 327 |
if (this.isGridPointVisible_(oldGrid)) { |
| 328 |
if (!this.isGridPointVisible_(newGrid)) { |
| 329 |
this.removeOverlay_(marker); |
| 330 |
changed = true; |
| 331 |
} |
| 332 |
} else { |
| 333 |
if (this.isGridPointVisible_(newGrid)) { |
| 334 |
this.addOverlay_(marker); |
| 335 |
changed = true; |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
oldGrid.x = oldGrid.x >> 1; |
| 340 |
oldGrid.y = oldGrid.y >> 1; |
| 341 |
newGrid.x = newGrid.x >> 1; |
| 342 |
newGrid.y = newGrid.y >> 1; |
| 343 |
--zoom; |
| 344 |
} |
| 345 |
if (changed) { |
| 346 |
this.notifyListeners_(); |
| 347 |
} |
| 348 |
}; |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
MarkerManager.prototype.removeMarker = function (marker) { |
| 357 |
var zoom = this.maxZoom_; |
| 358 |
var changed = false; |
| 359 |
var point = marker.getPosition(); |
| 360 |
var grid = this.getTilePoint_(point, zoom, new google.maps.Size(0, 0, 0, 0)); |
| 361 |
while (zoom >= 0) { |
| 362 |
var cell = this.getGridCellNoCreate_(grid.x, grid.y, zoom); |
| 363 |
|
| 364 |
if (cell) { |
| 365 |
this.removeFromArray_(cell, marker); |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
if (zoom === this.mapZoom_) { |
| 371 |
if (this.isGridPointVisible_(grid)) { |
| 372 |
this.removeOverlay_(marker); |
| 373 |
changed = true; |
| 374 |
} |
| 375 |
} |
| 376 |
grid.x = grid.x >> 1; |
| 377 |
grid.y = grid.y >> 1; |
| 378 |
--zoom; |
| 379 |
} |
| 380 |
if (changed) { |
| 381 |
this.notifyListeners_(); |
| 382 |
} |
| 383 |
this.numMarkers_[marker.MarkerManager_minZoom]--; |
| 384 |
}; |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
MarkerManager.prototype.addMarkers = function (markers, minZoom, opt_maxZoom) { |
| 396 |
var maxZoom = this.getOptMaxZoom_(opt_maxZoom); |
| 397 |
for (var i = markers.length - 1; i >= 0; i--) { |
| 398 |
this.addMarkerBatch_(markers[i], minZoom, maxZoom); |
| 399 |
} |
| 400 |
|
| 401 |
this.numMarkers_[minZoom] += markers.length; |
| 402 |
}; |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
MarkerManager.prototype.getOptMaxZoom_ = function (opt_maxZoom) { |
| 413 |
return opt_maxZoom || this.maxZoom_; |
| 414 |
}; |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
MarkerManager.prototype.getMarkerCount = function (zoom) { |
| 424 |
var total = 0; |
| 425 |
for (var z = 0; z <= zoom; z++) { |
| 426 |
total += this.numMarkers_[z]; |
| 427 |
} |
| 428 |
return total; |
| 429 |
}; |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
MarkerManager.prototype.getMarker = function (lat, lng, zoom) { |
| 442 |
var mPoint = new google.maps.LatLng(lat, lng); |
| 443 |
var gridPoint = this.getTilePoint_(mPoint, zoom, new google.maps.Size(0, 0, 0, 0)); |
| 444 |
|
| 445 |
var marker = new google.maps.Marker({position: mPoint}); |
| 446 |
|
| 447 |
var cellArray = this.getGridCellNoCreate_(gridPoint.x, gridPoint.y, zoom); |
| 448 |
if (cellArray !== undefined) { |
| 449 |
for (var i = 0; i < cellArray.length; i++) |
| 450 |
{ |
| 451 |
if (lat === cellArray[i].getLatLng().lat() && lng === cellArray[i].getLatLng().lng()) { |
| 452 |
marker = cellArray[i]; |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
return marker; |
| 457 |
}; |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
MarkerManager.prototype.addMarker = function (marker, minZoom, opt_maxZoom) { |
| 467 |
var maxZoom = this.getOptMaxZoom_(opt_maxZoom); |
| 468 |
this.addMarkerBatch_(marker, minZoom, maxZoom); |
| 469 |
var gridPoint = this.getTilePoint_(marker.getPosition(), this.mapZoom_, new google.maps.Size(0, 0, 0, 0)); |
| 470 |
if (this.isGridPointVisible_(gridPoint) && |
| 471 |
minZoom <= this.shownBounds_.z && |
| 472 |
this.shownBounds_.z <= maxZoom) { |
| 473 |
this.addOverlay_(marker); |
| 474 |
this.notifyListeners_(); |
| 475 |
} |
| 476 |
this.numMarkers_[minZoom]++; |
| 477 |
}; |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
function GridBounds(bounds) { |
| 486 |
|
| 487 |
|
| 488 |
this.minX = Math.min(bounds[0].x, bounds[1].x); |
| 489 |
this.maxX = Math.max(bounds[0].x, bounds[1].x); |
| 490 |
this.minY = Math.min(bounds[0].y, bounds[1].y); |
| 491 |
this.maxY = Math.max(bounds[0].y, bounds[1].y); |
| 492 |
|
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
GridBounds.prototype.equals = function (gridBounds) { |
| 501 |
if (this.maxX === gridBounds.maxX && this.maxY === gridBounds.maxY && this.minX === gridBounds.minX && this.minY === gridBounds.minY) { |
| 502 |
return true; |
| 503 |
} else { |
| 504 |
return false; |
| 505 |
} |
| 506 |
}; |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
GridBounds.prototype.containsPoint = function (point) { |
| 514 |
var outer = this; |
| 515 |
return (outer.minX <= point.x && outer.maxX >= point.x && outer.minY <= point.y && outer.maxY >= point.y); |
| 516 |
}; |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
MarkerManager.prototype.getGridCellCreate_ = function (x, y, z) { |
| 529 |
var grid = this.grid_[z]; |
| 530 |
if (x < 0) { |
| 531 |
x += this.gridWidth_[z]; |
| 532 |
} |
| 533 |
var gridCol = grid[x]; |
| 534 |
if (!gridCol) { |
| 535 |
gridCol = grid[x] = []; |
| 536 |
return (gridCol[y] = []); |
| 537 |
} |
| 538 |
var gridCell = gridCol[y]; |
| 539 |
if (!gridCell) { |
| 540 |
return (gridCol[y] = []); |
| 541 |
} |
| 542 |
return gridCell; |
| 543 |
}; |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
MarkerManager.prototype.getGridCellNoCreate_ = function (x, y, z) { |
| 557 |
var grid = this.grid_[z]; |
| 558 |
|
| 559 |
if (x < 0) { |
| 560 |
x += this.gridWidth_[z]; |
| 561 |
} |
| 562 |
var gridCol = grid[x]; |
| 563 |
return gridCol ? gridCol[y] : undefined; |
| 564 |
}; |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
MarkerManager.prototype.getGridBounds_ = function (bounds, zoom, swPadding, nePadding) { |
| 579 |
zoom = Math.min(zoom, this.maxZoom_); |
| 580 |
|
| 581 |
var bl = bounds.getSouthWest(); |
| 582 |
var tr = bounds.getNorthEast(); |
| 583 |
var sw = this.getTilePoint_(bl, zoom, swPadding); |
| 584 |
|
| 585 |
var ne = this.getTilePoint_(tr, zoom, nePadding); |
| 586 |
var gw = this.gridWidth_[zoom]; |
| 587 |
|
| 588 |
|
| 589 |
if (tr.lng() < bl.lng() || ne.x < sw.x) { |
| 590 |
sw.x -= gw; |
| 591 |
} |
| 592 |
if (ne.x - sw.x + 1 >= gw) { |
| 593 |
|
| 594 |
sw.x = 0; |
| 595 |
ne.x = gw - 1; |
| 596 |
} |
| 597 |
|
| 598 |
var gridBounds = new GridBounds([sw, ne]); |
| 599 |
gridBounds.z = zoom; |
| 600 |
|
| 601 |
return gridBounds; |
| 602 |
}; |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
MarkerManager.prototype.getMapGridBounds_ = function () { |
| 611 |
return this.getGridBounds_(this.map_.getBounds(), this.mapZoom_, this.swPadding_, this.nePadding_); |
| 612 |
}; |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
MarkerManager.prototype.onMapMoveEnd_ = function () { |
| 623 |
this.objectSetTimeout_(this, this.updateMarkers_, 0); |
| 624 |
}; |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
MarkerManager.prototype.objectSetTimeout_ = function (object, command, milliseconds) { |
| 642 |
return window.setTimeout(function () { |
| 643 |
command.call(object); |
| 644 |
}, milliseconds); |
| 645 |
}; |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
MarkerManager.prototype.visible = function () { |
| 656 |
return this.show_ ? true : false; |
| 657 |
}; |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
MarkerManager.prototype.isHidden = function () { |
| 666 |
return !this.show_; |
| 667 |
}; |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
MarkerManager.prototype.show = function () { |
| 674 |
this.show_ = true; |
| 675 |
this.refresh(); |
| 676 |
}; |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
MarkerManager.prototype.hide = function () { |
| 683 |
this.show_ = false; |
| 684 |
this.refresh(); |
| 685 |
}; |
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
MarkerManager.prototype.toggle = function () { |
| 692 |
this.show_ = !this.show_; |
| 693 |
this.refresh(); |
| 694 |
}; |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
MarkerManager.prototype.refresh = function () { |
| 705 |
if (this.shownMarkers_ > 0) { |
| 706 |
this.processAll_(this.shownBounds_, this.removeOverlay_); |
| 707 |
} |
| 708 |
|
| 709 |
if (this.show_) { |
| 710 |
this.processAll_(this.shownBounds_, this.addOverlay_); |
| 711 |
} |
| 712 |
this.notifyListeners_(); |
| 713 |
}; |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
MarkerManager.prototype.updateMarkers_ = function () { |
| 720 |
this.mapZoom_ = this.map_.getZoom(); |
| 721 |
var newBounds = this.getMapGridBounds_(); |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
if (newBounds.equals(this.shownBounds_) && newBounds.z === this.shownBounds_.z) { |
| 726 |
return; |
| 727 |
} |
| 728 |
|
| 729 |
if (newBounds.z !== this.shownBounds_.z) { |
| 730 |
this.processAll_(this.shownBounds_, this.removeOverlay_); |
| 731 |
if (this.show_) { |
| 732 |
this.processAll_(newBounds, this.addOverlay_); |
| 733 |
} |
| 734 |
} else { |
| 735 |
|
| 736 |
this.rectangleDiff_(this.shownBounds_, newBounds, this.removeCellMarkers_); |
| 737 |
|
| 738 |
|
| 739 |
if (this.show_) { |
| 740 |
this.rectangleDiff_(newBounds, this.shownBounds_, this.addCellMarkers_); |
| 741 |
} |
| 742 |
} |
| 743 |
this.shownBounds_ = newBounds; |
| 744 |
|
| 745 |
this.notifyListeners_(); |
| 746 |
}; |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
MarkerManager.prototype.notifyListeners_ = function () { |
| 753 |
google.maps.event.trigger(this, 'changed', this.shownBounds_, this.shownMarkers_); |
| 754 |
}; |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
MarkerManager.prototype.processAll_ = function (bounds, callback) { |
| 764 |
for (var x = bounds.minX; x <= bounds.maxX; x++) { |
| 765 |
for (var y = bounds.minY; y <= bounds.maxY; y++) { |
| 766 |
this.processCellMarkers_(x, y, bounds.z, callback); |
| 767 |
} |
| 768 |
} |
| 769 |
}; |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
MarkerManager.prototype.processCellMarkers_ = function (x, y, z, callback) { |
| 781 |
var cell = this.getGridCellNoCreate_(x, y, z); |
| 782 |
if (cell) { |
| 783 |
for (var i = cell.length - 1; i >= 0; i--) { |
| 784 |
callback(cell[i]); |
| 785 |
} |
| 786 |
} |
| 787 |
}; |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
MarkerManager.prototype.removeCellMarkers_ = function (x, y, z) { |
| 798 |
this.processCellMarkers_(x, y, z, this.removeOverlay_); |
| 799 |
}; |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
MarkerManager.prototype.addCellMarkers_ = function (x, y, z) { |
| 810 |
this.processCellMarkers_(x, y, z, this.addOverlay_); |
| 811 |
}; |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
MarkerManager.prototype.rectangleDiff_ = function (bounds1, bounds2, callback) { |
| 827 |
var me = this; |
| 828 |
me.rectangleDiffCoords_(bounds1, bounds2, function (x, y) { |
| 829 |
callback.apply(me, [x, y, bounds1.z]); |
| 830 |
}); |
| 831 |
}; |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
MarkerManager.prototype.rectangleDiffCoords_ = function (bounds1, bounds2, callback) { |
| 843 |
var minX1 = bounds1.minX; |
| 844 |
var minY1 = bounds1.minY; |
| 845 |
var maxX1 = bounds1.maxX; |
| 846 |
var maxY1 = bounds1.maxY; |
| 847 |
var minX2 = bounds2.minX; |
| 848 |
var minY2 = bounds2.minY; |
| 849 |
var maxX2 = bounds2.maxX; |
| 850 |
var maxY2 = bounds2.maxY; |
| 851 |
|
| 852 |
var x, y; |
| 853 |
for (x = minX1; x <= maxX1; x++) { |
| 854 |
|
| 855 |
for (y = minY1; y <= maxY1 && y < minY2; y++) { |
| 856 |
callback(x, y); |
| 857 |
} |
| 858 |
|
| 859 |
for (y = Math.max(maxY2 + 1, minY1); |
| 860 |
y <= maxY1; y++) { |
| 861 |
callback(x, y); |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
for (y = Math.max(minY1, minY2); |
| 866 |
y <= Math.min(maxY1, maxY2); y++) { |
| 867 |
|
| 868 |
for (x = Math.min(maxX1 + 1, minX2) - 1; |
| 869 |
x >= minX1; x--) { |
| 870 |
callback(x, y); |
| 871 |
} |
| 872 |
|
| 873 |
for (x = Math.max(minX1, maxX2 + 1); |
| 874 |
x <= maxX1; x++) { |
| 875 |
callback(x, y); |
| 876 |
} |
| 877 |
} |
| 878 |
}; |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
MarkerManager.prototype.removeFromArray_ = function (array, value, opt_notype) { |
| 890 |
var shift = 0; |
| 891 |
for (var i = 0; i < array.length; ++i) { |
| 892 |
if (array[i] === value || (opt_notype && array[i] === value)) { |
| 893 |
array.splice(i--, 1); |
| 894 |
shift++; |
| 895 |
} |
| 896 |
} |
| 897 |
return shift; |
| 898 |
}; |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
function ProjectionHelperOverlay(map) { |
| 913 |
|
| 914 |
this.setMap(map); |
| 915 |
|
| 916 |
var TILEFACTOR = 8; |
| 917 |
var TILESIDE = 1 << TILEFACTOR; |
| 918 |
var RADIUS = 7; |
| 919 |
|
| 920 |
this._map = map; |
| 921 |
this._zoom = -1; |
| 922 |
this._X0 = |
| 923 |
this._Y0 = |
| 924 |
this._X1 = |
| 925 |
this._Y1 = -1; |
| 926 |
|
| 927 |
|
| 928 |
} |
| 929 |
if (typeof(google) != 'undefined' && google.maps) { |
| 930 |
ProjectionHelperOverlay.prototype = new google.maps.OverlayView(); |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
ProjectionHelperOverlay.prototype.LngToX_ = function (lng) { |
| 939 |
return (1 + lng / 180); |
| 940 |
}; |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
ProjectionHelperOverlay.prototype.LatToY_ = function (lat) { |
| 948 |
var sinofphi = Math.sin(lat * Math.PI / 180); |
| 949 |
return (1 - 0.5 / Math.PI * Math.log((1 + sinofphi) / (1 - sinofphi))); |
| 950 |
}; |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
ProjectionHelperOverlay.prototype.LatLngToPixel = function (latlng, zoom) { |
| 959 |
var map = this._map; |
| 960 |
var div = this.getProjection().fromLatLngToDivPixel(latlng); |
| 961 |
var abs = {x: ~~(0.5 + this.LngToX_(latlng.lng()) * (2 << (zoom + 6))), y: ~~(0.5 + this.LatToY_(latlng.lat()) * (2 << (zoom + 6)))}; |
| 962 |
return abs; |
| 963 |
}; |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
ProjectionHelperOverlay.prototype.draw = function () { |
| 972 |
if (!this.ready) { |
| 973 |
this.ready = true; |
| 974 |
google.maps.event.trigger(this, 'ready'); |
| 975 |
} |
| 976 |
}; |