kml_id = md5(microtime()); $this->x = $x; $this->y = $y; $this->icon = $icon; $this->title = $title; $this->description = $description; } function setLookAt($range, $heading) { $this->lookAt_range = $range; $this->lookAt_heading = $heading; } function createObjFromKML($kml_doc) { $data = $kml_doc; if(!$data){ echo "document empty."; return false; } $this->kml = $this->char_encode($data); $parser = xml_parser_create(CHARSET); xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET); xml_parse_into_struct($parser,$data,$values,$tags); xml_parser_free($parser); $section; $cnt_format = 0; $parent = array(); $myParent = array(); $cnt_layer = -1; $layer_style = array(); $cnt_styles = -1; foreach ($values as $element) { if(strtoupper($element[tag]) == "KML" && $element[type] == "open"){ $section = "kml"; } if ($section == "kml" && strtoupper($element[tag]) == "PLACEMARK" && $element[type] == "open") { $section = "placemark"; } if ($section == "placemark" && strtoupper($element[tag]) == "DESCRIPTION" && $element[type] == "complete") { $this->description = $element[value]; } if ($section == "placemark" && strtoupper($element[tag]) == "NAME" && $element[type] == "complete") { $this->title = $element[value]; } if ($section == "placemark" && strtoupper($element[tag]) == "LOOKAT" && $element[type] == "open") { $section = "lookat"; } if ($section == "lookat") { if (strtoupper($element[tag]) == "RANGE" && $element[type] == "complete") { $this->lookAt_range = $element[value]; } if (strtoupper($element[tag]) == "HEADING" && $element[type] == "complete") { $this->lookAt_heading = $element[value]; } if (strtoupper($element[tag]) == "TILT" && $element[type] == "complete") { $this->lookAt_tilt = $element[value]; } } if (strtoupper($element[tag]) == "STYLE" && $element[type] == "open") { $section = "style"; } if ($section == "style" && strtoupper($element[tag]) == "ICONSTYLE" && $element[type] == "open") { $section = "iconstyle"; } if ($section == "iconstyle" && strtoupper($element[tag]) == "ICON" && $element[type] == "open") { $section = "icon"; } if ($section == "icon" && strtoupper($element[tag]) == "HREF" && $element[type] == "complete") { $this->icon = $element[value]; } if (strtoupper($element[tag]) == "POINT" && $element[type] == "open") { $section = "point"; } if ($section == "point" && strtoupper($element[tag]) == "COORDINATES" && $element[type] == "complete") { $array = explode(",", $element[value]); $this->x = $array[0]; $this->y = $array[1]; } } return true; } function createObjFromDB($kml_id) { $this->kml_id = $kml_id; $sql = "SELECT kml FROM mb_meetingpoint WHERE mb_meetingpoint_id = $1"; $v = array($kml_id); $t = array('s'); $res = db_prep_query($sql, $v, $t); $row = db_fetch_array($res); return $this->createObjFromKML($row['kml']); } function createKMLFromObj(){ $kml = ""; $kml .= "\n"; $kml .= "\n"; $kml .= "\n"; $kml .= "\t" . $this->description . "\n"; $kml .= "\t" . $this->title . "\n"; $kml .= "\t\n"; $kml .= "\t\t" . $this->x . "\n"; $kml .= "\t\t" . $this->y . "\n"; $kml .= "\t\t" . $this->lookAt_range . "\n"; $kml .= "\t\t" . $this->lookAt_tilt . "\n"; $kml .= "\t\t" . $this->lookAt_heading . "\n"; $kml .= "\t\n"; $kml .= "\t0\n"; $kml .= "\t\n"; $kml .= "\t\n"; $kml .= "\t\t1\n"; $kml .= "\t\t" . $this->x . "," . $this->y . "\n"; $kml .= "\t\n"; $kml .= "\n"; $kml .= ""; $this->kml = $kml; return $kml; } function char_encode($s){ if(CHARSET == 'UTF-8'){ $s = utf8_encode($s); } return $s; } } // end class ?>