Skip Navigation

[Gelöst] Map marker pop-up open on page load

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
A map has a single marker which has some content that appears in a pop-up when clicked. How is it possible to have the pop-up already open on page load?

Solution:
You would need to add some custom JS to your map:

( function( $ ) {
    $( document ).bind( 'js_event_wpv_addon_maps_init_map_completed', function(){
  
        var mapId = Object.keys(WPViews.view_addon_maps.maps)[0];
        var map = WPViews.view_addon_maps.maps[mapId];
        var mapsMarkers = WPViews.view_addon_maps.markers[Object.keys(WPViews.view_addon_maps.markers)[0]];
        var markerId = Object.keys(mapsMarkers)[0];
        var marker = mapsMarkers[Object.keys(mapsMarkers)[0]];
        WPViews.view_addon_maps.infowindows[ mapId ].setContent( $('div.js-wpv-addon-maps-marker-'+markerId).html() );
        WPViews.view_addon_maps.infowindows[mapId].open(map, marker);
  
    });
})( jQuery );

Dies ist das technische Support-Forum für Toolset – eine Suite von Plugins zur Entwicklung von WordPress-Websites ohne PHP-Pogrammierung.

Jeder kann in diesem Forum lesen, aber nur Toolset-Kunden können darin Beiträge veröffentlichen. Der Toolset-Support arbeitet 6 Tage pro Woche, 19 Stunden pro Tag.

This topic contains 6 Antworten, has 2 Stimmen.

Last updated by Nigel vor 3 Jahre, 2 Monate.

Assigned support staff: Nigel.

Author
Artikel
#611705

Hi,

is it possible to open a Single Marker Popup on Map at startup/onLoad of Browser?

hidden link

There is only one Marker

[wpv-map-marker map_id="projektmap" marker_id="marker-1" lat="[types field='google-maps-lat' output='raw'][/types]" lon="[types field='google-maps-lang' output='raw'][/types]" marker_title="[wpv-post-title output="sanitize"]"][wpv-post-title output="sanitize"]<br/>[types field='strasse'][/types]<br />[types field='plz'][/types] [types field='ort'][/types][/wpv-map-marker]

This can be an Option in Markers for the Future.

Thanks for an Answer - best regards - alex

#611771

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+01:00)

Hi Alex

You want the map marker to be in its open "clicked" state immediately on page load, yes?

You should be able to achieve that by adding a little JS to your map View.

Try the following JS added to the custom JS section of your template, making sure to edit the map ID and the marker ID:

( function( $ ) {
	$( document ).bind( 'js_event_wpv_addon_maps_init_map_completed', function(){

		var mapID = 'map-5'; // Edit
		var markerID = $('[data-marker]').attr('data-marker');

		var map = WPViews.view_addon_maps.get_map( mapID );
		var marker = WPViews.view_addon_maps.get_map_marker( markerID, mapID );

		WPViews.view_addon_maps.infowindows[ markerID ].open(map, marker);

	});
})( jQuery );
#611797

Hi,
it dont work..

in my case i added:

( function( $ ) {
$( document ).bind( 'js_event_wpv_addon_maps_init_map_completed', function(){

var mapID = 'projektmap'; // Edit
var markerID = $('[marker-1]').attr('marker-1');

var map = WPViews.view_addon_maps.get_map( mapID );
var marker = WPViews.view_addon_maps.get_map_marker( markerID, mapID );

WPViews.view_addon_maps.infowindows[ markerID ].open(map, marker);

});
})( jQuery );

is this right?

best regard - alex

#611802

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+01:00)

Hi Alex

I didn't fully test that code, it seems the popup is empty.

Please try again with this:

( function( $ ) {
	$( document ).bind( 'js_event_wpv_addon_maps_init_map_completed', function(){

		var mapId = Object.keys(WPViews.view_addon_maps.maps)[0];
		var map = WPViews.view_addon_maps.maps[mapId];
		var mapsMarkers = WPViews.view_addon_maps.markers[Object.keys(WPViews.view_addon_maps.markers)[0]];
		var markerId = Object.keys(mapsMarkers)[0];
		var marker = mapsMarkers[Object.keys(mapsMarkers)[0]];
		WPViews.view_addon_maps.infowindows[ mapId ].setContent( $('div.js-wpv-addon-maps-marker-'+markerId).text() );
		WPViews.view_addon_maps.infowindows[mapId].open(map, marker);

	});
})( jQuery );

You shouldn't need to edit anything, it will automatically get the first map on the page and the first marker of that map and open the popup with its content set.

I did test that locally and it worked, but please let me know if it doesn't for you.

Btw, I forgot to mention, when I visit your link I see several JS errors in your console.

You will need to identify where they are coming from and fix them, otherwise any code you add is unlikely to work.

#611823

Hi,
yes - this works. But now it is all in one Line - without the Breaks in Marker - i do that with <br/> - it is possible to do this with html tags in Popup?

This is the code in content template for the popup (with line breaks <br/>:

[wpv-post-title output="sanitize"]<br/>[types field='strasse'][/types]<br />[types field='plz'][/types] [types field='ort'][/types]

#611867

Hi,

i got it:

you have to do the content as html instead of text:

#this ->
WPViews.view_addon_maps.infowindows[ mapId ].setContent( $('div.js-wpv-addon-maps-marker-'+markerId).text() );
#to that ->
WPViews.view_addon_maps.infowindows[ mapId ].setContent( $('div.js-wpv-addon-maps-marker-'+markerId).html() );
( function( $ ) {
    $( document ).bind( 'js_event_wpv_addon_maps_init_map_completed', function(){
 
        var mapId = Object.keys(WPViews.view_addon_maps.maps)[0];
        var map = WPViews.view_addon_maps.maps[mapId];
        var mapsMarkers = WPViews.view_addon_maps.markers[Object.keys(WPViews.view_addon_maps.markers)[0]];
        var markerId = Object.keys(mapsMarkers)[0];
        var marker = mapsMarkers[Object.keys(mapsMarkers)[0]];
        WPViews.view_addon_maps.infowindows[ mapId ].setContent( $('div.js-wpv-addon-maps-marker-'+markerId).html() );
        WPViews.view_addon_maps.infowindows[mapId].open(map, marker);
 
    });
})( jQuery );
#611868

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+01:00)

You beat me to it, thanks for the update.

Das Forum „Toolset Professioneller Support“ ist für neue Themen und Antworten geschlossen.