Skip to content

Commit

Permalink
Revert "Split payload body into two variables (latitude/longitude) " (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
BreezeRo authored Aug 22, 2016
1 parent c324da6 commit 7abb814
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
8 changes: 3 additions & 5 deletions map-chat/javascript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ function initialiseEventBus(){

client.on("message", function(topic, payload) {
//alert([topic, payload].join(": "));

//client.end();

Materialize.toast(payload, 4000);
Materialize.toast(payload, 2000);

//@ro: let's grab the message and split that shit. (simple for now, maybe we could just parse the json instead)
var pLoadR = payload.toString();
var pLoadR2 = pLoadR.split(",");
var olat = pLoadR2[0]
var olong = pLoadR2[1]
var sessid = pLoadR2[2]

displayMessageOnMap(payload, olat, olong, sessid);
//client.end();
displayMessageOnMap(payload, olat, olong);
});

client.publish("pgomapcatch", "I just connected to the map!");
Expand Down
42 changes: 16 additions & 26 deletions map-chat/javascript/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ function createMessage(text){
};
}

function displayMessageOnMap(msg, olat, olong, sessid){
function displayMessageOnMap(msg, olat, olong){

// @ro: passing values split from incoming payload into two variables for now (lat and long)
var newPosition = new google.maps.LatLng(olat, olong);
var msgSessionId = sessid;
var msgSessionId = msg.sessionId;

// @ro: just checking the output
console.log(olat);
Expand All @@ -150,32 +150,22 @@ function displayMessageOnMap(msg, olat, olong, sessid){
"<a target='_blank' href='$1'>$1</a>");

if(markersMap[msgSessionId]){ // update existing marker
var infoWindow = new google.maps.InfoWindow({
content: msg.text,
maxWidth: 400,
disableAutoPan: true,
zIndex: infoWindowZIndex
});
infoWindowZIndex++;

var marker = new google.maps.Marker({
position: newPosition,
map: map,
draggable: false,
icon: markerImage,
title: "Click to mute/un-mute User "+msgSessionId
});
var existingMarker = markersMap[msgSessionId].marker;
var existingInfoWindow = markersMap[msgSessionId].infoWindow;
var existingTimeoutId = markersMap[msgSessionId].timeoutId;

marker.addListener('click',function() {
if (markersMap[msgSessionId].disabled) {
markersMap[msgSessionId].disabled = false;
marker.setIcon(markerImage);
} else{
markersMap[msgSessionId].disabled = true;
marker.setIcon(disabledMarkerImage);
infoWindow.close();
existingMarker.setPosition(newPosition);
existingInfoWindow.setContent(msg.text);
existingInfoWindow.setZIndex(infoWindowZIndex);
infoWindowZIndex++;
if (msg.text && !markersMap[msgSessionId].disabled) {
if (existingTimeoutId){
clearTimeout(existingTimeoutId);
}
});
markersMap[msgSessionId].timeoutId =
setTimeout(function() { existingInfoWindow.close() }, 10000);
existingInfoWindow.open(map, existingMarker);
}
} else { // new marker
var infoWindow = new google.maps.InfoWindow({
content: msg.text,
Expand Down

0 comments on commit 7abb814

Please sign in to comment.