Skip to content

Commit

Permalink
fixed: google maps api functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Sep 11, 2020
1 parent b9db8d9 commit 51c334b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 77 deletions.
6 changes: 1 addition & 5 deletions views/default/event_manager/listing/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
throw new EntityNotFoundException();
}

if (elgg_view_exists("event_manager/maps/{$maps_provider}/onthemap.js")) {
elgg_require_js("event_manager/maps/{$maps_provider}/onthemap");
}

$page_owner = elgg_extract('page_owner', $vars);

$body = elgg_format_element('div', [
Expand All @@ -28,6 +24,6 @@

echo elgg_format_element('div', ['id' => 'event_manager_event_map'], $body);

echo elgg_format_element('script', [], 'require(["elgg"], function(elgg) {
echo elgg_format_element('script', [], 'require(["elgg", "event_manager/maps/' . $maps_provider . '/onthemap"], function(elgg) {
elgg.trigger_hook("tab:onthemap", "event_manager");
});');
2 changes: 1 addition & 1 deletion views/default/event_manager/maps/google/location.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<script>
require(['event_manager/maps'], function (EventMap) {
EventMap.setup('#event-manager-gmaps-location', '<?php echo $location; ?>', {
zoom: <?= $zoom_level ?>
zoom: <?php echo $zoom_level; ?>
});
});
</script>
3 changes: 1 addition & 2 deletions views/default/event_manager/maps/google/location_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ define(['jquery'], function($) {
executeSearch();
});

$(document).on('click', '#event-manager-edit-maps-search-container input[name="address_search_save"]', function() {

$(document).on('click', '#event-manager-edit-maps-search-container button[name="address_search_save"]', function() {
var address = $('#event-manager-edit-maps-search-container input[name="address_search"]').val();
var $location_field = $('#event_manager_event_edit input[name="location"]');
var $latitude = $('#event_manager_event_edit input[name="latitude"]');
Expand Down
132 changes: 64 additions & 68 deletions views/default/event_manager/maps/google/onthemap.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,81 @@
define(['jquery', 'elgg'], function($, elgg) {
define(['jquery', 'elgg', 'elgg/Ajax'], function($, elgg, Ajax) {

var execute_search_map = function(event) {

require(['elgg/spinner'], function(spinner) {
spinner.start();

var mapBounds = elgg.event_manager.map.gmap.getBounds();
var latitude = mapBounds.getCenter().lat();
var longitude = mapBounds.getCenter().lng();
var distance_latitude = mapBounds.getNorthEast().lat() - latitude;
var distance_longitude = mapBounds.getNorthEast().lng() - longitude;
if (distance_longitude < 0) {
distance_longitude = 360 + distance_longitude;
}
var mapBounds = elgg.event_manager.map.gmap.getBounds();
var latitude = mapBounds.getCenter().lat();
var longitude = mapBounds.getCenter().lng();
var distance_latitude = mapBounds.getNorthEast().lat() - latitude;
var distance_longitude = mapBounds.getNorthEast().lng() - longitude;
if (distance_longitude < 0) {
distance_longitude = 360 + distance_longitude;
}

var ajax = new Ajax();

$("#latitude").val(latitude);
$("#longitude").val(longitude);
$("#distance_latitude").val(distance_latitude);
$("#distance_longitude").val(distance_longitude);

elgg.action('event_manager/event/search', {
data: $('#event_manager_search_form').serialize(),
success: function(data) {
var response = data.output;

if (!response.markers) {
return;
var canvas_data = $('#event_manager_onthemap_canvas').data();

ajax.action('event_manager/maps/data', {
data: {
...canvas_data,
latitude: latitude,
longitude: longitude,
distance_latitude: distance_latitude,
distance_longitude: distance_longitude
},
success: function(data) {
if (!data.markers) {
return;
}

var shadowIcon = new google.maps.MarkerImage("//chart.apis.google.com/chart?chst=d_map_pin_shadow",
new google.maps.Size(40, 37),
new google.maps.Point(0, 0),
new google.maps.Point(12, 35));

$.each(data.markers, function(i, event) {
if (!elgg.event_manager.markers) {
elgg.event_manager.markers = [];
}

var shadowIcon = new google.maps.MarkerImage("//chart.apis.google.com/chart?chst=d_map_pin_shadow",
new google.maps.Size(40, 37),
new google.maps.Point(0, 0),
new google.maps.Point(12, 35));
var ownIcon = "//maps.google.com/mapfiles/ms/icons/yellow-dot.png";
var attendingIcon = "//maps.google.com/mapfiles/ms/icons/blue-dot.png";

$.each(response.markers, function(i, event) {
if (!elgg.event_manager.markers) {
elgg.event_manager.markers = [];
}

if (elgg.event_manager.markers[event.guid]) {
// already added, so return
return;
}
if (elgg.event_manager.markers[event.guid]) {
// already added, so return
return;
}

var markerOptions = {
lat: event.lat,
lng: event.lng,
animation: google.maps.Animation.DROP,
title: event.title,
shadow: shadowIcon,
};

if (event.iscreator) {
markerOptions.icon = ownIcon;
} else {
if (event.has_relation) {
markerOptions.icon = attendingIcon;
}
var markerOptions = {
lat: event.lat,
lng: event.lng,
animation: google.maps.Animation.DROP,
title: event.title,
shadow: shadowIcon,
};

if (event.iscreator) {
markerOptions.icon = "//maps.google.com/mapfiles/ms/icons/yellow-dot.png";
} else {
if (event.has_relation) {
markerOptions.icon = "//maps.google.com/mapfiles/ms/icons/blue-dot.png";
}

elgg.event_manager.markers[event.guid] = elgg.event_manager.map.gmap.addMarker(markerOptions);
}

elgg.event_manager.markers[event.guid] = elgg.event_manager.map.gmap.addMarker(markerOptions).addListener('click', function() {
require(['elgg/lightbox'], function(lightbox) {
lightbox.open({
'href': elgg.normalize_url('ajax/view/event_manager/event/popup?guid=' + event.guid),
});
});
});
},
complete: function() {
spinner.stop();
}
});
});
}
});
};

var initialize_tab = function() {
if (typeof elgg.event_manager.map === 'undefined') {
require(['elgg/spinner'], function(spinner) {
spinner.start();

require(['event_manager/maps'], function (EventMap) {
elgg.event_manager.map = EventMap.setup('#event_manager_onthemap_canvas');
elgg.event_manager.map.gmap.addListener('idle', execute_search_map);
});
require(['event_manager/maps'], function (EventMap) {
elgg.event_manager.map = EventMap.setup('#event_manager_onthemap_canvas');
elgg.event_manager.map.gmap.addListener('idle', execute_search_map);
});
} else {
execute_search_map();
Expand Down
2 changes: 1 addition & 1 deletion views/default/js/hpneo/gmaps/gmaps.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@
GMaps.staticMapURL = function(options){
var parameters = [],
data,
static_root = (location.protocol === 'file:' ? 'http:' : location.protocol ) + '//maps.googleapis.com/maps/api/staticmap';
static_root = (location.protocol === 'file:' ? 'https:' : location.protocol ) + '//maps.googleapis.com/maps/api/staticmap';

if (options.url) {
static_root = options.url;
Expand Down

0 comments on commit 51c334b

Please sign in to comment.