简体   繁体   中英

Display a hidden element / Simulate click

at the bottom of the site, I have a Google Maps plugin. Here you can see a black marker. If you click that marker, it shows you a box with text inside it.

I want the box to be shown without having to click the marker first.

I thought i could solve this by imitating a click after the website has loaded, but i can't find out how to address that specific marker to click.

Could anyone hint me to a solution? I couldn't solve this without breaking the whole Map :/..

Thanks a lot.

This problem concerns the following website: http://prusiklackierbetrieb.de/neu/black/indexnewimages.html

I have found the location where the infowindow is created. However, when i change the event from "click" to "load" or "domready" it does not fire. i think it is because the script is loaded after these events fire. How can I still open the window by default?

Code Snippet:

!function(a) {
"use strict";
var t = {
    cntClass: "map",
    mapClass: "map_model",
    locationsClass: "map_locations",
    marker: {
        basic: "images/gmap_marker.png",
        active: "images/gmap_marker_active.png"
    },
    styles: [],
    onInit: !1
}
  , o = {
    map: {
        x: -73.9924068,
        y: 40.646197,
        zoom: 14
    },
    locations: []
}
  , n = function(t, o) {
    var n = t.parent().find("." + o.locationsClass).find("li")
      , e = [];
    return n.length > 0 && n.each(function(t) {
        var n = a(this);
        n.data("x") && n.data("y") && (e[t] = {
            x: n.data("x"),
            y: n.data("y"),
            basic: n.data("basic") ? n.data("basic") : o.marker.basic,
            active: n.data("active") ? n.data("active") : o.marker.active
        },
        a.trim(n.html()) ? e[t].content = '<div class="iw-content">' + n.html() + "</div>" : e[t].content = !1)
    }),
    e
};
a.fn.googleMap = function(e) {
    e = a.extend(!0, {}, t, e),
    a(this).each(function() {
        var t = a(this)
          , s = a.extend(!0, {}, o, {
            map: {
                x: t.data("x"),
                y: t.data("y"),
                zoom: t.data("zoom")
            },
            locations: n(t, e)
        })
          , i = new google.maps.Map(this,{
            center: new google.maps.LatLng(parseFloat(s.map.y),parseFloat(s.map.x)),
            styles: e.styles,
            zoom: s.map.zoom,
            scrollwheel: !1
        });
        e.onInit && e.onInit.call(this, i);
        var c = new google.maps.InfoWindow
          , l = [];
        for (var r in s.locations)
            l[r] = new google.maps.Marker({
                position: new google.maps.LatLng(parseFloat(s.locations[r].y),parseFloat(s.locations[r].x)),
                map: i,
                icon: s.locations[r].basic,
                index: r
            }),
            s.locations[r].content && (google.maps.event.addListener(l[r], "DOMContentLoaded", function() {
                for (var t in l)
                    l[t].setIcon(s.locations[t].basic);
                c.setContent(s.locations[this.index].content),
                c.open(i, this),
                a(".gm-style-iw").parent().parent().addClass("gm-wrapper"),
                this.setIcon(s.locations[this.index].active)
            }),
            google.maps.event.addListener(c, "closeclick", function() {
                for (var a in l)
                    l[a].setIcon(s.locations[a].basic)
            }));
        google.maps.event.addDomListener(window, "resize", function() {
            i.setCenter(new google.maps.LatLng(parseFloat(s.map.y),parseFloat(s.map.x)))
        })
    })
}}(jQuery);

When you crate the infowindow just call open

infowindow.open(map, marker);

You can look an example here https://www.ibeernalia.com/#dorigen .

The map is loaded in an IFRAME so you cannot simulate click on an element in the IFRAME. What you can do it to use the Google Maps API for that

More Info:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM