X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=js%2Fsyp.js;h=8e32d8580d4d7e86d7b0f178cfa46f627d0c8e99;hp=d83b1fefe44801cfb69318dc671cac378c54820d;hb=d31c25de8cf1735ca350f55b3520f7bbcb5e2c2e;hpb=71623749afbd4c1faf523a4ef0f99320a91c68f4 diff --git a/js/syp.js b/js/syp.js index d83b1fe..8e32d85 100644 --- a/js/syp.js +++ b/js/syp.js @@ -32,10 +32,10 @@ var SYP = { init: function() { this.map = new OpenLayers.Map("map", { controls:[ + new OpenLayers.Control.SypAttribution(), new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoom(), - new OpenLayers.Control.Permalink(), - new OpenLayers.Control.SypAttribution() + new OpenLayers.Control.Permalink() ], projection: new OpenLayers.Projection("EPSG:900913"), displayProjection: new OpenLayers.Projection("EPSG:4326") @@ -140,7 +140,7 @@ var SYP = { this.map.events.unregister("movestart", this, this._unselect); return; } - popup = feature.popup; + var popup = feature.popup; if (popup.visible()) { popup.hide(); } @@ -228,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); + } + } +}