Provide a better way to define map controls
The main purpose of defining custom controls is to add custom behavior to the map (e.g a button to center the map on the current location). The current approach does not provide a way to directly access the map properties, the parent controller, or even the google.maps.Map object, so we have to set up a more complicated communication channel (e.g a service or relying on $rootScope messages) which, IMHO is overkill (take a look at this official example). Besides that, the current approach does not really allow easy reusability. Even though each control has its own controller, the fact that it has to use messages or a service to perform its actual purpose makes it hard to tell between multiple map instances. For example, if you want to reuse a center button in multiple maps of the same page, you would have to separate each map in each message/service, or otherwise clicking this center button would center all the maps.
My suggestion is to simplify the current approach, and make it consistent with the way windows are implemented (inheriting the parent scope, and defined inline). This has the following advantages:
- You have access to the parent scope (and therefore to the map options), so there is no need to set up a service/message to communicate with the map. Again, the current approach is not really 'enforcing' separation of concerns but unnecessary separation of implementation, as the actual behavior is still defined in the scope where the map resides (unless you're doing something trivial such as showing an alert).
- If you want to reuse this control in other map, you can always use template/templateParameters to pass data, or just define a directive that takes the necessary map options and modifies them accordingly.
- More consistency. Why a window can be defined inline (i.e the content of the directive is the window) yet you're obligated to define an external template for a map-control?
Thank you
P.D. I am aware of this issue, but it's old and doesn't really give enough reasons to do it.
+1
If someone wants to champion this, then by all means do it. I do not have the time to do this.
I have created an 'extended' map-control directive that only accepts inline templates. View code
<ui-gmap-map-extended-control position="top-right" index="1">
<div ng-controller="mapWidgetCtrl">
<button class="btn btn-lg btn-primary" ng-click="clearWidget.controlClick()">{{clearWidget.controlText}}</button>
</div>
</ui-gmap-map-extended-control>
What do you think? @0xDCA @nmccready
@mehanika looks fine to me, would be that hard to just make the existin map-control use transclusion?
@nmccready I feel more comfortable with the code now, I can give it a try
cool
@nmccready I wasn't so hard https://github.com/mehanika/angular-google-maps/commit/dedee469ad63398fa76cbaac510b0c0fd3f51250. I also removed the 'extended' map-control directive. Is the code ready for a PR?