-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.js
38 lines (38 loc) · 1.29 KB
/
init.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
var iDigBio = {
initLeafletData: function(rq) {
'use strict';
jQuery(function() {
var params = {
'rq': rq,
'type': 'points'
};
var url = 'https://search.idigbio.org/v2/mapping';
var getPopupContents = function(props) {
if (props && props.uuid) {
return '<div class="popup">' +
'<em>' + props.scientificname + '</em><br>' +
'<a href="https://www.idigbio.org/portal/records/'+ props.uuid + '" target="_blank">View record on iDigBio</a></div>';
}
else return null;
};
var addGeoJsonLayer = function(data) {
//If the map isn't there, try again in a bit.
if(!(WPLeafletMapPlugin && WPLeafletMapPlugin.maps && WPLeafletMapPlugin.maps[0])) {
setTimeout(function() {addGeoJsonLayer(data);}, 250);
return;
}
var geojsonurl = data['geojson'];
var l = new L.TileLayer.GeoJSON(geojsonurl, null, {
onEachFeature: function (feature, layer) {
var popupString = getPopupContents(feature.properties);
if(popupString) {
layer.bindPopup(popupString);
}
}
});
WPLeafletMapPlugin.maps[0].addLayer(l);
};
jQuery.get(url, params).done(addGeoJsonLayer);
});
}
};