| 1 |
/* global ol, eventpost_params */ |
| 2 |
jQuery( window ).load(function() { |
| 3 |
|
| 4 |
if(typeof ol !== 'undefined'){ |
| 5 |
ep_maps = []; |
| 6 |
ep_vectorSources = []; |
| 7 |
ep_pop_elements = []; |
| 8 |
ep_popups = []; |
| 9 |
ep_features = []; |
| 10 |
ep_icons = []; |
| 11 |
ep_proj_source = new ol.proj.Projection({code: 'EPSG:4326'}); |
| 12 |
ep_proj_destination = new ol.proj.Projection({code: 'EPSG:900913'}); |
| 13 |
ep_interactions = eventpost_params.map_interactions; |
| 14 |
ep_retina = (window.retina || window.devicePixelRatio > 1.5); |
| 15 |
|
| 16 |
function ep_is_retina(map_id){ |
| 17 |
return (eventpost_params.maptiles[map_id]['urls_retina'] && ep_retina); |
| 18 |
} |
| 19 |
|
| 20 |
/* ------------------------------------------------------------------------------------------------------------------ |
| 21 |
* Single Location link |
| 22 |
* show it in a tiny map instead of following the link |
| 23 |
*/ |
| 24 |
jQuery('a.event_link.gps').click(function () { |
| 25 |
if (jQuery(this).parent().data('latitude') !== undefined && jQuery(this).parent().data('longitude') !== undefined) { |
| 26 |
var lat = jQuery(this).parent().data('latitude'); |
| 27 |
var lon = jQuery(this).parent().data('longitude'); |
| 28 |
var marker = jQuery(this).parent().data('marker'); |
| 29 |
var id = jQuery(this).parent().data('id'); |
| 30 |
var map_id = 'event_map' + id; |
| 31 |
var position = new ol.proj.transform([lon, lat], ep_proj_source, ep_proj_destination); |
| 32 |
if (jQuery('#' + map_id).length === 0) { |
| 33 |
jQuery(this).parent().append('<div id="' + map_id + '-wrap"><div id="' + map_id + '" class="event_map"></div></div>'); |
| 34 |
jQuery('#' + map_id+'-wrap').css({ |
| 35 |
height: '400px', |
| 36 |
margin: 'auto', |
| 37 |
clear: 'both' |
| 38 |
}).animate({height: 'toggle'}, 1); |
| 39 |
|
| 40 |
ep_vectorSources[map_id] = new ol.source.Vector(); |
| 41 |
ep_maps[map_id] = new ol.Map({ |
| 42 |
target: map_id, |
| 43 |
layers: [ |
| 44 |
new ol.layer.Tile({ |
| 45 |
source: new ol.source.XYZ({ |
| 46 |
urls: (ep_is_retina(eventpost_params.defaulttile) ? eventpost_params.maptiles[eventpost_params.defaulttile]['urls_retina'] : eventpost_params.maptiles[eventpost_params.defaulttile]['urls']), |
| 47 |
tilePixelRatio: (ep_is_retina(eventpost_params.defaulttile) ? 2 : 1), |
| 48 |
attribution: eventpost_params.maptiles[eventpost_params.defaulttile]['attribution'] |
| 49 |
}) |
| 50 |
}), |
| 51 |
new ol.layer.Vector({ |
| 52 |
source: ep_vectorSources[map_id] |
| 53 |
}) |
| 54 |
], |
| 55 |
view: new ol.View({ |
| 56 |
center: position, |
| 57 |
zoom: eventpost_params.zoom |
| 58 |
}) |
| 59 |
}); |
| 60 |
|
| 61 |
ep_maps[map_id].addControl(new ol.control.Zoom()); |
| 62 |
var ep_feature = new ol.Feature({ |
| 63 |
geometry: new ol.geom.Point(position) |
| 64 |
}); |
| 65 |
|
| 66 |
if (ep_icons[marker] === undefined) { |
| 67 |
ep_icons[marker] = new ol.style.Style({ |
| 68 |
image: new ol.style.Icon(({ |
| 69 |
anchor: [16, 32], |
| 70 |
anchorXUnits: 'pixels', |
| 71 |
anchorYUnits: 'pixels', |
| 72 |
opacity: 1, |
| 73 |
src: marker |
| 74 |
})) |
| 75 |
}); |
| 76 |
} |
| 77 |
ep_feature.setStyle(ep_icons[marker]); |
| 78 |
ep_vectorSources[map_id].addFeature(ep_feature); |
| 79 |
|
| 80 |
} |
| 81 |
jQuery('#' + map_id+'-wrap').animate({height: 'toggle'}, 1000, function () { |
| 82 |
ep_maps[map_id].getView().setCenter(position); |
| 83 |
}); |
| 84 |
return false; |
| 85 |
} |
| 86 |
}); |
| 87 |
|
| 88 |
|
| 89 |
function ep_focus_feature(map_id, feature){ |
| 90 |
jQuery(ep_pop_elements[map_id]).hide(0); |
| 91 |
view = ep_maps[map_id].getView(); |
| 92 |
var geometry = feature.getGeometry(); |
| 93 |
var coord = geometry.getCoordinates(); |
| 94 |
var pan = view.animate({ |
| 95 |
duration: 1000, |
| 96 |
center: coord |
| 97 |
}); |
| 98 |
ep_popups[map_id].setPosition(coord); |
| 99 |
|
| 100 |
html_output = '<a href="' + feature.get('link') + '">' + |
| 101 |
(feature.get('thumbnail')!==''&&feature.get('thumbnail')!==undefined?'<img src="'+feature.get('thumbnail')+'">':'')+ |
| 102 |
'<strong>' + feature.get('name') + '</strong><br>' + |
| 103 |
'<time>' + feature.get('date') + '</time><br>' + |
| 104 |
'<address>' + feature.get('address') + '</address>' + |
| 105 |
(feature.get('desc')!==''&&feature.get('desc')!==undefined?'<p>'+feature.get('desc')+'</p>':'')+ |
| 106 |
'</a>'; |
| 107 |
jQuery(ep_pop_elements[map_id]).delay(500).html(html_output).show(500); |
| 108 |
} |
| 109 |
|
| 110 |
/* ------------------------------------------------------------------------------------------------------------------ |
| 111 |
* List of events |
| 112 |
* Making a big map with all available locations |
| 113 |
*/ |
| 114 |
// Parse all list wich have to be displayed as a map |
| 115 |
|
| 116 |
jQuery('.event_geolist').each(function () { |
| 117 |
var geo_id = jQuery(this).attr('id'); |
| 118 |
var map_id = 'event_map_all' + geo_id; |
| 119 |
var mark_id = 'event_markersall' + geo_id; |
| 120 |
var width = jQuery(this).data('width'); |
| 121 |
var height = jQuery(this).data('height'); |
| 122 |
var zoom = jQuery(this).data('zoom'); |
| 123 |
var maptile = jQuery(this).data('tile'); |
| 124 |
if(maptile===''){ |
| 125 |
maptile = eventpost_params.defaulttile; |
| 126 |
} |
| 127 |
var disabled_integrations = jQuery(this).data('disabled-interactions'); |
| 128 |
|
| 129 |
// Add html elements for map and popup |
| 130 |
var map_elements = '<div id="' + map_id + '" class="event_map map"></div><div id="' + map_id + '-popup" class="event_map_popup"></div>'; |
| 131 |
jQuery(this).addClass('event_geolist_parsed'); |
| 132 |
var list_position = false; |
| 133 |
// Wrap items if needed |
| 134 |
if(jQuery(this).hasClass('has-list')){ |
| 135 |
list_position = jQuery(this).data('list'); |
| 136 |
jQuery('.event_item', jQuery(this)).wrapAll('<div class="eventpost-item-list">'); |
| 137 |
jQuery('.eventpost-item-list a', jQuery(this)).click(function(e){ |
| 138 |
e.preventDefault(); |
| 139 |
feature_selector = geo_id+'-'+jQuery(this).parents('.event_item').first().data('id') |
| 140 |
console.log(feature_selector); |
| 141 |
if(ep_features[feature_selector] !== 'undefined'){ |
| 142 |
ep_focus_feature(map_id, ep_features[feature_selector]); |
| 143 |
} |
| 144 |
return false; |
| 145 |
}); |
| 146 |
} |
| 147 |
if(list_position === 'below' || list_position === 'right'){ |
| 148 |
jQuery(this).prepend(map_elements); |
| 149 |
} |
| 150 |
else{ |
| 151 |
jQuery(this).append(map_elements); |
| 152 |
} |
| 153 |
|
| 154 |
css = { |
| 155 |
margin: 'auto', |
| 156 |
clear: 'both' |
| 157 |
}; |
| 158 |
if (width !== 'auto') |
| 159 |
css.width = width; |
| 160 |
if (height !== 'auto') |
| 161 |
css.height = height; |
| 162 |
|
| 163 |
if(list_position === 'left' || list_position === 'right'){ |
| 164 |
css.width = '70%'; |
| 165 |
} |
| 166 |
if(list_position === 'above' || list_position === 'below'){ |
| 167 |
jQuery(this).css({height: 'auto'}); |
| 168 |
} |
| 169 |
jQuery('#' + map_id).css(css); |
| 170 |
|
| 171 |
// Create a layer for markers |
| 172 |
ep_vectorSources[map_id] = new ol.source.Vector(); |
| 173 |
|
| 174 |
// Create a popup object |
| 175 |
ep_pop_elements[map_id] = document.getElementById(map_id + '-popup'); |
| 176 |
ep_popups[map_id] = new ol.Overlay({ |
| 177 |
element: ep_pop_elements[map_id], |
| 178 |
positioning: 'bottom-center', |
| 179 |
stopEvent: false |
| 180 |
}); |
| 181 |
|
| 182 |
// Initialize map |
| 183 |
map_settings = { |
| 184 |
target: map_id, |
| 185 |
layers: [ |
| 186 |
new ol.layer.Tile({ |
| 187 |
source: new ol.source.XYZ({ |
| 188 |
urls: (ep_is_retina(maptile) ? eventpost_params.maptiles[maptile]['urls_retina'] : eventpost_params.maptiles[maptile]['urls']), |
| 189 |
tilePixelRatio: (ep_is_retina(maptile) ? 2 : 1), |
| 190 |
attribution: eventpost_params.maptiles[maptile]['attribution'] |
| 191 |
}) |
| 192 |
}), |
| 193 |
new ol.layer.Vector({ |
| 194 |
source: ep_vectorSources[map_id] |
| 195 |
}) |
| 196 |
], |
| 197 |
view: new ol.View({ |
| 198 |
center: [0, 0], |
| 199 |
zoom: isNaN(zoom) ? 12 : zoom, |
| 200 |
maxZoom: 18 |
| 201 |
}), |
| 202 |
overlays: [ep_popups[map_id]] |
| 203 |
}; |
| 204 |
|
| 205 |
ep_maps[map_id] = new ol.Map(map_settings); |
| 206 |
ep_maps[map_id].addControl(new ol.control.ZoomSlider()); |
| 207 |
|
| 208 |
//Add action for each markers |
| 209 |
ep_maps[map_id].on('click', function (evt) { |
| 210 |
var feature = ep_maps[map_id].forEachFeatureAtPixel(evt.pixel, |
| 211 |
function (feature, layer) { |
| 212 |
return feature; |
| 213 |
}); |
| 214 |
if (feature) { |
| 215 |
ep_focus_feature(map_id, feature); |
| 216 |
} else { |
| 217 |
jQuery(ep_pop_elements[map_id]).hide(200); |
| 218 |
} |
| 219 |
}); |
| 220 |
|
| 221 |
var feature_offset = 0; |
| 222 |
// Parse all items to create markers and put them on the map |
| 223 |
jQuery(this).find('address').each(function () { |
| 224 |
feature_offset++; |
| 225 |
var lat = parseFloat(jQuery(this).data('latitude')); |
| 226 |
var lon = parseFloat(jQuery(this).data('longitude')); |
| 227 |
jQuery(this).parents('.event_item').first().data('id', feature_offset); |
| 228 |
if (lat !== undefined && lon !== undefined) { |
| 229 |
var item = jQuery(this).parent().parent(); |
| 230 |
var marker = jQuery(this).data('marker'); |
| 231 |
var id = jQuery(this).data('id'); |
| 232 |
coords = new ol.proj.transform([lon, lat], ep_proj_source, ep_proj_destination); |
| 233 |
|
| 234 |
obj={ |
| 235 |
geometry: new ol.geom.Point(coords), |
| 236 |
name: item.find('h5').text(), |
| 237 |
address: jQuery(this).html(), |
| 238 |
date: item.find('time').text(), |
| 239 |
link: item.find('a').attr('href'), |
| 240 |
desc: item.find('.event_exerpt').html() |
| 241 |
}; |
| 242 |
if(item.find('img').length>0){ |
| 243 |
obj.thumbnail=item.find('img').attr('src'); |
| 244 |
} |
| 245 |
var feature_id = geo_id+'-'+feature_offset; |
| 246 |
ep_features[feature_id] = new ol.Feature(obj); |
| 247 |
|
| 248 |
|
| 249 |
if (ep_icons[marker] === undefined) { |
| 250 |
ep_icons[marker] = new ol.style.Style({ |
| 251 |
image: new ol.style.Icon(({ |
| 252 |
anchor: [16, 32], |
| 253 |
anchorXUnits: 'pixels', |
| 254 |
anchorYUnits: 'pixels', |
| 255 |
opacity: 1, |
| 256 |
src: marker |
| 257 |
})) |
| 258 |
}); |
| 259 |
} |
| 260 |
ep_features[feature_id].setStyle(ep_icons[marker]); |
| 261 |
ep_vectorSources[map_id].addFeature(ep_features[feature_id]); |
| 262 |
} |
| 263 |
}); |
| 264 |
|
| 265 |
//Center the map to show all markers |
| 266 |
ep_maps[map_id].getView().fit(ep_vectorSources[map_id].getExtent(), ep_maps[map_id].getSize()); |
| 267 |
if(!isNaN(zoom) && zoom !== '' && zoom>0){ |
| 268 |
ep_maps[map_id].getView().setZoom(zoom); |
| 269 |
} |
| 270 |
|
| 271 |
m_i=0; |
| 272 |
var int_key; |
| 273 |
for(int_key in ep_interactions){ |
| 274 |
if(disabled_integrations.indexOf(int_key+',')>-1){ |
| 275 |
ep_maps[map_id].getInteractions().getArray()[m_i].setActive(false); |
| 276 |
} |
| 277 |
m_i++; |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
}); |
| 282 |
} |
| 283 |
else{ |
| 284 |
jQuery('.event_geolist').hide(); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
/* ------------------------------------------------------------------------------------------------------------------ |
| 289 |
* Calendar Widget |
| 290 |
*/ |
| 291 |
function eventpost_cal_links() { |
| 292 |
jQuery('.eventpost_calendar table td h4').each(function(){ |
| 293 |
event_datas = jQuery(this).next('.event_data'); |
| 294 |
jQuery(this).css({ |
| 295 |
borderColor: event_datas.css('border-left-color'), |
| 296 |
color: event_datas.css('border-left-color'), |
| 297 |
backgroundColor: event_datas.css('background-color') |
| 298 |
}); |
| 299 |
}); |
| 300 |
jQuery('.eventpost_cal_bt').click(function () { |
| 301 |
var calcont = jQuery(this).parents('.eventpost_calendar'); |
| 302 |
jQuery.get( |
| 303 |
eventpost_params.ajaxurl, |
| 304 |
{ |
| 305 |
action: 'EventPostCalendar', |
| 306 |
date: jQuery(this).data('date'), |
| 307 |
cat: calcont.data('cat'), |
| 308 |
mf: calcont.data('mf'), |
| 309 |
dp: calcont.data('dp'), |
| 310 |
color: calcont.data('color'), |
| 311 |
display_title: calcont.data('title'), |
| 312 |
thumbnail: calcont.data('thumbnail') |
| 313 |
}, |
| 314 |
function (data) { |
| 315 |
calcont.html(data); |
| 316 |
eventpost_cal_links(); |
| 317 |
}); |
| 318 |
} |
| 319 |
); |
| 320 |
jQuery('.eventpost_cal_link').click(function () { |
| 321 |
var calcont = jQuery(this).parents('.eventpost_calendar'); |
| 322 |
jQuery('.eventpost_cal_list', calcont).fadeOut(function () { |
| 323 |
jQuery(this).remove(); |
| 324 |
}); |
| 325 |
jQuery.get( |
| 326 |
eventpost_params.ajaxurl, |
| 327 |
{ |
| 328 |
action: 'EventPostCalendarDate', |
| 329 |
date: jQuery(this).data('date'), |
| 330 |
cat: calcont.data('cat'), |
| 331 |
mf: calcont.data('mf'), |
| 332 |
dp: calcont.data('dp'), |
| 333 |
color: calcont.data('color'), |
| 334 |
display_title: calcont.data('title'), |
| 335 |
thumbnail: calcont.data('thumbnail') |
| 336 |
}, |
| 337 |
function (data) { |
| 338 |
calcont.append('<div class="eventpost_cal_list"><button class="eventpost_cal_close">x</button>' + data + '</div>'); |
| 339 |
calcont.find('.eventpost_cal_list').hide(1).fadeIn(500); |
| 340 |
calcont.find('.eventpost_cal_close').click(function () { |
| 341 |
jQuery(this).parent().hide(500).remove(); |
| 342 |
}); |
| 343 |
}); |
| 344 |
}); |
| 345 |
|
| 346 |
} |
| 347 |
jQuery('.eventpost_calendar').each(function () { |
| 348 |
var calcont = jQuery(this); |
| 349 |
calcont.html('<img src="' + eventpost_params.imgpath + 'cal-loader.gif" class="eventpost_cal_loader"/>'); |
| 350 |
jQuery.get( |
| 351 |
eventpost_params.ajaxurl, |
| 352 |
{ |
| 353 |
action: 'EventPostCalendar', |
| 354 |
date: jQuery(this).data('date'), |
| 355 |
cat: jQuery(this).data('cat'), |
| 356 |
mf: jQuery(this).data('mf'), |
| 357 |
dp: jQuery(this).data('dp'), |
| 358 |
color: jQuery(this).data('color'), |
| 359 |
display_title: jQuery(this).data('title'), |
| 360 |
thumbnail: jQuery(this).data('thumbnail') |
| 361 |
}, |
| 362 |
function (data) { |
| 363 |
calcont.html(data); |
| 364 |
eventpost_cal_links(); |
| 365 |
}); |
| 366 |
}); |
| 367 |
|
| 368 |
}); |
| 369 |
|