var IE = document.all?true:false if (!IE) document.captureEvents(Event.MOUSEMOVE) document.onmousemove = getMouseXY; var mouseX = 0; var mouseY = 0; function getMouseXY(evt) { if (IE) { mouseX = event.clientX + document.body.scrollLeft; mouseY = event.clientY + document.body.scrollTop; } else { mouseX = evt.pageX; mouseY = evt.pageY; } } /** * Handels images and identifier for clickable features. */ var ImageHandler = Class.extend({ images : [], symbolizer : null, addImage : function(tag, value, operator, url) { this.images.push({ "tag" : tag, "value" : value, "operator" : operator, "url" : url }); }, setSymbolObject : function(symbolizer) { this.symbolizer = symbolizer; return this.refresh(); }, getCustomRules : function() { var style = new OpenLayers.Style(); for(var i = 0; i < this.images.length; i++) { var rule = new OpenLayers.Rule({ filter : new OpenLayers.Filter.Comparison({ type : this.images[i]["operator"], property : this.images[i]["tag"], value : this.images[i]["value"], }), symbolizer : {pointRadius : 8, externalGraphic : this.images[i]["url"], graphicOpacity : 1, fillOpacity : 1} }); style.addRules([rule]); } style.addRules([ new OpenLayers.Rule({ elseFilter : true, symbolizer : {pointRadius : 8, externalGraphic : this.symbolizer.getElseSymbol(), graphicOpacity : 1, fillOpacity : 1} }) ]); return style; }, refresh : function() { var ret = false; var symbols = this.symbolizer.getSymbols(); for(index in symbols) { if(this.images.length > 0) { var found = true; for(var i = 0; i < this.images.length; i++) { if(this.images[i]["tag"] == symbols[index][0] && this.images[i]["value"] == symbols[index][1]) { found = false; break; } } if(found) { this.addImage(symbols[index][0], symbols[index][1], symbols[index][2], symbols[index][3]); ret = true; } } else { this.addImage(symbols[index][0], symbols[index][1], symbols[index][2], symbols[index][3]); ret = true; } } return ret; } }); /** * Feature Filter class * - handles most important functions */ var FeatureFilter = Class.extend({ map : null, imageHandler : null, /** * key defines the wfs-tag */ construct : function(map, imageHandler) { this.map = map; this.imageHandler = imageHandler; }, addLayer : function(layer, html, footer, featureServer, typeName, idAttribute, clusterLabel, clusterDelimiter, clusterHTML, clusterAmount, navigation, clusterAmount) { if(typeof(layer.styleMap) != 'undefined') { layer.styleMap.styles = {"default" : this.imageHandler.getCustomRules()}; } this.map.addLayer(layer); if(html.length > 0) this.addSelectControl(layer, html, footer, featureServer, typeName, idAttribute, clusterLabel, clusterDelimiter, clusterHTML, clusterAmount, navigation, clusterAmount); }, removeLayer : function(id) { var layer; if((layer = this.map.getLayer(id)) != null) layer.destroy(); }, removeAllLayers : function() { var layers = this.map.getLayersByClass('OpenLayers.Layer.Vector'); for(index in layers) { layers[index].destroy(); } }, getLayer : function(id) { return this.map.getLayer(id); }, refreshStyleMaps : function() { layers = this.map.getLayersByClass('OpenLayers.Layer.Vector'); for(index in layers) { if(typeof(layers[index].styleMap) != 'undefined') { layers[index].styleMap.styles = {"default" : this.imageHandler.getCustomRules()}; } } }, redrawLayers : function() { layers = this.map.getLayersByClass('OpenLayers.Layer.Vector'); for(index in layers) { layers[index].redraw(); } }, addSelectControl : function(layer, html, footer, featureServer, typeName, idAttribute, clusterLabel, clusterDelimiter, clusterHTML, clusterAmount, navigation, clusterAmount) { /* var layers = []; for(key in this.map.layers) { if(this.map.layers[key] instanceof OpenLayers.Layer.WFSFilter) layers.push(this.map.layers[key]); } selectControl = new OpenLayers.Control.SelectFeature(layers, {*/ selectControl = new OpenLayers.Control.SelectFeature([layer], { hover : false, toggle : true, highlightOnly: false, tooltipDiv : null, multiple : false, callbacks : { over : function(feature) { var regex = new RegExp(/\$\{([^}]+)\}/); var match = null; this.tooltipDiv = document.createElement('div'); style = document.createAttribute('style'); style.nodeValue = 'z-index: 3000;position:absolute;left:'+(mouseX+10)+'px;top:'+(mouseY+10)+'px;background-color:#FFFFCC;border:1px solid #BBBBBB;padding:1px;'; this.tooltipDiv.setAttributeNode(style); if(feature.attributes.name.length > 0) { this.tooltipDiv.innerHTML = (feature.attributes.name == "None") ? "
No Name
" : ""+feature.attributes.name+"
"; } else { this.tooltipDiv.innerHTML = "" + eval(regex.exec(clusterAmount)[1]) + " features in this cluster
"; } document.body.appendChild(this.tooltipDiv); }, out : function(feature) { if(this.tooltipDiv != null) { document.body.removeChild(this.tooltipDiv); this.tooltipDiv = null; } }, click : function(feature) { if(this.tooltipDiv != null) { document.body.removeChild(this.tooltipDiv); this.tooltipDiv = null; } this.clickFeature(feature); } }, onSelect: function(feature) { var regex = new RegExp(/\$\{([^}]+)\}/); var match = null; var output = html; var popup = null; var ids = []; try { ids = eval(regex.exec(clusterLabel)[1]).split(clusterDelimiter); ids.splice(0,1); } catch(err) { } if(ids.length > 0) { //feature is a cluster -> load addtional info var counter = 0; output = '...
"; } if(typeof(navigation) == "function") { output += navigation(oldFeature); } else { output += navigation; while((match = regex.exec(output)) != null) { output = output.replace(match[0], eval(match[1])); } } output = "