angular-ui / ui-map

Google Maps
http://angular-ui.github.io/ui-map
MIT License
288 stars 93 forks source link

ui-map-marker should create a marker FOR you, instead of merely attach to an existing one. #8

Open ProLoser opened 11 years ago

ProLoser commented 11 years ago

Kind of annoying if I want to put a few markers onto the page. I think it would be more sensible to do something like this:

<div ui-map>
  <div ng-repeat="marker in markers" ui-map-marker="marker">Popup Html Goes Here</div>
</div>
$scope.markers = [ { position: 11 }, { position: 12 } ];

The 'map' property would be added automatically to the object, and new markers would be generated for you.

glebm commented 11 years ago

Do you need to watch the array of markers for changes for this? If so, there is code in ui-calendar that watches arrays and calls onAdded/onChanged/onRemoved

ProLoser commented 11 years ago

Right now you have to call new google.maps.marker({ map: mapObject, ...}) etc

I feel this should not be necessary.

glebm commented 11 years ago

Right. So you watch the array of user-supplied marker, and:

onAdded(marker): new google.maps.marker onRemoved(marker): delete marker onChanged(marker): update marker position and other attributes

The code that can efficiently watch for array changes and emit those events is in the changeWatcher in ui-calendar. If I understand correctly, and that code would be perfect for these needs, maybe we should extract it into a service and move it to ui-utils

ajoslin commented 11 years ago

The direction of ui-map is that it doesn't try to take away google's Apis from you: that is too much work. There are a billion ways you could want to create and initialize a marker. The directives just $apply events for you and make them declarative. 

Andy Joslin from my mobile

On Thu, May 16, 2013 at 10:11 AM, Gleb Mazovetskiy notifications@github.com wrote:

Right. So you watch the array of user-supplied marker, and: onAdded(marker): new google.maps.marker onRemoved(marker): delete marker onChanged(marker): update marker position and other attributes

The code that can efficiently watch for array changes and emit those events is in the changeWatcher in ui-calendar. If I understand correctly, and that code would be perfect for these needs, maybe we should extract it into a service and move it to ui-utils

Reply to this email directly or view it on GitHub: https://github.com/angular-ui/ui-map/issues/8#issuecomment-18003369

glebm commented 11 years ago

This doesn't take away the ability use native marker api if you want to. Why not offer both options? Simple common use case, and advanced use still possible.

ProLoser commented 11 years ago

@ajoslin Yeah after my friend got it working I was less concerned with hand-holding the tag creation for you as I realize there are a lot of open questions it raises. I still think it would be nice to try dabbling with however in a simplistic manner (you pass the entire object to the child tag as an attribute, and the linking takes care of the timing, instead of $scope.$watch('map'))

For now though I think it's more important to clean up the docs and provide an example of loading the map with markers pre-populated.

ajoslin commented 11 years ago

Yeah, if there is a better way, definitely do it!!

glebm commented 11 years ago

By the way, looks like this implementation does automatic marker binding https://github.com/dylanfprice/angular-gm/blob/master/src/directives/gmMarkers.js