Reputation: 83
I am trying to create an application where I have 3 layers.
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
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.
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)
Create a dragbox
interaction to use for you user to draw box
Select features from both layers that fall within your dragbox
Use the JSTS library to find the intersections of lines , polygons and the draw box
Create a new vector layer with full visibility and place the intersecting features
here is your fiddle
Upvotes: 3