X-Git-Url: https://dev.renevier.net/gitweb.cgi?a=blobdiff_plain;f=js%2Fsyp.js;h=fdd69ed7253b293e1d6dd9b0c1044925ee8fa4e8;hb=ae3851e4befcc7f6bee6d161dc77ac2e4e9c6515;hp=e350d88af3ea303dbe1aeeae820351ff8d6fdc5f;hpb=d9822b8cde6431e71121e9dc13d6457dfbf5fceb;p=syp.git diff --git a/js/syp.js b/js/syp.js index e350d88..fdd69ed 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") @@ -71,21 +71,31 @@ var SYP = { }, createDataLayer: function(map) { + var defaultStyle = new OpenLayers.Style({ + externalGraphic: this.Settings.MARKER_ICON, + graphicHeight: "${height}" + }, { + context: { + height: function(feature) { + var defaultHeight = SYP.Settings.MARKER_ICON_HEIGHT || 32; + var increase = 4 * (feature.attributes.count - 1); + return Math.min(defaultHeight + increase, 50); + } + } + }); + var selectStyle = new OpenLayers.Style({ + externalGraphic: this.Settings.MARKER_SELECT_ICON, + graphicHeight: this.Settings.MARKER_SELECT_ICON_HEIGHT || 32 + }); var styleMap = new OpenLayers.StyleMap ( - {"default": { - externalGraphic: this.Settings.MARKER_ICON, - graphicHeight: this.Settings.MARKER_ICON_HEIGHT - || 32 - }, - "select": { - externalGraphic: this.Settings.MARKER_SELECT_ICON, - graphicHeight: this.Settings.MARKER_SELECT_ICON_HEIGHT - || 32 - } - }); + {"default": defaultStyle, + "select": selectStyle}); var layer = new OpenLayers.Layer.GML("KML", "items.php", { + strategies: [ + new OpenLayers.Strategy.Cluster() + ], styleMap: styleMap, format: OpenLayers.Format.KML, projection: this.map.displayProjection, @@ -136,6 +146,10 @@ var SYP = { if (permaControl[0]) { permaControl[0].div.style.display = ""; } + if (!feature.popup) { + this.map.events.unregister("movestart", this, this._unselect); + return; + } var popup = feature.popup; if (popup.visible()) { popup.hide(); @@ -144,6 +158,12 @@ var SYP = { onFeatureSelect: function(feature) { var map = feature.layer.map; + if (feature.attributes.count > 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"; @@ -154,23 +174,27 @@ var SYP = { // 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 = "