[OpenLayers-Users] Towards an eraser tool in OpenLayers

Dan Garland dan at dangarland.co.uk
Fri Jan 29 04:42:58 EST 2010


Hi Atle,

Yes we tried an approach that used the split function on a feature to 
remove points, calculating the necessary distance to move points away 
from the intersection, and found it wasn't nearly fast enough to match 
the eraser function one might expect in say an graphics package. I 
gather that from the responses (and non-responses!) that masking is more 
difficult but might be my only option.

Thanks for the ideas so far... I'll post anything I discover on the topic

Dan

Atle Frenvik Sveen wrote:
> Aha, now I understand what you mean.
> 
> Not that I am any export on this, but I still think it is a bit ugly to
> mask the SVG and these things. The underlaying vector features will not
> reflect the change if you do so, but perhaps it is the best solution for
> a given context?
> 
> Another approach could be to make an "eraser tool" by drawing a line,
> and checking for intersects between this line and the existign
> line-features in your layer.
> 
> Then you could split the lines that do intersect, and move their
> endpoints a certain distance away from the split point? Or maybe this
> will get to complicated?
> 
> I am not sure what is the right solution, but I personally would have
> tried to make sure that the underlying vectors where indeed affected by
> the erasing, not just the presentation of them. If this is possible (or
> reasonable) to do with OpenLayers I cannot say.
> 
> Anyways: good luck!
> 
> -atle
> 
> On Thu, 2010-01-28 at 11:42 +0000, Dan Garland wrote:
>> Thanks for your response Atle,
>>
>> I'm trying to achieve a result that when I draw lots of lines on a page, 
>> that I can erase everything underneath a path, preserving the parts of 
>> the features not touched by the eraser. This isn't therefore a case of 
>> removing the entire feature (more of a 'hide' feature) but cutting out 
>> parts of the drawing. I've tried deleting points from the geometry, but 
>> found it imprecise and slow.
>>
>> Thanks,
>> Dan
>>
>> Atle Frenvik Sveen wrote:
>>> Hmm, I think your proposal looks overly complicated. Why don't just
>>> remove the feature from the layer it is drawn on? 
>>>
>>> And possibly store it somewhere else if you want to regret the deletion?
>>>
>>> Or am I misunderstanding you here?
>>>
>>> -atle
>>>
>>> On Wed, 2010-01-27 at 12:28 +0000, Dan Garland wrote:
>>>> Any takers? Or am I on the wrong track here?
>>>>
>>>> Thanks in advance,
>>>> Dan
>>>>
>>>> Dan Garland wrote:
>>>>> Hi all,
>>>>>
>>>>> I'm a Ruby on Rails developer working on my first project with 
>>>>> OpenLayers. I'm tasked with developing an free-hand eraser tool that can 
>>>>> erase features created by the drawFeatures tool. Amongst other things 
>>>>> we've tried, my thinking is moving towards creating a SVG mask, based on 
>>>>> the existing drawing tool, in which the 'erased' line is actually a 
>>>>> black line within a white, rectangular SVG mask, which when applied over 
>>>>> the top of the tile layer would mask any drawn features from underneath. 
>>>>> I anticipate something like this:
>>>>>
>>>>> <svg width="8cm" height="8cm" viewBox="0 0 800 800" version="1.1"
>>>>>       xmlns="http://www.w3.org/2000/svg" 
>>>>> xmlns:xlink="http://www.w3.org/1999/xlink">
>>>>>    <defs>
>>>>>      <mask id="Mask" maskUnits="userSpaceOnUse" x="0" y="0" width="3968" 
>>>>> height="2964">
>>>>>        <rect x="0" y="0" width="3968" height="2964" fill="white" />
>>>>>        <!-- The 'eraser' line -->
>>>>>        <polyline fill="none" stroke="black" stroke-width="25" 
>>>>> points="400,0 400,800" />
>>>>>      </mask>
>>>>>    </defs>
>>>>>
>>>>> <!-- Example drawn features -->
>>>>>
>>>>>    <polyline id="myline" points="0,0 800,800" fill="none" 
>>>>> stroke-opacity="1" stroke-width="25" stroke-linecap="round" 
>>>>> stroke-linejoin="round" stroke-dasharray="none"/>
>>>>>    <polyline id="myline2" points="0,100 800,100" fill="none" 
>>>>> stroke-opacity="1" stroke-width="25" stroke-linecap="round" 
>>>>> stroke-linejoin="round" stroke-dasharray="none"/>
>>>>>    <polyline id="myline3" points="0,400 800,400" fill="none" 
>>>>> stroke-opacity="1" stroke-width="25" stroke-linecap="round" 
>>>>> stroke-linejoin="round" stroke-dasharray="none"/>
>>>>>
>>>>>     <use xlink:href="#myline" stroke="red" mask="url(#Mask)" />
>>>>>     <use xlink:href="#myline2" stroke="red" mask="url(#Mask)" />
>>>>>     <use xlink:href="#myline3" stroke="red" mask="url(#Mask)" />
>>>>>
>>>>> </svg>
>>>>>
>>>>> The problems I face with this approach is knowing how best to manipulate 
>>>>> the existing SVG object being referenced by OpenLayers. I wonder whether 
>>>>> it is feasible in OpenLayers to develop a control based on the 
>>>>> drawFeature tool that
>>>>>
>>>>> 1) Adds the mask <defs> section to the SVG Root at startup
>>>>> 2) Creates polyline elements with the mask
>>>>> 3) Adds <use> elements for each element in the tile layer to connect the 
>>>>> id and the mask
>>>>>
>>>>> Before I dive in and spent hours in an unfamiliar area I wonder if any 
>>>>> OpenLayers developers have encountered this use case and have a better 
>>>>> solution, or can shed any light on this proposed approach.
>>>>>
>>>>> Best Regards,
>>>>> Dan Garland
>>>>>
>>>>> _______________________________________________
>>>>> Users mailing list
>>>>> Users at openlayers.org
>>>>> http://openlayers.org/mailman/listinfo/users
>>>> _______________________________________________
>>>> Users mailing list
>>>> Users at openlayers.org
>>>> http://openlayers.org/mailman/listinfo/users
>>>>
>>>
> 
> 



More information about the Users mailing list