Tiddlywikis — Who, What, How, Why?

My current area of development in my Call of Cthulhu TW is the Geospatial plugin. The documentation isn't too great, but it's simple enough to use the basic version. I made a tiddler called "PlaceMapTemplate" with the following code and a "list-after" field of "$:/core/ui/ViewTemplate/body":
1792514330269.png

Then, when I make a tiddler and tag it "place" and give it a "coordinates" field, Geospatial will put in a map.
1792514386172.png

There are a few caveats. One is, Geospatial uses various map providers under their free licenses, and one of them changed recently so some of the maps don't show anything.
1792514602500.png

Another caveat is, I haven't yet figured out how to change the default zoom on the plugin. The default seems to be maximum zoom, when I'd like it to differ based on an additional tag: "city" tag should give one zoom, "village" maybe a little closer in, etc.
 

log in or register to remove this ad

Okay, this proved to be complicated. Reading Talk TW, the default zoom level is set by a "state" tiddler which can be created for each "place". I created an InitializePlaceMapStartup tiddler with the following code:
<$list filter="[tag[place]has[point]]" variable="place">
<$action-setfield
$tiddler={{{ [<place>addprefix[$:/temp/place-map/]] }}}
lat={{{ [<place>get[point]split[,]first[]trim[]] }}}
long={{{ [<place>get[point]split[,]last[]trim[]] }}}
zoom={{{ [<place>tag[region]then[10]] :else[<place>tag[city]then[12]] :else[<place>tag[town]then[14]] :else[<place>tag[village]then[15]] :else[[8]] }}}
/>
</$list>
And I gave it a "$:/tags/StartupAction/Browser" tag. The tag tells the TW that it should be run when the browser opens the file. When the file is opened, each "place" tiddler has a "state" tiddler created (basically, the same name, but with a prefix of "$:/temp/place-map/". This state tiddler will hold the metadata Geospatial uses to display maps.
I also changed my "PlaceMapTemplate" tiddler to the following code:
<$list filter="[all[current]tag[place]has[coordinates]has[point]]">
<$let
latitude={{{ [<currentTiddler>get[coordinates]split[,]first[]] }}}
longitude={{{ [<currentTiddler>get[coordinates]split[,]last[]] }}}
mapstate={{{ [<currentTiddler>addprefix[$:/temp/place-map/]] }}}
<div style="width: 100%; height: 640px; margin: 10px 0; overflow: hidden;">
<$geomap state=<<mapstate>>>
<$geobaselayer title="$:/plugins/tiddlywiki/geospatial/baselayers/esri-world-imagery"/>
<$geolayer lat=<<latitude>> long=<<longitude>>/>
</$geomap>
</div>
</$let>
</$list>
This tiddler has the tag of "$:/tags/ViewTemplate" so it's run as a template, and a "list-after" field value of "$:/core/ui/ViewTemplate/body" means it displays under the title and any text I put in the body of the tiddler.

Geospatial uses separate "lat" and "long" variables, so I used a filter to split the "point" field of my "place" tiddlers at the comma, leaving "lat" for the first part and "long" for the second part. Then, I defined a default zoom. The first plugin for Tiddlywikis that handled maps was called "leaflet" and it had several defaults; those are what I copied for my "zoom" line. Initially, I thought I could just mush the "<place>...else" parts together, but that didn't work: all the "place" tiddlers had a default zoom of 8. Putting in the " :" made that work correctly.

This one improvement took weeks of occasional noodling around and experimenting. But once you pick up an improvement, all your subsequent TWs improve as well.

EDIT: What it looks like.
1792519498805.png

The next step is to incorporate the maps for various fictional places. That's going to be more complicated. I can easily now make Geospatial show a point I've designated on Earth, but I'm going to need to learn how to substitute a different map...
 

Remove ads

Top