-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
leaflet_helper.js
144 lines (125 loc) · 5.64 KB
/
leaflet_helper.js
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
function setupLeafletMap() {
//Bounding map.
var bounds = new L.LatLngBounds(new L.LatLng(84.67351257 , -172.96875) , new L.LatLng(-54.36775852 , 178.59375)) ;
var map = L.map('map_leaflet' , {
maxBounds: bounds ,
maxBoundsViscosity: 0.75
}) ;
return map ;
}
function PLmarker_default(){
L.Icon.PLmarker = L.Icon.extend({
options: {
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-black.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
}
});
return new L.Icon.PLmarker();
}
function peopleLayerParser(map, markers_hash) {
var NWlat = map.getBounds().getNorthWest().lat ;
var NWlng = map.getBounds().getNorthWest().lng ;
var SElat = map.getBounds().getSouthEast().lat ;
var SElng = map.getBounds().getSouthEast().lng ;
map.spin(true) ;
let people_url = "/api/srch/nearbyPeople?nwlat=" + NWlat + "&selat=" + SElat + "&nwlng=" + NWlng + "&selng=" + SElng;
$.getJSON(people_url , function (data) {
if (!!data.items) {
for (i = 0; i < data.items.length; i++) {
var default_markers = PLmarker_default();
var mid = data.items[i].doc_id ;
var url = data.items[i].doc_url;
var title = data.items[i].doc_title;
var m = L.marker([data.items[i].latitude, data.items[i].longitude], {
title: title,
icon: default_markers
}) ;
if(markers_hash.has(mid) === false){
m.addTo(map).bindPopup("<a href=" + url + ">" + title + "</a>") ;
markers_hash.set(mid , m) ;
}
}
}
map.spin(false) ;
});
}
function contentLayerParser(map, markers_hash, map_tagname) {
var NWlat = map.getBounds().getNorthWest().lat ;
var NWlng = map.getBounds().getNorthWest().lng ;
var SElat = map.getBounds().getSouthEast().lat ;
var SElng = map.getBounds().getSouthEast().lng ;
map.spin(true) ;
if(map_tagname === null || (typeof map_tagname === "undefined")) {
taglocation_url = "/api/srch/taglocations?nwlat=" + NWlat + "&selat=" + SElat + "&nwlng=" + NWlng + "&selng=" + SElng ;
} else {
taglocation_url = "/api/srch/taglocations?nwlat=" + NWlat + "&selat=" + SElat + "&nwlng=" + NWlng + "&selng=" + SElng + "&tag=" + map_tagname ;
}
$.getJSON(taglocation_url , function (data) {
if (!!data.items) {
for (i = 0; i < data.items.length; i++) {
var url = data.items[i].doc_url;
var title = data.items[i].doc_title;
var author = data.items[i].doc_author;
var image_url = data.items[i].doc_image_url;
var default_url = PLmarker_default();
var mid = data.items[i].doc_id ;
var m = L.marker([data.items[i].latitude, data.items[i].longitude], {icon: default_url}).bindPopup("<a href=" + url + ">" + title + "</a>") ;
if(markers_hash.has(mid) === false){
if(image_url) {
m.addTo(map).bindPopup("<div><img src=" + image_url+ " height='140px' /><br>" + "<b>Title:</b> " + title + "<br><b>Author:</b> <a href=" + 'https://publiclab.org/profile/' + author + ">" + author + "</a><br>" + "<a href=" + url + ">" + "Read more..." + "</a></div>" ) ;
} else {
m.addTo(map).bindPopup("<span><b>Title:</b> " + title + "</span><br><span><b>Author:</b> <a href=" + 'https://publiclab.org/profile/' + author + ">" + author + "</a></span><br>" + "<a href=" + url + ">" + "<br>Read more..." + "</a>" ) ;
}
markers_hash.set(mid , m) ;
}
}
}
map.spin(false) ;
});
}
function setupInlineLEL(map , layers, mainLayer, markers_hash) {
layers = layers.split(',');
L.tileLayer('https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png').addTo(map) ;
var oms = omsUtil(map, {
keepSpiderfied: true,
circleSpiralSwitchover: 0
});
L.LayerGroup.EnvironmentalLayers({
include: layers,
}).addTo(map);
if(typeof mainLayer !== "undefined" && mainLayer !== ""){
if(mainLayer === "people"){
peopleMap();
map.on('zoomend', peopleMap);
map.on('moveend', peopleMap);
}
else {
mainLayer = (mainLayer === "content") ? null : mainLayer;
contentMap();
map.on('zoomend', contentMap);
map.on('moveend', contentMap);
}
}
function contentMap() {
contentLayerParser(map, markers_hash, mainLayer);
}
function peopleMap() {
peopleLayerParser(map, markers_hash);
}
}
function setupLEL(map , sethash){
L.tileLayer('https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map) ;
var oms = omsUtil(map, {
keepSpiderfied: true,
circleSpiralSwitchover: 0
});
L.LayerGroup.EnvironmentalLayers({
hash: !!sethash,
}).addTo(map);
}