nicemap_capabilities

nicemap/nicemap.module, line 83

Versions
6
nicemap_capabilities($base_url)

The raw nicemap compatibilities parsing function

Parameters

$base_url the base URL of the WMS server

Return value

array on success, exception on error

▾ 2 functions call nicemap_capabilities()

nicemap_capabilities_cache in nicemap/nicemap.module
A proxy to the nicemap compatibilities cache
nicemap_capabilities_cache in nicemap/nicemap.module
A proxy to the nicemap compatibilities cache

Code

<?php
function nicemap_capabilities($base_url) {
  $capabilities = $base_url .'?request=GetCapabilities&service=WMS';

  // Supress errors caused by offline servers
  $cxml = @simplexml_load_file($capabilities);

  if (!$cxml) {
    drupal_set_message('The WMS server could not be reached.');
    return array();
  }

  //if ((float) $cxml['version'] < '1.1.1') {
  //  throw new Exception('WMS Server verson must be 1.1.1. The specified server defined '.
  //    $cxml['version'] .' instead.');
  //}
  //TODO: This could use more error checking
  foreach ($cxml->Capability->Request->GetMap->Format as $f) {
    $file_types[] = (String) $f;
  }

  // Overall info
  $c['info'] = array(
    'name' =>         (String) $cxml->Service->Name,
    'title' =>        (String) $cxml->Service->Title,
    'abstract' =>     (String) $cxml->Service->Abstract,
    'filetypes' =>    (String) $file_types);

  if ($layers = $cxml->Capability->Layer->Layer) {
    // Master layer info
    if (isset($cxml->Capability->Layer->CRS)) {
      $c['crs'][] = (String) $cxml->Capability->Layer->CRS;
    }
    // Grab information particular to each layer
    foreach ($layers as $l) {
      $c['layers'][(String) $l->Name] = array(
        'title' => (String) $l->Title,
        'bounds' =>
          array(
            'minx' => (float) $l->LatLonBoundingBox['minx'],
            'miny' => (float) $l->LatLonBoundingBox['miny'],
            'maxx' => (float) $l->LatLonBoundingBox['maxx'],
            'maxy' => (float) $l->LatLonBoundingBox['maxy']),
        );
        if ((String) $l->SRS) {
          $c['layers'][(String) $l->Name]['srs'] =  (String) $l->SRS;
        }
        if ($l->Style) {
          foreach ($l->Style as $style) {
            $c['layers'][(String) $l->Name]['styles'][(String) $style->Name] = (String) $style->Title;
          }
          // Sort styles
          ksort($c['layers'][(String) $l->Name]['styles']);
        }
    }
  }
  return $c;
}
?>