mapstraction / mxn

A Javascript Mapping Abstraction library.
http://mapstraction.com/
Other
580 stars 132 forks source link

Actions need callbacks #315

Open riklaunim opened 10 years ago

riklaunim commented 10 years ago

Without callbacks for actions it's hard to take full use of map features. Like I wanted to highlight a result on list when infobubble is opened and de-highlight it when closed.

I've hacked the googlv3.core.js and added custom attribute for markers:

@@ -636,6 +658,8 @@ Marker: {
                this.openInfoBubble.fire( { 'marker': this } );
                infowindow.open(this.map, this.proprietary_marker);
                this.proprietary_infowindow = infowindow; // Save so we can close it later
+        var callback = marker.getAttribute('bubbleOpenedCallback');
+        callback(marker);
        },

        closeBubble: function() {
@@ -643,6 +667,8 @@ Marker: {
                        this.proprietary_infowindow.close();
                        this.proprietary_infowindow = null;
                        this.closeInfoBubble.fire( { 'marker': this } );
+            var callback = this.getAttribute('bubbleClosedCallback');
+            callback();
                }
        },

@@ -711,3 +737,4 @@ Polyline: {

It's not a generic solution, but such callbacks would be very handy in general.

Closing other infobubbles on Google v3 when another one is getting opened could also be a callback or built it (openstreetmap closes other bubbles) - mxn.googlev3.core.js release-3.0 branch:

@@ -621,6 +637,12 @@ Marker: {
        },

        openBubble: function() {
+        clearExistingInfoBubbles(this.mapstraction.markers);
+        function clearExistingInfoBubbles(markers) {
+            markers.forEach(function(marker) {
+                marker.closeBubble();
+            });
+        }
                var infowindow, marker = this;
                if (!this.hasOwnProperty('proprietary_infowindow') || this.proprietary_infowindow === null) {
                        infowindow = new google.maps.InfoWindow({