GeoXML3 - Open an info window automatically

安稳与你 提交于 2020-02-02 13:34:07

问题


I have created a polygon and would like the info window to open automatically on load. How do I do this?

This is what I have so far:

var geoxml = null;

function initialize() {

  infoWindow = new google.maps.InfoWindow();
  var myLatlng = new google.maps.LatLng(100.9530044, 110.8574693);
  var myOptions = {
    maxZoom: 13, 
    center: myLatlng,
    streetViewControl: false,
    zoomControlOptions: {
      style: google.maps.ZoomControlStyle.SMALL
      },    
      mapTypeId: google.maps.MapTypeId.ROADMAP,
    };

    map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
    geoXml = new geoXML3.parser({
      map: map,
      singleInfoWindow: true,
      infoWindowOptions: {maxWidth:350,cornerRadius: 12},
    });

    geoXml.parse('file.xml');

};

回答1:


You can trigger a click on the placemark (polygon), when the KML is done rendering (the map idle event fires). This will open the infowindow on the first placemark:

google.maps.event.addListenerOnce(map, 'idle', function() {
  google.maps.event.trigger(geoXml.docs[0].placemarks[0].polygon,'click')
});

working example



来源:https://stackoverflow.com/questions/17691794/geoxml3-open-an-info-window-automatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!