-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
283 lines (250 loc) · 8.36 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>maps.refuges.info - Hiking rendering</title>
<link rel="shortcut icon" href="/images/favicon.png"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style type="text/css">
#map {
left:0px;
width: 100%;
height: 100%;
border: 0px;
padding: 0px;
position: absolute;
}
body {
border: 0px;
margin: 0px;
margin-bottom: 2px;
padding: 0px;
height: 100%;
font-family: arial, helvetica;
}
form { display: inline; margin: 0; }
/* search block */
#search {
position: absolute;
top: 10px;
left: 50px;
z-index: 1008;
font-size:12px;
padding: 5px;
border-radius: 10px;
background: white;
}
div#search li {
text-decoration: underline;
color: blue;
cursor: pointer;
}
#search input { border: solid 1px #eee; }
/* END search block */
#permalinks {
position: absolute;
bottom: 10px;
right: 0px;
text-align: right;
z-index: 1008;
font-size:12px;
padding: 0 5px;
}
#attributions {
position: absolute;
bottom: 10px;
left: 10px;
font-size:12px;
text-align: right;
z-index: 1008;
white-space: nowrap;
background: white;
opacity: 0.5;
padding: 5px;
padding-top: 0px;
width: 450px;
border-radius: 10px;
}
a:link, a:visited {
color: blue;
text-decoration: none;
}
li {
list-style-type: none;
display:table;
}
</style>
<script src="/libs/ol/OpenLayers.js"></script>
<script src="/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/libs/styles.js"></script>
<script type="text/javascript">
<!--
var map;
function qs_init() {
var params = {};
var qs = location.search.substring(1, location.search.length);
qs = qs.replace(/\+/g, ' ');
var args = qs.split('&'); // parse out name/value pairs separated via &
for (var i = 0; i < args.length; i++) {
var pair = args[i].split('=');
var name = decodeURIComponent(pair[0]);
var value = (pair.length==2)? decodeURIComponent(pair[1]): name;
params[name] = value;
}
return params;
}
function init()
{
var global_numZoomLevels = 19;
var switcher = new OpenLayers.Control.LayerSwitcher();
map = new OpenLayers.Map({
div: "map",
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
eventListeners: { "moveend": mapMoved },
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation({
dragPanOptions: {
enableKinetic: true
}
}),
new OpenLayers.Control.MousePosition(),
switcher,
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Permalink("permalink")
],
numZoomLevels: global_numZoomLevels,
});
map.getNumZoomLevels = function() {
return global_numZoomLevels;
};
// var layerSwitcher = new OpenLayers.Control.LayerSwitcher();
// map.addcontrol(layerSwitcher);
switcher.maximizeControl();
var permalink_potlatch = new OpenLayers.Control.Permalink("permalink.potlatch");
permalink_potlatch.base = "http://www.openstreetmap.org/edit";
map.addControl(permalink_potlatch);
var layers = [];
/* Base layers inclusion */
for ( var idx in all_available_styles ) {
var local_numZoomLevels = global_numZoomLevels;
if ("numZoomLevels" in all_available_styles[idx]) {
local_numZoomLevels = all_available_styles[idx].numZoomLevels;
}
var l = new OpenLayers.Layer.XYZ(
all_available_styles[idx].name,
all_available_styles[idx].tile_urls,
{
attribution: all_available_styles[idx].attribution + ' | Données <a href="http://www.openstreetmap.org/copyright">© les contributeurs OpenStreetMap</a>',
sphericalMercator: true,
wrapDateLine: true,
transitionEffect: "resize",
buffer: 0,
numZoomLevels: local_numZoomLevels,
}
);
layers.push(l);
}
/* Transparent overlays (must be png with alpha channel) */
for ( var idx in all_available_overlays ) {
var local_numZoomLevels = global_numZoomLevels;
if ("numZoomLevels" in all_available_overlays[idx]) {
local_numZoomLevels = all_available_overlays[idx].numZoomLevels;
}
var overlay = new OpenLayers.Layer.XYZ(
all_available_overlays[idx].name,
all_available_overlays[idx].tile_urls,
{
attribution: all_available_overlays[idx].attribution,
sphericalMercator: true,
wrapDateLine: true,
/* not pretty with alpha transitionEffect: "resize", */
buffer: 0,
numZoomLevels: local_numZoomLevels,
displayOutsideMaxExtent: false,
visibility: false,
isBaseLayer: false,
}
);
layers.push(overlay);
}
map.addLayers(layers);
var params = qs_init();
if (! (params["q"] || params["lat"] || params["lon"] || params["zoom"])) {
// Default coords are set to center view on France
map.setCenter(new OpenLayers.LonLat(2.3508, 46.4).transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() ), 6);
// Try to geolocalise the browser :
if (typeof navigator.geolocation !== 'undefined') {
var gl = navigator.geolocation;
gl.getCurrentPosition( function(position) {
map.setCenter(new OpenLayers.LonLat(position.coords.longitude, position.coords.latitude).transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() ), 12);
}, null);
}
} else if (params["q"]) {
refineSearch();
}
}
/* The code below was shamelessly copied from nominatim's home */
function panToLatLonBoundingBox(lat,lon,minlat,maxlat,minlon,maxlon,points) {
var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326");
var proj_map = map.getProjectionObject();
map.zoomToExtent(new OpenLayers.Bounds(minlon,minlat,maxlon,maxlat).transform(proj_EPSG4326, proj_map));
}
var lastRefine = null;
function refineSearch() {
var q = $("input#q").val();
$("#search_results").empty();
$.get('https://nominatim.openstreetmap.org/search.php?email=sylvain@refuges.info&format=json&q='+q, function (data) {
if (data[0]) {
// map.setCenter(new OpenLayers.LonLat(data[0].lon,data[0].lat).transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() ), 12);
$("#search_results").append('<ul class="search_results">');
for (i in data) {
whereIsThat = data[i].lat+', '+data[i].lon+', '+data[i].boundingbox[0]+', '+data[i].boundingbox[1]+', '+data[i].boundingbox[2]+', '+data[i].boundingbox[3];
$('#search_results').append( '<li '+( (i)?'':' selected')+'onclick="panToLatLonBoundingBox('+whereIsThat+')">'+data[i].display_name+'</li>' );
console.log(data[i]);
}
$("#search_results").append('</ul>');
panToLatLonBoundingBox( data[0].lat, data[0].lon, data[0].boundingbox[0], data[0].boundingbox[1], data[0].boundingbox[2], data[0].boundingbox[3] );
if(history.pushState)
history.pushState({"id":101}, "", "?q="+q);
} else {
$("#search_results").append('<i>Empty result</i>');
}
}, "json");
}
function mapMoved() {
var proj = new OpenLayers.Projection("EPSG:4326");
var bounds = map.getExtent();
bounds = bounds.transform(map.getProjectionObject(), proj);
$('input#viewbox').val = Math.floor(bounds.left,2)+','+Math.ceil(bounds.top,2)+','+Math.ceil(bounds.right,2)+','+Math.floor(bounds.bottom,2);
console.log( Math.floor(bounds.left,2)+','+Math.ceil(bounds.top,2)+','+Math.ceil(bounds.right,2)+','+Math.floor(bounds.bottom,2) );
}
// -->
</script>
</head>
<!-- Le contenu -->
<body onload="init()">
<div id="map"></div>
<div id="search">
<form method="get" onsubmit="return false;">
<input type="text" id="q" value="" name="q" autocomplete="off" />
<input type="hidden" name="viewbox" id="viewbox" />
<input style="vertical-align: middle" onclick="refineSearch()" type="image" src="images/nominatim.gif" title="Search with Nominatim" />
<input type="submit" style="display: none;" />
</form>
<div id="search_results"></div>
</div>
<!--
<div id="attributions">
<p>
<font color="red">The server is currently in maintenance or experiencing problems</font>
</p>
</div>
-->
<div id="permalinks">
<ul>
<li><a id="permalink" href="">Permalink</a></li>
<li><a id="permalink.potlatch" target="_blank" href="">Edit the map</a></li>
</ul>
</div>
</body>
</html>