diff --git a/README.md b/README.md
index 519f800..6d825a8 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
Simple directive to draw polygons over image using canvas
### Demo:
-https://sedrakpc.github.io/
+ this demo does not support zoom feature: https://sedrakpc.github.io/
### Preview:

@@ -11,9 +11,11 @@ https://sedrakpc.github.io/
### Usage:
```html
-
+
+
```
### Parameters
@@ -22,5 +24,7 @@ _Param name_ | _Description_
points | where to store drawing polygons coordinates
active | current active polygon
image-url | background image url
-enabled | is drawing enabled
+editable | is drawing enabled
+double-click | double click event on image
+original-size | size of images when points are made
colorArray | color array with hex colors for every polygon layer, if color not specified for layer will be generated randomly
diff --git a/src/angular-canvas-area-draw.js b/src/angular-canvas-area-draw.js
index bfd0b62..5b5966f 100644
--- a/src/angular-canvas-area-draw.js
+++ b/src/angular-canvas-area-draw.js
@@ -1,234 +1,425 @@
+///Require jQuery version 2.1.4
+
'use strict';
(function(window) {
- angular.module('sd.canvas-area-draw', []);
- angular.module('sd.canvas-area-draw')
- .directive('canvasAreaDraw', function () {
+ angular.module('sd.canvas-area-draw', []);
+ angular.module('sd.canvas-area-draw')
+ .directive('canvasAreaDraw', function () {
+ return {
+ restrict: 'A',
+ scope: {
+ imageUrl: '=',
+ enabled: '=editable',
+ doubleClick: '&',
+ palette: '=',
+ points: '=',
+ originalSize: '=',
+ active: '='
+ },
+ controller: function () {
+ this.dotLineLength = function(x, y, x0, y0, x1, y1, o) {
+ function lineLength(x, y, x0, y0){
+ return Math.sqrt((x -= x0) * x + (y -= y0) * y);
+ }
+ if(o && !(o = function(x, y, x0, y0, x1, y1){
+ if(!(x1 - x0)) return {x: x0, y: y};
+ else if(!(y1 - y0)) return {x: x, y: y0};
+ var left, tg = -1 / ((y1 - y0) / (x1 - x0));
+ return {x: left = (x1 * (x * tg - y + y0) + x0 * (x * - tg + y - y1)) / (tg * (x1 - x0) + y0 - y1), y: tg * left - tg * x + y};
+ }(x, y, x0, y0, x1, y1), o.x >= Math.min(x0, x1) && o.x <= Math.max(x0, x1) && o.y >= Math.min(y0, y1) && o.y <= Math.max(y0, y1))){
+ var l1 = lineLength(x, y, x0, y0), l2 = lineLength(x, y, x1, y1);
+ return l1 > l2 ? l2 : l1;
+ }
+ else {
+ var a = y0 - y1, b = x1 - x0, c = x0 * y1 - y0 * x1;
+ return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);
+ }
+ };
+ this.hexToRgb = function(hex){
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
+ return result ? {
+ r: parseInt(result[1], 16),
+ g: parseInt(result[2], 16),
+ b: parseInt(result[3], 16)
+ } : null;
+ };
+ this.getMousePos = function (canvas, evt) {
+ var rect = canvas.getBoundingClientRect();
return {
- restrict: 'A',
- scope: {
- imageUrl: '=',
- enabled: '=',
- palette: '=',
- points: '=',
- active: '='
- },
- controller: function () {
- this.dotLineLength = function(x, y, x0, y0, x1, y1, o) {
- function lineLength(x, y, x0, y0){
- return Math.sqrt((x -= x0) * x + (y -= y0) * y);
- }
- if(o && !(o = function(x, y, x0, y0, x1, y1){
- if(!(x1 - x0)) return {x: x0, y: y};
- else if(!(y1 - y0)) return {x: x, y: y0};
- var left, tg = -1 / ((y1 - y0) / (x1 - x0));
- return {x: left = (x1 * (x * tg - y + y0) + x0 * (x * - tg + y - y1)) / (tg * (x1 - x0) + y0 - y1), y: tg * left - tg * x + y};
- }(x, y, x0, y0, x1, y1), o.x >= Math.min(x0, x1) && o.x <= Math.max(x0, x1) && o.y >= Math.min(y0, y1) && o.y <= Math.max(y0, y1))){
- var l1 = lineLength(x, y, x0, y0), l2 = lineLength(x, y, x1, y1);
- return l1 > l2 ? l2 : l1;
- }
- else {
- var a = y0 - y1, b = x1 - x0, c = x0 * y1 - y0 * x1;
- return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);
- }
- };
- this.hexToRgb = function(hex){
- var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
- return result ? {
- r: parseInt(result[1], 16),
- g: parseInt(result[2], 16),
- b: parseInt(result[3], 16)
- } : null;
- };
- this.getMousePos = function (canvas, evt) {
- var rect = canvas.getBoundingClientRect();
- return {
- x: evt.clientX - rect.left,
- y: evt.clientY - rect.top
- };
- };
- },
- link: function(scope, element, attrs, ctrl){
-
- var activePoint, settings = {};
- var $canvas, ctx, image;
-
- settings.imageUrl = scope.imageUrl;
-
- if(!scope.points) {
- scope.points = [[]];
- }
-
- if(!scope.active) {
- scope.active = 0;
- }
-
- $canvas = $('