Skip to content

Commit

Permalink
Merge pull request #39 from Mygod/fix-anchor
Browse files Browse the repository at this point in the history
Fix anchor again
  • Loading branch information
versx authored Aug 17, 2020
2 parents 80bdb8d + 279ed82 commit b32ff2a
Showing 1 changed file with 42 additions and 52 deletions.
94 changes: 42 additions & 52 deletions src/views/index-js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ $(function () {
iconUrl: availableIconStyles[selectedIconStyle] + '/device/0.png',
iconSize: [30, 30],
iconAnchor: [30 / 2, 30 / 2],
popupAnchor: [0, 30 * -1.567]
popupAnchor: [0, 30 * -.6]
});
deviceOfflineIcon = L.icon({
iconUrl: availableIconStyles[selectedIconStyle] + '/device/1.png',
iconSize: [30, 30],
iconAnchor: [30 / 2, 30 / 2],
popupAnchor: [0, 30 * -1.567]
popupAnchor: [0, 30 * -.6]
});

$('#filtersModal').on('show.bs.modal', function () {
Expand Down Expand Up @@ -3619,7 +3619,7 @@ function getNestMarker (nest, geojson, ts) {
iconUrl: '/img/pokemon/1.png',
iconSize: [30, 30],
iconAnchor: [30 / 2, 30 / 2],
popupAnchor: [0, 30 * -1.567]
popupAnchor: [0, 30 * -.6]
});
return L.marker(latlng, {icon: icon});
},
Expand All @@ -3637,7 +3637,7 @@ function getNestMarker (nest, geojson, ts) {
const icon = L.divIcon({
iconSize: [40, 40],
iconAnchor: [40 / 2, 40 / 2],
popupAnchor: [0, 30 * -1.567],
popupAnchor: [0, 40 * -.6],
className: 'nest-marker',
html: `<center><img src="${availableIconStyles[selectedIconStyle]}/pokemon/${getPokemonIcon(nest.pokemon_id, 0)}" style="width:40px;height:auto; background-color:transparent;"/><br>${typesIcon}</center>`
});
Expand All @@ -3646,7 +3646,7 @@ function getNestMarker (nest, geojson, ts) {
iconUrl: '/img/pokemon/' + nest.pokemon_id + '.png',
iconSize: [30, 30],
iconAnchor: [30 / 2, 30 / 2],
popupAnchor: [0, 30 * -1.567],
popupAnchor: [0, 30 * -.6],
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
shadowSize: [41, 41]
});
Expand Down Expand Up @@ -3693,7 +3693,7 @@ function getPokemonMarkerIcon (pokemon, ts) {
const icon = L.divIcon({
iconSize: [size, size],
iconAnchor: [size / 2, size / 2],
popupAnchor: [0, -(size / 2)],
popupAnchor: [0, size * -.6],
className: 'pokemon-marker',
html: `<center><img src="${availableIconStyles[selectedIconStyle]}/pokemon/${pokemonIdString}" style="width:${size}px;height:auto; background-color:transparent; ` +
(
Expand Down Expand Up @@ -3729,18 +3729,16 @@ function getPokemonMarker (pokemon, ts) {
}

function getPokestopMarkerIcon (pokestop, ts) {
let iconSize = 30;
let iconHtml = '<span class="text-nowrap text-center">';
let iconUrl = '';
let sizeId = '0';
let iconAnchor = [];
let questSize = 0;
let iconHtml = '';
const lureIconId = getLureIconId(pokestop.lure_id);
const activeLure = showPokestops && lureIconId > 0 && pokestop.lure_expire_timestamp >= ts;
const activeInvasion = showInvasions && pokestop.incident_expire_timestamp >= ts;
if (showQuests && pokestop.quest_type !== null && pokestop.quest_rewards[0] !== undefined) {
const id = pokestop.quest_rewards[0].type;
const info = pokestop.quest_rewards[0].info;
let rewardString;
let iconUrl;
if (id === 1 && info !== undefined && info.amount !== undefined) {
iconUrl = `${availableIconStyles[selectedIconStyle]}/item/-2.png`;
} else if (id === 2 && info !== undefined && info.amount !== undefined && info.item_id !== undefined) {
Expand All @@ -3761,35 +3759,28 @@ function getPokestopMarkerIcon (pokestop, ts) {
iconUrl = `${availableIconStyles[selectedIconStyle]}/pokemon/${getPokemonIcon(info.pokemon_id, 0)}`;
}
}
iconHtml += `<img src="${iconUrl}" style="width:${iconSize}px;height:auto; background-color:transparent; display:inline-block; padding:0; margin:0 0 0 0;"/>`;
iconSize = getQuestSize(rewardString);
iconAnchor = [iconSize / 2, iconSize * 1.9];//1.567];
} else {
iconSize = getPokestopSize(sizeId);
iconAnchor = [iconSize / 2, iconSize];// * 1.567];
questSize = getQuestSize(rewardString);
iconHtml += `<img src="${iconUrl}" style="width:${questSize}px;height:${questSize}px; background-color:transparent; display:inline-block; padding:0; margin:0 0 0 0;"/><br>`;
}
let sizeId = '0';
if (activeInvasion && activeLure) {
sizeId = 'i' + lureIconId;
iconSize = getPokestopSize(sizeId);
iconAnchor = [iconSize / 2, iconSize * 1.567];
} else if (activeInvasion) {
sizeId = 'i0';
iconSize = getPokestopSize(sizeId);
iconAnchor = [iconSize / 2, iconSize];// * 1.567],
} else if (activeLure) {
sizeId = lureIconId;
iconSize = getPokestopSize(sizeId);
iconAnchor = [iconSize / 2, iconSize];// * 1.567],
}
iconHtml += '</span>';
const stopSize = getPokestopSize(sizeId);
const iconWidth = Math.max(questSize, stopSize);
const iconAnchorY = questSize + stopSize * .896;
const icon = L.divIcon({
iconSize: [iconSize, iconSize],
iconAnchor: iconAnchor,
popupAnchor: [0, iconSize * -1.567],
iconSize: [iconWidth, questSize + stopSize],
iconAnchor: [iconWidth / 2, iconAnchorY],
popupAnchor: [0, -8 - iconAnchorY],
className: 'pokestop-marker',
html: activeInvasion
? `<center>${iconHtml}<img src="${availableIconStyles[selectedIconStyle]}/invasion/${sizeId}_${pokestop.grunt_type}.png" style="width:${iconSize}px;height:auto; background-color:transparent;"/><br></center>`
: `<center>${iconHtml}<img src="${availableIconStyles[selectedIconStyle]}/pokestop/${sizeId}.png" style="width:${iconSize}px;height:auto; background-color:transparent;"/><br></center>`
? `<center>${iconHtml}<img src="${availableIconStyles[selectedIconStyle]}/invasion/${sizeId}_${pokestop.grunt_type}.png" style="width:${stopSize}px;height:${stopSize}px; background-color:transparent;"/></center>`
: `<center>${iconHtml}<img src="${availableIconStyles[selectedIconStyle]}/pokestop/${sizeId}.png" style="width:${stopSize}px;height:${stopSize}px; background-color:transparent;"/></center>`
});
return icon;
}
Expand Down Expand Up @@ -3858,43 +3849,42 @@ function getGymMarkerIcon (gym, ts) {
}

const raidLevel = gym.raid_level;
let iconSize;
let raidSize = 0;
let iconHtml = '';
let ignoreGymIcon = false;
if (gym.raid_battle_timestamp <= ts && gym.raid_end_timestamp >= ts && showRaids && parseInt(gym.raid_level) > 0) {
if (gym.raid_pokemon_id !== 0 && gym.raid_pokemon_id !== null) {
// Raid Boss
iconSize = getRaidSize('p' + gym.raid_pokemon_id);
iconHtml = `<img src="${availableIconStyles[selectedIconStyle]}/pokemon/${getPokemonIcon(gym.raid_pokemon_id, gym.raid_pokemon_form)}" style="width:${iconSize}px;height:auto; background-color:transparent;"/>`;
raidSize = getRaidSize('p' + gym.raid_pokemon_id);
iconHtml = `<img src="${availableIconStyles[selectedIconStyle]}/pokemon/${getPokemonIcon(gym.raid_pokemon_id, gym.raid_pokemon_form)}" style="width:${raidSize}px;height:${raidSize}px; background-color:transparent;"/><br>`;
} else {
// Egg
iconSize = getRaidSize('l' + raidLevel);
iconHtml = `<img src="${availableIconStyles[selectedIconStyle]}/unknown_egg/${raidLevel}.png" style="width:${iconSize}px;height:auto; background-color:transparent;"/>`;
raidSize = getRaidSize('l' + raidLevel);
iconHtml = `<img src="${availableIconStyles[selectedIconStyle]}/unknown_egg/${raidLevel}.png" style="width:${raidSize}px;height:${raidSize}px; background-color:transparent;"/><br>`;
}
} else if (gym.raid_end_timestamp >= ts && parseInt(gym.raid_level) > 0 && showRaids) {
// Egg
iconSize = getRaidSize('l' + raidLevel);
iconHtml = `<img src="${availableIconStyles[selectedIconStyle]}/egg/${raidLevel}.png" style="width:${iconSize}px;height:auto; background-color:transparent;"/>`;
raidSize = getRaidSize('l' + raidLevel);
iconHtml = `<img src="${availableIconStyles[selectedIconStyle]}/egg/${raidLevel}.png" style="width:${raidSize}px;height:${raidSize}px; background-color:transparent;"/><br>`;
}
// Gym
let gymSize;
if (gym.in_battle) {
// Gym Battle
gymSize = 55; //Set Larger Size For Battle
iconHtml += `<img src="${availableIconStyles[selectedIconStyle]}/battle/${gym.team_id}_${size}.png" style="width:${gymSize}px;height:${gymSize}px; background-color:transparent;"/>`;
} else {
// Gym
if (gym.in_battle) {
// Gym Battle
iconSize = 55; //Set Larger Size For Battle
iconHtml = `<img src="${availableIconStyles[selectedIconStyle]}/battle/${gym.team_id}_${size}.png" style="width:${iconSize}px;height:auto; background-color:transparent;"/>`;
ignoreGymIcon = true;
} else {
// Gym
iconSize = getGymSize(gym.team_id);
}
gymSize = getGymSize(gym.team_id);
iconHtml += `<img src="${availableIconStyles[selectedIconStyle]}/gym/${gym.team_id}_${size}.png" style="width:${gymSize}px;height:${gymSize}px; background-color:transparent;"/>`;
}
const iconWidth = Math.max(raidSize, gymSize);
const iconAnchorY = raidSize + gymSize * .917;
const icon = L.divIcon({
iconSize: [iconSize, iconSize],
iconAnchor: [iconSize / 2, iconSize * 1.567],
popupAnchor: [0, iconSize * -1.567], // 0, -20
iconSize: [iconWidth, raidSize + gymSize],
iconAnchor: [iconWidth / 2, iconAnchorY],
popupAnchor: [0, -8 - iconAnchorY],
className: 'gym-marker',
html: ignoreGymIcon
? `<center>${iconHtml}<br></center>`
: `<center>${iconHtml}<br><img src="${availableIconStyles[selectedIconStyle]}/gym/${gym.team_id}_${size}.png" style="width:${iconSize}px;height:auto; background-color:transparent;"/><br></center>`
html: `<center>${iconHtml}</center>`
});
return icon;
}
Expand Down

0 comments on commit b32ff2a

Please sign in to comment.