Skip to content
Rob Clark edited this page Oct 15, 2018 · 6 revisions

CMB2 Roadway Segments Documentation

Adding a field

Basic Usage:

$cmb_map->add_field( array(    
    'name' => 'Segment',  
    'desc' => '',   
    'id' => $prefix . 'location',   
    'type' => 'snapmap',   
) ); 

To disable polyline drawing, set the "limit_drawing" argument:

$cmb_map->add_field( array(    
    'name' => 'Segment',  
    'desc' => '',   
    'id' => $prefix . 'location',   
    'limit_drawing' => true, 
    'type' => 'snapmap',   
) ); 

To disable roadway snapping for polylines, set the "disable_snap" argument:

$cmb_map->add_field( array(    
    'name' => 'Segment',  
    'desc' => '',   
    'id' => $prefix . 'location',   
    'disable_snap' => true, 
    'type' => 'snapmap',   
) ); 

Displaying A Map (Shortcode Option)

To display a map in post content, use the [snapmap] shortcode. The shortcode will only show a map that has been added to the same post.

Arguments:

  • width: Specify a width for the map (defaults to 100%)
  • height: Specify a height for the map (defaults to 400px)
  • zoom: Specify the map zoom level to start on (defaults to 16)

Displaying A Map (Template Tag)

To display a custom map in your theme, the following function can be utilized: snapmap_build_single($id='',$width='100%',$height='400px',$zoom='16', $center=false, $marker=false, $mapquery=false, $mapstyle=false, $terrain=false)

Arguments:

  • id: The ID of the current item. If providing a custom query, this can be any number.
  • width: Specify a width for the map (defaults to 100%)
  • height: Specify a height for the map (defaults to 400px)
  • zoom: Specify the map zoom level to start on (defaults to 16)
  • center: If you would like to manually set the center point of the map, provide an array with the longitude and latitude (ex: $center = array( 'lat' => '34.71718357761681', 'lng' => '-86.58217504620552' ) )
  • marker: If you would like to use a custom map marker for pins displayed on the map, provide an array with the marker's image URL, size in pixels (width/height), origin, and anchor. (ex: $marker = array( 'url' => 'http://my.domain.com/marker.png', 'size' => '50,50', 'origin' => '0,0', 'anchor' => '25,50' ) ). Used 'scaledSize' instead of size for retina markers.
  • mapquery: A custom set of WP_Query args to pull map data from multiple posts
  • mapstyle: A JSON array of custom map styles
  • terrain: If true, terrain will be overlaid onto the map.