X-Git-Url: https://dev.renevier.net/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=js%2Fsyp.js;h=40735c791cbb516ea273c0fe40a0e85d58ecb28b;hb=08738f64e1837fe334e6ad831b803d0f8ce555dd;hp=3228e62b5a7aeecbf70bb1f94c615b1b8aa13f94;hpb=3848f54e1bde1afac7fa595822526d6c96b1ff18;p=syp.git
diff --git a/js/syp.js b/js/syp.js
index 3228e62..40735c7 100644
--- a/js/syp.js
+++ b/js/syp.js
@@ -3,7 +3,7 @@
OpenLayers.Control.SypAttribution = OpenLayers.Class (OpenLayers.Control.Attribution, {
updateAttribution: function() {
- var attributions = ['propulsed by syp'];
+ var attributions = [SypStrings.propulsedByLink];
if (this.map && this.map.layers) {
for(var i=0, len=this.map.layers.length; i 1) {
+ this.unselect(feature);
+ var lonlat = new OpenLayers.LonLat(feature.geometry.x, feature.geometry.y);
+ map.setCenter(lonlat, map.zoom + 1);
+ return;
+ }
+ var permaControl = map.getControlsByClass("OpenLayers.Control.Permalink");
+ if (permaControl[0]) {
+ permaControl[0].div.style.display = "none";
+ }
var popup = feature.popup;
- var brCorner = SYP.Utils.brCorner(map, 8);
+ var popupPos = null;
+ if (sypSettings.popupNearfeature) {
+ popupPos = feature.geometry.getBounds().getCenterLonLat();
+ } else {
+ popupPos = SYP.Utils.brCorner(map, 8);
+ }
// 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;
- if (feature.attributes.name) {
+ if (feature.cluster[0].attributes.name) {
contentHTML = "" +
- feature.attributes.name +
+ feature.cluster[0].attributes.name +
"
" +
- feature.attributes.description;
+ feature.cluster[0].attributes.description;
} else {
- contentHTML = feature.attributes.description;
+ contentHTML = feature.cluster[0].attributes.description;
}
- popup = SYP.createPopup(brCorner, contentHTML);
+ if (!contentHTML || !contentHTML.length) {
+ this.map.events.register("movestart", this, this._unselect = function () { this.unselect(feature)});
+ return;
+ }
+ popup = SYP.createPopup(popupPos, contentHTML);
var control = this;
popup.hide = function () {
OpenLayers.Element.hide(this.div);
- control.unselect(feature);
+ control.unselectAll();
};
map.addPopup(popup);
feature.popup = popup;
+ var anchor = popup.div.getElementsByTagName("a")[0];
+ if (anchor) {
+ anchor.onclick = function() {
+ SYP.showBigImage(this.href);
+ return false;
+ }
+ }
+ },
+
+ showBigImage: function (href) {
+ try {
+ document.getElementById('bigimg_container').style.display = "table";
+ } catch(e) {
+ document.getElementById('bigimg_container').style.display = "block";
+ }
+ var maxHeight = document.body.clientHeight * 0.9;
+ var maxWidth = document.body.clientWidth * 0.9;
+ document.getElementById('bigimg').style.height = "";
+ document.getElementById('bigimg').style.width = "";
+ document.getElementById('bigimg').style.maxHeight = maxHeight + "px";
+ document.getElementById('bigimg').style.maxWidth = maxWidth + "px";
+ document.getElementById('bigimg').onload = function () {
+ var icon = document.getElementById('bigimg_close');
+ icon.style.top = this.offsetTop;
+ icon.style.left = this.offsetLeft + this.clientWidth - icon.clientWidth;
+
+ var heightRatio = this.clientHeight / parseInt(this.style.maxHeight);
+ var widthRatio = this.clientWidth / parseInt(this.style.maxWidth);
+ if (heightRatio > 1 || widthRatio > 1) {
+ if (heightRatio > widthRatio) {
+ this.style.height = this.style.maxHeight;
+ } else {
+ this.style.width = this.style.maxWidth;
+ }
+ }
+
+ };
+ document.getElementById('bigimg').src = href;
+ },
+
+ closeBigImage: function() {
+ document.getElementById('bigimg').src = "";
+ document.getElementById('bigimg').parentNode.innerHTML = document.getElementById('bigimg').parentNode.innerHTML;
+ document.getElementById('bigimg_container').style.display = "none";
},
Utils: {
@@ -176,6 +271,59 @@ var SYP = {
corner = map.getLonLatFromPixel(cornerAsPx);
return corner;
},
+
+ /* minimum bounds rectangle containing all feature locations.
+ * FIXME: if two features are close, but separated by 180th meridian,
+ * their mbr will span the whole earth. Actually, 179° lon and -170°
+ * lon are considerated very near.
+ */
+ mbr: function (layer) {
+ var features = [];
+ var map = layer.map;
+
+ var mapProj = map.getProjectionObject();
+ var sypOrigProj = new OpenLayers.Projection("EPSG:4326");
+
+ for (var i =0; i < layer.features.length; i++) {
+ if (layer.features[i].cluster) {
+ features = features.concat(layer.features[i].cluster);
+ } else {
+ features = features.concat(layer.features);
+ }
+ }
+
+ var minlon = 180;
+ var minlat = 88;
+ var maxlon = -180;
+ var maxlat = -88;
+
+ if (features.length == 0) {
+ // keep default values
+ } else if (features.length == 1) {
+ // in case there's only one feature, we show an area of at least
+ // 4 x 4 degrees
+ var pos = features[0].geometry.getBounds().getCenterLonLat().clone();
+ var lonlat = pos.transform(mapProj, sypOrigProj);
+
+ minlon = Math.max (lonlat.lon - 2, -180);
+ maxlon = Math.min (lonlat.lon + 2, 180);
+ minlat = Math.max (lonlat.lat - 2, -90);
+ maxlat = Math.min (lonlat.lat + 2, 90);
+ } else {
+ for (var i = 0; i < features.length; i++) {
+ var pos = features[i].geometry.getBounds().getCenterLonLat().clone();
+ var lonlat = pos.transform(mapProj, sypOrigProj);
+ minlon = Math.min (lonlat.lon, minlon);
+ minlat = Math.min (lonlat.lat, minlat);
+ maxlon = Math.max (lonlat.lon, maxlon);
+ maxlat = Math.max (lonlat.lat, maxlat);
+ }
+ }
+
+ return [minlon, minlat, maxlon, maxlat];
+
+ },
+
displayUserMessage: function(message, status) {
var div = document.getElementById('message');
while (div.firstChild)
@@ -201,7 +349,45 @@ var SYP = {
}
};
+// if possible, determine language with HTTP_ACCEPT_LANGUAGE instead of
+// navigator.language
+if (OpenLayers.Lang[SypStrings.language]) {
+ OpenLayers.Lang.setCode(SypStrings.language);
+}
+
// avoid alerts
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);
+ }
+ }
+}