kml.inc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide a kml geocoder.
  5. */
  6. /**
  7. * Plugins are described by creating a $plugin array which will be used
  8. * by the system that includes this file.
  9. */
  10. $plugin = array(
  11. 'title' => t("KML"),
  12. 'description' => t('Get the geometry out of a KML string, file, or URL. Supports KMZ files upload as well.'),
  13. 'callback' => 'geocoder_kml',
  14. 'field_types' => array('text', 'text_long', 'file', 'computed'),
  15. 'field_callback' => 'geocoder_kml_field',
  16. );
  17. /**
  18. * Process Markup
  19. */
  20. function geocoder_kml($kml_string, $options = array()) {
  21. geophp_load();
  22. return geoPHP::load($kml_string, 'kml');
  23. }
  24. function geocoder_kml_field($field, $field_item) {
  25. if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
  26. return geocoder_kml($field_item['value']);
  27. }
  28. if ($field['type'] == 'file') {
  29. if ($field_item['fid']) {
  30. $file = file_load($field_item['fid']);
  31. $path = $file->uri;
  32. if ($file->filemime == 'application/vnd.google-earth.kmz' && extension_loaded('zip')) {
  33. $path = 'zip://' . drupal_realpath($path) . '#doc.kml';
  34. }
  35. $kml = file_get_contents($path);
  36. return geocoder_kml($kml);
  37. }
  38. }
  39. }