You are here

kml.inc in Geocoder 7

File

plugins/geocoder_handler/kml.inc
View source
<?php

/**
 * @file
 * Plugin to provide a kml geocoder.
 */
$plugin = array(
  'title' => t('KML'),
  'description' => t('Get the geometry out of a KML string, file, or URL. Supports KMZ files upload as well.'),
  'callback' => 'geocoder_kml',
  'field_types' => array(
    'text',
    'text_long',
    'file',
    'computed',
  ),
  'field_callback' => 'geocoder_kml_field',
);

/**
 * Process Markup.
 */
function geocoder_kml($kml_string, $options = array()) {
  geophp_load();
  return geoPHP::load($kml_string, 'kml');
}

/**
 * Plugin callback.
 */
function geocoder_kml_field($field, $field_item) {
  if ($field['type'] === 'text' || $field['type'] === 'text_long' || $field['type'] === 'computed') {
    return geocoder_kml($field_item['value']);
  }
  if ($field['type'] === 'file') {
    if ($field_item['fid']) {
      $file = file_load($field_item['fid']);
      $path = $file->uri;
      if ($file->filemime === 'application/vnd.google-earth.kmz' && extension_loaded('zip')) {
        $path = 'zip://' . drupal_realpath($path) . '#doc.kml';
      }
      $kml = file_get_contents($path);
      return geocoder_kml($kml);
    }
  }
}

Functions

Namesort descending Description
geocoder_kml Process Markup.
geocoder_kml_field Plugin callback.