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) { $section = null; $values = null; $tags = null; $data = $kml_doc; if(!$data){ echo "document empty."; return false; } $this->kml = $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); $cnt_format = 0; $parent = array(); $myParent = array(); $cnt_layer = -1; $layer_style = array(); $cnt_styles = -1; foreach ($values as $element) { if(mb_strtoupper($element[tag]) == "KML" && $element[type] == "open"){ $section = "kml"; } if ($section == "kml" && mb_strtoupper($element[tag]) == "PLACEMARK" && $element[type] == "open") { $section = "placemark"; } if ($section == "placemark" && mb_strtoupper($element[tag]) == "DESCRIPTION" && $element[type] == "complete") { $this->description = $element[value]; } if ($section == "placemark" && mb_strtoupper($element[tag]) == "NAME" && $element[type] == "complete") { $this->title = $element[value]; } if ($section == "placemark" && mb_strtoupper($element[tag]) == "LOOKAT" && $element[type] == "open") { $section = "lookat"; } if ($section == "lookat") { if (mb_strtoupper($element[tag]) == "RANGE" && $element[type] == "complete") { $this->lookAt_range = $element[value]; } if (mb_strtoupper($element[tag]) == "HEADING" && $element[type] == "complete") { $this->lookAt_heading = $element[value]; } if (mb_strtoupper($element[tag]) == "TILT" && $element[type] == "complete") { $this->lookAt_tilt = $element[value]; } } if (mb_strtoupper($element[tag]) == "STYLE" && $element[type] == "open") { $section = "style"; } if ($section == "style" && mb_strtoupper($element[tag]) == "ICONSTYLE" && $element[type] == "open") { $section = "iconstyle"; } if ($section == "iconstyle" && mb_strtoupper($element[tag]) == "ICON" && $element[type] == "open") { $section = "icon"; } if ($section == "icon" && mb_strtoupper($element[tag]) == "HREF" && $element[type] == "complete") { $this->icon = $element[value]; } if (mb_strtoupper($element[tag]) == "POINT" && $element[type] == "open") { $section = "point"; } if ($section == "point" && mb_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; } } // end class ?>