0

I'm trying to use RLayers for a project, but I'm having a hard time with pretty simple task: "Add some 1 by 1 km squares to the map". I don't know if it's the issue, but I can see when I inspect things that the RMap itself has the correct 100% height (also it works fine), but the RLayerVector has a height of 0 - which could explain why I can't see them:

<RMap width={"100%"} height={"100%"}
    initial={view}
    view={[view, setView]} 
    className="MapView">
    <ROSM />
    <div className="MapView_squares_overlay"> //this div might not be needed
        <RLayerVector zIndex={10}>
            <RStyle.RStyle>
                {/* styling for said squares */}
                <RStyle.RRegularShape points={4}>
                    <RStyle.RFill color="blue" />
                </RStyle.RRegularShape>
            </RStyle.RStyle>
            {zones.map((zone, index) => {
                const x1 = view.center[0]; //to assure that they're within the viewport
                const y1 = view.center[1];
                return <RFeature
                    key={index}
                    geometry={
                        new Polygon([
                            [
                                [x1, y1],
                                [x1, y1 + 1000],
                                [x1 + 1000, y1 + 1000],
                                [x1 + 1000, y1],
                                [x1, y1],
                            ],
                        ])
                    }
                    style={undefined}
                />;
            })}
        </RLayerVector>
    </div>
</RMap>

I got some styling to go with it, but I doubt that that is doing any difference right now:

.MapView{
    position: fixed;
    top:0;
    right:0;
    margin: 0; 
    padding: 0;
    width: 100vw;
    height: 100vh;
}

.MapView_squares_overlay{
    position: absolute;
    top:0;
    right:0;
    margin: 0; 
    padding: 0;
    width: 100vw;
    height: 100vh;
}

Any suggestions are appreciated!

1 Answer 1

1

You are using a point style - it specifies a shape which means that it can be applied only to a point.

Transform your style to

<RStyle.RStyle>
  <RStyle.RFill color='blue' />
</RStyle.RStyle>

and you will see them.

However they will tend to move around as you move and zoom since they depend on the view center.

6
  • I got around to that solution eventually - however, still no dice. Im still using the RLayerVector, with a high zIndex, and now a LineString between the coords. I can get the stroke working just fine, but that fill you're mentioning doesn't work. I got an extends property on it as well set to the the extends of the LineString. Commented Apr 24, 2023 at 15:20
  • A Fill will work only with a Polygon, a LineString has only a Stroke Commented Apr 24, 2023 at 17:12
  • So a LineString only supports stroke - while a Polygon only supports fill (i.e. layer them to get both)? Is there anywhere you can lookup what style properties each support? Commented Apr 25, 2023 at 18:18
  • 1
    Polygon supports both Fill and Stroke. These come from OpenLayers but I was not able to find any explicit documentation. All features that have lines support Stroke. Polygon and all icon-like shapes like Circle and RegularShape support Fill. Only Point supports icon-like shapes. They throw exceptions when nested improperly between them, but none throws an exception when applied to a feature because the feature type is not known in advance. Commented Apr 25, 2023 at 19:33
  • Using open layers for more custom graphics besides your standard location markers might be an edgecase depending on what it is usually used for. I found the ol geom documentation, but no mention of styling properties. Thx for taking the time btw. Greatly enjoy your library so far :) Commented Apr 25, 2023 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.