Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infobox for multple icons #20

Closed
rodrigorahal opened this issue Apr 26, 2016 · 9 comments
Closed

Infobox for multple icons #20

rodrigorahal opened this issue Apr 26, 2016 · 9 comments
Assignees

Comments

@rodrigorahal
Copy link

rodrigorahal commented Apr 26, 2016

When you have multiple icons, you can't set different infoboxes for each icon.

In the initialize_ function in gmapsj.html, the getInfoCallback({{gmap.varname}}, "{{gmap.infobox[loop.index0]|safe}}")) is inside the markers[icon] loop:

      {% for icon in gmap.markers %}
            {% for marker in gmap.markers[icon] %}
                var marker_{{loop.index0}} = new google.maps.Marker({
                    position: new google.maps.LatLng({{marker.0}}, {{marker.1}}),
                    map: {{gmap.varname}},
                    icon: "{{ icon }}"
                });
                {% if gmap.infobox != None %}
                        {% if gmap.typeflag %}
                            google.maps.event.addListener(marker_{{loop.index0}}, 'click',
                            getInfoCallback({{gmap.varname}}, "{{gmap.infobox[loop.index0]|safe}}"));
                        {% else %}
                            google.maps.event.addListener(marker_{{loop.index0}}, 'click',
                            getInfoCallback({{gmap.varname}}, "{{gmap.infobox|safe}}"));
                        {% endif %}
                {% endif %}
            {% endfor %}
        {% endfor %}

In the case where you have one marker per icon and a infobox list, you always get the first value of the list for every marker.

It's not clear to me what's the best way to add multiple infoboxes for multiple icons without breaking the multiple infoboxes for multiple markers with one icon. Maybe a flag multipleiconflag and a call to getInfoCallback outside the marker loop?

@rochacbruno
Copy link
Member

@rodrigorahal have you tried the idea described here: #16 ?

@rodrigorahal
Copy link
Author

@rochacbruno yes, I have. And it works perfectly for the case mentioned: one icon with multiple markers.

markers ={'http://maps.google.com/mapfiles/ms/icons/green-dot.png': [(40, -105), (47.6097, -122.331), (32.7150, -117.1625), (35, -109)]}

But in my case, I have multiples icons, each one, with one marker:

markers = {
'http://www.google.com/mapfiles/markerA.png': [(-23.5351362915591,
                                                 -46.622890842239)],
 'http://www.google.com/mapfiles/markerB.png': [(-23.5207733697969,
                                                 -46.7042080745129)],
 'http://www.google.com/mapfiles/markerC.png': [(-23.6126009008082,
                                                 -46.656741804507)],
 'http://www.google.com/mapfiles/markerD.png': [(-23.5959902668285,
                                                 -46.5699709525433)],
 'http://www.google.com/mapfiles/markerE.png': [(-23.5395284094939,
                                                 -46.7103705368317)],
 'http://www.google.com/mapfiles/markerF.png': [(-23.5909617398358,
                                                 -46.6930480683089)],
 'http://www.google.com/mapfiles/markerG.png': [(-23.6178733502168,
                                                 -46.7171064276025)],
 'http://www.google.com/mapfiles/markerH.png': [(-23.5709619159424,
                                                 -46.697547147761)],
 'http://www.google.com/mapfiles/markerI.png': [(-23.5057447511124,
                                                 -46.7343485442649)],
 'http://www.google.com/mapfiles/markerJ.png': [(-23.5480934690999,
                                                 -46.6973826214375)]}

and my infobox looks like this:
infobox = [u'Judy Reed', u'Linda Tucker', u'Dorothy Young', u'Amy Robinson', u'Edward Reid', u'Doris Reynolds', u'Jane Hamilton', u'Ashley Schmidt', u'Marilyn Martinez', u'Anne Jacobs']

The result I get is this:
captura de tela 2016-04-26 as 16 37 10

Looking at the source code, my results make sense. gmap.infobox[loop.index0] is inside the loop for marker in gmaps.markers[icon]. Having one marker per icon makes loop.index0 always equal to zero: the first element in the infobox list (Judy Reed).

Maybe the infobox should also be a dict that maps an icon to a list of infoboxes? Making gmap.infobox[icon][loop.index0]?

@AhanM
Copy link

AhanM commented Jun 28, 2016

I'm facing the same problem.This is a rather concerning flaw.
Could you please patch this?

@rochacbruno
Copy link
Member

I want to fix this, but I need help, what is the best idea?

Getting a dict in gmaps.infobox?

@AhanM
Copy link

AhanM commented Jun 28, 2016

The dict idea is the first that comes to mind.
I don't think it's the most efficient one but it should fix the flaw. I'd recommend going ahead with it.

@rochacbruno
Copy link
Member

Fixed now in master, preparing to release 0.2.0, see example.py to get new way of defining infoboxes as dicts

@rochacbruno
Copy link
Member

@rodrigorahal @AhanM done and released 0.2.0

I may use your help to improve and document features.

Thanks

@rodrigorahal
Copy link
Author

thanks @rochacbruno!
Sure, it will be a pleasure to help.

@AhanM
Copy link

AhanM commented Jul 2, 2016

@rochacbruno I'd be more than happy to assist you.

@rochacbruno rochacbruno self-assigned this Jul 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants