Handling a Leaflet/Mapbox Map in multiple components of an Angular 2 App

Ask A Question

Login To post a question

I’m just beginning my dive into Angular 2 and want to create a single page application that utilizes Mapbox. I understand the general structure of the Angular application, but I’m trying to figure out a good approach to passing around the map object that is ultimately going to be created once.

It seems like I’d want a singleton service object that initializes the map and then any component could access the map through the service and add event handlers to it… But I’m questioning if this will just create piles of spaghetti code down the line.

I’m looking for input from someone who is more familiar with Angular applications. Pointing to a guide/page would be awesome that follows the situation that I’m running into. I’ve been doing a lot of searching and tutorials, but I haven’t come across an example that uses multiple components that utilize the map.

For example: I know my app will have a component that will render markers and information in a panel, but that component will have child elements that will also render layers on the map.

For more info please click herehttps://stackoverflow.com/q/51752673

Have a question or need a custom quote?