> For the complete documentation index, see [llms.txt](https://runette.gitbook.io/alcm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://runette.gitbook.io/alcm/interacting-with-the-control.md).

# Interacting with the Control

There are broadly four types of interaction with the Control from the Angular Component:

1. Using Structural Directives to control the control,
2. interactions between&#x20;

## Feed Data Back

Some controls are associated to data returned to the app. The word choice is deliberate, I give the example of location data that is "associated" with the location control but generated by the map.

My prefered methid to expose the data to the app is to output the data from the control component even thought the data is coming from the map. This improves readability and means that the listeners are created and destroyed correctly as the control is clawed up and clawed down in app DOM.

So:

1. the listeners should be setup when the control is added to the map,
2. the listeners should be removed when the component is destroyed,
3. there should be an Output property for the value and new values should be `.emit()` 'ed on this property.
4. IN the parent component, the directive should listen to the value and call a local method when it receives a new value.

e.g.

```typescript
@Input() set map(map: Map){
    if (map) {
      this._map = map;
      this.control = new Control.Locate(this.options);
      this.control.addTo(map);
      let location$ = this.location$;
      map.on('locationfound', function(e) {
        const newLocation = new Location(latLng(e.latlng.lat, e.latlng.lng, Math.round(e.altitude || 0)),e.accuracy || 0);
        newLocation.speed = e.speed || 0;
        newLocation.timestamp = Date.now();
        location$.emit(newLocation);
      });
    }
  }
  get map(): Map {
    return this._map
  }
```

and

```typescript
<leaflet-locate-control 
    [map]="map"
    [options]="locateOptions"
    (location$)="onNewLocation($event)"
    ></leaflet-locate-control>
```

## Worked Examples

For some worked examples of these issues and some discussion, see:

{% embed url="<https://medium.com/runic-software/advanced-interactive-maps-in-angular-with-leaflet-68baafa03f72>" %}

The Demo code is included in this stackblitz

{% embed url="<https://stackblitz.com/edit/angular-leaflet-custom>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://runette.gitbook.io/alcm/interacting-with-the-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
