From 0fb779168df5af03f2a74b6bf1766d5a1c0f1a7e Mon Sep 17 00:00:00 2001 From: arno Date: Sun, 16 Aug 2009 23:52:32 +0200 Subject: [PATCH] option to show popup near marker or on a corner Now, it's possible to set the popup on one of the four corners instead of just bottom right one. --- inc/html/index.php | 8 ++++---- inc/settings.php.in | 9 +++++--- js/syp.js | 50 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/inc/html/index.php b/inc/html/index.php index 8382159..5de0a53 100644 --- a/inc/html/index.php +++ b/inc/html/index.php @@ -16,10 +16,10 @@ if (defined ("THUMBSMAXSIZE") && (THUMBSMAXSIZE > 0)) { $thumbsmaxsize = 400; // default value; } -if (defined ("POPUPNEARFEATURE") && (POPUPNEARFEATURE)) { - $popupnearfeature = true; +if (defined ("POPUPPOS")) { + $popuppos = POPUPPOS; } else { - $popupnearfeature = false; + $popuppos = 3; } ?> @@ -52,7 +52,7 @@ if (defined ("POPUPNEARFEATURE") && (POPUPNEARFEATURE)) { noImageRegistered: "" }; var sypSettings = { - popupNearfeature: + popupPos: }; diff --git a/inc/settings.php.in b/inc/settings.php.in index 5d4910a..ed12c5f 100644 --- a/inc/settings.php.in +++ b/inc/settings.php.in @@ -47,7 +47,10 @@ define ("THUMBSDIRURL", ""); // uploaded image is bigger, images will be resized. define ("THUMBSMAXSIZE", 400); -// if set to 0 (default), popup will appear at bottom right corner of the map. -// If set to 1 or true, popup will appear near marker. -define ("POPUPNEARFEATURE", 0); +// If set to 0 popup will appear near selected marker. +// If set to 1, popup will appear at top left corner of the map +// If set to 2, popup will appear at top right corner of the map +// If set to 3 (default), popup will appear at bottom right corner of the map +// If set to 4, popup will appear at bottom left corner of the map +define ("POPUPPOS", 3); ?> diff --git a/js/syp.js b/js/syp.js index 40735c7..c361387 100644 --- a/js/syp.js +++ b/js/syp.js @@ -184,10 +184,25 @@ var SYP = { var popup = feature.popup; var popupPos = null; - if (sypSettings.popupNearfeature) { - popupPos = feature.geometry.getBounds().getCenterLonLat(); - } else { - popupPos = SYP.Utils.brCorner(map, 8); + switch (sypSettings.popupPos) { + case 0: + popupPos = feature.geometry.getBounds().getCenterLonLat(); + break; + case 1: + popupPos = SYP.Utils.tlCorner(map, 8); + break; + case 2: + popupPos = SYP.Utils.trCorner(map, 8); + break; + case 3: + popupPos = SYP.Utils.brCorner(map, 8); + break; + case 4: + popupPos = SYP.Utils.blCorner(map, 8); + break; + default: + popupPos = SYP.Utils.brCorner(map, 8); + break; } // we cannot reuse popup; we need to recreate it in order for IE @@ -263,13 +278,36 @@ var SYP = { }, Utils: { + tlCorner: function(map, margin) { + var bounds = map.calculateBounds(); + var corner = new OpenLayers.LonLat(bounds.left, bounds.top); + var cornerAsPx = map.getPixelFromLonLat(corner); + cornerAsPx = cornerAsPx.add( +margin, +margin); + return map.getLonLatFromPixel(cornerAsPx); + }, + + trCorner: function(map, margin) { + var bounds = map.calculateBounds(); + var corner = new OpenLayers.LonLat(bounds.right, bounds.top); + var cornerAsPx = map.getPixelFromLonLat(corner); + cornerAsPx = cornerAsPx.add( -margin, +margin); + return map.getLonLatFromPixel(cornerAsPx); + }, + brCorner: function(map, margin) { var bounds = map.calculateBounds(); var corner = new OpenLayers.LonLat(bounds.right, bounds.bottom); var cornerAsPx = map.getPixelFromLonLat(corner); cornerAsPx = cornerAsPx.add( -margin, -margin); - corner = map.getLonLatFromPixel(cornerAsPx); - return corner; + return map.getLonLatFromPixel(cornerAsPx); + }, + + blCorner: function(map, margin) { + var bounds = map.calculateBounds(); + var corner = new OpenLayers.LonLat(bounds.left, bounds.bottom); + var cornerAsPx = map.getPixelFromLonLat(corner); + cornerAsPx = cornerAsPx.add( +margin, -margin); + return map.getLonLatFromPixel(cornerAsPx); }, /* minimum bounds rectangle containing all feature locations. -- 2.39.2