0

我正在使用以下代码填充 Google 地图:

    <script type="text/javascript">
  google.maps.event.addDomListener(window, 'load', function() {
    var map = new google.maps.Map(document.getElementById('gmap'), {
      zoom: 8,
      center: new google.maps.LatLng(51.414487, -0.207644),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infoWindow = new google.maps.InfoWindow;

    var onMarkerClick = function() {
      var marker = this;
      var latLng = marker.getPosition();
      infoWindow.setContent('<div class="map-info-window">\
                <h3>WEA [[+pagetitle]]</h3>\
                <p><strong>Branch contact:</strong> [[+branch-latlng]]</p>\
                <p><strong>Telephone no:</strong> [[+branch-phone:htmlent]]</p>\
                <p><strong>Email:</strong> [[+branch-email.htmlent]]</p>\
                [[+branch-more.htmlent]]\
              </div>' );

      infoWindow.open(map, marker);
    };
    google.maps.event.addListener(map, 'click', function() {
      infoWindow.close();
    });

[[getResources? &debug=`0` &showHidden=`1` &parents=`[[*id]]` &depth=`4` &tpl=`newBranchMapMarkerTpl` &includeTVs=`1` &processTVs=`1` &tvPrefix=`` &limit=`0` &where=`{"template:=":9}`]]

[[getResources? &debug=`0` &showHidden=`1` &parents=`[[*id]]` &depth=`4` &tpl=`newMarkerInit` &includeTVs=`1` &processTVs=`1` &tvPrefix=`` &limit=`0` &where=`{"template:=":9}`]]
  });
</script>

并且 2 个 getResources 调用的内容如下:

newBranchMapMarkerTpl:

var marker[[+id]] = new google.maps.Marker({
      map: map,
      position: new google.maps.LatLng([[+branch-latlng]]),
                        title:"[[+pagetitle]]"
    });

新标记初始化:

google.maps.event.addListener(marker[[+id]], 'click', onMarkerClick);

但它不会抓取 setContent 代码中列出的模板变量;这是因为它只在地图页眉中被引用一次,并且通常需要遍历每个文档。我试图在 BranchMapMarkerTpl 中创建一个新的信息窗口,它可以工作,但在打开另一个信息窗口时不会关闭最后一个信息窗口。

如何重新分解它以便获取模板变量值?

提前致谢。

4

1 回答 1

0

模板中模板变量的语法是[[*tvname]]. 尝试:

infoWindow.setContent('<div class="map-info-window">\
    <h3>WEA [[*pagetitle]]</h3>\
    <p><strong>Branch contact:</strong> [[*branch-latlng]]</p>\
    <p><strong>Telephone no:</strong> [[*branch-phone:htmlent]]</p>\
    <p><strong>Email:</strong> [[*branch-email:htmlent]]</p>\
    [[*branch-more:htmlent]]\
</div>' );

[[+tvname]]在您的 getResources 块中使用是正确的,因为模板变量值正在输出到占位符,而不是通过模板变量标签进行解析。

于 2012-09-20T08:42:35.050 回答