0

I have just tried the solutions presented in Why is an embedded google map altering Safari's font rendering? and was hoping this would fix the issue, seeing as they are both webkit based browsers.

However, I still see a difference with some text, specifically, the text which is within position: fixed sections of content (i.e. the header, and menu sections) after I add the Google Map to the page.

I am using the Google Maps API to embed the map on the page on page load as follows:

$(document).ready(function() {        
    createMap("gmap", "<?php echo $this->business['location']; ?>");
});

function createMap(target, location) {
    var url = "http://maps.google.com/maps/api/geocode/json?address=" + location + "&sensor=false";
    $.getJSON(url,function (data, textStatus, jqXHR) {
        var r = data.results[0];            
        var jobLatLang = new google.maps.LatLng(r.geometry.location.lat, r.geometry.location.lng);
        var mapOptions = {
            zoom: 12,
            center: jobLatLang
        };

        var map, marker;
        map = new google.maps.Map(document.getElementById(target),mapOptions);
        marker = new google.maps.Marker({
            position: jobLatLang,
            map: map,
            title: r.formatted_address
        });
        marker.setMap(map);
        map.panTo(marker.getPosition());
    });
}

and if I block the call to createMap there is no issue with the text rendering (of course this also means no map) and I have no idea why this would cause text rendered within position: fixed elements to possibly re-render?

Any ideas?

UPDATE: I have now been able to get the <div> element containing the map to prevent the addition of any further translates by adding style="-webkit-transform:none !important;" however the problem still persists.

UPDATE 2: I have just found a horrible workaround, which more just confirms the issue, than fixes it. using the following function from Is it possible to remove inline styles with jQuery?

(function($)
{
    $.fn.removeStyle = function(style)
    {
        var search = new RegExp(style + '[^;]+;?', 'g');

        return this.each(function()
        {
            $(this).attr('style', function(i, style)
            {
                return style.replace(search, '');
            });
        });
    };
}(jQuery));

and adding this awful piece of code after the $.getJSON call

setTimeout(function() {
    $("#" + target).removeStyle("-webkit-transform");
    $("#" + target).find("*").each(function() {
         $(this).removeStyle("-webkit-transform");
    });
}, 5000);

The fuzzy text disappears after the removal of all the inline -webkit-transform styles.

UPDATE 3: I have decided to just use this work around, which is a slightly improved version of update 2, until something better becomes available. I have added an idle event listener to the Google Map which according to the documentation https://developers.google.com/maps/documentation/javascript/reference#Map

This event is fired when the map becomes idle after panning or zooming.

which in my case is what is required. Please note, I tried attaching the event listener to tilesloaded and you would think it would work, however it does not.

So putting it all together I have the following:

(function($)
{
    $.fn.removeStyle = function(style)
    {
        var search = new RegExp(style + '[^;]+;?', 'g');

        return this.each(function()
        {
            $(this).attr('style', function(i, style)
            {
                return style.replace(search, '');
            });
        });
    };
}(jQuery));

var mapTargetElement, mapIdleListener;
function createMap(target, location) {
    mapTargetElement = target;
    var url = "http://maps.google.com/maps/api/geocode/json?address=" + location + "&sensor=false";
    $.getJSON(url,function (data, textStatus, jqXHR) {
        var r = data.results[0];            
        var jobLatLang = new google.maps.LatLng(r.geometry.location.lat, r.geometry.location.lng);
        var mapOptions = {
            zoom: 12,
            center: jobLatLang
        };

        var map, marker;
        map = new google.maps.Map(document.getElementById(target),mapOptions);
        mapIdleListener = google.maps.event.addListener(map,'idle',removeWebkitTransforms);
        marker = new google.maps.Marker({
            position: jobLatLang,
            map: map,
            title: r.formatted_address
        });
        marker.setMap(map);
        map.panTo(marker.getPosition());        
    });
}

function removeWebkitTransforms() {
    google.maps.event.removeListener(mapIdleListener);
    $("#" + mapTargetElement).removeStyle("-webkit-transform").find("*").each(function() {
        $(this).removeStyle("-webkit-transform");
    });
}
Community
  • 1
  • 1
samazi
  • 1,161
  • 12
  • 24
  • Does [this](https://code.google.com/p/chromium/issues/detail?id=20574) match your problem? In that case, looks like it's been unresolved for quite a few years. – elzi Nov 11 '14 at 00:30
  • @elzi Sure, that definitely seems to be a candidate as the rendered Google Map has `-webkit-transform: translateZ(0px);` which is apparently to force GPU access to render the page. Only difference is the rendering in this case is done after the DOM has loaded. I might try to delay loading the map for a few seconds and see what happens. – samazi Nov 11 '14 at 00:32
  • FYI, delaying the map render for 5 seconds causes the same issue. – samazi Nov 11 '14 at 00:36
  • @elzi issue still remains with your suggestion, tried also adding `box-sizing: border-box` with no luck – samazi Nov 11 '14 at 00:55
  • if you can get it online somewhere or reproduce the error in a demo I'm happy to help further. Out of ideas for now and can't do much without tinkering in inspector. – elzi Nov 11 '14 at 00:58
  • @elzi Sure the website is http://www.yewin.com and we are currently doing some BETA testing, so if you want to request an invite just put your email address in on the landing page and you can create an account. Then you will need to create a business page and the problem will show up in the action bar and the menu. – samazi Nov 11 '14 at 01:16

1 Answers1

0

Code:

.google-map.google-map-wide 
{ 
   -webkit-transform: none !important;"
}

into CSS code.

And it sorted the font rendering issue straight away.

Jatin
  • 3,065
  • 6
  • 28
  • 42
Marcos
  • 1
  • 1