FloatingTips with stay active on hover - mootools

I am using FloatingTip tool tip for my project and i am struggling for how to stay active and not to be closed when cursor is on tooltip.
Hear is jsFiddle [http://jsfiddle.net/SLvUz/3/][1]
For example: When mouse hover to tooltip and anchor Let me see! tooltip stay open.
Detail link: https://github.com/lorenzos/FloatingTips
Any ideas or suggestions? Thanks.

Unfortunately this plugin doesn't have such option at the moment, but it has methods and events, so you can implement this behavior using them. The code may look like following:
$$('#advanced a').each(function(elem){
var instance = new FloatingTips(elem, {
// example options
content: function() { return $('htmlcontent'); },
html: true, // I want that content is interpreted as HTML
center: false, // I do not want to center the tooltip
arrowOffset: 16, // Arrow is a little more the the right
offset: { x: -10 }, // Position offset {x, y}
// override show/hide events
showOn: null,
hideOn: null
});
// customize tooltip behavior
var delay = 100, timer;
var tipHover = function() {
clearTimeout(timer);
}
var tipLeave = function() {
clearTimeout(timer);
timer = setTimeout(function(){
instance.hide(elem);
}, delay);
}
instance.addEvents({
show: function(tip, elem){
tip.addEvents({
mouseover: tipHover,
mouseout: tipLeave
});
},
hide: function(tip, elem){
tip.removeEvents({
mouseover: tipHover,
mouseout: tipLeave
});
}
});
elem.addEvents({
mouseover: function() {
clearTimeout(timer);
timer = setTimeout(function(){
instance.show(elem);
}, delay);
},
mouseout: function() {
clearTimeout(timer);
timer = setTimeout(function(){
instance.hide(elem);
}, delay);
}
});
});
Check updated fiddle here: http://jsfiddle.net/SLvUz/455/

Related

How to toggle gmaps.js setContextMenu content in google map

I am working on google-map api using gmaps.js. I have a problem with google map's setcontextmenu.
When the user right-clicks the map, the context menu will appear. I tried to change the content of context menu option from "measure distance" to "stop measure distance".
Below is the code when the user right-clicks, it displays two menus: "measure distance" and "stop measuring". I want to toggle between the two. When the user clicks "measure distance" menu, I want the "measure distance" menu to disappear and the "stop measuring" menu to appear.
How can I do this? Any help would be appreciated so much.
I tried to put flag variable inside the contextmenu but it just didn't work.
map_2.setContextMenu({
control: 'map',
options: [
{
title: 'Measure Distance',
name: 'measure_distance',
action: function(e) {
// some codes here
}
},
{
title: 'Stop Measuring',
name: 'stop_measure_distance',
action: function(e) {
// some codes here
}
}
]
});
Why isn't the flag variable solution working for you? I just tried coding this real quick and it is working on my end, please test the below code:
<script>
var map;
var flag = true;
function initMap() {
map = new GMaps({
div: '#map',
lat: -12.043333,
lng: -77.028333
});
toggle();
}
function toggle() {
if (map) {
if (flag) {
map.setContextMenu({
control: 'map',
options: [{
title: 'Measure Distance',
name: 'measure_distance',
action: function(e) {
flag = false;
toggle();
}
}]
});
}
else {
map.setContextMenu({
control: 'map',
options: [{
title: 'Stop Measuring',
name: 'stop_measure_distance',
action: function(e) {
flag = true;
toggle();
}
}]
});
}
}
}
</script>
Hope this helps!

show google map inside a jquery dialogue form

Hi i'm trying to show a map in my form inside a jquery dialogue,
my jquery dialogue return a partial view where i put this code inside #section scripts and i called also the maps api
<script type="text/javascript">
$(document).ready(function () {
Initialize();
});
// Where all the fun happens
function Initialize() {
// Google has tweaked their interface somewhat - this tells the api to use that new UI
google.maps.visualRefresh = true;
var Liverpool = new google.maps.LatLng(53.408841, -2.981397);
// These are options that set initial zoom level, where the map is centered globally to start, and the type of map to show
var mapOptions = {
zoom: 14,
center: Liverpool,
mapTypeId: google.maps.MapTypeId.G_NORMAL_MAP
};
// This makes the div with id "map_canvas" a google map
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
// This shows adding a simple pin "marker" - this happens to be the Tate Gallery in Liverpool!
var myLatlng = new google.maps.LatLng(53.40091, -2.994464);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Tate Gallery'
});
// You can make markers different colors... google it up!
marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png')
// a sample list of JSON encoded data of places to visit in Liverpool, UK
// you can either make up a JSON list server side, or call it from a controller using JSONResult
var data = [
{ "Id": 1, "PlaceName": "Liverpool Museum", "OpeningHours": "9-5, M-F", "GeoLong": "53.410146", "GeoLat": "-2.979919" },
{ "Id": 2, "PlaceName": "Merseyside Maritime Museum ", "OpeningHours": "9-1,2-5, M-F", "GeoLong": "53.401217", "GeoLat": "-2.993052" },
{ "Id": 3, "PlaceName": "Walker Art Gallery", "OpeningHours": "9-7, M-F", "GeoLong": "53.409839", "GeoLat": "-2.979447" },
{ "Id": 4, "PlaceName": "National Conservation Centre", "OpeningHours": "10-6, M-F", "GeoLong": "53.407511", "GeoLat": "-2.984683" }
];
// Using the JQuery "each" selector to iterate through the JSON list and drop marker pins
$.each(data, function (i, item) {
var marker = new google.maps.Marker({
'position': new google.maps.LatLng(item.GeoLong, item.GeoLat),
'map': map,
'title': item.PlaceName
});
// Make the marker-pin blue!
marker.setIcon('http://maps.google.com/mapfiles/ms/icons/blue-dot.png')
// put in some information about each json object - in this case, the opening hours.
var infowindow = new google.maps.InfoWindow({
content: "<div class='infoDiv'><h2>" + item.PlaceName + "</h2>" + "<div><h4>Opening hours: " + item.OpeningHours + "</h4></div></div>"
});
// finally hook up an "OnClick" listener to the map so it pops up out info-window when the marker-pin is clicked!
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
})
}
i'm calling the map inside a div :
<div id="map_canvas" style="height: 240px; border: 1px solid gray"> map here</div>
but the problem that my map is not showing in the dialogue, even though it works well in normal page
any help plz !?
I've solved this issue with the following code:
this code is on the main view, the #next is a trigger of the form to submit, and the #dialog is inside the #form.
$(function () {
datepair();
$('#dialog').dialog({
autoOpen: false,
modal: true,
height: 720,
width: 700,
resizable: false,
title: 'Verify Location',
show: "fade",
hide: "fade",
open: function (event, ui) {
var form = $('#form');
$.ajax({
url: form.attr('actoin'),
type: form.attr('method'),
data: form.serialize(),
context: this,
success: function (result) {
$(this).html(result);
}
});
}
});
$('#next').click(function (e) {
$('#dialog').dialog('open');
return false;
});
});
this code is on the partialView
$(function () {
window.$required = $('<div></div>').dialog({
autoOpen: false,
resizable: false,
modal: true,
title: 'Verity Location Error',
buttons: {
"Ok": function () {
$(this).dialog('close');
callback();
}
}
});
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (json) {
Initialize();
}
});
return false;
});
function callback() {
$('#dialog').dialog('close');
}
function Initialize() {
//init the map
}
and this is the controller
public ActionResult PartialViewMapController()
{
return PartialView();
}
Hope it not to late for you :)

How to set another function to closebutton in panorama

(sorry for my english) i have a problem,,, I´m trying to create a web in which user click on a polygon and it move user to another page with Google Street View Panorama (this i have). But i also need a code to move user back from "panorama page" to "polygons page" after clicking on close button in panorama. I tried to use the same code like i used before to move user to "panorama page" but it doesn´t work (it just closes panorama, but doesn´t move back to "polygons page"). The line:
google.maps.event.addListener(panorama, "closeclick", function(event) { window.location = "index.html"; })
is the code to move user back to "polygons page" (index.html). Here is the whole code:
function initialize() {
var panoOptions = {
pano: 'Kuchyn',
enableCloseButton: true,
pov: {
heading: 0,
pitch: 0,
zoom: 0
},
panoProvider: getCustomPanorama,
visible: true};
var panorama = new google.maps.StreetViewPanorama(
document.getElementById('map-canvas'), panoOptions);
function getCustomPanoramaTileUrl(pano, zoom, tileX, tileY) {
return 'images/Untitled.jpg';}
function getCustomPanorama(pano, zoom, tileX, tiley) {
if (pano == 'Kuchyn') {
return {
location:
{pano: 'Kuchyn',
description: 'Kromeriz - Kuchyn'},
links: [],
copyright: 'Oznog (c) 2013',
Heading: 180,
tiles:
{tileSize: new google.maps.Size(4096, 2048),
worldSize: new google.maps.Size(4096, 2048),
centerHeading: 180,
verticalFOV: 90,
getTileUrl: getCustomPanoramaTileUrl}
};
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addListener(panorama, "closeclick", function(event) { window.location = "index.html"; })
Please help me, Jan.
Your eventListener for panorama is outside initialize function, move it under panorama declaration as follows:
var panorama = new google.maps.StreetViewPanorama(
document.getElementById('map-canvas'), panoOptions);
// move it here
google.maps.event.addListener(panorama, "closeclick", function(event) { window.location = "index.html"; });
This is because you are not declaring panorama as a global variable, so it cant be attached correctly. Other option is to declare it as global variable var panorama; to above your initialize method.
Cheers.

street view panorama completely grey

I have created a street view backbone view. The problem is that when shown, the panorama is completely grey. I am not sure if it has to do with the fact that it is inside a tab and the panorama is rendered when the tab is opened.
I am guessing that it might be an analogous problem that is fixed calling the resize event. Is there any similar thing that I could do?
App.DetailStreetView = Backbone.View.extend({
initialize: function() {
this.latLng = new google.maps.LatLng(37.869085,-122.254775);
},
render: function() {
var sv = new google.maps.StreetViewService();
this.panorama = new google.maps.StreetViewPanorama(this.el);
sv.getPanoramaByLocation(this.latLng, 50, this.processSVData);
},
processSVData: function(data, status) {
if (status == google.maps.StreetViewStatus.OK) {
// calculate correct heading for POV
var heading = google.maps.geometry.spherical.computeHeading(data.location.latLng, this.latLng);
this.panorama.setPano(data.location.pano);
this.panorama.setPov({
heading: 270,
pitch:0,
zoom:1,
});
}
},
refresh: function() {
this.panorama.setVisible(true);
google.maps.event.trigger(this.panorama, 'resize');
}
});
EDIT:
I created a JSFiddle that replicates the problem: http://jsfiddle.net/kNS2L/3/
Yeah, this is the old display:none with Maps and Panoramas. It works when I add setVisible(true):
$('button').click(function() {
$('#pano').show();
panorama.setVisible(true);
});

changing z index of marker on hover to make it visible

I'm trying to make the marker i'm currently hovering on have a greater z-index than the others, so that even if it's hidden by other markers it'll gain full visibility when I hover on it.
On click of any marker i want to do the same .
google.maps.event.addListener(this.marker, 'mouseover', function() {
this.old_ZIndex = this.getZIndex(); //trying to get the current z- index
console.log(this.old_ZIndex); //this is undefined: why?
this.setZIndex(this.old_ZIndex + 100); //setting a higher z-index than all other markers
console.log("the old z index is ",this.old_ZIndex);
});
But with this i would be infinitely increase the z index .. is there some other way in which I can have the to revert back when i hover or click any other marker . .
Or is there any better way to implement it ??
'this.getZIndex()' always returns 'undefined' if you haven't previously set a zIndex on the marker, either when initialising it in the first place or by using the setOption() function.
Your script may also not work 100% if there are more than 100 markers.
I've put together a very simple map below that contains 2 markers, slightly overlapping. On hover of one of the markers it will set the zIndex to the highest needed to bring it to the top, then return it back to what it was previously on mouseout:
var map;
var markers = new Array();
var highestZIndex = 0;
function initialize() {
/* SETUP MAP */
var myLatlng = new google.maps.LatLng(52.06768, -1.33758);
var mapOptions = {
center: myLatlng,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
/* ADD 1st MARKER */
var markerOptions = {
position: new google.maps.LatLng(52.06768, -1.32058),
map: map,
zIndex:1
};
marker = createMarker(markerOptions, false);
marker.set("myZIndex", marker.getZIndex());
google.maps.event.addListener(marker, "mouseover", function() {
getHighestZIndex();
this.setOptions({zIndex:highestZIndex+1});
});
google.maps.event.addListener(marker, "mouseout", function() {
this.setOptions({zIndex:this.get("myZIndex")});
});
/* ADD 2nd MARKER */
var markerOptions = {
position: new google.maps.LatLng(52.06768, -1.33758),
map: map,
zIndex:2
};
marker = createMarker(markerOptions, false);
marker.set("myZIndex", marker.getZIndex());
google.maps.event.addListener(marker, "mouseover", function() {
getHighestZIndex();
this.setOptions({zIndex:highestZIndex+1});
});
google.maps.event.addListener(marker, "mouseout", function() {
this.setOptions({zIndex:this.get("myZIndex")});
});
}
function createMarker(markerOptions) {
var marker = new google.maps.Marker(markerOptions);
markers.push(marker);
return marker;
}
function getHighestZIndex() {
// if we haven't previously got the highest zIndex
// save it as no need to do it multiple times
if (highestZIndex==0) {
if (markers.length>0) {
for (var i=0; i<markers.length; i++) {
tempZIndex = markers[i].getZIndex();
if (tempZIndex>highestZIndex) {
highestZIndex = tempZIndex;
}
}
}
}
return highestZIndex;
}
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
zIndex: 1
});
google.maps.event.addListener(marker, 'mouseover', function () {
this.setOptions({zIndex:10});
});
google.maps.event.addListener(marker, 'mouseout', function () {
this.setOptions({zIndex:1});
});
I think the easiest way is to use CSS instead of Javascript:
.your-custom-marker-class {
z-index: 100;
}
.your-custom-marker-class:hover {
z-index: 101;
}
This does mean you have to use CustomOverlays (https://developers.google.com/maps/documentation/javascript/customoverlays#introduction) instead of default markers, but that has some other advantages too, if you want to customize layout, etc.
So this question was a year ago but I figured something out and thought others might appreciate it. There's even icon rollovers involved as a bonus. I'm dealing with thousands of bus and train stops being shown so this turned out to be pretty efficient for me.
google.maps.event.addListener(marker, 'mouseover', function () {
if (this.getIcon() === busnot) { this.setIcon(busovr); }
if (this.getIcon() === lrtnot) { this.setIcon(lrtovr); }
$.each($.grep(markers, function (item) { return item.getZIndex() == 10 }), function (i, e) { e.setOptions({ zIndex: 1 }); });
this.setOptions({zIndex:10});
});
google.maps.event.addListener(marker, 'mousemove', function () {
if (this.getIcon() === busnot) { this.setIcon(busovr); }
if (this.getIcon() === lrtnot) { this.setIcon(lrtovr); }
$.each($.grep(markers, function (item) { return item.getZIndex() == 10 }), function (i, e) { e.setOptions({ zIndex: 1 }); });
this.setOptions({ zIndex: 10 });
});
google.maps.event.addListener(marker, 'mouseout', function () {
if (this.getIcon() === busovr) { this.setIcon(busnot); }
if (this.getIcon() === lrtovr) { this.setIcon(lrtnot); }
$.each($.grep(markers, function (item) { return item.getZIndex() == 10 }), function (i, e) { e.setOptions({ zIndex: 1 }); });
});
The way I did it was to have one variable(highestZ) set the zIndex for all my markers(in my case i did it with polylines) and increments, and one variable to temporarily hold the z-index of whichever marker i "mouseover" on:
Set the variables as global:
var highestZ = 1; //set 1 for the first z-index
var tmpZIndex = 0;
Then when building/initializing your marker options just add this
zIndex : highestZ++ //this sets the z-index for the marker and increments it for the next one
Sample (i did mine in a loop) :
var routePath = new google.maps.Polyline({
strokeWeight: 5,
zIndex : highestZ++ //set zIndex and increment it
});
And finally just do mouseover and mouseout event handlers like this:
google.maps.event.addListener(routePath, "mouseover", function() {
tempZIndex = routePath.zIndex; //set "this" z-index value to tempZIndex for mouseout
routePath.setOptions({
zIndex: highestZ + 1 //set the z-index to the highest z-index available plus 1 for it to be the topmost marker on mouseover
});
});
google.maps.event.addListener(routePath, "mouseout", function() {
routePath.setOptions({
zIndex: tempZIndex //set the z-index back to it's original set upon mouseover earlier
});
My answer is probably simple, and general and of course incomplete to focus on the problem only, hopefully you can work it further to fit your project.