css - Google Maps v3 - 防止 API 加载 Roboto 字体

标签 css google-maps google-maps-api-3

Google 将样式添加到覆盖我的样式的 map 容器。
我知道如何解决这个问题。但是 API (v3.8/9/exp) 也会加载我并不真正需要/想要的网络字体“Roboto”。

是否有任何设置/选项/解决方法?
我可以阻止 API 添加额外的 CSS 吗?

这是 google-maps-API 添加到 <head> 的代码我的页面:

<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 方法:

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('//fonts.googleapis.com/css?family=Roboto') > -1) {

        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
});

关于css - Google Maps v3 - 防止 API 加载 Roboto 字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25523806/

相关文章:

javascript - Dragend 事件监听器未在 Google Maps API v3 中触发?

javascript - 谷歌地图显示最近的公园并带有标记

c# - Xamarin Forms Geolocator 持续更新位置

javascript - 如何从子元素文本值向父元素添加类?查询

javascript - 如何从视频标签的媒体播放器中删除/隐藏仅播放/暂停图标/按钮

javascript - 设计在 jQuery UI 对话框中弹出的 JS 警报的样式

javascript - 如何同时通过多个请求将数据从 php 传递到 javascript

java - 在 SupportMapFragment Java Android Studio 中使用 getMap() 的替代方法

javascript - 谷歌地图将标签添加到标记信息窗口

css - 当宽度为 100% 时表格换行到下一行