jQuery Image Annotation Plugin

 

jQuery Image Annotation Plugin

Tuesday, 17 March 2009

Download Released: 2nd April, 2009

Flickr was the first site to widely introduce the concept of annotating images with user comments. This concept was first pioneered by the Fotonotes JavaScript library, and has since been further popularised by Web 2.0 sites like Facebook.

When my current client asked my to integrate simlar functionality into there site, I started to look around for a jQuery plugin that could provide this, but none was available. The Image Annotate library for Drupal is based upon jQuery UI however, so taking this for a base, I adopted it to just use jQuery 1.2.6.

You can see a live example here.

Using the plugin is straight forward, simply hookup the plugin an call the imageAnnotate function on the image you would like to annotate.

  1. <html>  
  2.     <head>  
  3.   
  4.         <style type="text/css" media="all">@import "/css/annotation.css";</style>  
  5.         <script type="text/javascript" src="/js/jquery-1.2.6.min.js"></script>  
  6.         <script type="text/javascript" src="/js/jquery-ui-1.5.3.min.js"></script>  
  7.         <script type="text/javascript" src="/js/jquery.annotate.js"></script>  
  8.   
  9.         <script language="javascript">  
  10.   
  11.             $(window).load(function() {   
  12.   
  13.                $("#toAnnotate").annotateImage({   
  14.                     editable: true,   
  15.                     useAjax: false,   
  16.                     notes: [ { "top": 286,    
  17.                                "left": 161,    
  18.                                "width": 52,    
  19.                                "height": 37,    
  20.                                "text": "A read only annotation",    
  21.                                "editable": false },   
  22.                              { "top": 134,    
  23.                                "left": 179,    
  24.                                "width": 68,    
  25.                                "height": 74,    
  26.                                "text": "An editable annotation",    
  27.                                "editable": true } ]                       
  28.                 });   
  29.   
  30.             });   
  31.   
  32.         </script>  
  33.   
  34.     </head>  
  35.     <body>  
  36.   
  37.         <div class="main-content">  
  38.             <img src="/images/annotated.jpg" id="toAnnotate" />  
  39.         </div>  
  40.   
  41.     </body>  
  42. </html>  

The plugin requires jQuery 1.2.6 and jQuery UI with resiable and draggable options included. A saveAsHtml method is available in order to generate a dynamic HTML form with which to save the annotations back to the server.

AJAX Version

EDIT: see this post for server side code.

As well as operating in a static HTML mode, the plugin can load, update and delete annotations using AJAX calls. Specifying Get, Save and Delete URLs, plus setting the useAjax flag to true.

  1. $(window).load(function() {   
  2.                 $("#toAnnotate").annotateImage({   
  3.                     getUrl: "get.rails",   
  4.                     saveUrl: "save.rails",   
  5.                     deleteUrl: "delete.rails",   
  6.                     useAjax: true  
  7.                 });   
  8.             });  
$(window).load(function() {
                $("#toAnnotate").annotateImage({
                    getUrl: "get.rails",
                    saveUrl: "save.rails",
                    deleteUrl: "delete.rails",
                    useAjax: true
                });
            });

The Get url expects data to be returned as an JSON stream.

  1. [ { "top": 286,   
  2.     "left": 161,   
  3.     "width": 52,   
  4.     "height": 37,   
  5.     "text""Small people on the steps",   
  6.     "id""e69213d0-2eef-40fa-a04b-0ed998f9f1f5",   
  7.     "editable"false },   
  8.   { "top": 134,   
  9.     "left": 179,   
  10.     "width": 68,   
  11.     "height": 74,   
  12.     "text""National Gallery Dome",   
  13.     "id""e7f44ac5-bcf2-412d-b440-6dbb8b19ffbe",   
  14.     "editable"true } ]     
[ { "top": 286,
    "left": 161,
    "width": 52,
    "height": 37,
    "text": "Small people on the steps",
    "id": "e69213d0-2eef-40fa-a04b-0ed998f9f1f5",
    "editable": false },
  { "top": 134,
    "left": 179,
    "width": 68,
    "height": 74,
    "text": "National Gallery Dome",
    "id": "e7f44ac5-bcf2-412d-b440-6dbb8b19ffbe",
    "editable": true } ]   

Window Load Event

When calling the plugin it is important to use the $(window).load() event. This event fires after the page an all it's images have loaded. The $(document).ready() event fires after the page has loaded, but before the browser has retrieved all the images. Calling the plugin in this event will result in the plugin rending a blank DIV as the image hasn't loaded.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: OxyPlot Annotation是一个在OxyPlot库中功能强大的注释工具。注释是在图表上添加额外信息以增强数据可视化的一种方式。 使用OxyPlot Annotation,我们可以在图表上添加文本、线条、箭头、圆形等注释元素。这些注释元素可以帮助我们更好地描述和解释图表中的数据。 例如,我们可以使用注释添加一个标题来说明该图表的主题或目的。我们可以选择注释的位置、字体、大小和颜色等样式,以及背景色和边框等外观效果。 除了文本注释,我们还可以使用注释绘制线条,比如表示趋势线或连接两个数据点之间的关系。线条注释有许多样式和参数可以定制,例如线的颜色、线宽、线型和箭头的形状等。 另外,我们还可以使用注释绘制圆形或矩形等形状。这些形状可以用来突出显示某个数据点或数据区域,或者用来标记某个特殊事件发生的位置。 总之,OxyPlot Annotation提供了丰富的注释功能,使我们能够更好地展示和解释数据。通过使用不同的注释元素和样式,我们可以设计出具有吸引力和易读性的图表,帮助用户更好地理解和分析数据。 ### 回答2: OxyPlot Annotation是一个功能强大的注释工具,可以在OxyPlot图表中添加文本、箭头、线条等。它提供了一种方便的方式来标记和注释图表上的特定区域或数据点。 通过OxyPlot Annotation,用户可以在图表中添加静态或动态的注释,以便更好地理解数据的含义。这些注释可以用于指示特定数据点或趋势、说明数据变化的原因、提示特定事件的发生等。 使用OxyPlot Annotation,用户可以自定义注释的外观和位置。例如,可以调整文本的颜色、字体、大小和对齐方式;可以设置箭头的样式、宽度和长度;可以绘制自定义的线条并将其连接到图表上的任何位置。 除了静态注释,OxyPlot Annotation还支持动态注释。用户可以根据特定的事件或条件,在图表上动态地添加、更新或删除注释。这使得用户可以根据数据的变化自动更新注释,以便更好地呈现动态或实时的数据。 总之,OxyPlot Annotation是一个非常实用的工具,能够让用户在OxyPlot图表中添加各种注释,以便更好地理解和展示数据。无论是在科学研究、数据可视化、教育培训还是其他领域,OxyPlot Annotation都能为用户提供强大而灵活的注释功能。 ### 回答3: OxyPlot是一个用于绘制图形和图表的开源.NET绘图库。Annotation(注释)是OxyPlot中的一个重要功能,用于向绘图中添加额外的注释信息,以便更好地展示数据。 OxyPlot中的Annotation提供了多种类型的注释,包括文本注释、线条注释、矩形注释、椭圆注释等。通过调整注释的位置、大小、颜色、字体等属性,我们可以将注释放置在适当的位置,并与图形数据进行关联。 首先,我们可以使用文本注释来添加带有说明或说明的文字。通过指定文字的位置、大小、颜色等属性,我们可以将文字注释放置在图形的特定位置,并使其与相应的数据点相关联。 其次,线条注释可以用于在图形中添加直线或曲线。通过指定线条的起始点和终点,以及颜色、宽度等属性,我们可以将线条注释放置在图形中,并以可视化方式突出显示数据之间的关联。 矩形注释和椭圆注释可以用于在图形中创建一个矩形或椭圆形区域。通过指定其位置、大小、颜色等属性,我们可以将矩形或椭圆注释放置在图形中的指定区域,并突出显示该区域的特定数据。 综上所述,OxyPlot中的Annotation提供了丰富的注释功能,能够帮助我们更好地理解和分析绘图数据。通过使用不同类型的注释对象,并设置其属性,我们可以轻松地将注释添加到图表中,并使其与相应的数据点或数据区域相关联。这样,我们就能够更直观地呈现数据,并更好地传达数据的含义。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值