fcapellini25 / gmaps-utility-gis

Automatically exported from code.google.com/p/gmaps-utility-gis
0 stars 0 forks source link

fusiontips does not use style object #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. Call 'enableMapTips' as documented.
2. See that the opts object is not passed to the constructor.
3. See that the onAdd function adds styles directly to the tooltip div.

Fix 1: pass the options object to the constructor.
Fix 2: let users pass a CSS class name to the options:

var mapTipOptions = {
    ...
    className: 'mapToolTip'
}

google.maps.FusionTablesLayer.prototype.enableMapTips = function(opts) {
    opts = opts || {};
    var maptip = new FusionTipOverlay(opts, null);
    ...

function FusionTipOverlay(opts) {
    ...
    this.style_ = opts.style || {};
    this.className = opts.className || '';
  }

FusionTipOverlay.prototype.onAdd = function() {
    var div = document.createElement('DIV');
    if (this.className) {
// use user style
        div.className = this.className;
    } else {
// no style to use, so create fallback style
        div.style.border = "1px solid black";
        div.style.position = "absolute";
        div.style.whiteSpace = "nowrap";
        div.style.backgroundColor = "#ffffcc";
        div.style.fontSize = 'x-small';
    }
    if (this.style_) {
// override with style object passed in options
      for (var x in this.style_) {
        if (this.style_.hasOwnProperty(x)) {
          div.style[x] = this.style_[x]
        }
      }
    }

Original issue reported on code.google.com by arthurclemens on 26 Jan 2012 at 11:19

GoogleCodeExporter commented 9 years ago
Is there an example of your use case you can share (or attach to this issue)?
Do you need the css class applied or just the styles that are passed into the 
enableMapTips call?

Like this (temporary test link):
http://www.geocodezip.com/fusiontips/examples/fusiontips_style.html

Original comment by geocodezip on 19 Sep 2013 at 6:00

GoogleCodeExporter commented 9 years ago
Passing a style object in Javascript is not ideal, I would see it as another 
workaround.
Because the downside is that you will have defined styles in different places. 
Especially when you use a CSS preprocessor (LESS, SASS) styles will only be 
managed as CSS.

Original comment by arthurclemens on 19 Sep 2013 at 6:12

GoogleCodeExporter commented 9 years ago
Do you have a patch that does that?

Original comment by geocodezip on 20 Sep 2013 at 6:07

GoogleCodeExporter commented 9 years ago
It is not formally a patch, but the code above should get you a long way.

Original comment by arthurclemens on 20 Sep 2013 at 6:32

GoogleCodeExporter commented 9 years ago
> the code above should get you a long way.

It did. It works for the style object, but not for the className. 

Original comment by geocodezip on 20 Sep 2013 at 8:25

GoogleCodeExporter commented 9 years ago
It does seem to be working:
http://www.geocodezip.com/fusiontips/examples/fusiontips_class.html

Original comment by geocodezip on 3 Oct 2013 at 4:47

GoogleCodeExporter commented 9 years ago
Any feedback on this test version?  It seems to be working, I will check it in 
if there isn't any objection.

Original comment by geocodezip on 5 Oct 2013 at 8:59

GoogleCodeExporter commented 9 years ago
fixed revision 512
http://gmaps-utility-gis.googlecode.com/svn/trunk/fusiontips/examples/fusiontips
_class.html

Original comment by geocodezip on 7 Oct 2013 at 12:44