简体   繁体   English

基本网址和谷歌geochart

[英]Base url and google geochart

I use <base href="/"> on my site. 我在我的网站上使用<base href="/"> It is the angular project with using google geo chart. 这是使用谷歌地理图表的角度项目。 But I have the problem with legend's gradient. 但我有传说的渐变问题。 It's empty without colors. 没有颜色,它是空的。 I'm trying to use code on callback: 我正在尝试在回调上使用代码:

    $(element).find('svg').each(function () {
        $(this).find("g").each(function () {
            if ($(this).attr('clip-path')) {
                if ($(this).attr('clip-path').indexOf('url(#') == -1) return;
                $(this).attr('clip-path', 'url(' + document.location + $(this).attr('clip-path').substring(4))
            }
        });
        $(this).find("rect").each(function () {
             if ($(this).attr('fill')) {
                 if ($(this).attr('fill').indexOf('url(#') == -1) return;
                 $(this).attr('fill', 'url(' + document.location + $(this).attr('fill').substring(4))
             }
        });
    });

It's work, but when I hover on something on the map, the legend is broken again. 这是工作,但当我在地图上的某些东西上盘旋时,传奇再次被打破。 I can't remove base url because it's need for pretty urls on the angular. 我无法移除基本网址,因为它需要角度上的漂亮网址。 You can see this problem there: http://jsfiddle.net/w5DYt/47/ 你可以在那里看到这个问题: http//jsfiddle.net/w5DYt/47/

Any solutions ? 有解决方案吗

the problem is: you assign the url to particular elements, but when you take a look at the console you'll see that these elements will be removed when you hover a region and a new legend will be created. 问题是:您将URL分配给特定元素,但是当您查看控制台时,您会看到当您悬停区域时将删除这些元素,并且将创建新的图例。

Possible solution: 可能的方法:

Use global styles to override the fill-attributes: 使用全局样式覆盖fill-attributes:

function fixGoogleCharts(element){
    return function () {               
    var  rules=[],
         pre=element+' svg ';
      $('svg defs>*[id]',$(element)).each(function(){
        switch(this.tagName.toLowerCase()){
          case 'lineargradient':
            rules.push(pre + '[fill^="url(#"]{fill:url('+location.href+'#'+this.id+') !important;}');
              break;
          default:break;

        }
      });
      $('head').append('<style>'+rules.join('')+'</style>');

    }
}

Fiddle: http://jsfiddle.net/w5DYt/57/ 小提琴: http//jsfiddle.net/w5DYt/57/

(Note: it's just a quick and dirty way to set global css, but for me it works in all tested browsers...Chrome,FF,Opera,IE,Safari ....for the correct way take a look at insertRule ) (注意:它只是设置全局css的快速而肮脏的方式,但对我而言,它适用于所有经过测试的浏览器...... Chrome,FF,Opera,IE,Safari ......以正确的方式看看insertRule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM