<?php #-*-Mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/*
jjfMapper, a cartography program for PHP 4.
Copyright (C) 2004 John J Foerch
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
include_once(JJFM_LIBDIR.'/built_in_icons.php');
include_once(JJFM_LIBDIR.'/geoformat.php');
include_once(JJFM_LIBDIR.'/coordial.php');
class geoformat_coordinatelist extends GeoFormat {
var $filename;
var $dot = false;
var $coords = array();
var $dotcolor = false;
var $drawtrail = false;
var $trailweight = 1;
var $trailcolor = 'lightgray';//default trail color
function parse_instructions (&$ops, &$symbols) {
$ret = array();
if (isset($ops['FILE']))
{
$ret['file'] = expand_symbols ($ops['FILE'], $symbols);
}
if (isset($ops['DOT']))
{
$ret['dot'] = $ops['DOT'];
}
if (isset ($ops['DOTCOLOR']))
{
$ret['dotcolor'] = $ops['DOTCOLOR'];
}
if(isset($ops['TRAILCOLOR']))
{
$ret['trailcolor'] = $ops['TRAILCOLOR'];
}
if(isset($ops['TRAILWEIGHT']))
{
$ret['trailweight'] = $ops['TRAILWEIGHT'];
}
return $ret;
}
function geoformat_coordinatelist($args) {
if (! is_array($args) ||
count($args) == 0)//must have at least a filename or inline data
{
$this->ok=false;
$this->error = 'no args passed';
return;
}
if (isset ($args['file'])) $this->filename = $args['file'];
if ($this->filename == '' && isset ($args['inline']))
{
$content = $args['inline'];
}
if ($this->filename == '' && $content == '')
{
$this->ok=false;
$this->error = 'neither filename nor content were passed';
return;
}
if (isset ($args['trailweight']))
{
$this->trailweight = $args['trailweight'];
$this->drawtrail = true;
}
if (isset ($args['trailcolor']))
{
$this->trailcolor = $args['trailcolor'];
$this->drawtrail = true;
}
if (isset ($args['dot'])) $this->dot = $args['dot'];
else if ($this->drawtrail == false) $this->dot = 'dot';
if (isset ($args['dotcolor']))
{
$this->dotcolor = $args['dotcolor'];
if ($this->dot === false) $this->dot = 'dot';
}
if ($this->filename != '')
{
if (! file_exists ($this->filename))
{
$this->ok=false;
$this->error = 'specified file was not found.';
return;
}
$f = fopen($this->filename,'r');
$content = fread($f,filesize($this->filename));
fclose($f);
}
$content = str_replace("\t",'',$content);
$content = str_replace("\r\n","\n",$content);
$content = str_replace("\r","\n",$content);
$contentarray = explode ("\n",$content);
foreach ($contentarray as $v) {
if (strlen($v) > 0)
{
$c = new Coordial($v);
$this->coords[] = $c->longitude_dc();
$this->coords[] = $c->latitude_dc();
}
}
}
function bounds() {
$minlat = $maxlat = $minlon = $maxlon = false;
for ($a = 0; $a < count ($this->coords) * .5; ++$a) {
$lon = $this->coords[$a * 2];
$lat = $this->coords[$a * 2 + 1];
if ($minlat === false || $minlat > $lat) $minlat = $lat;
if ($minlon === false || $minlon > $lon) $minlon = $lon;
if ($maxlat === false || $maxlat < $lat) $maxlat = $lat;
if ($maxlon === false || $maxlon < $lon) $maxlon = $lon;
}
return array($minlat, $maxlat, $minlon, $maxlon);
}
function validate() {
//TODO: write validation code for coordinatelist
return true;
}
function draw(&$projection) {
$geometry = array();
if ($this->drawtrail)
{
$geometry['track'] = array (
'color' => $this->trailcolor,
'weight' => $this->trailweight,
'data' => $this->coords
);
}
$geometry['point'] = array (
'dot' => $this->dot,
'dotcolor' => $this->dotcolor,
'data' => $this->coords
);
$projection->draw ($geometry);
}
}
?>