Google地图v3 - 防止API加载Roboto字体 [英] Google Maps v3 - prevent API from loading Roboto font
本文介绍了Google地图v3 - 防止API加载Roboto字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Google会将地图容器中的样式新增至覆写我的样式。
我知道如何解决这个问题。但是API(v3.8 / 9 / exp)也加载了我不真正需要/想要的webfontRoboto。
Google adds styles to the maps container that override my styles.
I know how to fix this. But the API (v3.8/9/exp) also loads the webfont "Roboto" which I don't really need/want.
有任何设置/选项/方式?
我可以阻止API添加额外的CSS吗?
Is there any setting/option/way around this?
Can I prevent the API from adding the extra CSS?
这是google-maps-API添加的代码我的网页的< head>
:
This is the code the google-maps-API adds to the <head>
of my page:
<style type="text/css">
.gm-style .gm-style-cc span,
.gm-style .gm-style-cc a,
.gm-style .gm-style-mtc div {
font-size:10px
}
</style>
<link type="text/css"
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700">
<style type="text/css">
@media print {
.gm-style .gmnoprint,
.gmnoprint {
display:none
}
}
@media screen {
.gm-style .gmnoscreen,
.gmnoscreen {
display:none
}
}
</style>
<style type="text/css">
.gm-style {
font-family: Roboto,Arial,sans-serif;
font-size: 11px;
font-weight: 400;
text-decoration: none
}
</style>
推荐答案
您可以在Google脚本调用之前替换insertBefore it:
You can replace the insertBefore method before the Google script invokes it:
http://jsfiddle.net/coma/7st6d9p2/
var head = document.getElementsByTagName('head')[0];
// Save the original method
var insertBefore = head.insertBefore;
// Replace it!
head.insertBefore = function (newElement, referenceElement) {
if (newElement.href && newElement.href.indexOf('https://fonts.googleapis.com/css?family=Roboto') === 0) {
console.info('Prevented Roboto from loading!');
return;
}
insertBefore.call(head, newElement, referenceElement);
};
// Check it!
new google.maps.Map(document.getElementById('map'), {
center : new google.maps.LatLng(51.508742,-0.120850),
zoom : 16,
mapTypeId : google.maps.MapTypeId.ROADMAP,
streetViewControl: false,
zoomControl : false,
panControl : false,
mapTypeControl : false
});
这篇关于Google地图v3 - 防止API加载Roboto字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文