如何防止google map 加载Roboto字体
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                如何防止google map 加载Roboto字体
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                思路是在window.onload中當檢測到加載Roboto字體時,skip掉就可以了。
如下:
var head = document.getElementsByTagName('head')[0];// Save the original methodvar insertBefore = head.insertBefore;// Replace it!head.insertBefore = function (newElement, referenceElement) {if (newElement.href && newElement.href.indexOf('fonts.googleapis.com/css?family=Roboto') > 0) {console.info('Prevented Roboto from loading!');return;}insertBefore.call(head, newElement, referenceElement);};?
完整代碼如下:
<script type="text/javascript">var map, geocoder, bounds;//, marker, infowindow;window.onload = function() {var head = document.getElementsByTagName('head')[0];// Save the original methodvar insertBefore = head.insertBefore;// Replace it!head.insertBefore = function (newElement, referenceElement) {if (newElement.href && newElement.href.indexOf('fonts.googleapis.com/css?family=Roboto') > 0) {console.info('Prevented Roboto from loading!');return;}insertBefore.call(head, newElement, referenceElement);};// Creating a new mapvar options = {zoom: 10,center: new google.maps.LatLng(27.9679125,120.7272096),mapTypeId: google.maps.MapTypeId.ROADMAP,panControl: true,streetViewControl: false,scaleControl: true};map = new google.maps.Map(document.getElementById('map_canvas'), options);// Making the Geocoder callgetCoordinates("Parallelweg 2, Groenlo, Netherlands", "PR50S");return true;}// Create a function the will return the coordinates for the addressfunction getCoordinates(address, name) {// Check to see if we already have a geocoded object. If not we create oneif (!geocoder) {geocoder = new google.maps.Geocoder();}if (!bounds) {bounds = new google.maps.LatLngBounds();}// Creating a GeocoderRequest objectvar geocoderRequest = {address: address}// Making the Geocode requestgeocoder.geocode(geocoderRequest, function(results, status) {// Check if status is OK before proceedingif (status == google.maps.GeocoderStatus.OK) {// Center the map on the returned location//map.setCenter(results[0].geometry.location);// Creating a new marker and adding it to the map// at the position of the marker to the returned locationvar marker = new google.maps.Marker({map: map,position: results[0].geometry.location});if (name) {// Creating a new InfoWindowvar infoWindow = new google.maps.InfoWindow();// Creating the content of the InfoWindow to the address and the returned positionvar content = '<strong>' + name + '</strong><br />';content += '<strong>' + address + '</strong><br />';// Adding the content to the InfoWindowinfoWindow.setContent(content);// Opening the InfoWindow//infoWindow.open(map, marker);google.maps.event.addListener(marker, 'click', function() {infoWindow.open(map, marker);});}// Extend bounds to contain new markerbounds.extend(marker.getPosition());//bounds.extend(infoWindow.getPosition());map.fitBounds(bounds);}// Zoom out a little more to see some surroundingsmap.setZoom(map.getZoom() - 5);});}</script>?
?
?
總結(jié)
以上是生活随笔為你收集整理的如何防止google map 加载Roboto字体的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 【C语言进阶深度学习记录】三十一 数组作
- 下一篇: caffe 初学参考链接
