X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=js%2Fsyp.js;h=032a6ac71e4264c29922c8e496f76a845cb9f272;hb=e4a4e5149d55cf01a86f26392c52fdca803654ce;hp=e350d88af3ea303dbe1aeeae820351ff8d6fdc5f;hpb=d9822b8cde6431e71121e9dc13d6457dfbf5fceb;p=syp.git diff --git a/js/syp.js b/js/syp.js index e350d88..032a6ac 100644 --- a/js/syp.js +++ b/js/syp.js @@ -136,7 +136,11 @@ var SYP = { if (permaControl[0]) { permaControl[0].div.style.display = ""; } - var popup = feature.popup; + if (!feature.popup) { + this.map.events.unregister("movestart", this, this._unselect); + return; + } + popup = feature.popup; if (popup.visible()) { popup.hide(); } @@ -154,7 +158,7 @@ var SYP = { // we cannot reuse popup; we need to recreate it in order for IE // expressions to work. Otherwise, we get a 0x0 image on second view. - if (popup) { + if (popup) { popup.destroy(); } var contentHTML; @@ -166,6 +170,10 @@ var SYP = { } else { contentHTML = feature.attributes.description; } + if (!contentHTML || !contentHTML.length) { + this.map.events.register("movestart", this, this._unselect = function () { this.unselect(feature)}); + return; + } popup = SYP.createPopup(brCorner, contentHTML); var control = this; popup.hide = function () { @@ -220,3 +228,35 @@ if (OpenLayers.Lang[SypStrings.language]) { OpenLayers.Console.userError = function(error) { SYP.Utils.displayUserMessage(error, "error"); } + +// sometimes, especially when cache is clear, firefox does not compute +// correctly popup size. That's because at the end of getRenderedDimensions, +// dimensions of image is not known. So, we work around that problem by setting +// image width and image height. That way, dimensions of image are set in +// innerHTML, and are therefore known in getRenderedDimensions +OpenLayers.Popup.Anchored.prototype.registerImageListeners = function() { + var onImgLoad = function() { + this.img.width = this.img.width; + this.img.height = this.img.height; + this.popup.updateSize(); + OpenLayers.Event.stopObserving( + this.img, "load", this.img._onImageLoad + ); + }; + + var images = this.contentDiv.getElementsByTagName("img"); + for (var i = 0, len = images.length; i < len; i++) { + var img = images[i]; + if (img.width == 0 || img.height == 0) { + + var context = { + 'popup': this, + 'img': img + }; + + img._onImgLoad = OpenLayers.Function.bind(onImgLoad, context); + + OpenLayers.Event.observe(img, 'load', img._onImgLoad); + } + } +}