polygon-clipping icon indicating copy to clipboard operation
polygon-clipping copied to clipboard

Example of use without node.js

Open yurikaz opened this issue 5 years ago • 5 comments

Thanx a lot for you lib Please can you give a small example of using it without node.js We have "snake" track and we need to calculate interselections and show it. is anyone hase the same task ?

yurikaz avatar Nov 12 '18 10:11 yurikaz

Hi @yurikaz

Depending on how your app is setup you should be able to use the files within the dist directory of this repo as they have been compiled and are ready for use in the browser.

So for example with the most basic approach you should be able to do something like

// Include one of the dist files in your html doc
<script src="polygon-clipping.min.js"></script>

// Then reference the lib using the polygon-clipping global var that is exposed
<script>
const poly1 = [[[0,0],[2,0],[0,2],[0,0]]]
const poly2 = [[[-1,0],[1,0],[0,1],[-1,0]]]

polygon-clipping.union(poly1, poly2)

</script>

Hope that helps

rowanwins avatar Nov 19 '18 03:11 rowanwins

Thanx for your answer. When I am doing something lile this I have an error "Uncaught ReferenceError: polygon is not defined"

yurikaz avatar Nov 20 '18 19:11 yurikaz

I think if we change in js "polygon-clipping" to "polygonclipping" it will work

yurikaz avatar Nov 20 '18 19:11 yurikaz

ah yes of course the hyphen isn't ideal, that said as a temporary work around you can do something like window['polygon-clipping'].union(poly1, poly2)

rowanwins avatar Nov 21 '18 05:11 rowanwins

Agreed, it would be good to add to the README quickstart instructions for use directly in the browser. I'll try to fit this into the next non-bug-fix-focused release.

mfogel avatar Jan 29 '19 13:01 mfogel