【问题标题】:How to populate info window with html for google maps when using vue2-google-maps?使用 vue2-google-maps 时如何使用 html 填充谷歌地图的信息窗口?
【发布时间】:2018-06-14 05:32:14
【问题描述】:

我想在使用 vue2-google-maps 时为 Google 地图制作一个自定义信息窗口。但到目前为止,据我所知,我们只能将文本添加到信息窗口。有什么方法可以使用我的自定义 HTML 来自定义它,如下所示。

我希望使用 vue2-google-maps 来完成。

谢谢。

【问题讨论】:

标签: google-maps vuejs2 vue2-google-maps


【解决方案1】:

我们可以通过在 infoOptions 属性中发送“content”参数来实现。

             <gmap-map
                :center="center"
                :zoom="13"
                :options="mapStyle"
                ref="map"
                style="width: 100%; height: 100%"
                >
                <gmap-info-window
                :options="infoOptions"
                :position="infoPosition"
                :opened="infoOpened"
                :content="infoContent"
                @closeclick="infoOpened=false">

                </gmap-info-window>
                <gmap-marker v-if="mapLoaded"
                :key="index"
                v-for="(m, index) in markers"
                :position="m.position"
                :clickable="true"
                @click="toggleInfo(m, index)"
                ></gmap-marker>
            </gmap-map>

在数据中

    data() {
    return {
      map: null,
      mapLoaded: false,
      center: { lat: 22.449769, lng: .3902178 },

      markers: [
        {
          position: {
            lat: 22.449769,
            lng: .3902178
          }
        }
      ],
      infoPosition: null,
      infoContent: null,
      infoOpened: false,
      infoCurrentKey: null,
      infoOptions: {
        pixelOffset: {
          width: 0,
          height: -35
        },
        content:
          '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
      '<div id="bodyContent">'+
      '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
      'sandstone rock formation in the southern part of the '+
      'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
      'south west of the nearest large town, Alice Springs; 450&#160;km '+
      '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
      'features of the Uluru - Kata Tjuta National Park. Uluru is '+
      'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
      'Aboriginal people of the area. It has many springs, waterholes, '+
      'rock caves and ancient paintings. Uluru is listed as a World '+
      'Heritage Site.</p>'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>'+
      '</div>'
      }
    };
}

【讨论】:

  • 为什么这对我不起作用?如何调用 toggleInfo 方法?
  • 您可以将“toggleInfo”放入方法部分。 @fdR 我认为这个 tut 可以帮助你:teunohooijer.com/tag/vue2-google-maps
  • 谢谢!文档有点少——这是一个很大的帮助
猜你喜欢
  • 2020-02-29
  • 2018-04-02
  • 1970-01-01
  • 1970-01-01
  • 2019-07-22
  • 2016-07-10
  • 2013-05-18
  • 1970-01-01
相关资源
最近更新 更多