Infowindow close event listener on gmaps4rails - ruby-on-rails

I have some list of markers being shown in google map. Now I want to do some additional things when I close the infowindow.
google.maps.event.addListener(Gmaps.map.visibleInfoWindow,'closeclick',function()
{
do_something();
});
It doesn't seem to working. Please provide some tutorial or code block to achieve this.

You should override the way infowindows are created.
Something like this:
old_method = Gmaps4Rails.Google.Marker.prototype.createInfoWindow
Gmaps4Rails.Google.Marker.prototype.createInfoWindow = function(){
old_method();
// then access the infowindow with: this.infowindow and add whatever you need
}
For 1.x, do the same but with: Gmaps4RailsGoogle.prototype.createInfoWindow

Related

Dynamic Data To Google Sheet

I'm trying to pull dynamic data (form) to a google sheet.
I can't seem to find the right function.
I'm running this:
function name(){
return $('input[type="text"]').val();
}
I tried this:
function fullname(){
return $('#form-field-1-1').val();
}
No success for now.
I've attached the elements below.
Thank you [https://i.stack.imgur.com/Tt5Gk.png]
Your best choise is to use a Variable "DOM element" and capture it by ID. but if you prefer a custom JS this will do:
function(){
return document.getElementById('form-field-1-1').innerHTML;
}
Hope it helps.

Implementing a search function for a marker

I have Markers setup with gmaps4rails.
Now I want to implement a classic search function.
If I find one object, it should directly show the marker.infowindow
How do I open it directly?
I tried:
function focusSearch() {
handler.map.centerOn({ lat: <%=#searchy.latitude %>, lng: <%=#searchy.longitude %>});
handler.getMap().setZoom(16);
marker = <%=#searchy.id%>
marker.infowindow.open(map, marker.serviceObject);
}
But I guess I am going wrong there...
Anyone can help?
If you have an Idea how to directly use the #search:params, I am happy!
Thanks for helping out!
I've created a plunkr with working code here.
Basically steps are:
associate the marker to the original json data where ids are available
search the marker list for the id you expect
trigger the 'click' google map event on the marker which triggers pan + infowindow

How to register map move / map pan events in OpenLayers 3

I'm looking for OpenLayer 3 map event for map move/map pan, something like:
map.on('move', function(){
...
}
Does anyone know how to implement?
The moveend event might be the one you search for - it detects any move made, even those not invoked by dragging.
map.on('moveend', function (e) {
console.log("moved");
});
See http://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html
UPDATE:
These events are no longer present in recent versions. Please refer to the more recent answer for an up-to-date information.
Names of the events you're looking for are drag and/or dragend (it's probably a better idea to depend on properties names, though: ol.MapBrowserEvent.EventType.DRAG but it didn't work on the demo page):
map.on('drag', function() {
console.log('Dragging...');
});
map.on('dragend', function() {
console.log('Dragging ended.');
});
Reverse-engineered by looking inside mapbrowserevent.js, the documentation explicitly mentions events are not documented yet.
MoveEnd trigger if u move the map with a script.
I have use that in OpenLayers 6:
map.on('pointerdrag', function (event) {
is_map_center = false;
})
hf gl!
I believe this functionality exists in 2 functions within the View of a map, not the map itself. You can monitor the center property of the View by listening for change:center events. There is also a getInteracting() method in ol.View that will return a boolean if an interaction (zooming or panning) is occurring.
https://openlayers.org/en/v4.6.5/apidoc/ol.View.html#getInteracting

jQuery Gmap3: where is the success callback?

I would like to know when my gmap is loaded. I didn't see any callback method in the documentation and around the web.
I'm using this plugin: http://gmap3.net/en/catalog/
Any tip? Thx
Regards
I think you will have to revert and use the google maps native function. The answer toyour question is outlined in this question: How can I check whether Google Maps is fully loaded?
and it looks like the best answer is given with this code snippet:
google.maps.event.addListenerOnce(map, 'idle', function(){
// do something only the first time the map is loaded
});
it doesn't seem to be documented but there is a callback property on the map object
$('#map_canvas').gmap3(
{
map: {
options: {
zoom: 9,
center: [view.lat, view.lng]
},
callback: function (e) {
alert("loaded");
}
}
});

How to make Google Analytics count pop up posts

I have a wordpress site where you can view posts in two ways. You can view them on their single page or you can click on thumbs from the homepage and view them in an ajax popup that shows the full post. My problem obviously is that Analytics isn't counting the popup views. I use a template to popup the post and I'm looking for a way to make analytics recoginze it as a page view and tell me what post it was. I tried adding the analytics code to the top of the template page but that didn't do anything. Any ideas? I use the SimpleModal jquery plugin to popup posts and call them like this.
jQuery(document).ready(function() {
jQuery('a.postpopup').live('click', function(){
var id = jQuery(this).attr('rel');
jQuery('<div id="ajax-popup"></div>').hide().appendTo('body').load('http://mysite.com/ajax-handler/?id='+id).modal({
opacity:90,
position: ["0%"],
containerCss:{width:"100%"},
overlayClose:true,
onOpen: function (dialog) {
dialog.overlay.fadeIn('200', function () {
dialog.data.hide();
dialog.container.fadeIn('500', function () {
dialog.data.fadeIn('slow');
});
});
},
onClose: function (dialog) {
dialog.data.fadeOut('slow', function () {
dialog.container.hide('500', function () {
dialog.overlay.fadeOut('200', function () {
$.modal.close();
});
});
});
}
});
return false;
});
});
you can simulate a page view by using _trackPageView
Google Analytics has several options to track non-pageview related user activity that I think you could use here:
Virtual pageviews - as mentioned by user273895, you can add the call to your code when the dialog pops-up to see a "fake" pageview in your reports with a title like '/popup/post-name'
Events - you can instrument the above call with an event, for example: _trackEvent("popup", "click", "post-name"). The interaction is then trackable in the event reports and can be used to specify additional segments and filters for more advanced analysis.
Custom variables - you can set up a page or session level custom variable to record the interaction.
I'd suggest the first 2 options. Personally I tend to use events for this sort of thing but in your case it may make more sense to use a virtual pageview.

Resources