Rooney
Rooney

Reputation: 83

how do i know what line segments and polygons are inside the polygon in openlayers-3?

I am trying to create an application where I have 3 layers.

  1. Background layer (OSM)
  2. Layer - 1 (which has only Line)
  3. Layer - 2 (which has only Polygon)

My layer - 1 and Layer - 2 are invisible and when I draw a polygon in the background layer I want only the lines and polygons (from layer 1 and layer 2) be visible inside the polygon that i have drawn.

Can anyone suggest if it is possible using OL3?

Cheers

Upvotes: 3

Views: 646

Answers (1)

pavlos
pavlos

Reputation: 3081

As @Jonatas sais you have to start and we have to help you afterwards, if we have the time and mood to do it. So the message is "HELP TO GET HELPED".

Anyway, today I am in a good mood and I have some spare time.

So for your case and as long as you want to get back the intersections you need to use the JSTS topology suite. There is also the TURF.js library for such actions but I am not familiar with it. So I ll give a solution using JSTS.

  1. Declare you line and polygon layers and asign a style with 0 alpha chanel so be invisible on map. (within the supplied fiddle I have used 0.2 for alpha chanel so be little bit of visisble for testing purposes)

  2. Create a dragbox interaction to use for you user to draw box

  3. Select features from both layers that fall within your dragbox

  4. Use the JSTS library to find the intersections of lines , polygons and the draw box

  5. Create a new vector layer with full visibility and place the intersecting features

here is your fiddle

Upvotes: 3

Related Questions