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

How to insert active link #133

Closed
Salomoun opened this issue May 22, 2017 · 3 comments
Closed

How to insert active link #133

Salomoun opened this issue May 22, 2017 · 3 comments

Comments

@Salomoun
Copy link

Salomoun commented May 22, 2017

Hi. How can I insert active link in every sepate marker - for example into text, or in description - or make clickable whole info window? Thanx

@jawj
Copy link
Owner

jawj commented May 22, 2017

Hi there. Either I didn't understand you question, or this is really a general Google Maps API question and not connected to this library. If you have a question about the OverlappingMarkerSpiderfier, please clarify, otherwise I suggest you check out StackOverflow or some other appropriate venue.

@jawj jawj closed this as completed May 22, 2017
@Salomoun
Copy link
Author

Hi.
I would like to open my link inserted within info window. And in this case is particularly connected with this library. I know, how can I accomplish it with standard Google api. But with your great library, I have to use two click listeners. One for icon behavior and second one for infowindow, and I’m not sure, if my solution is correct. So, my humble question is, could I use something like this? It works, but I’m not sure with using click and spider_click solution. Don’t look at the var content – it is only for testing.
Thanx a lot for your work!

` for (var i = 0, len = window.mapData.length; i < len; i++) {
(function () { // make a closure over the marker and marker data
var markerData = window.mapData[i]; // e.g. { lat: 50.123, lng: 0.123, text: 'XYZ' }
var marker = new google.maps.Marker({ position: markerData, url: markerData.brslink, icon: markerData.brsico }); //

                var content = '<a href="' + marker.url + '" class="maplink">' + marker.url + '<br>' + markerData.text + '</a>'

                var infowindow = new google.maps.InfoWindow();

                google.maps.event.addListener(marker, 'spider_click', (function (marker, content, infowindow) {
                    return function () {
                        infowindow.setContent(content);
                        infowindow.open(map, marker);
                        /* keep the handle, in order to close it on next click event */
                        infos[0] = infowindow;
                    };
                })(marker, content, infowindow));


                google.maps.event.addListener(marker, 'click', iwClose);
                oms.addMarker(marker, function (e) {
                    iw.setContent(markerData.text);
                    iw.open(map, marker);
                });

            })();`

@jawj
Copy link
Owner

jawj commented May 23, 2017

You have one listener too many, and you're unnecessarily creating an InfoWindow on every pass through the loop.

I think all you need to do is adapt the simple demo, changing the line where the content is assigned to the InfoWindow: iw.setContent(markerData.text);.

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

2 participants