mousebird-consulting-inc / WhirlyGlobe

WhirlyGlobe Development
Other
831 stars 255 forks source link

Appear extra lines :addVectors? #424

Closed ludawei closed 8 years ago

ludawei commented 9 years ago

with he following codes:

-(void)testAddVector
{
    UIColor *color = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.6];
    NSDictionary *vectorDict = @{
                   kMaplyColor: color,
                   kMaplyDrawPriority: @(kMaplyLoftedPolysDrawPriorityDefault),
                   kMaplyFilled: @(true),
                   };
    NSString *fileName = [[NSBundle mainBundle] pathForResource:@"USA" ofType:@"geojson"];
    if (fileName)
    {
        NSData *jsonData = [NSData dataWithContentsOfFile:fileName];
        if (jsonData)
        {
            MaplyVectorObject *wgVecObj = [MaplyVectorObject VectorObjectFromGeoJSON:jsonData];

            [baseViewC addVectors:[NSArray arrayWithObject:wgVecObj] desc:vectorDict mode:MaplyThreadCurrent];
        }
    }
}

Some extra lines appear in the filled area: img_0417

And, rotate the earth: img_0423

mousebird commented 9 years ago

Yeah, so the problem here is that you're overlaying a giant polygonal feature on a sphere. We need to break the polygonal feature up to make it look reasonable. In an ideal world I'd use a triangulation engine that understood spheres... but no, we have to hack it.

The way you hack it is to ask the vectors to subdivide on the sphere. Try setting the following in the description dictionary for the addVectors call: kMaplySubdivType: kMaplySubdivSimple, kMaplySubdivEpsilon: @(0.001)

ludawei commented 9 years ago

Yes, I tried setting the following in the description dictionary for the addVectors call: kMaplySubdivType: kMaplySubdivSimple, kMaplySubdivEpsilon: @(0.001)

... but, nothing changes.

I tried some other colors and found that, Set the color of the alpha value is 1.0, extra lines in the filled area disappear.

Is the problem caused by the color of the alpha?

mousebird commented 9 years ago

No, it's the tessellation. Does it at least look different with the subdivision on?

If adjusting the alpha reduces the problem, that seems like a fine workaround.

ludawei commented 9 years ago

But not a fundamental solution.

Setting the alpha to 1.0, will not show the map information behind the filled area. That's not so good.

Any other ideas?

mousebird commented 9 years ago

True. So you'll need to try a few things.

With the subdivision on, set kMaplyFilled: @(NO) Ideally you should see a bunch of rectangles. This is what we're breaking that big areal down into. Try a small subdivision number and see if it results in more rectangles. In any case, post the snapshot so I can see what's going on.

ludawei commented 9 years ago

Hi, The following are some of the test cases:

imageimage image

ludawei commented 9 years ago

image imagedefault

Set kMaplyFilled: @(NO), it works well.

ludawei commented 9 years ago

image imageimage

mousebird commented 9 years ago

Try setting the kMaplySubdivType to kMaplySubdivGrid.

That epsilon my be too low for grid, by the way. Try setting it back to the number I gave you before and then dividing by 10 until you get something.

What you should see is a lot of little grid cells over the areal feature.

ludawei commented 9 years ago

UIColor color = [UIColor colorWithRed:1 green:0 blue:0 alpha:1.0]; NSDictionary vectorDict = @{ kMaplyColor: color, kMaplyDrawPriority: @(kMaplyLoftedPolysDrawPriorityDefault), kMaplySubdivType: kMaplySubdivGrid, kMaplySubdivEpsilon: @(0.000001), kMaplyFilled: @(NO), };

Other settings unchanged , test epsilon from 1 to 0.000001. image But nothing appears. :)

mousebird commented 9 years ago

Unfortunately setting the grid doesn't show up with the outlines. I did get this to work pretty well with the following settings: desc[kMaplyFilled] = @(YES); desc[kMaplySubdivType] = kMaplySubdivGrid; desc[kMaplySubdivEpsilon] = @(0.01);

That seems to clean things up well for me.