I'd like to refresh google maps after a style change.
I'm following this basic styling example
But how do I swap/refresh/reload with/to the new style, after setting it via:
// Enable the visual refresh
google.maps.visualRefresh = true;
function setMapStyle(mapStyle)
{
map.setOptions({styles: mapStyle});
}
Perhaps its possible to addListener on style options?
Related
There has been a change in the click behavior in the model browser from version 2 to version 3 of the Forge Viewer. In v2, a single click would select the elements and a double click would zoom to the selected elements. In v3, a single click will zoom to the elements. Sometimes this is great, but often it would be nice to disable this behavior. Is there an easy way to do this today? And if not, could it be possible to add a disableZoomOnSelection function to the viewer API?
I know that the eyes in the browser will take care of the show and hide elements, but it’s very easy to klick in the three by accident and suddenly the viewer zoom without the user intention.
Regards
Frode
I dig that code for you looking at the implementation of the ViewerModelStructurePanel that I was exposing in that article: Supporting multiple models in the new ModelStructurePanel
Events that occur in the tree are mapped to predefined actions through the options.docStructureConfig object, so the workaround is to instantiate a new ViewerModelStructurePanel with the desired options:
viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, () => {
var options = {
docStructureConfig: {
// go with default, which is viewer.select(node)
// click: {
// onObject: ["toggleOverlayedSelection"]
//},
clickShift: {
onObject: ["toggleMultipleOverlayedSelection"]
},
clickCtrl: {
onObject: ["toggleMultipleOverlayedSelection"]
}
}
}
var customModelStructurePanel =
new Autodesk.Viewing.Extensions.ViewerModelStructurePanel(
viewer, 'Browser', options)
viewer.setModelStructurePanel(customModelStructurePanel)
})
The double-click however is not linked to an event in the current implementation, so for a more powerful customization I would recommend you replace the whole implementation by a custom one as exposed in the article and implement desired action handlers. I implemented it as drop-in replacement, so in that case you just need to include it to your html after the viewer script and don't have to replace the model browser in OBJECT_TREE_CREATED_EVENT
The model browser receives an options object in its constructor. There, you can specify the actions for different events (click, clickCtrl, clickShift, etc).
To set the old behavior you can try the following:
var options = {};
options.docStructureConfig = {
"click": {
"onObject": ["isolate"]
},
"clickCtrl": {
"onObject": ["toggleVisibility"]
}
};
NOP_VIEWER.setModelStructurePanel(new ave.ViewerModelStructurePanel(NOP_VIEWER, "", options));
NOP_VIEWER can be replaced with your own viewer variable.
I have a v3 google map and in the bottom-right corner of the map, there is a "Report a map error" link overlaid onto the map. Does anyone know if it is possible to remove this from the map?
Edit:
Here is an example of what I mean: http://jsfiddle.net/ahfA5/
You could style the map to get rid of this. Check this out.
Notice that if you compare the first two screenshots, the "Report a map error" link is present in the first, but not in the second.
The simplest way to apply a dummy style to the map so that it still looks like google maps but without the error link would be to do the following:
const styleOptions = {
name: `Dummy Style`,
}
const MAP_STYLE = [
{
featureType: `road`,
elementType: `all`,
stylers: [{ visibility: `on` }],
},
]
const mapType = new google.maps.StyledMapType(MAP_STYLE, styleOptions)
map.mapTypes.set(`Dummy Style`, mapType)
map.setMapTypeId(`Dummy Style`)
Here's the updated JSFiddle.
An issue with the custom style map is that when switching back from map/satellite or street view it does not return to the custom style instance.
// remove the wrapping container
.gm-style-cc:last-child {
display: none !important;
}
// remove the link only
a[title="Report errors in the road map or imagery to Google"] {
display: none !important;
}
There isn't a way to disable this feature properly via the API.
Keep in mind, if you hide it without using the API it will violate the Google Maps API Terms of Service which, as of the date of this post, doesn't allow developers to manipulate this link. Refer to 10.1.1.f.x:
delete, obscure, or in any manner alter any brand features, logos, warnings, notices... or links that appear in the Service or the Content;
The example presented here does works:
var styleOptions = {
name: "Dummy Style"
};
var MAP_STYLE = [
{
featureType: "road",
elementType: "all",
stylers: [
{ visibility: "on" }
]
}
];
var mapType = new google.maps.StyledMapType(MAP_STYLE, styleOptions);
map.mapTypes.set("Dummy Style", mapType);
map.setMapTypeId("Dummy Style");
Initially the map get displayed WITHOUT the link on the Default map!
BUT
upon selecting either:
the MAP/Terrain or the SATELLITE/Label from the menu the Report map error link RETURNS on the map refresh.
If you choose as an alternative to create a StyledMapType MAP.
The Report a map error link can be disabled permanently on the StyledMap.
But you now have two MAPS (Default and the StyledMap).
I couldn't find a way to hide the default map.
Bottom line I couldn't remove the link Report a map error from the Default map permanently.
You can not do this - Google's attempt at providing accurate data via crowd-sourcing will cause this on occasion. Live with it and accept that limitation. you can layer a custom element on top of the canvas if you position it absolute or fixed. But that kind of violates their TOS as it also covers the copyright notice.
You can hide it using CSS trick. It's dirty but working:
/* remove ugly google report-a-bug button from maps */
.gmnoprint:last-child {
display: none !important;
}
I'm adding new layers to my google map application and want to add new logo there. Like in this case:
Is there some clean way how to do it in the google maps API, like using GCopyright and GCopyrightCollection classes in google maps API v2? Or is this missing in v3 (like many other features) and I have to do it manually?
In Google Maps API v3, there's no copyright API. Note that in v2, the GCopyright was used to add textual copyright information, not a logo.
To add a logo to the map you have to create a custom control.
Create a logo custom control:
function MyLogoControl(controlDiv) {
controlDiv.style.padding = '5px';
var logo = document.createElement('IMG');
logo.src = 'img/my_logo.png';
logo.style.cursor = 'pointer';
controlDiv.appendChild(logo);
google.maps.event.addDomListener(logo, 'click', function() {
window.location = 'http://www.example.com';
});
}
Add the control to the map:
var logoControlDiv = document.createElement('DIV');
var logoControl = new MyLogoControl(logoControlDiv);
logoControlDiv.index = 0; // used for ordering
map.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(logoControlDiv);
Similarly a copyright information can be added. But you can't modify the default copyrights, you have to add yours somewhere next to the defaults.
If you want to add a copyright information that's bound to a bounding box and/or zoom level, you have to create such behaviour manually.
I've already subclass my overlay object under the instruction of google document, and my onAdd() function is listed below:
MyOverlay.onAdd() {
var div_parent = document.createElement("DIV");
var div_child = document.createElement("DIV");
div_child.innerHTML = "Click Me";
div_parent.appendChild( div_child );
this.getPanes().overlayLayer.appendChild(div_parent);
var this = that;
google.maps.event.addDomListener( div_parent, 'click', function(){
google.maps.event.trigger(that, 'click'); // from [http://stackoverflow.com/questions/3361823/make-custom-overlay-clickable-google-maps-api-v3]
alert("Clicked");
} );
}
My code can work well ONLY in IE, but in Firefox and Chrome, the click event will not be triggered anymore.
So how to solve the problem?
Instead of using overlayLayer mapPanes, you should use overlayMouseTarget.
Reference: http://code.google.com/apis/maps/documentation/javascript/overlays.html#CustomOverlays
I know this is an old post, but if you were wondering, here is the solution:
In your code above, you need to change the overlay function from:
this.getPanes().overlayLayer.appendChild(div_parent);
to:
this.getPanes().overlayMouseTarget.appendChild(div_parent);
Also note although your click events will be captured on desktop even if you use overlay pane, for touch events to work, mouse target pane is necessary.
Are there any contextual menus available for Google Maps v3?
You can add context menu as it is decribed here How to add context menu to google maps, using api V3:
Here is a full JQuery solution : http://gmap3.net/examples/context-menu.html
Old question but it came up in my googling so I thought I would post the simplest answer. It's a context menu without the use of more 3rd party js libraries. There's also a latlon object in the event that you can get the lat/lon for where the person clicked, to add a maker or whatever.
var contextMenu = google.maps.event.addListener(
map,
"rightclick",
function (event) {
// use JS Dom methods to create the menu
// use event.pixel.x and event.pixel.y
// to position menu at mouse position
$('.contextmenu').remove(); //remove previous context menus
contextmenuDir = document.createElement("div");
contextmenuDir.className = 'contextmenu';
//now add our options.
contextmenuDir.innerHTML = '<a id="menu1"><div class="context">menu item 1<\/div><\/a>'
+ '<a id="menu2"><div class="context">menu item 2<\/div><\/a>';
$(map.getDiv()).append(contextmenuDir);
contextmenuDir.style.visibility = "visible";
// might need to offset if you have moved the map div like i did (then - the pixel size off)
$('.contextmenu').css('left', event.pixel.x );
$('.contextmenu').css('top', event.pixel.y);
console.log(event); //log some details about the object we get
});
None yet. Google working on one now.