mpriour / azimuthjs

A geo webapp building companion to AngularJS
52 stars 19 forks source link

Adding Event Listeners for vector layers #5

Open apaleja opened 10 years ago

apaleja commented 10 years ago

Hi Matt,

I am glad to find AzimuthJS for openlayers integration. I am new to AngularJS, So I am facing some difficulty in implementation. I would like to add listeners to vector layer but I am not able to find any example for same.

how can I achieve it?

Thanks Anand

mpriour commented 10 years ago

You're right the one example that would give you an idea of how to do this is overly dense with no explanation. I should address this (#6)

However, to answer your question you should simply be able to add a event-listeners attribute to the layer directive. Though I haven't tried it yet. I'm certain that a globally available function would work, I'm not sure about a function within a controller, like is possible with the map directive.

myLyrFunction(evt){
   var lyr = evt.object;
   lyr.style = ({ default: { color: '#0088ff' } });
   lyr.redraw();
}
<az-layer lyr-type="geojson"
  lyr-url="examples/data/airports.json" projection="EPSG:4326"
  event-listeners="{loadend: myLyrFunction}">
</az-layer>
mpriour commented 10 years ago

Nope!

There are 2 problems.

  1. The options are assumed to be protocol options for geojson layers in ol-map directives. an event-listeners attribute is applied to the wrong place. However, this should work for tile and wms layers.
  2. The function has to be in the scope available to the layer when the directive attributes are parsed. I'm not sure yet, exactly where that would be. I would think a scoped controller would do the trick, but I honestly don't know without doing some more testing.