biopama_protected_areas-8.x-1.3/js/search/pa-search.js
js/search/pa-search.js
//
var mapLoaded = 0;
function mapPostLoadOptions() {
class mapSatControl {
onAdd(thisMap) {
this._map = thisMap;
this._container = document.createElement('div');
this._container.className = 'mapboxgl-ctrl mapboxgl-ctrl-group';
this._container.innerHTML = "<button class='mapboxgl-ctrl-icon mapboxgl-ctrl-sat' title='Toggle Satellite base layer' id='satellite-layer' type='button'><i class='fab fa-grav'></i></button>";
return this._container;
}
onRemove() {
this._container.parentNode.removeChild(this._container);
this._map = undefined;
}
}
mapSat = new mapSatControl();
thisMap.addControl(new mapboxgl.FullscreenControl());
thisMap.addControl(new mapboxgl.NavigationControl());
thisMap.addControl(mapLoader, 'top-left');
thisMap.addControl(mapSat, 'top-right');
jQuery('.mapboxgl-ctrl.ajax-loader').toggle(false);
/* thisMap["dragPan"].disable();
thisMap["scrollZoom"].disable();
thisMap["boxZoom"].disable();
thisMap["dragRotate"].disable();
thisMap["keyboard"].disable();
thisMap["doubleClickZoom"].disable();
thisMap["touchZoomRotate"].disable(); */
jQuery('#satellite-layer').bind("click", function(){
if (jQuery( "#satellite-layer" ).hasClass( "sat-on" )) {
jQuery('#satellite-layer').removeClass( "sat-on" );
thisMap.setLayoutProperty('satellite', 'visibility', 'none');
} else {
jQuery('#satellite-layer').addClass( "sat-on" );
thisMap.setLayoutProperty('satellite', 'visibility', 'visible');
}
});
thisMap.setMinZoom(0);
thisMap.setPaintProperty('wdpaAcpFill', 'fill-opacity', 1);
mapLoaded = 1;
}
(function ($, Drupal) {
Drupal.behaviors.paSearchUpdate = {
attach: function (context, settings) {
if (mapLoaded == 1){
updateSearchMap();
}
/* var wdpaIDarray = jQuery( ".search-wdpa-id" ).map(function() {
return jQuery(this).text().trim();
})
//jQuery(wdpaIDarray).toArray();
console.log(wdpaIDarray);
var searchFilter = buildFilter(wdpaIDarray, 'in', 'WDPAID');
console.log(searchFilter);
thisMap.setFilter('wdpaAcpFill', searchFilter); */
}
};
function updateSearchMap(){
var wdpaIDarray = jQuery( ".search-wdpa-id" ).map(function() {
return parseInt(jQuery(this).text().trim());
})
//jQuery(wdpaIDarray).toArray();
console.log(wdpaIDarray);
var searchFilter = buildFilter(wdpaIDarray, 'in', 'WDPAID');
console.log(searchFilter);
thisMap.setFilter('wdpaAcpFill', searchFilter);
thisMap.setLayoutProperty('wdpaAcpFill', 'visibility', 'visible');
}
})(jQuery, Drupal);