1
|
|
2
|
|
3
|
|
4
|
function draw_cap_map() {
|
5
|
|
6
|
var zcontrol;
|
7
|
if (typeof zoom_control != 'undefined') {
|
8
|
switch (zoom_control) {
|
9
|
case 'full':
|
10
|
zcontrol = new OpenLayers.Control.PanZoomBar();
|
11
|
break;
|
12
|
case 'light':
|
13
|
default:
|
14
|
zcontrol = new OpenLayers.Control.Zoom();
|
15
|
}
|
16
|
} else zcontrol = new OpenLayers.Control.Zoom();
|
17
|
|
18
|
var map = new OpenLayers.Map({
|
19
|
div: "map",
|
20
|
zoom: typeof zoom == 'undefined' ? 10:zoom,
|
21
|
controls:[zcontrol,
|
22
|
new OpenLayers.Control.KeyboardDefaults(),
|
23
|
new OpenLayers.Control.Navigation()],
|
24
|
});
|
25
|
|
26
|
if (typeof scale_line != 'undefined' && scale_line == true) {
|
27
|
map.addControl(new OpenLayers.Control.ScaleLine({bottomOutUnits: ''}));
|
28
|
}
|
29
|
|
30
|
if (typeof base_layers != 'undefined') {
|
31
|
var layers = new OpenLayers.Control.LayerSwitcher();
|
32
|
map.addControl(layers);
|
33
|
for (var i = 0; i < base_layers.length; i++) {
|
34
|
map.addLayer(base_layers[i]);
|
35
|
}
|
36
|
|
37
|
|
38
|
function update_tilt() {
|
39
|
for (var i = 0; i < base_layers.length; i++) {
|
40
|
if (base_layers[i].type == google.maps.MapTypeId.SATELLITE) {
|
41
|
base_layers[i].mapObject.setTilt(this.checked?1:0);
|
42
|
|
43
|
base_layers[i].removeMap;
|
44
|
base_layers[i].redraw;
|
45
|
}
|
46
|
}
|
47
|
}
|
48
|
document.getElementById("tilt").onchange = update_tilt;
|
49
|
|
50
|
|
51
|
|
52
|
function show_pos(e) {
|
53
|
alert(formatLonlats(map.getLonLatFromViewPortPx(e.xy)));
|
54
|
}
|
55
|
function set_pos(e) {
|
56
|
if(this.checked) {
|
57
|
document.getElementById("position").style.display = 'none';
|
58
|
map.events.register("click", map, show_pos);
|
59
|
} else {
|
60
|
document.getElementById("position").style.display = 'block';
|
61
|
map.events.unregister("click", map, show_pos);
|
62
|
}
|
63
|
}
|
64
|
var panel = new OpenLayers.Control.Panel({
|
65
|
div: document.getElementById("panel")
|
66
|
});
|
67
|
|
68
|
function formatLonlats(lonLat) {
|
69
|
lonLat.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
|
70
|
var lat = lonLat.lat;
|
71
|
var lon = lonLat.lon;
|
72
|
var dist = OpenLayers.Util.distVincenty(lonLat, new OpenLayers.LonLat(ln.lon1, ln.lat1))*1000;
|
73
|
return lat.toFixed(5) + ', ' + lon.toFixed(5) + ' à ' + parseInt(dist) + ' mètres';
|
74
|
}
|
75
|
|
76
|
map.addControl (new OpenLayers.Control.MousePosition({
|
77
|
div: document.getElementById("position"),
|
78
|
formatOutput: formatLonlats
|
79
|
}));
|
80
|
|
81
|
var history = new OpenLayers.Control.NavigationHistory();
|
82
|
map.addControl(history);
|
83
|
panel.addControls([history.next, history.previous]);
|
84
|
map.addControl(panel);
|
85
|
|
86
|
document.getElementById("clic_pos").onchange = set_pos;
|
87
|
layers.layersDiv.appendChild(document.getElementById("extra"));
|
88
|
|
89
|
} else {
|
90
|
map.addLayer(new OpenLayers.Layer.OSM());
|
91
|
}
|
92
|
|
93
|
if (typeof contour != 'undefined') contours = [contour];
|
94
|
if (typeof contours == 'undefined') contours = new Array;
|
95
|
for (var i = 0; i < contours.length; i++) {
|
96
|
var ct = contours[i];
|
97
|
var cntr = new OpenLayers.Layer.Vector("contour_"+i, {
|
98
|
strategies: [new OpenLayers.Strategy.Fixed()],
|
99
|
projection: new OpenLayers.Projection("EPSG:4326"),
|
100
|
styleMap: new OpenLayers.StyleMap({
|
101
|
strokeWidth: ct.strokeWidth,
|
102
|
strokeColor: ct.strokeColor,
|
103
|
strokeOpacity: ct.strokeOpacity,
|
104
|
fillOpacity: ct.fillOpacity,
|
105
|
fillColor: ct.fillColor
|
106
|
}),
|
107
|
protocol: new OpenLayers.Protocol.HTTP({
|
108
|
url: ct.url,
|
109
|
format: new OpenLayers.Format.OSM(),
|
110
|
}),
|
111
|
eventListeners: {
|
112
|
"featuresadded": function () {
|
113
|
if (typeof fit_contours == 'undefined' || fit_contours) this.map.zoomToExtent(this.getDataExtent());
|
114
|
}
|
115
|
}
|
116
|
});
|
117
|
map.addLayer(cntr);
|
118
|
}
|
119
|
|
120
|
if (typeof ref_line != 'undefined') ref_lines = [ref_line];
|
121
|
if (typeof ref_lines != 'undefined') {
|
122
|
if (typeof def_line_style == 'undefined') def_line_style = {};
|
123
|
var def_ln = {
|
124
|
width: def_line_style.width? def_line_style.width:2,
|
125
|
color: def_line_style.color? def_line_style.color:'#00F',
|
126
|
length: def_line_style.length? def_line_style.length:20000,
|
127
|
opacity: def_line_style.opacity? def_line_style.opacity:1}
|
128
|
|
129
|
var lineLayer = new OpenLayers.Layer.Vector("ref_lines");
|
130
|
map.addControl(new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path));
|
131
|
for (var i = 0; i < ref_lines.length; i++) {
|
132
|
var ln = ref_lines[i];
|
133
|
if(isNaN(ln.cap)) {
|
134
|
var pt = {lon: ln.lon2, lat: ln.lat2};
|
135
|
} else {
|
136
|
var LonLat = new OpenLayers.LonLat(ln.lon1, ln.lat1);
|
137
|
var dist = ln.length? ln.length:def_ln.length;
|
138
|
var pt = OpenLayers.Util.destinationVincenty(LonLat, ln.cap, dist);
|
139
|
}
|
140
|
var points = new Array(
|
141
|
new OpenLayers.Geometry.Point(ln.lon1, ln.lat1),
|
142
|
new OpenLayers.Geometry.Point(pt.lon, pt.lat)
|
143
|
);
|
144
|
points[0].transform("EPSG:4326", map.getProjectionObject());
|
145
|
points[1].transform("EPSG:4326", map.getProjectionObject());
|
146
|
var line = new OpenLayers.Geometry.LineString(points);
|
147
|
|
148
|
var style = {
|
149
|
strokeColor: ln.color? ln.color:def_ln.color,
|
150
|
strokeWidth: ln.width? ln.width:def_ln.width,
|
151
|
strokeOpacity: ln.width? ln.opacity:def_ln.opacity
|
152
|
};
|
153
|
|
154
|
var lineFeature = new OpenLayers.Feature.Vector(line, null, style);
|
155
|
lineLayer.addFeatures([lineFeature]);
|
156
|
}
|
157
|
map.addLayer(lineLayer);
|
158
|
}
|
159
|
|
160
|
if (typeof ref_point != 'undefined') ref_points = [ref_point];
|
161
|
if (typeof ref_points != 'undefined') {
|
162
|
refpts_layer = new OpenLayers.Layer.Vector("ref_points", {projection: "EPSG:4326"});
|
163
|
var selectMarkerControl = new OpenLayers.Control.SelectFeature(refpts_layer, {
|
164
|
onSelect: function(feature) {
|
165
|
var le_popup = new OpenLayers.Popup.FramedCloud("Popup",
|
166
|
feature.attributes.lonlat,
|
167
|
null,
|
168
|
feature.attributes.description,
|
169
|
null,
|
170
|
true);
|
171
|
|
172
|
feature.popup = le_popup;
|
173
|
map.addPopup(le_popup);
|
174
|
},
|
175
|
onUnselect: function(feature) {
|
176
|
|
177
|
map.removePopup(feature.popup);
|
178
|
feature.popup.destroy();
|
179
|
feature.popup = null;
|
180
|
},
|
181
|
multiple: true,
|
182
|
toggle: true,
|
183
|
});
|
184
|
map.addControl(selectMarkerControl);
|
185
|
|
186
|
selectMarkerControl.activate();
|
187
|
map.addLayer(refpts_layer);
|
188
|
|
189
|
|
190
|
if (typeof def_points_style == 'undefined') def_points_style = {};
|
191
|
var def_pt = {
|
192
|
icon_url: def_points_style.icon_url,
|
193
|
icon_width: def_points_style.icon_width,
|
194
|
icon_height: def_points_style.icon_height,
|
195
|
showPopup: def_points_style.showPopup ? def_points_style.showPopup:false,
|
196
|
icon_shiftX: def_points_style.icon_shiftX ? def_points_style.icon_shiftX:0,
|
197
|
icon_shiftY: def_points_style.icon_shiftY ? def_points_style.icon_shiftY:0,
|
198
|
opacity: def_points_style.opacity ? def_points_style.opacity:1}
|
199
|
|
200
|
for (var i = 0; i < ref_points.length; i++) {
|
201
|
var pt = ref_points[i];
|
202
|
var ptGeo = new OpenLayers.Geometry.Point(pt.lon, pt.lat);
|
203
|
ptGeo.transform("EPSG:4326", map.getProjectionObject());
|
204
|
var LonLat = new OpenLayers.LonLat(pt.lon, pt.lat).transform("EPSG:4326", map.getProjectionObject());
|
205
|
map.setCenter(LonLat);
|
206
|
var laFeature = new OpenLayers.Feature.Vector(ptGeo,
|
207
|
{description:pt.descr, lonlat: LonLat},
|
208
|
{externalGraphic: pt.icon_url? pt.icon_url:def_pt.icon_url,
|
209
|
graphicWidth: pt.icon_width? pt.icon_width:def_pt.icon_width,
|
210
|
graphicHeight: pt.icon_height? pt.icon_height:def_pt.icon_height,
|
211
|
graphicXOffset: pt.icon_shiftX? pt.icon_shiftX:def_pt.icon_shiftX,
|
212
|
graphicYOffset: pt.icon_shiftY? pt.icon_shiftY:def_pt.icon_shiftY,
|
213
|
graphicOpacity: pt.opacity? pt.opacity:def_pt.opacity,
|
214
|
title: pt.title? pt.title :''});
|
215
|
if (i == 0) elFeature = laFeature;
|
216
|
refpts_layer.addFeatures(laFeature);
|
217
|
if (pt.showPopup) selectMarkerControl.select(laFeature);
|
218
|
}
|
219
|
if (typeof zoom == 'undefined') map.zoomToExtent(refpts_layer.getDataExtent());
|
220
|
}
|
221
|
if (typeof get_lon_lat != 'undefined' && get_lon_lat) {
|
222
|
map.events.register("click", map, function(e) {
|
223
|
var position = map.getLonLatFromViewPortPx(e.xy);
|
224
|
position.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
|
225
|
alert(position.lat.toFixed(5) + ', ' + position.lon.toFixed(5));
|
226
|
});
|
227
|
}
|
228
|
}
|