Datasets:

License:
File size: 27,868 Bytes
3897bd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
<!DOCTYPE html>
            <html>
              <head>
                <title>colored_ca_range_size_rarity.tif</title>
                <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
                <meta http-equiv='imagetoolbar' content='no'/>
                <style type="text/css"> v\:* {behavior:url(#default#VML);}
                    html, body { overflow: hidden; padding: 0; height: 100%; width: 100%; font-family: 'Lucida Grande',Geneva,Arial,Verdana,sans-serif; }
                    body { margin: 10px; background: #fff; }
                    h1 { margin: 0; padding: 6px; border:0; font-size: 20pt; }
                    #header { height: 43px; padding: 0; background-color: #eee; border: 1px solid #888; }
                    #subheader { height: 12px; text-align: right; font-size: 10px; color: #555;}
                    #map { height: 95%; border: 1px solid #888; }
                 </style>
          <!-- Replace URL below with https://maps.googleapis.com/maps/api/js?key=INSERT_YOUR_KEY_HERE -->
          <script src='https://maps.googleapis.com/maps/api/js'></script>
          <script>
          //<![CDATA[

                /*
                 * Constants for given map
                 * TODO: read it from tilemapresource.xml
                 */

                var mapBounds = new google.maps.LatLngBounds(
                    new google.maps.LatLng(31.423689826371422, -125.08104466955334),
                    new google.maps.LatLng(43.470185949106565, -113.80939078827362));
                var mapMinZoom = 1;
                var mapMaxZoom = 10;


                var initialOpacity = 0.75 * 100;
                var map;

                /*
                 * Full-screen Window Resize
                 */

                function getWindowHeight() {
                    if (self.innerHeight) return self.innerHeight;
                    if (document.documentElement && document.documentElement.clientHeight)
                        return document.documentElement.clientHeight;
                    if (document.body) return document.body.clientHeight;
                    return 0;
                }

                function getWindowWidth() {
                    if (self.innerWidth) return self.innerWidth;
                    if (document.documentElement && document.documentElement.clientWidth)
                        return document.documentElement.clientWidth;
                    if (document.body) return document.body.clientWidth;
                    return 0;
                }

                function resize() {
                    var map = document.getElementById("map");
                    var header = document.getElementById("header");
                    var subheader = document.getElementById("subheader");
                    map.style.height = (getWindowHeight()-80) + "px";
                    map.style.width = (getWindowWidth()-20) + "px";
                    header.style.width = (getWindowWidth()-20) + "px";
                    subheader.style.width = (getWindowWidth()-20) + "px";
                    // map.checkResize();
                }


                // getZoomByBounds(): adapted from https://stackoverflow.com/a/9982152
                /**
                * Returns the zoom level at which the given rectangular region fits in the map view.
                * The zoom level is computed for the currently selected map type.
                * @param {google.maps.Map} map
                * @param {google.maps.LatLngBounds} bounds
                * @return {Number} zoom level
                **/
                function getZoomByBounds(  map, bounds ){
                  var MAX_ZOOM = 21 ;
                  var MIN_ZOOM =  0 ;

                  var ne= map.getProjection().fromLatLngToPoint( bounds.getNorthEast() );
                  var sw= map.getProjection().fromLatLngToPoint( bounds.getSouthWest() );

                  var worldCoordWidth = Math.abs(ne.x-sw.x);
                  var worldCoordHeight = Math.abs(ne.y-sw.y);
                  //Fit padding in pixels
                  var FIT_PAD = 40;
                  for( var zoom = MAX_ZOOM; zoom >= MIN_ZOOM; --zoom ){
                      if( worldCoordWidth*(1<<zoom)+2*FIT_PAD < map.getDiv().offsetWidth &&
                          worldCoordHeight*(1<<zoom)+2*FIT_PAD < map.getDiv().offsetHeight )
                      {
                          if( zoom > mapMaxZoom )
                              zoom = mapMaxZoom;
                          return zoom;
                      }
                  }
                  return 0;
                }

                function fromMercatorPixelToLatLng(pixel, zoom)
                {
                    var CST = 6378137 * Math.PI;
                    var res = 2 * CST / 256 / Math.pow(2, zoom);
                    var X = -CST + pixel.x * res;
                    var Y = CST - pixel.y * res;
                    var lon = X / CST * 180;
                    var lat = Math.atan(Math.sinh(Y / CST * Math.PI)) / Math.PI * 180;
                    return new google.maps.LatLng(lat, lon);
                }


                var OPACITY_MAX_PIXELS = 57; // Width of opacity control image

                function createOpacityControl(map, opacity) {
                    var sliderImageUrl = "https://gdal.org/resources/gdal2tiles/opacity-slider.png";

                    // Create main div to hold the control.
                    var opacityDiv = document.createElement('DIV');
                    var opacityDivMargin = 5;
                    opacityDiv.setAttribute("style", "margin:" + opacityDivMargin + "px;overflow-x:hidden;overflow-y:hidden;background:url(" + sliderImageUrl + ") no-repeat;width:71px;height:21px;cursor:pointer;");

                    // Create knob
                    var opacityKnobDiv = document.createElement('DIV');
                    opacityKnobDiv.setAttribute("style", "padding:0;margin:0;overflow-x:hidden;overflow-y:hidden;background:url(" + sliderImageUrl + ") no-repeat -71px 0;width:14px;height:21px;");
                    opacityDiv.appendChild(opacityKnobDiv);

                    var opacityCtrlKnob = new ExtDraggableObject(opacityKnobDiv, {
                        restrictY: true,
                        container: opacityDiv
                    });

                    google.maps.event.addListener(opacityCtrlKnob, "dragend", function () {
                        setOpacity(opacityCtrlKnob.valueX());
                    });

                    google.maps.event.addDomListener(opacityDiv, "click", function (e) {
                        var left = this.getBoundingClientRect().left;
                        var x = e.pageX - left - opacityDivMargin;
                        opacityCtrlKnob.setValueX(x);
                        setOpacity(x);
                    });

                    map.controls[google.maps.ControlPosition.TOP_RIGHT].push(opacityDiv);

                    // Set initial value
                    var initialValue = OPACITY_MAX_PIXELS / (100 / opacity);
                    opacityCtrlKnob.setValueX(initialValue);
                    setOpacity(initialValue);
                }

                function setOpacity(pixelX) {
                    // Range = 0 to OPACITY_MAX_PIXELS
                    var value = (100 / OPACITY_MAX_PIXELS) * pixelX;
                    if (value < 0) value = 0;
                    if (value == 0) {
                        if (overlay.visible == true) {
                            overlay.hide();
                        }
                    }
                    else {
                        overlay.setOpacity(value);
                        if (overlay.visible == false) {
                            overlay.show();
                        }
                    }
                }

                function createCopyrightControl(map, copyright) {
                    const label = document.createElement("label");
                    label.style.backgroundColor = "#ffffff";
                    label.textContent = copyright;

                    const div = document.createElement("div");
                    div.appendChild(label);

                    map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(div);
                }

                
// Beginning of https://github.com/gavinharriss/google-maps-v3-opacity-control/blob/master/ExtDraggableObject.js

/**
 * @name ExtDraggableObject
 * @version 1.0
 * @author Gabriel Schneider
 * @copyright (c) 2009 Gabriel Schneider
 * @fileoverview This sets up a given DOM element to be draggable
 *     around the page.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Sets up a DOM element to be draggable. The options available
 *     within {@link ExtDraggableObjectOptions} are: top, left, container,
 *     draggingCursor, draggableCursor, intervalX, intervalY,
 *     toleranceX, toleranceY, restrictX, and restrictY.
 * @param {HTMLElement} src The element to make draggable
 * @param {ExtDraggableObjectOptions} [opts] options
 * @constructor
 */
function ExtDraggableObject(src, opt_drag) {
  var me = this;
  var event_ = (window["GEvent"]||google.maps.Event||google.maps.event);
  var opt_drag_=opt_drag||{};
  var draggingCursor_ = opt_drag_.draggingCursor||"default";
  var draggableCursor_ = opt_drag_.draggableCursor||"default";
  var moving_ = false, preventDefault_;
  var currentX_, currentY_, formerY_, formerX_, formerMouseX_, formerMouseY_;
  var top_, left_;
  var mouseDownEvent_, mouseUpEvent_, mouseMoveEvent_;
  var originalX_, originalY_;
  var halfIntervalX_ = Math.round(opt_drag_.intervalX/2);
  var halfIntervalY_ = Math.round(opt_drag_.intervalY/2);
  var target_ = src.setCapture?src:document;

  if (typeof opt_drag_.intervalX !== "number") {
    opt_drag_.intervalX = 1;
  }
  if (typeof opt_drag_.intervalY !== "number") {
    opt_drag_.intervalY = 1;
  }
  if (typeof opt_drag_.toleranceX !== "number") {
    opt_drag_.toleranceX = Infinity;
  }
  if (typeof opt_drag_.toleranceY !== "number") {
    opt_drag_.toleranceY = Infinity;
  }

  mouseDownEvent_ = event_.addDomListener(src, "mousedown", mouseDown_);
  mouseUpEvent_ = event_.addDomListener(target_, "mouseup", mouseUp_);

  setCursor_(false);
  if (opt_drag_.container) {

  }
  src.style.position = "absolute";
  opt_drag_.left = opt_drag_.left||src.offsetLeft;
  opt_drag_.top = opt_drag_.top||src.offsetTop;
  opt_drag_.interval = opt_drag_.interval||1;
  moveTo_(opt_drag_.left, opt_drag_.top, false);

  /**
   * Set the cursor for {@link src} based on whether or not
   *     the element is currently being dragged.
   * @param {Boolean} a Is the element being dragged?
   * @private
   */
  function setCursor_(a) {
    if(a) {
      src.style.cursor = draggingCursor_;
    } else {
      src.style.cursor = draggableCursor_;
    }
  }

  /**
   * Moves the element {@link src} to the given
   *     location.
   * @param {Number} x The left position to move to.
   * @param {Number} y The top position to move to.
   * @param {Boolean} prevent Prevent moving?
   * @private
   */
  function moveTo_(x, y, prevent) {
    var roundedIntervalX_, roundedIntervalY_;
    left_ = Math.round(x);
    top_ = Math.round(y);
    if (opt_drag_.intervalX>1) {
      roundedIntervalX_ = Math.round(left_%opt_drag_.intervalX);
      left_ = (roundedIntervalX_<halfIntervalX_)?(left_-roundedIntervalX_):(left_+(opt_drag_.intervalX-roundedIntervalX_));
    }
    if (opt_drag_.intervalY>1) {
      roundedIntervalY_ = Math.round(top_%opt_drag_.intervalY);
      top_ = (roundedIntervalY_<halfIntervalY_)?(top_-roundedIntervalY_):(top_+(opt_drag_.intervalY-roundedIntervalY_));
    }
    if (opt_drag_.container&&opt_drag_.container.offsetWidth) {
      left_ = Math.max(0,Math.min(left_,opt_drag_.container.offsetWidth-src.offsetWidth));
      top_ = Math.max(0,Math.min(top_,opt_drag_.container.offsetHeight-src.offsetHeight));
    }
    if (typeof currentX_ === "number") {
      if (((left_-currentX_)>opt_drag_.toleranceX||(currentX_-(left_+src.offsetWidth))>opt_drag_.toleranceX)||((top_-currentY_)>opt_drag_.toleranceY||(currentY_-(top_+src.offsetHeight))>opt_drag_.toleranceY)) {
        left_ = originalX_;
        top_ = originalY_;
      }
    }
    if(!opt_drag_.restrictX&&!prevent) {
      src.style.left = left_ + "px";
    }
    if(!opt_drag_.restrictY&&!prevent) {
      src.style.top = top_ + "px";
    }
  }

  /**
   * Handles the mousemove event.
   * @param {event} ev The event data sent by the browser.
   * @private
   */
  function mouseMove_(ev) {
    var e=ev||event;
    currentX_ = formerX_+((e.pageX||(e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft))-formerMouseX_);
    currentY_ = formerY_+((e.pageY||(e.clientY+document.body.scrollTop+document.documentElement.scrollTop))-formerMouseY_);
    formerX_ = currentX_;
    formerY_ = currentY_;
    formerMouseX_ = e.pageX||(e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft);
    formerMouseY_ = e.pageY||(e.clientY+document.body.scrollTop+document.documentElement.scrollTop);
    if (moving_) {
      moveTo_(currentX_,currentY_, preventDefault_);
      event_.trigger(me, "drag", {mouseX: formerMouseX_, mouseY: formerMouseY_, startLeft: originalX_, startTop: originalY_, event:e});
    }
  }

  /**
   * Handles the mousedown event.
   * @param {event} ev The event data sent by the browser.
   * @private
   */
  function mouseDown_(ev) {
    var e=ev||event;
    setCursor_(true);
    event_.trigger(me, "mousedown", e);
    if (src.style.position !== "absolute") {
      src.style.position = "absolute";
      return;
    }
    formerMouseX_ = e.pageX||(e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft);
    formerMouseY_ = e.pageY||(e.clientY+document.body.scrollTop+document.documentElement.scrollTop);
    originalX_ = src.offsetLeft;
    originalY_ = src.offsetTop;
    formerX_ = originalX_;
    formerY_ = originalY_;
    mouseMoveEvent_ = event_.addDomListener(target_, "mousemove", mouseMove_);
    if (src.setCapture) {
      src.setCapture();
    }
    if (e.preventDefault) {
      e.preventDefault();
      e.stopPropagation();
    } else {
      e.cancelBubble=true;
      e.returnValue=false;
    }
    moving_ = true;
    event_.trigger(me, "dragstart", {mouseX: formerMouseX_, mouseY: formerMouseY_, startLeft: originalX_, startTop: originalY_, event:e});
  }

  /**
   * Handles the mouseup event.
   * @param {event} ev The event data sent by the browser.
   * @private
   */
  function mouseUp_(ev) {
    var e=ev||event;
    if (moving_) {
      setCursor_(false);
      event_.removeListener(mouseMoveEvent_);
      if (src.releaseCapture) {
        src.releaseCapture();
      }
      moving_ = false;
      event_.trigger(me, "dragend", {mouseX: formerMouseX_, mouseY: formerMouseY_, startLeft: originalX_, startTop: originalY_, event:e});
    }
    currentX_ = currentY_ = null;
    event_.trigger(me, "mouseup", e);
  }

  /**
   * Move the element {@link src} to the given location.
   * @param {Point} point An object with an x and y property
   *     that represents the location to move to.
   */
  me.moveTo = function(point) {
    moveTo_(point.x, point.y, false);
  };

  /**
   * Move the element {@link src} by the given amount.
   * @param {Size} size An object with an x and y property
   *     that represents distance to move the element.
   */
  me.moveBy = function(size) {
    moveTo_(src.offsetLeft + size.width, src.offsetHeight + size.height, false);
  }

  /**
   * Sets the cursor for the dragging state.
   * @param {String} cursor The name of the cursor to use.
   */
  me.setDraggingCursor = function(cursor) {
    draggingCursor_ = cursor;
    setCursor_(moving_);
  };

  /**
   * Sets the cursor for the draggable state.
   * @param {String} cursor The name of the cursor to use.
   */
  me.setDraggableCursor = function(cursor) {
    draggableCursor_ = cursor;
    setCursor_(moving_);
  };

  /**
   * Returns the current left location.
   * @return {Number}
   */
  me.left = function() {
    return left_;
  };

  /**
   * Returns the current top location.
   * @return {Number}
   */
  me.top = function() {
    return top_;
  };

  /**
   * Returns the number of intervals the element has moved
   *     along the X axis. Useful for scrollbar type
   *     applications.
   * @return {Number}
   */
  me.valueX = function() {
    var i = opt_drag_.intervalX||1;
    return Math.round(left_ / i);
  };

  /**
   * Returns the number of intervals the element has moved
   *     along the Y axis. Useful for scrollbar type
   *     applications.
   * @return {Number}
   */
  me.valueY = function() {
    var i = opt_drag_.intervalY||1;
    return Math.round(top_ / i);
  };

  /**
   * Sets the left position of the draggable object based on
   *     intervalX.
   * @param {Number} value The location to move to.
   */
  me.setValueX = function(value) {
    moveTo_(value * opt_drag_.intervalX, top_, false);
  };

  /**
   * Sets the top position of the draggable object based on
   *     intervalY.
   * @param {Number} value The location to move to.
   */
  me.setValueY = function(value) {
    moveTo_(left_, value * opt_drag_.intervalY, false);
  };

  /**
   * Prevents the default movement behavior of the object.
   *     The object can still be moved by other methods.
   */
  me.preventDefaultMovement = function(prevent) {
    preventDefault_ = prevent;
  };
}
  /**
   * @name ExtDraggableObjectOptions
   * @class This class represents the optional parameter passed into constructor of
   * <code>ExtDraggableObject</code>.
   * @property {Number} [top] Top pixel
   * @property {Number} [left] Left pixel
   * @property {HTMLElement} [container] HTMLElement as container.
   * @property {String} [draggingCursor] Dragging Cursor
   * @property {String} [draggableCursor] Draggable Cursor
   * @property {Number} [intervalX] Interval in X direction
   * @property {Number} [intervalY] Interval in Y direction
   * @property {Number} [toleranceX] Tolerance X in pixel
   * @property {Number} [toleranceY] Tolerance Y in pixel
   * @property {Boolean} [restrictX] Whether to restrict move in X direction
   * @property {Boolean} [restrictY] Whether to restrict move in Y direction
   */

 // End of https://github.com/gavinharriss/google-maps-v3-opacity-control/blob/master/ExtDraggableObject.js


                /*
                 * Main load function:
                 */

                function load() {

                    var options = {
                      center: mapBounds.getCenter(),
                      zoom: mapMaxZoom,
                      mapTypeId: google.maps.MapTypeId.HYBRID,

                      // Add map type control
                      mapTypeControl: true,
                      mapTypeControlOptions: {
                          style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
                          position: google.maps.ControlPosition.TOP_LEFT
                      },

                      // Add scale
                      scaleControl: true,
                      scaleControlOptions: {
                          position: google.maps.ControlPosition.BOTTOM_RIGHT
                      }
                    };

                    map = new google.maps.Map( document.getElementById("map"), options);
                    google.maps.event.addListenerOnce(map, "projection_changed", function() {
                       map.setZoom(getZoomByBounds( map, mapBounds ));
                    });

                    
// Beginning of https://github.com/gavinharriss/google-maps-v3-opacity-control/blob/master/CustomTileOverlay.js
// with CustomTileOverlay.prototype.getTileUrl() method customized for gdal2tiles needs.

/*******************************************************************************
Copyright (c) 2010-2012. Gavin Harriss
Site: http://www.gavinharriss.com/
Originally developed for: http://www.topomap.co.nz/
Licences: Creative Commons Attribution 3.0 New Zealand License
http://creativecommons.org/licenses/by/3.0/nz/
******************************************************************************/

CustomTileOverlay = function (map, opacity) {
    this.tileSize = new google.maps.Size(256, 256); // Change to tile size being used

    this.map = map;
    this.opacity = opacity;
    this.tiles = [];

    this.visible = false;
    this.initialized = false;

    this.self = this;
}

CustomTileOverlay.prototype = new google.maps.OverlayView();

CustomTileOverlay.prototype.getTile = function (p, z, ownerDocument) {
    // If tile already exists then use it
    for (var n = 0; n < this.tiles.length; n++) {
        if (this.tiles[n].id == 't_' + p.x + '_' + p.y + '_' + z) {
            return this.tiles[n];
        }
    }

    // If tile doesn't exist then create it
    var tile = ownerDocument.createElement('div');
    var tp = this.getTileUrlCoord(p, z);
    tile.id = 't_' + tp.x + '_' + tp.y + '_' + z
    tile.style.width = this.tileSize.width + 'px';
    tile.style.height = this.tileSize.height + 'px';
    tile.style.backgroundImage = 'url(' + this.getTileUrl(tp, z) + ')';
    tile.style.backgroundRepeat = 'no-repeat';

    if (!this.visible) {
        tile.style.display = 'none';
    }

    this.tiles.push(tile)

    this.setObjectOpacity(tile);

    return tile;
}

// Save memory / speed up the display by deleting tiles out of view
// Essential for use on iOS devices such as iPhone and iPod!
CustomTileOverlay.prototype.deleteHiddenTiles = function (zoom) {
    var bounds = this.map.getBounds();
    var tileNE = this.getTileUrlCoordFromLatLng(bounds.getNorthEast(), zoom);
    var tileSW = this.getTileUrlCoordFromLatLng(bounds.getSouthWest(), zoom);

    var minX = tileSW.x - 1;
    var maxX = tileNE.x + 1;
    var minY = tileSW.y - 1;
    var maxY = tileNE.y + 1;

    var tilesToKeep = [];
    var tilesLength = this.tiles.length;
    for (var i = 0; i < tilesLength; i++) {
        var idParts = this.tiles[i].id.split("_");
        var tileX = Number(idParts[1]);
        var tileY = Number(idParts[2]);
        var tileZ = Number(idParts[3]);
        if ((
                (minX < maxX && (tileX >= minX && tileX <= maxX))
                || (minX > maxX && ((tileX >= minX && tileX <= (Math.pow(2, zoom) - 1)) || (tileX >= 0 && tileX <= maxX))) // Lapped the earth!
            )
            && (tileY >= minY && tileY <= maxY)
            && tileZ == zoom) {
            tilesToKeep.push(this.tiles[i]);
        }
        else {
            delete this.tiles[i];
        }
    }

    this.tiles = tilesToKeep;
};

CustomTileOverlay.prototype.pointToTile = function (point, z) {
    var projection = this.map.getProjection();
    var worldCoordinate = projection.fromLatLngToPoint(point);
    var pixelCoordinate = new google.maps.Point(worldCoordinate.x * Math.pow(2, z), worldCoordinate.y * Math.pow(2, z));
    var tileCoordinate = new google.maps.Point(Math.floor(pixelCoordinate.x / this.tileSize.width), Math.floor(pixelCoordinate.y / this.tileSize.height));
    return tileCoordinate;
}

CustomTileOverlay.prototype.getTileUrlCoordFromLatLng = function (latlng, zoom) {
    return this.getTileUrlCoord(this.pointToTile(latlng, zoom), zoom)
}

CustomTileOverlay.prototype.getTileUrlCoord = function (coord, zoom) {
    var tileRange = 1 << zoom;
    var y = tileRange - coord.y - 1;
    var x = coord.x;
    if (x < 0 || x >= tileRange) {
        x = (x % tileRange + tileRange) % tileRange;
    }
    return new google.maps.Point(x, y);
}

// Modified for gdal2tiles needs
CustomTileOverlay.prototype.getTileUrl = function (tile, zoom) {

      if ((zoom < mapMinZoom) || (zoom > mapMaxZoom)) {
          return "https://gdal.org/resources/gdal2tiles/none.png";
      }
      var ymax = 1 << zoom;
      var y = ymax - tile.y -1;
      var tileBounds = new google.maps.LatLngBounds(
          fromMercatorPixelToLatLng( new google.maps.Point( (tile.x)*256, (y+1)*256 ) , zoom ),
          fromMercatorPixelToLatLng( new google.maps.Point( (tile.x+1)*256, (y)*256 ) , zoom )
      );
      if (mapBounds.intersects(tileBounds)) {
          return zoom+"/"+tile.x+"/"+tile.y+".png";
      } else {
          return "https://gdal.org/resources/gdal2tiles/none.png";
      }

}

CustomTileOverlay.prototype.initialize = function () {
    if (this.initialized) {
        return;
    }
    var self = this.self;
    this.map.overlayMapTypes.insertAt(0, self);
    this.initialized = true;
}

CustomTileOverlay.prototype.hide = function () {
    this.visible = false;

    var tileCount = this.tiles.length;
    for (var n = 0; n < tileCount; n++) {
        this.tiles[n].style.display = 'none';
    }
}

CustomTileOverlay.prototype.show = function () {
    this.initialize();
    this.visible = true;
    var tileCount = this.tiles.length;
    for (var n = 0; n < tileCount; n++) {
        this.tiles[n].style.display = '';
    }
}

CustomTileOverlay.prototype.releaseTile = function (tile) {
    tile = null;
}

CustomTileOverlay.prototype.setOpacity = function (op) {
    this.opacity = op;

    var tileCount = this.tiles.length;
    for (var n = 0; n < tileCount; n++) {
        this.setObjectOpacity(this.tiles[n]);
    }
}

CustomTileOverlay.prototype.setObjectOpacity = function (obj) {
    if (this.opacity > 0) {
        if (typeof (obj.style.filter) == 'string') { obj.style.filter = 'alpha(opacity:' + this.opacity + ')'; }
        if (typeof (obj.style.KHTMLOpacity) == 'string') { obj.style.KHTMLOpacity = this.opacity / 100; }
        if (typeof (obj.style.MozOpacity) == 'string') { obj.style.MozOpacity = this.opacity / 100; }
        if (typeof (obj.style.opacity) == 'string') { obj.style.opacity = this.opacity / 100; }
    }
}

// End of https://github.com/gavinharriss/google-maps-v3-opacity-control/blob/master/CustomTileOverlay.js


                    overlay = new CustomTileOverlay(map, initialOpacity);
                    overlay.show();

                    google.maps.event.addListener(map, 'tilesloaded', function () {
                        overlay.deleteHiddenTiles(map.getZoom());
                    });

                    // Add opacity control and set initial value
                    createOpacityControl(map, initialOpacity);

                    var copyright = "";
                    if( copyright != "" ) {
                        createCopyrightControl(map, copyright);
                    }

                    resize();
                }

                onresize=function(){ resize(); };

                //]]>
                </script>
              </head>
              <body onload="load()">
                  <div id="header"><h1>colored_ca_range_size_rarity.tif</h1></div>
                  <div id="subheader">Generated by <a href="https://gdal.org/programs/gdal2tiles.html">GDAL2Tiles</a>, Copyright &copy; 2008 <a href="http://www.klokan.cz/">Klokan Petr Pridal</a>,  <a href="https://gdal.org">GDAL</a> &amp; <a href="http://www.osgeo.org/">OSGeo</a> <a href="http://code.google.com/soc/">GSoC</a>
            <!-- PLEASE, LET THIS NOTE ABOUT AUTHOR AND PROJECT SOMEWHERE ON YOUR WEBSITE, OR AT LEAST IN THE COMMENT IN HTML. THANK YOU -->
                  </div>
                   <div id="map"></div>
              </body>
            </html>