Recent site activity

Guides‎ > ‎

Short custom field and marker example

This example is from a mailing list thread:

Put in functions.php (perhaps with your own prefix in place of my_):

function my_geo_mashup_locations_json_filter( $json_properties, $queried_object ) {
   $post_id = $queried_object->object_id;
   $imagetype = get_post_meta( $post_id, 'imagetype', true);
   if ( $imagetype == 'faked' ) {
      $json_properties['my_complete'] = 1;
   } else if ( $imagetype == 'real' ) {
      $json_properties['my_complete'] = 2;
   } else {
      $json_properties['my_complete'] = 3;
   }

   return $json_properties;
}
add_filter( 'geo_mashup_locations_json_object','my_geo_mashup_locations_json_filter', 10, 2 );

Here you defined what your custom field is (imagetype in my case) and define the possible values and give them a number.

Put in custom.js:

GeoMashup.addAction( 'objectIcon', function( properties, object ) {
   // Use a special icon in case the custom 'complete' var is set to 1
   if ( object.my_complete == 1 ) {
      object.icon.image = properties.template_url_path + '/images/marker.png';
   } else if ( object.my_complete == 2 ) {
      object.icon.image = properties.template_url_path + '/images/marker1.png';
   } else {
      object.icon.image = properties.template_url_path + '/images/marker2.png';
   }
} );

Here you will define what number has to display a certain marker.
Comments