APIs
Log In
APIs

MarkerLayer.setOnclickEvent

MarkerLayer.setOnclickEvent(function:Function)

Sets an onclick event on each marker of a given MarkerLayer.
At a click on a marker, the given function will be called (can be used to display infowindows for example).

function onYoumapsApiLoaded(){
  console.log("YoumapsAPI loaded!");
  var mapdataLayer = youmapsApi.getMapdata(<MAPDATA_ID>);
	mapdataLayer.setOnclickEvent(createAndOpenInfowindow);
}

function createAndOpenInfowindow(marker) {
	var content = '<div id="iw-container" style="overflow: auto; width: 400px;">'
		+ '<div class="iw-title"><h3>' + marker.displayedName + '</h3></div>'
		+ '<div class="iw-content">';

	var attributes = marker.getFields();
  
	for (attr in attributes) {
		content += '<div><b>' + attr.toUpperCase() + ' : </b>' + attributes[attr] + '</div><br>';
	}

	content += '</div></div>';

	var infowindow = new google.maps.InfoWindow({
	   content: content
	});
	
	infowindow.open(marker.map, marker.gmarker);
}

var mapOptions = {  
  center : new google.maps.LatLng(48.858386, 2.343435), // Paris,
  zoom : 11,
  minZoom : 6,
  maxZoom : 17
};

var youmapsApi = new YoumapsAPI(
  {
    techID : <YOUR_TECH_ID>, 
    initMapboards : true,
    mapDivId : "map",
    mapOptions : mapOptions
  },
  onYoumapsApiLoaded
);