# j-DrawZone

> The component can draw a zone (polygon). This component uses [OpenLayers](https://openlayers.org/) library with the [OpenStreetMap](https://www.openstreetmap.org/) map engine.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 25636de0932ae5cd9b1bf1ba4bdc00241b7046615bf38ca8cfad6301d3a9b957
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

The component can draw a zone (polygon). This component uses [OpenLayers](https://openlayers.org/) library with the [OpenStreetMap](https://www.openstreetmap.org/) map engine.


__Configuration__:

- `parent {String}` a parent element (default: `undefined`)
- `height {Number}` a fixed (minimal) height (default: `200`)
- `color {String}` a default color for polygon (default: `#fcba03`)
- `zoom {Number}` a default zoom level (default: `11`)
- `readonly {Boolean}` enables readonly mode (default: `false`)
- `stroke {Number}` a stroke width (default: `2`)
- `radius {Number}` a radius size of points in the polygon (default: `7`)
- `center {String}` a default map position (default: `48.73702478789267,19.137712002562715`)
- `opacity {Number}` determines the transparency of the polygon in percentage (default: `40`)
- `required {Boolean}` optional (default: `false`)
- `filter {String}` optional, CSS filter e.g. `filter:grayscale(90%) invert(100%)` (default: `null`)
- __NEW__: `exec {String}` optional, a link to the `function(value, component)` (it will be executed when the value is changed)

__Data-source__ needs to contain:

```js
{
    points: [{ lat: 48.75152530164132, lng: 19.13902142954625 }, { lat: 48.726826662905296, lng: 19.123238694044034 }, ...] // polygon points
    color: '#FD391A', // optional
    zoom: 13 // optional
}
```

__Methods__:

- `component.clear([draw])` clears the polygon `@draw {Boolean}` (default: `false`)
- `component.move(lat, lng)` moves the map to the specific position
- `component.export(opt, callback(base64))` exports data into the picture
    - `opt.width {Number}` required
    - `opt.height {Number}` required
    - `opt.zoom {Number}` (default: `13`)
    - `opt.type {png|jpg}` (default: `png`)
    - `opt.quality {Number}` only for JPEG
    - `opt.points {Array Number}`
    - `opt.color {String}` (default: `config.color`)
    - `opt.radius {Number}` (default: `config.radius`)
    - `opt.opacity {Number}` (default: `config.opacity`)

__Output__:

- is extended by `center { lat: Number, lng: Number }` property

__Good to know__:

- `double click` on vertices (created point) will delete selected point

Use it with `<ui-component name="drawzone">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Sirka & Dodo Marton. Source: the Componentator components repository, MIT license.

```html example.html
<style>
	body { margin: 0; padding: 0; }
</style>

<ui-component name="drawzone" path="map" config="parent:window;color:#FD391A;geolocation:0"></ui-component>

<script>
	var map = { 
		points: []
	};
</script>
```
