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

Marker click changes center #559

Open
WaqarHassan opened this issue Mar 30, 2018 · 2 comments
Open

Marker click changes center #559

WaqarHassan opened this issue Mar 30, 2018 · 2 comments

Comments

@WaqarHassan
Copy link

WaqarHassan commented Mar 30, 2018

I ma using Gmap4rails gem to populate rich markers on map.
When I click on marker, It changes map center automatically.
I don't want to change center on marker click.
Following is the code

var RichMarkerBuilder,
    extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    hasProp = {}.hasOwnProperty;

RichMarkerBuilder = (function(superClass) {
    extend(RichMarkerBuilder, superClass);

    function RichMarkerBuilder() {
        return RichMarkerBuilder.__super__.constructor.apply(this, arguments);
    }

    RichMarkerBuilder.prototype.create_marker = function() {
        var options;
        options = _.extend(this.marker_options(), this.rich_marker_options());
        return this.serviceObject = new RichMarker(options);
    };

    RichMarkerBuilder.prototype.rich_marker_options = function() {
        var marker;
        marker = document.createElement("div");
        marker.setAttribute('class', 'marker_container '+ this.args.id);
        marker.innerHTML = this.args.custom_marker;
        return {
            content: marker
        };
    };
    return RichMarkerBuilder;

})(Gmaps.Google.Builders.Marker);

this.buildMap = function(markers) {
    // var handler;
    markers = _.filter(markers, function(marker){
        return marker.lat !== undefined;
    });
    window.handler = Gmaps.build('Google', {
        builders: {
            Marker: RichMarkerBuilder
        }
    });
    return handler.buildMap({
        provider: {fullscreenControl: false , clickableIcons: false },
        internal: {
            id: 'map'
        }
    }, function() {
        
        markers = markers.map(function(m) {
            marker = handler.addMarker(m);
            marker.serviceObject.set('id', m.id); // You can add other attributes using set
            return marker;
        });
        handler.bounds.extendWith(markers);
        handler.fitMapToBounds();
        // handler.getMap().setZoom(12);
        if (window.zoom && window.zoom !== undefined)
        {
            handler.getMap().setZoom(window.zoom)

        }else {handler.getMap().setZoom(12); window.zoom = 12}
        if (window.center && window.center !== undefined)
        {
            // handler.getMap().setCenter(window.center)

        }
        setTimeout(function(){
            bind_map_bounds_change()
        },100)
        return
    });
};

@WaqarHassan
Copy link
Author

After spending days, I am unable to solve this issue,
Would be very grateful for the help.
Thanks

@apneadiving
Copy link
Owner

you should create a js fiddle or whatever online tool where we can actually see/reproduce the problem

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