forked from pnizet/koken_mapbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.lens
281 lines (242 loc) · 8.1 KB
/
map.lens
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
<koken:include file="inc/header.html" />
<koken:load limit="4">
<koken:head>
<meta property="og:site_name" content="{{ site.title }}" />
<meta property="og:title" content="Map..." />
<meta property="og:description" content="Map...." />
<meta property="og:type" content="website" />
<koken:first>
<meta property="og:image" content="{{ content.presets.medium_large.url }}" />
<meta property="og:image:width" content="{{ content.presets.medium_large.width }}" />
<meta property="og:image:height" content="{{ content.presets.medium_large.height }}" />
</koken:first>
<meta property="og:url" content="{{ location.site_url }}{{ location.here }}" />
<koken:not empty="profile.twitter">
<meta name="twitter:card" content="gallery" />
<meta name="twitter:site" content="@{{ profile.twitter }}" />
<meta name="twitter:creator" content="@{{ profile.twitter }}" />
<koken:loop>
<meta name="twitter:image{{ index }}" content="{{ content.presets.medium_large.cropped.url }}">
</koken:loop>
</koken:not>
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.2.3/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.2.3/mapbox.css' rel='stylesheet' />
<style type="text/css">
#map_full { top:0; bottom:0; width:100%; height: 450px; margin-top: -5px;}
@media screen and (min-width: 766px) {
#map_full {
display: inline-block;
height: 1000px;
width: 100%;
}
}
</style>
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/leaflet.markercluster.js'></script>
<style type="text/css">
.marker-cluster-small div {
background-image:url(http://a.tiles.mapbox.com/v3/marker/pin-s+CC3A00.png);
background-repeat:no-repeat;
padding-right:10px
}
.marker-cluster-medium div {
background-image:url(http://a.tiles.mapbox.com/v3/marker/pin-m+CC0001.png)
}
.marker-cluster-large div {
background-image:url(http://a.tiles.mapbox.com/v3/marker/pin-l+CC0001.png)
}
.leaflet-oldie .marker-cluster-small {
background-color:#b5e28c
}
.leaflet-oldie .marker-cluster-small div {
background-color:#6ecc39
}
.leaflet-oldie .marker-cluster-medium {
background-color:#f1d357
}
.leaflet-oldie .marker-cluster-medium div {
background-color:#f0c20c
}
.leaflet-oldie .marker-cluster-large {
background-color:#fd9c73
}
.leaflet-oldie .marker-cluster-large div {
background-color:#f18017
}
.marker-cluster {
background-clip:padding-box;
border-radius:20px
}
.marker-cluster div {
width:30px;
height:50px;
margin-left:5px;
margin-top:5px;
text-align:center;
color:#fff;
font-family:raleway;
font-weight:600
}
.marker-cluster-medium span {
line-height:28px
}
.marker-cluster-large span {
line-height:37px
}
.leaflet-popup-content {
width: 120px
}
</style>
</koken:head>
</koken:load>
<script type="text/javascript">
$(document).ready(function(){
//Check if the current URL contains '#'
if(document.URL.indexOf("#")==-1){
// Set the URL to whatever it was plus "#".
url = document.URL+"#";
location = "#";
//Reload the page
location.reload(true);
}
});
function getParamValue(param,url)
{
var u = url == undefined ? document.location.href : url;
var reg = new RegExp('(\\?|&|^)'+param+'=(.*?)(&|$)');
matches = u.match(reg);
return matches[2] != undefined ? decodeURIComponent(matches[2]).replace(/\+/g,' ').replace('#', '') : '';
}
</script>
<div id='map_full'></div>
<script>
L.mapbox.accessToken= 'Your Koken Access Token';
// Array containing markers datas
var points = new Array();
var useablemarkers = new Array();
var LngA = new Array();
var LatA = new Array();
//function which calculate the median of an array will be used to center the map where you have taken most of your pictures
function median(values) {
values.sort( function(a,b) {return a - b;} );
var half = Math.floor(values.length/2);
if(values.length % 2)
return values[half];
else
return (values[half-1] + values[half]) / 2.0;
}
//koken loop to populate markers datas
<koken:load source="contents">
<koken:loop>
points.push({
cLng: {{ geolocation.longitude }} +0, // hack to add empty coordinate
cLat: {{ geolocation.latitude }} +0,
title: "{{ content.title }}",
url: "{{ content.url }}",
image: "{{ content.presets.small.url }}"
});
</koken:loop>
</koken:load>
// Mapbox spiders
L.MarkerClusterGroup.include({
_zoomOrSpiderfy: function (e) {
var map = this._map;
// The following first condition is the part that is missing in the
// current plugin release, and which triggers a spiderfy if all
// contained markers are still clustered at maximum zoom.
if (e.layer._bounds._northEast.equals(e.layer._bounds._southWest)) {
if (this.options.spiderfyOnMaxZoom) {
e.layer.spiderfy();
}
} else if (map.getMaxZoom() === map.getZoom()) {
if (this.options.spiderfyOnMaxZoom) {
e.layer.spiderfy();
}
} else if (this.options.zoomToBoundsOnClick) {
e.layer.zoomToBounds();
}
// Focus the map again for keyboard users.
if (e.originalEvent && e.originalEvent.keyCode === 13) {
map._container.focus();
}
}
});
// Using clusters
var markers = L.markerClusterGroup(
{
// UNCOMMENT to get a custom icon for a group, here, it's the same as child (ie a camera)
//(be carefull : not work for group over 100 elements)
/* iconCreateFunction: function(cluster) {
return L.mapbox.marker.icon({
// show the number of markers in the cluster on the icon.
'marker-symbol': cluster.getChildCount(),
"marker-size": "large",
"marker-color": "#CC0001",
});
}
,*/
// custom polygon appearance
polygonOptions: {
fillColor: '#FF3D3D',
color: '#FF3D3D',
weight: 2,
opacity: 1,
fillOpacity: 0.5
},
disableClusteringAtZoom : 17,
maxClusterRadius : 50,
spiderfyOnMaxZoom : true
}
);
//loop to populate the median
for(var idx in points) {
// Only for non empty coordinates
if((points[idx].cLng != 0) && (points[idx].cLat != 0)) {
LngA.push(points[idx].cLng);
LatA.push(points[idx].cLat);
}
}
// Is there coordinates in URL from content.lens
if (document.URL.indexOf("qlong")>0)
{
var lat = getParamValue('qlat');
var long = getParamValue('qlong');
var z = 14;
}
else
{
var lat = median(LatA);
var long = median(LngA);
var z = 3;
}
var map = L.mapbox.map('map_full', 'Your Map Id', {'minZoom':'3', 'maxZoom':'15'}).setView([lat, long], z);
// loop to populate marker in clusters
for(var idx in points) {
// Only for non empty coordinates
if((points[idx].cLng != 0) && (points[idx].cLat != 0)) {
var title = points[idx].title+"<br/> <img src=\""+points[idx].image+"\" /> <br/> <a href=\""+points[idx].url+"\">See the picture</a>";
var marker = L.marker(new L.LatLng(points[idx].cLat,points[idx].cLng),
{
icon: L.mapbox.marker.icon({
"title" : "<div>"+points[idx].title+"<br/> <img src=\""+points[idx].image+"\" /> <br/> <a href=\""+points[idx].url+"\">See the picture</a></div>",
"marker-size": "medium",
"marker-color": "#CC0001",
"marker-symbol": "camera"
})
});
marker.bindPopup(title);
markers.addLayer(marker);
}
}
map.addLayer(markers);
// Fits map to markers, uncomment this block if you prefer to see all your markers on the map, it will unzoom in order to fit all the marker in the map
/*
map.on('ready', function() {
map.fitBounds(markers.getBounds());
});
*/
// Center Maps to marker when click
markers.on('click', function(e) {
map.panTo(e.layer.getLatLng());
});
</script>
<koken:include file="inc/footer.html" />