Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix polygon fill and opacity interaction. #744

Merged
merged 1 commit into from
Nov 1, 2017
Merged

Conversation

manthey
Copy link
Contributor

@manthey manthey commented Oct 31, 2017

When using a constant opacity but a non-constant fill, the fill would appear to not be honored.

When using a constant opacity but a non-constant fill, the fill would appear to not be honored.
@manthey
Copy link
Contributor Author

manthey commented Oct 31, 2017

Paste this code into the editor tutorial to see the problem in master and the fix in this branch:

var map = geo.map({
  node: '#map',
  center: {
    x: -88.0,
    y: 29
  },
  zoom: 4
});
map.createLayer('osm');
var layer = map.createLayer('feature', {
  features: ['polygon']
});
var polygons = layer.createFeature('polygon', {selectionAPI: true});
$.getJSON('../../data/land_polygons.json').done(function (data) {
  polygons
    .position(function (d) {
      return {x: d[0], y: d[1]};
    })
    .data(data)
    .style({
      uniformPolygon: true,
      fill: function (d, i) { return i!=125; },  // Cuba
      fillOpacity: 0.5,
      fillColor: function (d, idx, poly, polyidx) {
        return poly.hover ? 'blue' : 'yellow';
      },
      stroke: function (poly, polyidx) {
        return poly.hover;
      },
      strokeWidth: 1,
      strokeColor: {r: 0, g: 0, b: 0}
    })
    .geoOn(geo.event.feature.mouseover, function (evt) {
      if (!evt.data.hover) {
        evt.data.hover = true;
        this.modified();
        this.draw();
      }
    })
    .geoOn(geo.event.feature.mouseout, function (evt) {
      if (evt.data.hover) {
        evt.data.hover = false;
        this.modified();
        this.draw();
      }
    })
    .draw();
});

@manthey manthey merged commit c8bb321 into master Nov 1, 2017
@manthey manthey deleted the fix-uniform-opacity branch November 1, 2017 13:14
@aashish24
Copy link
Member

@matthewma7 this should fix your use-case I believe. Perhaps you want to go back to changing fill and not opacity since that would optimize the code I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants