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

Enhancement: Add a callback when creating markers #38

Open
GoogleCodeExporter opened this issue May 25, 2015 · 5 comments
Open

Enhancement: Add a callback when creating markers #38

GoogleCodeExporter opened this issue May 25, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

Can you add a callback that allows for customized processing of the placemark 
for a marker?  I don't want to replicate everything you do, just add/change a 
few items.

perhaps, just before the infoWindow opening event handler, add a callback:

  if (!!parserOptions.pmParseMk) parserOptions.pmParseMk(marker, placemark);
   // Infowindow-opening event handler
    google.maps.event.addListener(marker, 'click', function() {
    this.infoWindow.close();
        marker.infoWindow.setOptions(infoWindowOptions);
    this.infoWindow.open(this.map, this);
    });



Original issue reported on code.google.com by johnbyr...@gmail.com on 28 Sep 2011 at 2:28

@GoogleCodeExporter
Copy link
Author

Could you provide an example use case?  
What kind of "items" would you want to add/change?   

Can you provide a map and data that would use it? (modify your local version of 
geoxml3 with your proposed change and show it in action)

I would think if this was implemented, there should be similar callbacks for 
polylines and polygons.

Original comment by geocodezip on 28 Sep 2011 at 11:53

  • Added labels: Priority-Low, Type-Enhancement
  • Removed labels: Priority-Medium, Type-Defect

@GoogleCodeExporter
Copy link
Author

Original comment by geocodezip on 28 Sep 2011 at 11:53

@GoogleCodeExporter
Copy link
Author

Thanks for the response:

Use case:

I want to create my own listeners for the marker, in order to better manage
the infowindow mobile devices (particularly webkit browsers which by and
large don't manage embedded objects like youtube videos very well). I also
want to add my own attribute to the marker (to set a timeout option in this
particular case).

Yes, it is likely that polys need the same callback feature, although I
would make them separate callbacks.

the geoxml modification (*bold*) to createMarker() function:

 *if (!!parserOptions.pmParseMk) parserOptions.pmParseMk(marker, placemark);
**
* // Infowindow-opening event handler
   google.maps.event.addListener(marker, 'click', function() {
        this.infoWindow.close();
        marker.infoWindow.setOptions(infoWindowOptions);
        this.infoWindow.open(this.map, this);
    });

then in my js file, as part of the specification of the options passed to
geoXML3.parser(options):

        pmParseMk: (function addMarkerAttr (marker, placemark) {
            marker.waitTime = placemark.waitTime;
            google.maps.event.addListener(marker, 'click', function() {
                removeVideoFloatElement();
                this.infoWindow.timeLeft = marker.waitTime;
            });
            google.maps.event.addListener(marker.infoWindow, 'closeclick',
function() {
                removeVideoFloatElement();
            });
        })

I'm a little concerned about the two listeners for the same events (mine and
geoxml's), but it seems to work OK, at least for the current versions of the
API's.

JB

Original comment by johnbyr...@gmail.com on 29 Sep 2011 at 1:17

@GoogleCodeExporter
Copy link
Author

My approach is to pass a custom createMarker function as the createMarker 
option to the geoXML3.parser call: 

    function (placemark, document) {
        document.markers = document.markers || [];
        var found = false;
        if (document.reload) {
            for (var j = 0; j < document.markers.length; j++) {
                if (document.markers[j].getPosition().equals(placemark.latlng)) {
                    found = document.markers[j].active = true;
                    break;
                }
            }
        }
        if (!found) {
            var marker = kmlParser.createMarker(placemark, document);
            marker.active = true;
            google.maps.event.addListener(marker, "click", function () { ... do something ... });
        }
    }

My own createMarker function calls the built-in createMarker function, and then 
adds the listener. It works fine, as far as I can see.

The down side is that I had to duplicate some of the code in the render 
function to make it work. For example, if I leave out the

    document.markers = document.markers || [];

line, the built-in createMarker function no longer works. Ideally, I think, my 
function would have read like this:

    var marker = kmlParser.createMarker(placemark, document);
    google.maps.event.addListener(marker, "click", function () { ... do something ... });

Original comment by verm...@nurc.nato.int on 21 Dec 2011 at 1:33

@GoogleCodeExporter
Copy link
Author

And a question about this part:

    if (doc.markers[j].getPosition().equals(placemark.latlng)) {
        found = doc.markers[j].active = true;

Are two markers identical if they have the same latlng position? What if I have 
two markers at the same position? What if an update to a previously loaded kml 
document has a marker with an unchanged position, but a change in the name, or 
description? If I understand the code correctly, these changes would be ignored?

Original comment by verm...@nurc.nato.int on 21 Dec 2011 at 1:38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant