Skip to content

Commit

Permalink
fix(map-chat): fix pokemon icon scale
Browse files Browse the repository at this point in the history
  • Loading branch information
geminiyellow committed Aug 25, 2016
1 parent a529e0e commit f8449b5
Showing 1 changed file with 46 additions and 88 deletions.
134 changes: 46 additions & 88 deletions map-chat/javascript/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function initialize() {
scaledSize: new google.maps.Size(30, 30)
};


var mapOptions = {
center: defaultLatLng,
zoom: defaultZoom, // The initial zoom level when your map loads (0-20)
Expand Down Expand Up @@ -135,6 +134,41 @@ function createMessage(text) {
text: text
};
}

function setupMarkerAndInfoWindow(msgSessionId, content, position, map, icoOn, icoOff) {
var infoWindow = new google.maps.InfoWindow({
content: content,
maxWidth: 400,
disableAutoPan: true,
zIndex: infoWindowZIndex
});
infoWindowZIndex++;

var marker = new google.maps.Marker({
position: position,
map: map,
draggable: false,
icon: icoOn,
title: "Click to mute/un-mute User " + msgSessionId
});

marker.addListener('click', function () {
if (markersMap[msgSessionId].disabled) {
markersMap[msgSessionId].disabled = false;
marker.setIcon(icoOn);
} else {
markersMap[msgSessionId].disabled = true;
marker.setIcon(icoOff);
infoWindow.close();
}
});

return {
marker: marker,
infoWindow: infoWindow
};
}

function displayChatMessageOnMap(raw) {
var msg = JSON.parse(raw)
//console.log(msg)
Expand Down Expand Up @@ -170,39 +204,15 @@ function displayChatMessageOnMap(raw) {
if (existingTimeoutId) {
clearTimeout(existingTimeoutId);
}
markersMap[msgSessionId].timeoutId =
setTimeout(function () { existingInfoWindow.close() }, 10000);
markersMap[msgSessionId].timeoutId = setTimeout(function () { existingInfoWindow.close() }, 10000);
existingInfoWindow.open(map, existingMarker);
}
} else { // new 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
});

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();
}
});
var markerWindow = setupMarkerAndInfoWindow(msgSessionId,msg.text, newPosition, map, markerImage, disabledMarkerImage);
var infoWindow = markerWindow.infoWindow;
var marker = markerWindow.marker;

if (msg.text) {
if (msg.text !== 'undefined') {
infoWindow.open(map, marker);
}

Expand Down Expand Up @@ -231,7 +241,6 @@ function timeUntil(now, then) {
return diff;
}


function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick) {
// @ro: passing values split from incoming payload into two variables for now (lat and long)
var newPosition = new google.maps.LatLng(olat, olong);
Expand Down Expand Up @@ -264,65 +273,14 @@ function displayMessageOnMap(msg, olat, olong, sessid, icostr, expir, pokenick)
"<a target='_blank' href='$1'>$1</a>"
);

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

var marker = new google.maps.Marker({
position: newPosition,
map: map,
draggable: false,
icon: icostr,
icon: { url: icostr, scaledSize: new google.maps.Size(60, 60) },
title: "Click to mute/un-mute User " + msgSessionId
});
var icon = { url: icostr, scaledSize: new google.maps.Size(36, 36) };
var markerMap = setupMarkerAndInfoWindow(msgSessionId, pName, newPosition, map, icon, icon);
var marker = markerMap.marker;
var infoWindow = markerMap.infoWindow;

marker.addListener('click', function () {
if (markersMap[msgSessionId].disabled) {
markersMap[msgSessionId].disabled = false;
marker.setIcon(icostr);
} else {
markersMap[msgSessionId].disabled = true;
marker.setIcon(disabledMarkerImage);
infoWindow.close();
}
});
} else { // new marker
var infoWindow = new google.maps.InfoWindow({
content: pName,
maxWidth: 400,
disableAutoPan: true,
zIndex: infoWindowZIndex
});
infoWindowZIndex++;

var marker = new google.maps.Marker({
position: newPosition,
map: map,
draggable: false,
icon: { url: icostr, scaledSize: new google.maps.Size(60, 60) },
title: "Click to mute/un-mute User " + msgSessionId
});

marker.addListener('click', function () {
if (markersMap[msgSessionId].disabled) {
markersMap[msgSessionId].disabled = false;
marker.setIcon(icostr);
} else {
markersMap[msgSessionId].disabled = true;
marker.setIcon(icostr);
infoWindow.close();
}
});

if (msg.text) {
if (!markersMap[msgSessionId]) { // new marker
if (msg.text !== 'undefined') {
infoWindow.open(map, marker);

}

var timeoutId = setTimeout(function () { infoWindow.close() }, 10000);
Expand Down

0 comments on commit f8449b5

Please sign in to comment.