zhangnaisong
2024-01-26 638c705c6a23974ff6aea3229bc297aad0683acc
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
class HTMLMapMarker extends google.maps.OverlayView {
    constructor(args) {
      super();
      this._latlng = args.latlng;
      this._html = args.html;
      this._map = args.map;
      this._width = args.width;
      this._height = args.height;
      this.setMap(args.map);
    }
  
    createDiv() {
      this.div = document.createElement('div');
      this.div.style.position = 'absolute';
      if (this._width && this._height) {
        this.div.style.width = this._width;
        this.div.style.height = this._height;
      }
      if (this._html) {
        this.div.innerHTML = this._html;
      }
 
      google.maps.event.addDomListener(this.div, 'click', (event) => {
        event.stopPropagation();
 
        google.maps.event.trigger(this, 'click', event);
      });        
    }
  
    positionDiv() {
      const point = this.getProjection().fromLatLngToDivPixel(this._latlng);
      if (point) {
        const left = point.x - this.div.clientWidth/2;
        this.div.style.left = `${left}px`;
        const top = point.y - this.div.clientHeight/2;
        this.div.style.top = `${top}px`;
      }
    } 
    onAdd() {
      if (!this.div) {
        this.createDiv();
        this.getPanes().overlayMouseTarget.appendChild(this.div);
      }
      this.positionDiv();
    }
 
    draw() {
      this.positionDiv();
    }
  
    onRemove() {
      if (this.div) {
        this.div.parentNode.removeChild(this.div);
        this.div = null;
      }
    }
 
    getPosition() {
      return this._latlng;
    }
 
    detach() {
      if (this.getMap()) {
        this.setMap(null);
      }
    };
 
    attach() {
      if (!this.getMap()) {
        this.setMap(this._map);
      }
    };
 
    setSize(width, height) {
      this._width = width;
      this._height = height;   
      if (this.div) {
          this.div.style.width = this._width;
          this.div.style.height = this._height;   
      }   
    }
  }