Skip to content

Commit

Permalink
feat: add zoom level option to geotags so that they can appear only w…
Browse files Browse the repository at this point in the history
…hen zoomed in
  • Loading branch information
qthequartermasterman committed Dec 15, 2023
1 parent 7353329 commit b8d0afa
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
21 changes: 21 additions & 0 deletions docs/Background/geography/neighborhoods.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,27 @@ The PC with the highest Charisma makes a settlement reputation test **(CHA + Rep
- Motel: A motel that provides lodging for travelers and traders passing through the settlement. The motel is run by its manager Lily Harper who oversees the settlement's hospitality operations.
- Apartment Complexes: Scarsdale is the home of several apartment complexes, where residents and visitors can find shelter and rest. The apartment complexes are managed by a superintendent Felix Mitchell who oversees the settlement's housing operations.
- Houses: On the southern edge of the settlement, there are several houses where wealthier residents live.
<geotag
latitude=29.597067373785425
longitude=-95.19903809659499
icon="FOOD"
name="Pipes Bar and Grill"
zoom=TOWN
/>
<geotag
latitude=29.59671287345751
longitude=-95.19940287700209
icon="WAREHOUSE"
name="Scarsdale Market"
zoom=TOWN
/>
<geotag
latitude=29.5970860316629
longitude=-95.20082981212396
icon="HOSPITAL"
name="Medical Clinic"
zoom=TOWN
/>

### NPCs
- Rumormonger Wilkins: A chatty and inquisitive local resident. Wilkins can be found at any of the settlement's gathering area, but most frequently at Pipes, eager to share information, for those that will buy him a drink.
Expand Down
5 changes: 5 additions & 0 deletions render_map/map_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ class MapIcon(enum.Enum):

LIGHT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/e/ed/59.svg"
RADIO = "https://static.wikia.nocookie.net/fallout_gamepedia/images/6/64/62.svg"

FOOD = SETTLEMENT
WATER = SETTLEMENT
POWER = SETTLEMENT
DEFENSE = SETTLEMENT
36 changes: 34 additions & 2 deletions render_map/map_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@

<script type="text/javascript">
let markers = [];
// Hide town markers when zoomed out.
/**
* @param {google.maps.Map} map
* @param {{marker: google.maps.Marker, zoom: number}} marker
* @param {number} zoomLevel
*/
function updateMarkerVisibility(map, marker, zoomLevel) {
if (zoomLevel>=marker.zoom) {
marker.marker.setMap(map);
} else {
marker.marker.setMap(null);
}
}
/**
* @param {google.maps.Map} map
*/
function updateMarkersVisibility(map) {
const zoomLevel = map.getZoom();
if (zoomLevel) {
for (let i = 0; i < markers.length; i++) {
updateMarkerVisibility(map, markers[i], zoomLevel);
}
}
}

/**
* @param {{name: string, latitude: number, longitude: number, icon: string, zoom: number}} mapMarker
* @param {google.maps.Map} map
*/
function addMarker(mapMarker, map){
const title = mapMarker.name;
let marker = new google.maps.Marker({
Expand All @@ -20,7 +49,9 @@
title: title,
icon: {url: mapMarker.icon, scaledSize: new google.maps.Size(20, 20)},
});
markers.push(marker);
let marker_container = {'marker': marker, 'zoom': mapMarker.zoom};
updateMarkerVisibility(map, marker_container, map.getZoom());
markers.push(marker_container);

const infoWindowContent = `
<div class="info-window">
Expand Down Expand Up @@ -73,7 +104,8 @@ <h3>${title}</h3>
for (const mapMarker of mapMarkers) {
addMarker(mapMarker, map);
}

updateMarkersVisibility(map);
map.addListener('zoom_changed', () => {updateMarkersVisibility(map);} );
}
window.initMap = initMap;
</script>
15 changes: 14 additions & 1 deletion render_map/render_map.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import enum
import json
import pathlib
import re
Expand Down Expand Up @@ -30,6 +31,12 @@
)
MAP_TEMPLATE = MAP_TEMPLATE.replace("{{STYLE}}", json.dumps(MAP_STYLE_JSON))

class ZoomLevel(enum.Enum):
"""The zoom level of the map."""

WASTELAND = 0 # Always visible
TOWN=14


class GeoLink(pydantic.BaseModel):
model_config = pydantic.ConfigDict(use_enum_values=True)
Expand All @@ -40,6 +47,7 @@ class GeoLink(pydantic.BaseModel):
icon: map_icons.MapIcon = pydantic.Field(
default=map_icons.MapIcon.SETTLEMENT, validate_default=True
)
zoom: ZoomLevel = pydantic.Field(default=ZoomLevel.WASTELAND, validate_default=True)


GEO_LINKS: list[GeoLink] = []
Expand All @@ -65,6 +73,12 @@ def find_geo_links(markdown: str) -> list[GeoLink]:
else:
result.pop("icon")

if "zoom" in result:
if result["zoom"]:
result["zoom"] = getattr(ZoomLevel, result["zoom"])
else:
result.pop("zoom")

geo_links.append(GeoLink(**result))
return geo_links

Expand Down Expand Up @@ -144,7 +158,6 @@ def on_page_context(
return

if """<div id="map"></div>""" in page.content:
print(page.content)
map_source = create_map_template(config)

page.content += "\n\n\n\n"
Expand Down

0 comments on commit b8d0afa

Please sign in to comment.