Fixed Legend in Google Maps Mashup

前端 未结 2 2082
遥遥无期
遥遥无期 2021-02-06 02:32

I have a page with a Google Maps mashup that has pushpins that are color-coded by day (Monday, Tuesday, etc.) The IFrame containing the map is dynamically sized, so it gets resi

2条回答
  •  野性不改
    2021-02-06 02:40

    You can add your own Custom Control and use it as a legend.

    This code will add a box 150w x 100h (Gray Border/ with White Background) and the words "Hello World" inside of it. You swap out the text for any HTML you would like in the legend. This will stay Anchored to the Top Right (G_ANCHOR_TOP_RIGHT) 10px down and 50px over of the map.

    function MyPane() {}
    MyPane.prototype = new GControl;
    MyPane.prototype.initialize = function(map) {
      var me = this;
      me.panel = document.createElement("div");
      me.panel.style.width = "150px";
      me.panel.style.height = "100px";
      me.panel.style.border = "1px solid gray";
      me.panel.style.background = "white";
      me.panel.innerHTML = "Hello World!";
      map.getContainer().appendChild(me.panel);
      return me.panel;
    };
    
    MyPane.prototype.getDefaultPosition = function() {
      return new GControlPosition(
          G_ANCHOR_TOP_RIGHT, new GSize(10, 50));
          //Should be _ and not _
    };
    
    MyPane.prototype.getPanel = function() {
      return me.panel;
    }
    map.addControl(new MyPane());
    

提交回复
热议问题