1 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
6 MARKER_ICON: "openlayers/img/marker-blue.png",
7 MARKER_ICON_HEIGHT: 25,
8 MARKER_SELECT_ICON: "openlayers/img/marker-green.png",
9 MARKER_SELECT_ICON_HEIGHT: 25
18 this.map = new OpenLayers.Map("map", {
20 new OpenLayers.Control.Navigation(),
21 new OpenLayers.Control.PanZoom(),
22 new OpenLayers.Control.Permalink(),
23 new OpenLayers.Control.Attribution()
25 projection: new OpenLayers.Projection("EPSG:900913"),
26 displayProjection: new OpenLayers.Projection("EPSG:4326")
29 this.baseLayer = this.createBaseLayer();
30 this.dataLayer = this.createDataLayer();
31 this.map.addLayers([this.baseLayer, this.dataLayer]);
33 this.selectControl = this.createSelectControl();
34 this.map.addControl(this.selectControl);
35 this.selectControl.activate();
37 if (!this.map.getCenter()) {
38 var centerBounds = new OpenLayers.Bounds();
40 var mapProj = this.map.getProjectionObject();
41 var sypOrigProj = new OpenLayers.Projection("EPSG:4326");
43 var bottomLeft = new OpenLayers.LonLat(sypOrig[0],sypOrig[1]);
44 bottomLeft = bottomLeft.transform(sypOrigProj, mapProj);
45 var topRight = new OpenLayers.LonLat(sypOrig[2],sypOrig[3])
46 topRight = topRight.transform(sypOrigProj, mapProj);
48 centerBounds.extend(bottomLeft);
49 centerBounds.extend(topRight);
50 this.map.zoomToExtent(centerBounds);
54 createBaseLayer: function() {
55 return new OpenLayers.Layer.OSM("OSM");
58 createDataLayer: function(map) {
59 var styleMap = new OpenLayers.StyleMap (
61 externalGraphic: this.Settings.MARKER_ICON,
62 graphicHeight: this.Settings.MARKER_ICON_HEIGHT
66 externalGraphic: this.Settings.MARKER_SELECT_ICON,
67 graphicHeight: this.Settings.MARKER_SELECT_ICON_HEIGHT
72 var layer = new OpenLayers.Layer.GML("KML", "items.php",
75 format: OpenLayers.Format.KML,
76 projection: this.map.displayProjection,
77 eventListeners: { scope: this,
78 loadend: this.checkForFeatures
85 createSelectControl: function() {
86 var control = new OpenLayers.Control.SelectFeature(
88 onSelect: this.onFeatureSelect,
89 onUnselect: this.onFeatureUnselect,
96 checkForFeatures: function() {
97 var features = this.dataLayer.features;
98 if (features.length == 0) {
99 var message = "Il n'y a aucune photo enregistrée sur le site.";
100 this.Utils.displayUserMessage(message, "warn");
104 createPopup: function(position, contentHTML) {
105 var popup = new OpenLayers.Popup.Anchored("popup",
111 popup.autoSize = true;
112 popup.backgroundColor = ""; // deal with it in css
113 popup.border = ""; // deal with it in css
114 popup.closeOnMove = true;
118 onFeatureUnselect: function (feature) {
119 var popup = feature.popup;
120 if (popup.visible()) {
125 onFeatureSelect: function(feature) {
126 var map = feature.layer.map;
127 var popup = feature.popup;
129 var brCorner = SYP.Utils.brCorner(map, 8);
131 // we cannot reuse popup; we need to recreate it in order for IE
132 // expressions to work. Otherwise, we get a 0x0 image on second view.
137 if (feature.attributes.name) {
138 contentHTML = "<h2>" +
139 feature.attributes.name +
141 feature.attributes.description;
143 contentHTML = feature.attributes.description;
145 popup = SYP.createPopup(brCorner, contentHTML);
147 popup.hide = function () {
148 OpenLayers.Element.hide(this.div);
149 control.unselect(feature);
152 feature.popup = popup;
156 brCorner: function(map, margin) {
157 var bounds = map.calculateBounds();
158 var corner = new OpenLayers.LonLat(bounds.right, bounds.bottom);
159 var cornerAsPx = map.getPixelFromLonLat(corner);
160 cornerAsPx = cornerAsPx.add( -margin, -margin);
161 corner = map.getLonLatFromPixel(cornerAsPx);
164 displayUserMessage: function(message, status) {
165 var div = document.getElementById('message');
166 while (div.firstChild)
167 div.removeChild(div.firstChild);
168 var textNode = document.createTextNode(message);
171 div.style.color = "red";
174 div.style.color = "#FF8C00";
177 div.style.color = "green";
180 div.style.color = "black";
183 div.style.display = "block";
184 div.appendChild(textNode);
190 OpenLayers.Console.userError = function(error) {
191 SYP.Utils.displayUserMessage(error, "error");