Color Coding the Pins?

I am going to post this as a feature request, because I am pretty sure it is not currently possible.

I am working with some folks at Whitman College to create what will be an interdisciplinary Curatescape installation. The idea is that history students will tell history stories, biology students will create stories about trees and such, etc.

We could differentiate the kinds of stories by organizing them in tours, but what the faculty really want is color-coded pins. What would it take to do that?

Thanks.

Basically the only way to do this is to code it yourself using JavaScript and PHP.

Look at custom.php around line 570 in the theme. The icon property uses a custom function named icon() which accepts two arguments, color (c) and icon style (inner).

var marker = L.marker([item.latitude,item.longitude],{
	icon: icon(c,inner),
	title: convertHtmlToText(item.title),
	alt: convertHtmlToText(item.title),
	}).bindPopup(html);

You can see the definitions for those variables being set for each item in the loop. Currently each variable is defined according to the theme options for the map markers and the item’s featured status (i.e. if the item is featured and the theme option is set to use a star icon style for featured items or an alternate color, then that’s what it does). See line 560-561:

var c = (item.featured==1 && featured_color) ? featured_color : color;
var inner = (item.featured==1 && featuredStar) ? "star" : "circle";

So you could redefine those variables using whatever criteria you like, keeping in mind that you’d also need to add more data to the CuratescapeJSON plugin output, which only includes: id, title, latitude, longitude, street address, date modified, and image info. See views/shared/items/browse.mjson.php in the plugin.

$itemIdArray = array();
foreach
( $items as $item )
{
	if
	($item->public)
	{
		$itemIdArray[] = $item->id;
	}
}
$itemIdList=implode(',', $itemIdArray);

$db=get_db();
$prefix=$db->prefix;
$sql = "
SELECT i.id,
       i.featured,
       i.modified,
       l.latitude,
       l.longitude,
       et1.id 'title_index',
       et1.text 'title',
       et2.text 'address',
       f.filename
FROM ".$prefix."items AS i
JOIN ".$prefix."locations AS l
  ON i.id = l.item_id
JOIN (".$prefix."element_texts AS et1, ".$prefix."elements AS e1)
  ON (i.id = et1.record_id
      AND et1.record_type = 'Item'
      AND et1.element_id = e1.id
      AND e1.name='Title'
      )
LEFT JOIN (".$prefix."element_texts AS et2, ".$prefix."elements AS e2)
  ON (i.id = et2.record_id
      AND et2.record_type = 'Item'
      AND et2.element_id = e2.id
      AND e2.name='Street Address'
      )
LEFT JOIN (".$prefix."files AS f)
  ON (i.id = f.item_id
      AND f.has_derivative_image = 1
      AND f.order = 1
      )
WHERE i.id IN ($itemIdList)
ORDER BY i.id DESC;
";

Unless you like writing MySQL queries, you might want to set $itemJsonifier=true and make your changes in views/helpers.ItemJsonifier.php instead, which is easier to manage but does come with a performance hit for sites with a lot of items. The relevant lines are 62-69:

$itemMetadata = array(
	'id'          => $item->id,
	'featured'    => $item->featured,
	'modified'    => $item->modified,
	'latitude'    => $location[ 'latitude' ],
	'longitude'   => $location[ 'longitude' ],
	'title'       => $titles[0] ? trim(html_entity_decode( strip_formatting( $titles[0] ) )) : 'Untitled',
);

From there you would also probably want to add a key so users understand what each color/icon style represents. There are many ways to do this but ultimately it’s going to mean adding some HTML and CSS to each map instance.

If you pursue this, you’ll come to see why it’s not something we plan to add due to the complexity required to support every possible user preference (i.e. we’d need a dedicated UI to manage which subjects/tags and colors to use and it would be rather difficult to ensure that users make good choices in terms of using too many or too few subjects/tags).

Hope this helps.

PS: also keep in mind that the more you modify the theme and plugins, the harder it will become to take advantage of updates going forward.