[Mapbender-commits] r6597 - trunk/mapbender/http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Jul 13 09:24:16 EDT 2010
Author: kmq
Date: 2010-07-13 13:24:16 +0000 (Tue, 13 Jul 2010)
New Revision: 6597
Modified:
trunk/mapbender/http/plugins/mb_loadkmlgeorss.js
Log:
support for clickevents on icons
Modified: trunk/mapbender/http/plugins/mb_loadkmlgeorss.js
===================================================================
--- trunk/mapbender/http/plugins/mb_loadkmlgeorss.js 2010-07-13 13:23:44 UTC (rev 6596)
+++ trunk/mapbender/http/plugins/mb_loadkmlgeorss.js 2010-07-13 13:24:16 UTC (rev 6597)
@@ -76,7 +76,7 @@
var that = this;
that.feeds = [];
-that.$popup = $('<div></div>').dialog({autoOpen : false, height: 500});
+that.$popup = $('<div></div>').dialog({autoOpen : false, height: 500, width: 500});
$('<div id="'+ options.id +'_dialog"><label>GeoRSS <input type="radio" name="type" value="GeoRSS" checked="checked"/></label>'+
'<label>KML<input type="radio" name="type" value="KML"></label><br />'+
@@ -126,22 +126,22 @@
//title = feature.properties.title || feature.properties.name || translatedI18nObject.labelUntitled;
+
var geomArray = new GeometryArray();
+ var highlightArray = [];
geomArray.importGeoJSON(data);
- var h = new Highlight(['mapframe1'], "mapframe1_" + parseInt(Math.random()*100000,10),{
- "position":"absolute",
- "top": "0px",
- "left": "0px",
- "z-index": "80" },1);
for(var i =0; i < geomArray.count(); i++){
+ var h = new Highlight(['mapframe1'], "mapframe1_" + parseInt(Math.random()*100000,10),{
+ "position":"absolute",
+ "top": "0px",
+ "left": "0px",
+ "z-index": "80" },1);
g = geomArray.get(i);
- // per feature stuff
- g.e.setElement("Mapbender:icon","http://localhost:8080/trunk/http/img/marker/red.png");
- // THIS NEEDS AN OFFSET!
+ g.e.setElement("Mapbender:icon","http://satan:8080/trunk/http/img/marker/red.png");
title = g.e.getElementValueByName("title");
name = g.e.getElementValueByName("name");
- // kml uses name
- title = name? name : title;
+ alert("name "+ name + " - title "+ title);
+ title = name == false ? name : title;
description = g.e.getElementValueByName("description");
$row = $("<tr><td>"+ title +"</td></tr>");
$row.css("cursor","pointer");
@@ -153,21 +153,33 @@
})(title,description));
$("tbody",$table).append($row);
h.add(g);
+ /*
+ h.setMouseClick((function(j){
+ return function(){
+ alert(j);
+ }
+ })(j));
+ */
+ highlightArray.push(h);
+
title = "";
name = "";
}
- h.paint();
+ for(var i in highlightArray){
+ highlightArray[i].paint();
+ }
map.events.afterMapRequest.register(function () {
- h.paint();
+ for(var i in highlightArray){
+ highlightArray[i].paint();
+ }
});
that.feeds[url] = {
geomArray: geomArray,
- highlight: h
+ highlightArray: highlightArray
};
-
}
var $tableDialog = $("<div></div>").dialog({
@@ -177,8 +189,10 @@
beforeclose: (function(url){
return function(){
delete that.feeds[url];
- h.clean();
- };
+ for(var i in highlightArray){
+ highlightArray[i].clean();
+ }
+ };
})(url),
buttons: {"Close": function(){
$(this).dialog('close');
@@ -188,7 +202,6 @@
});
$tableDialog.append($table);
- Mapbender.languageId;
$table.dataTable({"bJQueryUI": true ,
"oLanguage":{
"sUrl":"../extensions/dataTables-1.5/lang/"+Mapbender.languageId +".txt"
@@ -211,7 +224,7 @@
Mapbender.modules.i18n.queue(options.id, originalI18nObject, function(translatedI18nObject){
$('.labelLoadError').text(translatedI18nObject.labelLoadError);
$('.labelUrlBox').text(translatedI18nObject.labelUrlBox);
- })
+ });
});
Mapbender.events.init.register(function () {
@@ -224,12 +237,36 @@
var clickPoint = map.convertPixelToReal(new Point(pos.x,pos.y));
var feed = null;
var requestGeometries = [];
+ // This uses two methods to determine wether a clickposition is on a geometry
+ // - Points are represented as icons, so we check if the click is on an icon
+ // - Polygons don't have a dom Element when not using Rapheljs, so we go ask postgis
+ // after that's finished the results are merged and displayed in a box
+ var pointGeometries = {};
+ var g,h,nodes = null;
for (var i in that.feeds){
feed = that.feeds[i] ;
+ requestGeometries = [];
for(var j = 0; j < feed.geomArray.count(); j++){
g = feed.geomArray.get(j);
- requestGeometries.push(g.toText());
+ h = feed.highlightArray[j];
+ nodes = h.getNodes();
+ if(g.geomType == geomType.point){
+ // we only add one point per highlight so we can assume there's only one node
+ if(!nodes[0]){ continue;}
+ var rect = nodes[0].getBoundingClientRect();
+ if(e.clientX >= rect.left && e.clientX <= rect.right &&
+ e.clientY >= rect.top && e.clientY <= rect.bottom){
+ // we just need the keys to exist
+ // theywill be merged with the ones coming from the
+ // server
+ pointGeometries[j] = true;
+ // console.log(nodes[0]);
+ }
+
+ }else{
+ requestGeometries.push(g.toText());
+ }
}
var req = new Mapbender.Ajax.Request({
url: "../php/intersection.php",
@@ -238,16 +275,18 @@
clickPoint: clickPoint.toText(),
geometries: requestGeometries
},
- callback: (function(geomArray){ return function(result, success, message){
+ callback: (function(geomArray,pointGeometries){ return function(result, success, message){
if(!success){
return;
}
// this is basically an onclick handler, !intersects means
// the click didn't happen on the polygon
- if(!result.geometries || result.geometries.length < 1){
+ $.extend(result.geometries,pointGeometries);
+ if(!result.geometries || result.geometries.length <1){
return;
}
+
$("*",that.$popup).remove();
var $tabs = $("<ul></ul>");
// this iterates over an object where the keys are _not_ the incremential
@@ -255,7 +294,6 @@
// this is why j is used
var j = 0;
for(i in result.geometries){
- //TODO: add the popup handler
var g = geomArray.get(i);
title = g.e.getElementValueByName("title");
description = g.e.getElementValueByName("description");
@@ -264,16 +302,21 @@
j++;
}
if(j > 1){
- that.$popup.prepend($tabs);
- $tabs.tabs();
+ var $tabcontainer = $("<div><div>");
+ $tabcontainer.append($tabs);
+ $tabcontainer.append($('div',that.$popup));
+ that.$popup.append($tabcontainer);
+ $tabcontainer.tabs();
}
that.$popup.dialog('open');
- }})(feed.geomArray)
+ }})(feed.geomArray, pointGeometries)
});
req.send();
requestGeometries = [];
+ pointGeometries = {};
}
});
});
+
More information about the Mapbender_commits
mailing list