I am working off the OpenLayers Icon Symbolizer example (https://openlayers.org/en/latest/examples/icon.html) to create an equivalent to a Google Maps marker

new google.maps.Marker({...})

With Google Maps, I was able to add a listener and assign the ngClick event I had defined for the html element that created the marker. This way, when I clicked on the marker, it would trigger the ngClick function:

google.maps.event.addListener(scope.marker, 'click', function() {
     scope.$apply(function() {

However, now that I am using the Open Layers icon, which is being added via adding a layer, I am not sure how I can link the ngClick function. This could be applied to any function that I am trying to pass on the icon click event like I had with marker. Everything I saw online, so far, has suggested that this needs to happen via map but I have not had success with it so far:

map.on('click', function(evt){
     var feature = map.forEachFeatureAtPixel(evt.pixel,
         function(feature) {

While this does not throw any errors, it does not trigger my ngClick function. The example shows how to add my own popup to the icon but I want to specifically tie a predefined function to the Marker/Icon click which may be different for different markers.

Can anyone recommend what I am missing?

  • If you have marker/icon defined as a feature as it is in example openlayers.org/en/latest/examples/icon.html, this should work. – TomazicM May 18 at 10:51
  • @TomazicM I'm unclear how this would work. Google Maps allowed me to add a listener and bind the ngClick action of the HTML marker element to the Marker. The link you posted shows a click event on the map but how do I tie it to the ngClick of the marker/icon? – Yusif Nurizade May 20 at 3:32
  • Method map.forEachFeatureAtPixel finds feature (marker in this case) at the click coordinates and returns marker object. In the mentioned example popup is then displayed above marker. – TomazicM May 20 at 15:50
  • @TomazicM I get how the example works, however, I am trying to trigger a function defined in the marker's ng-click field. Say I don't want to display a popup but, instead, trigger a function I passed in. Google Maps allows me to do this via addListener. I believe OpenLayers used to allow this when it has click event for markers. Now that click event are on the map, how can I trigger the ng-Click function when the marker is clicked? – Yusif Nurizade May 20 at 18:31
  • At what level is this ng-Click function defined? – TomazicM May 20 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.