I'm using google map API v3. I want to disable click action on default google landmark/poi. For example, when I zoom to UCLA, the school icon shows up (that's fine) but I don't want user to click and view details of that location. Which API function should I use?
Google has exposed an option for this. See clickableIcons of google.maps.MapOptions in the docs.
Example initialization code:
map = new google.maps.Map(document.getElementById('map'), {
clickableIcons: false
});
add this option to mapOption
clickableIcons: false
this is more options i think you will
draggable: true, // this is for disable the Draggable
disableDefaultUI: true, // this for disable Default UI
fullscreenControl: false, // this is for disable Full Screen
scrollwheel: true, // this is for disable Scroll Wheel
disableDoubleClickZoom: false, // this is for disable Double Click Zoom
draggableCursor:'crosshair',// this is for cursor type
draggingCursor:'move', // this is for dragging cursor type
minZoom: 3, // this is for min zoom for map
maxZoom: 18 , // this is for max zoom for map
//note : max, min zoom it's so important for my design.
zoom: 14, // this is to make default zoom
clickableIcons: false, // this is to disable all labels icons except your custom infowindow or Infobox.
I encountered this same problem.
Google appears to have recently changed their api to make the base map labels "clickable" and there is not yet a simple API call to disable their clickablility.
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/f1ac9ad4da3606fe
I would like to see google add a simple map option like this, but alas it doesn't exist yet
var opts = { clickableLabels:false };
var map = new maps.google.com.map(div,opts);
The following solution works, but because it relies on custom styled map tiles, free maps are limited to (2,500 maps loads per day) - See Google Maps FAQ.
function initialize() {
// For more details see
// http://code.google.com/apis/maps/documentation/javascript/styling.html
var noPOILabels = [
{
featureType: "poi",
elementType: "labels",
stylers: [ { visibility: "off" } ]
}
];
// Create a new StyledMapType object, passing it the array of styles,
// as well as the name to be displayed on the map type control.
var noPOIMapType = new google.maps.StyledMapType(noPOILabels,
{name: "NO POI"});
// Create a map object, and include the MapTypeId to add
// to the map type control.
var mapOptions = {
zoom: 11,
center: new google.maps.LatLng(55.6468, 37.581),
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'no_poi']
}
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
//Associate the styled map with the MapTypeId and set it to display.
map.mapTypes.set('no_poi', noPOIMapType);
map.setMapTypeId('no_poi');
}
This issue has been logged with google at:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=3866
Please star and comment your needs on this issue there.
I understand that the OP wants a solution that persists the labels/icons but suspends the click events. I'm not sure this is possible; please star this issue
However, some of us are drawing shapes sans Drawing Manager and labels/icons are obstructing the additions of new points. If it meets your requirements, you can temporarily remove the icons/labels. I've found that transit, poi, and landscape all need to be toggled:
var map = new google.maps.Map(document.getElementById("map"), {});
map.poi = function(state){
var styles = [
{
"featureType": "transit",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "poi",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "landscape",
"stylers": [
{ "visibility": "off" }
]
}
];
this.set("styles", (state)? {} : styles );
}
And the usage:
//turn the labels/icons off
map.poi(false);
//turn them back on
map.poi(true);
I understand that this question is old, but maybe this answer will help others:
I'm not sure if this is legal, but I ended up exploring the code and made this:
$("#google-map").on("mousedown",function(){
setTimeout(function(){
disableInfoWindows();
},500);
});
function disableInfoWindows()
{
$(".gm-iw.gm-sm").parent().parent().remove();
$("[style='position: absolute; left: -2px; top: -336px; width: 59px; height: 492px; -webkit-user-select: none; border: 0px; padding: 0px; margin: 0px;']")
.parent()
.parent()
.remove();
}
It worked for me, no infoWindow showing up, while preserving all the icons. Anyone who has an idea enhancing the code is welcome, the infoWindow is showing up just a bit the first time it is about to open, after that first one, it is completely gone.
Yeah, the other solutions work but you can also want to have ability to hide/disable only part of that pins or disable ability to go to details from popups, please see my post here with some tips how you can do that CLICK
Right, to sum up, if you want to "remove" popups, you can just use:
clickableIcons: false
for map options object. But if you want to have a popup, but without "View on Google Maps" label, you can use a hacky CSS trick:
google-map {
.view-link {
display: none !important;
}
}
That was my requirements, and it works!
If you want to define which icons/pins (elements or labels, however you call it) should be visible, you can use this site to generate proper JSON with map settings: https://mapstyle.withgoogle.com/
Related
I'm using FullCalendar v.3.4.0 with no CSS changes.
I have only the base css and the print version declared.
As you can see on the picture, the last event, that starts near midnight, is getting cut visually.
In Fullcalendar's Github, there is a sticky issue regarding Chrome's rendering of the table, but I'm not sure if the problem lies there.
I haven't tried Firefox, but I'm running this in a webview of a Cordova app on Android, so i'm bound to Chrome.
example of the issue
Init code
$('#events').fullCalendar({
defaultView: 'agendaDay',
allDaySlot: false,
editable: false,
eventLimit: true,
displayEventTime: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
events: "remote.php"
}
Can I add a "ghost" event so it pushes the overflowed view in order to see that event? I would like avoid jquerying my way into the DOM, but if there is no other change I will do so.
Thank you in advance.
Best regards
I have solved with the following steps:
Backend
Added a field called "time" ( or any field you wish to use ) and whenever you detect the end date goes to the next day you set "time" to "23-59".
Frontend
Add the following code to your Fullcalendar init:
eventRender: function(eventObj, $el) {
if (eventObj.time == "23-59") {
$($el).css({"overflow":"inherit","height":"50px"});
}
},
eventAfterAllRender : function (view) {
if (view.type == 'agendaDay') {
$(".fc-agendaDay-view .fc-slats table tbody").append('<tr>\
<td class="fc-axis fc-time fc-widget-content" style="height:100px"></td>\
<td class="fc-widget-content"> </td>\
</tr>');
}
}
This is not an elegant solution for v3 but it suits my requirements.
I'm developing a new tab replacement extension for Google Chrome and I'd like to allow the user to customize the background, to do so I'm using the storage.sync API as suggested by this page.
The problem is that the style changes are applied asynchronously, so the default background (white) is briefly used during the page load resulting in unpleasing flashes.
Possible (unsatisfying) solutions are:
do not allow to change the background;
hard code a black background in the CSS (and move the problem to custom light backgrounds);
use a CSS transition (still super-ugly).
What could be an alternative approach?
Follows a minimal example.
manifest.json
{
"manifest_version": 2,
"name": "Dummy",
"version": "0.1.0",
"chrome_url_overrides": {
"newtab": "newtab.html"
},
"permissions": [
"storage"
]
}
newtab.html
<script src="/newtab.js"></script>
newtab.js
chrome.storage.sync.get({background: 'black'}, ({background}) => {
document.body.style.background = background;
});
I come up with a reasonable solution. Basically since the localStorage API is synchronous we can use it as a cache for storage.sync.
Something like this:
newtab.js
// use the value from cache
document.body.style.background = localStorage.getItem('background') || 'black';
// update the cache if the value changes from the outside (will be used the next time)
chrome.storage.sync.get({background: 'black'}, ({background}) => {
localStorage.setItem('background', background);
});
// this represents the user changing the option
function setBackground(background) {
// save to storage.sync
chrome.storage.sync.set({background}, () => {
// TODO handle error
// update the cache
localStorage.setItem('background', background);
});
}
This doesn't work 100% of the times but neither do the simple:
document.body.style.background = 'black';
So it's good enough.¹
¹ In the real extension I change the CSS variables directly and I obtain much better results than setting the element style.
Hi all,
Hopefully this is an easy one. I've set up a legend with an onclick event but would like the mouse cursor to change to "pointer" when I hover over the labels (see chart screenshot above). Currently it's hard to tell that the labels are links because the mouse cursor doesn't change when I hover over them.
Also how do I add some margin/padding between the legend and chart (space below the legend).
Many thanks!
You can achieve the desired behavior using a combination of the legend onHover config option (to change the pointer style to pointer) and the custom tooltips config option (to change the pointer style back to default).
Here is an example config demonstrating a working solution. I wasn't sure if you were using jQuery or not so I decided not to use it. Feel free to change accordingly.
options: {
legend: {
position: 'top',
labels: {
fontColor: 'rgb(255, 99, 132)'
},
onHover: function(event, legendItem) {
document.getElementById("canvas").style.cursor = 'pointer';
}
},
tooltips: {
custom: function(tooltip) {
if (!tooltip.opacity) {
document.getElementById("canvas").style.cursor = 'default';
return;
}
}
}
}
I found a different way to make this work. This lines up more literally in my mind. Perhaps the framework was updated in the interim since this was initially answered.
// This event fires anytime you mouse over the chart canvas.
onHover: function (event) {
event.target.style.cursor = 'default';
},
responsive: true,
maintainAspectRatio: false,
legend: {
display: true,
position: 'bottom',
onHover: function (event, legendItem) {
// There is only a legendItem when your mouse is positioned over one
if (legendItem) {
event.target.style.cursor = 'pointer';
}
}
}
In case anyone wants to know more, here are the docs for events and the legend.
Faster, without scanning the DOM every time, you find the target under native in the hover event
Tested in version 3.2.1 and 3.3.2 (latest on 2021 jun 22)
options: {
plugins : {
legend: {
labels: {
onHover: function (e) {
e.native.target.style.cursor = 'pointer';
},
onLeave: function (e) {
e.native.target.style.cursor = 'default';
}
}
}
}
}
The accepted answer did not work for me because my tooltips are always visible (position: "nearest"). So I use a timeout to change and revert the cursor style:
onHover: function(event, legendItem) {
document.getElementById("canvas").style.cursor = "pointer";
clearTimeout(hoverTimeout); // global var
hoverTimeout = setTimeout(function() {
document.getElementById("canvas").style.cursor = "default";
}, 100);
}
It's a dirty trick but it works.
I'm relatively new to the Fusion Tables Api and I am trying to create a simple web app using Fusion Tables and Google Maps Api. The application will be used about three times a day and each time a new set of data will be added to the table, replacing the old entries with new ones.
So far, the application is working as expected, except for when changes are made to the fusion table. When I add or delete multiple rows from the table manually through the Fusion Table page and then return to my app, I notice that the styles stop working properly, and in many cases do not appear at all; however, after about an hour everything starts working normally again.
The code I use for creating the styles is this,
layer = new google.maps.FusionTablesLayer({
query: {
select: "geometry",
from: '11CIZUlNjBPiOM1Y4pDUP_Mn9TxkqF0etfpWhi5c'
},
styles:[
{
polygonOptions:{
fillColor: '#FF0000',
fillOpacity: 0.05
}
},
{
where: "Location LIKE 'PERDUE'",
polygonOptions: {
//fillColor: '#0000FF'
fillOpacity:0.2
}
},
{
where: "GeoBlock = 'AC1C'",
polygonOptions: {
//fillColor: '#0000FF'
fillOpacity:0.8
}
},
{
where: "Location = 'BENGOUGH'",
polygonOptions: {
//fillColor: '#0000FF'
fillOpacity:0.99
}
}]
});
layer.setMap(map);
I've researched a bit to see if anyone else is having similar issues, and the closest thing that I've come across that is similar to the problem I am having is that it may be a cache issue with the browser, but I've tested this scenario with multiple machines at the same time and have been getting the same result and I've also added the no-cache tag to my code to prevent the browser from caching the styles. I'm not sure if this is an Api issue or something else. I will appreciate any suggestions on how to approach this problem.
Thanks,
It's an API-issue, the tiles created to display the layers will also be cached by google.
What you can do: modify the queries, so that it still fetches the same results, but the String-representation for the query is different. This should speed-up the tile-update(and prevent from client-side caching).
Taking your code it could be done like this:
var and=' Location does not contain "'+new Date().getTime()+'"';
layer = new google.maps.FusionTablesLayer({
query: {
select: "geometry",
from: '11CIZUlNjBPiOM1Y4pDUP_Mn9TxkqF0etfpWhi5c',
where: and
},
styles:[
{
polygonOptions:{
fillColor: '#FF0000',
fillOpacity: 0.05
}
},
{
where: "Location LIKE 'PERDUE' and "+and,
polygonOptions: {
//fillColor: '#0000FF'
fillOpacity:0.2
}
},
{
where: "GeoBlock = 'AC1C' and "+and,
polygonOptions: {
//fillColor: '#0000FF'
fillOpacity:0.8
}
},
{
where: "Location = 'BENGOUGH' and "+and,
polygonOptions: {
//fillColor: '#0000FF'
fillOpacity:0.99
}
}]
});
Instead of using new Date().getTime() I would suggest to use(when available) e.g. the timestamp of the last modification so that the cached tiles still may be used when no update has been done.
i want to make a chrome extension on google reader and i found a problem. content script can not access to iframes. For all n, window.frames[n] = undefined. And i have this "all_frames": true in manifest.json. Or someone could tell me how to add a button under each article. Thank you!
From taking a quick look at Google Reader's rendered HTML, the only button that is in an IFRAME appears to be the Google Plus +1 button - all the other buttons are not in an IFRAME. So you don't need to worry about the IFRAME.
I'm assuming that the existing buttons are the buttons that appear underneath each article: +1, Share, Email, Keep Unread, Add Tags.
If you want to add a new button to the existing article buttons all you need to do is enumerate the DOM - specifically the "entry-actions" DIV classes and append say a new SPAN with your element/button to each article.
I suspect (but not sure) that Reader may dynamically update the DOM with new articles. If this is the case you may need to track new articles being added to the DOM so you can add your button again. To do this add an event listener for DOMNodeInserted - e.g.
document.addEventListener('DOMNodeInserted', onNodeInserted, false);
UPDATE:
The reason you can't see ".entry-actions" class is because it is added dynamically.
Here is a working very basic example. This will monitor the DOM and when it sees an entry-actions DIV that doesn't have our ".myclass" SPAN button, will add it.
You need to have jquery included in your extension for this to work. I've used jquery-1.7.1.min.js in this example. You will also need an icon file called foo.png too if you cut and paste the example.
manifest.json
{
// Required
"name": "Foo Extension",
"version": "0.0.1",
// Recommended
"description": "A plain text description",
"icons": { "48": "foo.png" },
//"default_locale": "en",
// Pick one (or none)
"browser_action": {
"default_icon": "Foo.png", // optional
"default_title": "Foo Extension" // optional; shown in tooltip
},
"permissions": [ "http://*/", "https://*/", "tabs" ],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery-1.7.1.min.js", "content_script.js" ],
"run_at": "document_idle"
}
]
}
content_script.js
var timer;
document.addEventListener('DOMNodeInserted', onNodeInserted, false);
function onNodeInserted(e)
{
if(timer) clearTimeout(timer);
timer = setTimeout("addButtons()", 250);
}
function addButtons()
{
console.log('add buttons');
var $actions = $(".entry-actions").filter(function() {
return $(this).find('.myclass').length === 0;
});
$actions.append('<span class="myclass">My button</span>');
}