Я работаю над php-файлом, который генерирует файл kml из таблицы mysql, который я затем могу использовать с картами Google.У меня есть файл, работающий и работающий, НО, у меня есть некоторые проблемы с текстом, который должен появиться в всплывающем окне после нажатия на маркер.Во-первых, отображается только первая часть текста [b_name], а во-вторых, я хотел бы отформатировать текст в пузырьке, но мои HTML-теги просто отображаются в виде текста.
Таблица, которую я вытягиваюинформация от - представление, созданное с помощью следующего sql:
create view totalbaeir as
select syslur.sysla, hreppar.hreppur, baeir.b_name, baeir.lat, baeir.lng, baertyper.stjarna
from hreppar, syslur, baeir, baertyper
where (syslur.syslaid = hreppar.syslaid)
AND (baeir.hrepparid = hreppar.hrepparid) order by baeir.b_name;
Это дает мне представление со следующими полями:
sysla (equivalent to f.x. a state)
hreppur (equivalent to f.x. a county)
b_name (farm name)
lat (latitude)
lng (longitude)
stjarna (farm-type, gives the value used to generate a style in the kml file).
Пример маркеров, сгенерированных phpФайл / kml можно увидеть здесь: http://hafdal.dk/index.php/da/kirker/kegnaes-kirke/9-test
Выход php / kml можно увидеть здесь: http://www.hafdal.dk/kml/phpsql_rakeltest1.php
Если вы посмотрите в файл php ниже, вы можете увидеть, чтотекст в пузыре генерируется с помощью следующего кода:
$descText = htmlentities("<b>".$row['b_name']."</b>".$row['hreppur']);
Но если вы посмотрите на пузырь, отображается только переменная b_name и форматирование не работает.
Любые идеи, какЯ могу решить это ??
Вот мой файл php:
<?php
require('phpsqlajax_dbinfo.php');
// Opens a connection to a MySQL server.
$connection = mysql_connect ($server, $username, $password);
if (!$connection)
{
die('Not connected : ' . mysql_error());
}
// Sets the active MySQL database.
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected)
{
die('Can\'t use db : ' . mysql_error());
}
// Selects all the rows in the markers table.
$query = 'SELECT * FROM totalbaeir WHERE lat !=0';
$result = mysql_query($query);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
// Creates the Document.
$dom = new DOMDocument('1.0', 'UTF-8');
// Creates the root KML element and appends it to the root document.
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml');
$parNode = $dom->appendChild($node);
// Creates a KML Document element and append it to the KML element.
$dnode = $dom->createElement('Document');
$docNode = $parNode->appendChild($dnode);
// Creates the two Style elements, one for baer and one for hus, and append the elements to the Document element.
$baerStyleNode = $dom->createElement('Style');
$baerStyleNode->setAttribute('id', 'baerStyle');
$baerIconstyleNode = $dom->createElement('IconStyle');
$baerIconstyleNode->setAttribute('id', 'baerIcon');
$baerIconNode = $dom->createElement('Icon');
$baerHref = $dom->createElement('href', 'http://www.hafdal.dk/kml/torfhus.PNG');
$baerIconNode->appendChild($baerHref);
$baerIconstyleNode->appendChild($baerIconNode);
$baerStyleNode->appendChild($baerIconstyleNode);
$docNode->appendChild($baerStyleNode);
$husStyleNode = $dom->createElement('Style');
$husStyleNode->setAttribute('id', 'husStyle');
$husIconstyleNode = $dom->createElement('IconStyle');
$husIconstyleNode->setAttribute('id', 'husIcon');
$husIconNode = $dom->createElement('Icon');
$husHref = $dom->createElement('href', 'http://www.hafdal.dk/kml/torfhus2.PNG');
$husIconNode->appendChild($husHref);
$husIconstyleNode->appendChild($husIconNode);
$husStyleNode->appendChild($husIconstyleNode);
$docNode->appendChild($husStyleNode);
// Iterates through the MySQL results, creating one Placemark for each row.
while ($row = @mysql_fetch_assoc($result))
{
// Creates a Placemark and append it to the Document.
$node = $dom->createElement('Placemark');
$placeNode = $docNode->appendChild($node);
// Creates an id attribute and assign it the value of id column.
//$placeNode->setAttribute('id', 'placemark' . $row['id']);
// Create name, and description elements and assigns them the values of the name and address columns from the results.
$nameNode = $dom->createElement('name',htmlentities($row['name']));
$placeNode->appendChild($nameNode);
$descText = htmlentities("<b>".$row['b_name']."</b>".$row['hreppur']);
$descNode = $dom->createElement('description', '');
$cdataNode = $dom->createCDATASection($descText);
$descNode->appendChild($cdataNode);
$placeNode->appendChild($descNode);
$styleUrl = $dom->createElement('styleUrl', '#' . $row['stjarna'] . 'Style');
$placeNode->appendChild($styleUrl);
// Creates a Point element.
$pointNode = $dom->createElement('Point');
$placeNode->appendChild($pointNode);
// Creates a coordinates element and gives it the value of the lng and lat columns from the results.
$coorStr = $row['lng'] . ',' . $row['lat'];
$coorNode = $dom->createElement('coordinates', $coorStr);
$pointNode->appendChild($coorNode);
}
$kmlOutput = $dom->saveXML();
while (@ob_end_clean());
header('content-type:text/xml;');
echo $kmlOutput;
?>