Update marker via model change
I'm trying to change marker's title which is already rendered. My model looks like this:
markers: [
id: counter,
coordinates: {
latitude: 57.156727,
longitude: 65.613536
},
options: {
draggable: true,
title: 'New point'
},
events: {
dragend: function(e) {
$scope.current_coords = {
latitude: e.position.k,
longitude: e.position.A
}
}
}
],
Markers are rendered on the map as they should. But if i try to change this object for example this way:
var marker = _.find($scope.map.markers, function(marker){
return marker.id == current_id;
});
var index = _.indexOf($scope.map.markers, marker);
$scope.map.markers[index].options.title = $scope.current_place;
$scope.map.markers[index].options.draggable = false;
markers on the map are not changed. How should I do this?
Can you provide a simple example in plunker?
See this: http://plnkr.co/edit/gwis5DXQzalgB5saeaiu?p=preview
Not sure how to save my plunk, please, try this link http://plnkr.co/edit/fz6Kpi?p=preview
Some typos in your plunker, but I get it working: http://plnkr.co/edit/VVsgH2?p=preview
Now I see what you mean. Yep, it's definitely an issue for me. Anything updated within marker.options won't work. I tried to add a marker-label to see if the title changed there, but no luck. I also noticed that adding a marker-label to a marker makes it undraggable .
Hopefully someone will see this issue and fix it or suggest a workaround.
yeah this looks to be a bug. Did anyone try markers instead?
The options property doesn't work on markers (title, draggable, etc).
labelContent="'options.title'" doesn't work either, but it updates correctly if used with a prop outside the options object: labelContent="'labelTitle'"
Updated plunker: http://plnkr.co/edit/VVsgH2?p=preview
Ok I will look into this when I get the chance.
Let's try to break this into two issues, one for markers and another for marker-label .
So for markers the following code causes the title to trip/change (currently):
https://github.com/nlaplante/angular-google-maps/blob/master/src/coffee/directives/api/models/child/marker-child-model.coffee#L108-L109
and
https://github.com/nlaplante/angular-google-maps/blob/master/src/coffee/directives/api/models/child/marker-child-model.coffee#L122-L129
Since you guys are trying to set the title of the labelContent via options nothing will be changed. This is for a couple of reasons. First your directive instance does not define the options attribute as even being watched. So changing options will do nothing. Second, when options does change it is only looking for the following properties:
opts:
labelAnchor
labelClass
labelContent
Again those were not changing.
Lastly, The function is only updating the label content based off the scope here:
opts.labelAnchor = @getLabelPositionPoint(scope.labelAnchor)
opts.labelClass = scope.labelClass
opts.labelContent = scope.labelContent //actual label content is labelTitle! not opt.title
So if you update your controllers marker property of labelTitle it does change. Now if you want thing to change via options changing then we would need to make that improvement. Along with your code actually watching the options to begin with.
Does this make sense?
I think there is a memory leak here as well with the original MarkerWithLabel not being erased as well.
Also in Markers it appears that none of the extended features like dragging, visible, and optomized and many more are not being used.
Instead of instantiating MarkerWithLabel in MarkerChildModel (used by Markers) it should be creating MarkerLabelChildModel instead. Then all the options would be handled in the same manner.
https://github.com/nlaplante/angular-google-maps/blob/master/src/coffee/directives/api/models/child/label-child-model.coffee#L10-L67
NVM ignore this as MarkerWithLabel takes care of all that MarkerChildModel does. In reality MarkerChildModel should possibly disappear.
So the best fix here is to allow options to be used directly for Label stuff to use options.labelContent.... etc and use scope.labelContent directly. I actually would be more inclined to get rid of the custom attributes all together as they my the whole issue more complex. That way options would be the only thing.
Here is the existing plunkr updated and working with labelContent updates via Markers.
http://plnkr.co/edit/6hnO3p
Thanks @nmccready ! Let me see if I understood you well:
- In my example the
optionsproperty within themarkers2model wasn't working because I forgot to addoptions="'options'"to themarkersdirective. - Currently, for
markersdirective,labelContentcannot be bound tooptions.whatever(i.e:options.title,options.labelContent), instead it must be bound to a single property within the model (i.e:labelTitleortitle). - It would be a great addition to allow
optionsto be used directly for label stuff.
As for the marker directive, if you dynamically change options.title it won't update the "mouseover" title of the marker(s) in the map. Also, if you try to add a marker-label directive the marker(s) will become undraggable and the same issues with label content will appear.
Thanks, @nmccready ! This is the thing I was looking for but wasn't able to find in official docs.
@rdelafuente yes I think all you stated is correct . As for the last part;
As for the marker directive, if you dynamically change options.title it won't update the "mouseover" title of the marker(s) in the map. Also, if you try to add a marker-label directive the marker(s) will become undraggable and the same issues with label content will appear.
I would need to look this ver again.
@phaeton2040 ahh, would like to fix the docs.
@rdelafuente would you be so kind to fix the issue and PR it?
This really should boil down to 3 new tickets.
- Documentation fixes/ updates for marker, and maybe markers
- Fix marker/ marker-label and make it consistent with markers
- Markers should have options that take title/label into account.
Who wants to do what?
@nmccready I'll take a look into
- Fix marker/ marker-label and make it consistent with markers
But first I need to get familiar with CoffeScript and angular-google-maps source code. I'll open an issue for it as soon as I have some news.
:+1:
Guys, I'm looking into this, because I need to be able to update markers on a map and change opacity to some of them.
How can I do this with angular-google-maps since updating options.opacity doesnt actually do anything?
@nmccready @rdelafuente
@antitoxic I don't see why this should not work. Make a new issue with a plnkr.