需求:
设置人员需要在图片上框选区域,并且后台针对区域读出数据后显示热点。
做法:
直接上代码:
/*****
* 作者:jww_dragon@163.com
* 依赖: jquery
*
********************/
var goog = function(tag) {
this._hotpoint = [];
this._square = {};
if (typeof tag === "string") {
this.canvas = document.getElementById(tag);
} else {
this.canvas = tag;
}
this.context = this.canvas.getContext('2d');
this.colorStyle = {};
this.colorStyle.selectColor = "rgba(255,0,0,0.8)";
this.colorStyle.selectedColor = "rgba(255,0,0,0.3)";
this.colorStyle.showColorBG = "rgba(0,0,0,0.2)";
this.colorStyle.shadowColor = "#000000";
this.colorStyle.fontStyle = "16px Arial Black";
this.colorStyle.fontColor = "yellow";
this.context.shadowOffsetX = 5;
this.context.shadowOffsetY = 5;
this.context.shadowBlur = 10;
}
/**
*换一个id监听(一般用不到)
**/
goog.prototype.listen = function(documentId) {
this.canvas = document.getElementById(documentId);
this.canvas = document.getElementById(documentId);
this.context = this.canvas.getContext('2d')
}
/**
*颜色配置
* selectColor,selectedColor 框选颜色,默认红色, showColorBG 展示的背景蒙层色
* shadowColor 影阴颜色,fontStyle 字体,fontColor 字体颜色
**/
goog.prototype.setColor = function(type, color) {
if (typeof color != "undefined" && type != "undefined") {
this.colorStyle[type] = color;
}
}
/**
* 以下是选择部分
***/
goog.prototype.init_mask = function() {
var position_top = this.canvas.offsetTop;
var position_left = this.canvas.offsetLeft;
this.temp_canvas = document.createElement("canvas");
this.temp_canvas.setAttribute('width', this.canvas.width);
this.temp_canvas.setAttribute('id', "mask-gogo123");
this.temp_canvas.setAttribute('height', this.canvas.height);
this.temp_canvas.setAttribute('style', 'position: absolute;left: '
+ position_left + 'px;top: ' + position_top + 'px;');
this.canvas.parentNode.appendChild(this.temp_canvas);
//return temp_canvas;
}
goog.prototype.drowInitSquare = function(_list) {
this.context.shadowColor = this.colorStyle.shadowColor;
this.context.font = this.colorStyle.fontStyle;
//this.con
/*****
* 作者:jww_dragon@163.com
* 依赖: jquery
*
********************/
var goog = function(tag) {
this._hotpoint = [];
this._square = {};
if (typeof tag === "string") {
this.canvas = document.getElementById(tag);
} else {
this.canvas = tag;
}
this.context = this.canvas.getContext('2d');
this.colorStyle = {};
this.colorStyle.selectColor = "rgba(255,0,0,0.8)";
this.colorStyle.selectedColor = "rgba(255,0,0,0.3)";
this.colorStyle.showColorBG = "rgba(0,0,0,0.2)";
this.colorStyle.shadowColor = "#000000";
this.colorStyle.fontStyle = "16px Arial Black";
this.colorStyle.fontColor = "yellow";
this.context.shadowOffsetX = 5;
this.context.shadowOffsetY = 5;
this.context.shadowBlur = 10;
}
/**
*换一个id监听(一般用不到)
**/
goog.prototype.listen = function(documentId) {
this.canvas = document.getElementById(documentId);
this.canvas = document.getElementById(documentId);
this.context = this.canvas.getContext('2d')
}
/**
*颜色配置
* selectColor,selectedColor 框选颜色,默认红色, showColorBG 展示的背景蒙层色
* shadowColor 影阴颜色,fontStyle 字体,fontColor 字体颜色
**/
goog.prototype.setColor = function(type, color) {
if (typeof color != "undefined" && type != "undefined") {
this.colorStyle[type] = color;
}
}
/**
* 以下是选择部分
***/
goog.prototype.init_mask = function() {
var position_top = this.canvas.offsetTop;
var position_left = this.canvas.offsetLeft;
this.temp_canvas = document.createElement("canvas");
this.temp_canvas.setAttribute('width', this.canvas.width);
this.temp_canvas.setAttribute('id', "mask-gogo123");
this.temp_canvas.setAttribute('height', this.canvas.height);
this.temp_canvas.setAttribute('style', 'position: absolute;left: '
+ position_left + 'px;top: ' + position_top + 'px;');
this.canvas.parentNode.appendChild(this.temp_canvas);
//return temp_canvas;
}
goog.prototype.drowInitSquare = function(_list) {
this.context.shadowColor = this.colorStyle.shadowColor;
this.context.font = this.colorStyle.fontStyle;
//this.con