1

I'm working on a project which involves the usage of maps where it is make operations, like plotting marker or polylines.

The functionalities are working fine but I 'm facing difficulty on using multiple map service provider.

I want to perform same set operation using a open layer. For do that, I have to change in all the places, like controllers and views. Plus, I have a service which feed the data to the controller in required format.

But I'm not sure how to create an abstraction layer for different map service provider on the client side.

I have all the map related logic in the controller

Basically I'm looking for some guidelines and suggestion which will help to switch between multiplier service provider with minimum number of changes.

Follows my controller code:

taxiFleetControlPanel.controller("overviewController", function ($scope,$location,sensorService,appService,nodeService,settingService,$timeout,$rootScope,instanceService,assetApiService) {

//google maps
function initMap() {.....}
function addMarker(){.....}
function addpolyLines(){....}

//openlayer maps
function openlayerInitMap() {.....}
function openlayerAddMarker(){.....}
function openlayerAddpolyLines(){....}


if there is requriment to use openalyer map the i will comment initMap(); in the same controller 

funtion init(){
initMap();
 //openlayerInitMap() 
}

init();
})

Is there a better way to do it?

there are so many other dependent functions as well I have not put to maintain simplicity.

I tried the follow idea:

Wrote two different controllers and changed the controller in the route but if the any change made in one controller i will literally copy paste the same set of methods to other i am not able to maintain a clean code

Note: The application can support multiple service provider like Google maps, openalyers and leaflet.

Ricardo Rocha
  • 14,612
  • 20
  • 74
  • 130
dhana lakshmi
  • 847
  • 1
  • 12
  • 29

1 Answers1

0

If I understand correctly, you want to extract out some logic so that it can be used everywhere in your application?

If so, there are two ways I know of that you could achieve this. First off, you could create a service that encapsulates the logic. That way you can inject it into each controller that you need to use it with and just call the methods that way.

Alternatively, you can declare the functions at $root level, that way it is accessible in any scope anywhere in the application.

Here's how you'd achieve this:

https://stackoverflow.com/a/15026440/5349719

Community
  • 1
  • 1
cullimorer
  • 755
  • 1
  • 5
  • 23
  • thank you i want to make my controller to act as a orchestrator based on the parameters ie, if say openlayers certain specific functionality should be picked by the controller or if it is google map another set of specific functionalities should be picked up by the controller and do corresponding thing that is what looking for – dhana lakshmi Aug 19 '16 at 13:56