[76] | 1 | /** |
---|
| 2 | * Copyright (c) 2008-2010 The Open Source Geospatial Foundation |
---|
| 3 | * |
---|
| 4 | * Published under the BSD license. |
---|
| 5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
---|
| 6 | * of the license. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /** api: (define) |
---|
| 10 | * module = GeoExt |
---|
| 11 | * class = LegendImage |
---|
| 12 | * base_link = `Ext.BoxComponent <http://dev.sencha.com/deploy/dev/docs/?class=Ext.BoxComponent>`_ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | Ext.namespace('GeoExt'); |
---|
| 16 | |
---|
| 17 | /** api: constructor |
---|
| 18 | * .. class:: LegendImage(config) |
---|
| 19 | * |
---|
| 20 | * Show a legend image in a BoxComponent and make sure load errors are |
---|
| 21 | * dealt with. |
---|
| 22 | */ |
---|
| 23 | GeoExt.LegendImage = Ext.extend(Ext.BoxComponent, { |
---|
| 24 | |
---|
| 25 | /** api: config[url] |
---|
| 26 | * ``String`` The url of the image to load |
---|
| 27 | */ |
---|
| 28 | url: null, |
---|
| 29 | |
---|
| 30 | /** api: config[defaultImgSrc] |
---|
| 31 | * ``String`` Path to image that will be used if the legend image fails |
---|
| 32 | * to load. Default is Ext.BLANK_IMAGE_URL. |
---|
| 33 | */ |
---|
| 34 | defaultImgSrc: null, |
---|
| 35 | |
---|
| 36 | /** api: config[imgCls] |
---|
| 37 | * ``String`` Optional css class to apply to img tag |
---|
| 38 | */ |
---|
| 39 | imgCls: null, |
---|
| 40 | |
---|
| 41 | /** private: method[initComponent] |
---|
| 42 | * Initializes the legend image component. |
---|
| 43 | */ |
---|
| 44 | initComponent: function() { |
---|
| 45 | GeoExt.LegendImage.superclass.initComponent.call(this); |
---|
| 46 | if(this.defaultImgSrc === null) { |
---|
| 47 | this.defaultImgSrc = Ext.BLANK_IMAGE_URL; |
---|
| 48 | } |
---|
| 49 | this.autoEl = { |
---|
| 50 | tag: "img", |
---|
| 51 | "class": (this.imgCls ? this.imgCls : ""), |
---|
| 52 | src: this.defaultImgSrc |
---|
| 53 | }; |
---|
| 54 | }, |
---|
| 55 | |
---|
| 56 | /** api: method[setUrl] |
---|
| 57 | * :param url: ``String`` The new URL. |
---|
| 58 | * |
---|
| 59 | * Sets the url of the legend image. |
---|
| 60 | */ |
---|
| 61 | setUrl: function(url) { |
---|
| 62 | this.url = url; |
---|
| 63 | var el = this.getEl(); |
---|
| 64 | if (el) { |
---|
| 65 | el.un("error", this.onImageLoadError, this); |
---|
| 66 | el.on("error", this.onImageLoadError, this, {single: true}); |
---|
| 67 | el.dom.src = url; |
---|
| 68 | } |
---|
| 69 | }, |
---|
| 70 | |
---|
| 71 | /** private: method[onRender] |
---|
| 72 | * Private method called when the legend image component is being |
---|
| 73 | * rendered. |
---|
| 74 | */ |
---|
| 75 | onRender: function(ct, position) { |
---|
| 76 | GeoExt.LegendImage.superclass.onRender.call(this, ct, position); |
---|
| 77 | if(this.url) { |
---|
| 78 | this.setUrl(this.url); |
---|
| 79 | } |
---|
| 80 | }, |
---|
| 81 | |
---|
| 82 | /** private: method[onDestroy] |
---|
| 83 | * Private method called during the destroy sequence. |
---|
| 84 | */ |
---|
| 85 | onDestroy: function() { |
---|
| 86 | var el = this.getEl(); |
---|
| 87 | if(el) { |
---|
| 88 | el.un("error", this.onImageLoadError, this); |
---|
| 89 | } |
---|
| 90 | GeoExt.LegendImage.superclass.onDestroy.apply(this, arguments); |
---|
| 91 | }, |
---|
| 92 | |
---|
| 93 | /** private: method[onImageLoadError] |
---|
| 94 | * Private method called if the legend image fails loading. |
---|
| 95 | */ |
---|
| 96 | onImageLoadError: function() { |
---|
| 97 | this.getEl().dom.src = this.defaultImgSrc; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | }); |
---|
| 101 | |
---|
| 102 | /** api: xtype = gx_legendimage */ |
---|
| 103 | Ext.reg('gx_legendimage', GeoExt.LegendImage); |
---|