Temat: Google Maps - nietypowo - pomoc za free
to jest kod ze strony, którą podałeś.
najpierw markery ładujesz do tablicy, a następnie tą tablicę przekazujesz do obiektu klasy MarkerClusterer. nie wydaje się to być bardzo skomplikowane.
Hehe tyle to ja wiem. Pomocy w tłumaczeniu nie potrzebuję... Niestety nie udało mi się pożenić tego z kodem, który już mam do generowania obecnych markerów...
EDIT:
To może wkleję cały kod wtyczki, ogólnodostępnej na licencji GPL. Trochę to przerabiałem, tak to wygląda:
<?php
/**
* Admin cpanel
*/
function lugmap_admin() {
add_management_page(__("Lug Map","lug-map"), __("Lug Map","lug-map"), 3, "lug-map", "lugmap_menu");
}
/**
* Admin actions
*/
function lugmap_menu() {
global $wpdb;
$table = $wpdb->prefix."lugmap";
if ( isset( $_POST['lugmap_api_key'] ) && isset( $_POST['lugmap_coord'] ) ) {
if($_POST['lugmap_api_key'])
update_option('lugmap_api_key', attribute_escape($_POST['lugmap_api_key']));
if($_POST['lugmap_coord'])
update_option('lugmap_coord', attribute_escape($_POST['lugmap_coord']));
?><div id="message" class="updated fade"><p><strong><?php echo __("Options saved.",'lug-map') ?></strong></p></div><?php
}
if( isset($_GET['delete_lugmap_marker'])) {
$lugmap_marker_id = attribute_escape($_GET['delete_lugmap_marker']);
$wpdb->query("DELETE FROM $table WHERE id = $lugmap_marker_id");
?><div id="message" class="updated fade"><p><strong><?php printf(__('Marker %1$s deleted.','lug-map'),"$lugmap_marker_id"); ?></strong></p></div><?php
}
if($_POST['lugmap_clean'] == 'true')
lugmap_clean();
?>
<div id="icon-tools" class="icon32"><br /></div>
<div class="wrap">
<h2><?php echo __('Lug Map Options','lug-map')?></h2>
<div id="poststuff" class="metabox-holder">
<div class="postbox">
<h3 class="hndle" ><?php echo __('How to use it?','lug-map')?></h3>
<div class="inside">
<p><?php echo __('Insert inside the content of a page or a post the shortcode: <code>[LUGMAP]</code>','lug-map')?></p>
</div>
</div>
<div class="postbox">
<h3 class="hndle" ><?php echo __('Google Maps API Key','lug-map')?>, <?php echo __('Lug Map Start-Up Location','lug-map')?></h3>
<div class="inside">
<form action="" method="post" >
<p>
<small><?php printf(__('Can be obtained <a href="%1$s">here</a>','lug-map'), 'http://code.google.com/apis/maps/signup.html')?>.</small>
</p>
<p>
<input size="86" maxlength="86" style="font-family: 'Courier New',Courier,mono; font-size: 1.5em;" type="text" name="lugmap_api_key" value="<?php form_option('lugmap_api_key') ?>" />
</p>
<p>
<small><?php printf(__('Please add the coordinates for the location wich should be loaded on showing up the map. You can use <a href="%1$s">this tool</a>','lug-map'),'http://itouchmap.com/latlong.html')?>.</small><br />
</p>
<p>
<input size="20" style="font-family: 'Courier New',Courier,mono; font-size: 1.5em;" type="text" name="lugmap_coord" value="<?php form_option('lugmap_coord') ?>" />
</p>
<p>
<input type="submit" class="button" value="<?php echo __('Save Changes','lug-map')?>" />
</p>
</form>
</div>
</div>
<div class="postbox">
<h3 class="hndle" ><?php echo __('Here you can delete entries','lug-map')?></h3>
<div class="inside">
<ol>
<?php $markers = $wpdb->get_results("SELECT * FROM $table");
$wpdb->show_errors();
foreach($markers as $marker) {
printf(__('<li><a href="%1$s" title="Delete this marker" style="font-weight: bolder;" >X</a> | Geolocation: %2$s, Name: <strong>%3$s</strong>, URL: <a href="%4$s">%4$s</a>, Contact: <a href="mailto:%5$s">%6$s</a><br />%7$s</li>','lug-map'), "?page=lug-map&delete_lugmap_marker=$marker->id", "$marker->point", "$marker->name", "$marker->web", "$marker->email", "$marker->cord", "$marker->dsc");
echo "\n";
}
?>
</ol>
</div>
</div>
<div class="postbox">
<h3 class="hndle" ><?php echo __('Remove Lug Map Content','lug-map')?></h3>
<div class="inside">
<p><?php echo __('Warning! This will drop lugmap table and recreate it, so the present markers will be removed totally','lug-map')?>.</p>
<form method="post" action="">
<input type="hidden" name="lugmap_clean" value="true" />
<input type="submit" class="button" value="<?php echo __('Clean Database','lug-map')?>" />
</form>
</div>
</div>
<?php
}
/**
* Insert posted data
*/if ( !empty( $_POST['lm_name'] ) && !empty( $_POST['lm_email'] ) && !empty( $_POST['lm_point'] ) && !empty( $_POST['lm_org'] ) ) {
global $wpdb;
$table = $wpdb->prefix."lugmap";
$lm_name = $wpdb->escape($_POST['lm_name']);
$lm_org = $wpdb->escape($_POST['lm_org']);
$lm_email = $wpdb->escape($_POST['lm_email']);
$lm_web = $wpdb->escape(apply_filters("the_title",$_POST['lm_web']));
$lm_dsc = $wpdb->escape(apply_filters("comment_status_pre ",trim(str_replace('/', '|', $_POST['lm_dsc']))));
$lm_point = $wpdb->escape(strtok($_POST['lm_point'],"()"));
$wpdb->query("
INSERT INTO $table(name, cord, email, web, dsc, point)
VALUES('$lm_name', '$lm_org', '$lm_email', '$lm_web', '$lm_dsc', '$lm_point')
");
}
/**
* Gmaps markers generation
*/
function lugmap_markers() {
global $wpdb;
$table = $wpdb->prefix."lugmap";
$markers = $wpdb->get_results("SELECT point FROM $table");
foreach($markers as $marker) {
echo "\t"."var point = new GLatLng(".stripslashes($marker->point).");"."\n";
$point_data = null; //otherwise it will collect the whole world :)
$marker_data = $wpdb->get_results("SELECT `name`,`cord`,`email`,`web`,`dsc` FROM `$table` WHERE `point` = '$marker->point'");
foreach($marker_data as $item) {
$point_data .= '<div class=\"bubble\"><span class=\"nick\">'.$item->name.'</span><br />'.$item->cord.'<br />'.attribute_escape($item->dsc).'</div>';
}
echo "\t"."var marker = createMarker(point,'$point_data');"."\n";
echo "\t"."map.addOverlay(marker);"."\n\n";
}
}
/**
* Loading meta stuff like js files and etc.
*/
function lugmap_header() {
$lugmap_api_key = get_option('lugmap_api_key');
$lugmap_coord = get_option('lugmap_coord');
?>
<script src="http://maps.google.com/maps?file=api&v=2.x&key=<?php echo $lugmap_api_key; ?>" type="text/javascript"></script>
<script type="text/javascript">
<!--
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(<?php echo $lugmap_coord ?>), 7);
geocoder = new GClientGeocoder();
map.setMapType(G_NORMAL_MAP);
<?php lugmap_markers(); ?>
}
}
function createMarker(point,html) {
var marker = new GMarker(point);
marker.getIcon().image = "http://maps.google.com/mapfiles/ms/micons/man.png";
marker.getIcon().iconSize = new GSize(32, 32);
marker.getIcon().shadow = "http://maps.google.com/mapfiles/ms/micons/man.shadow.png";
marker.getIcon().shadowSize = new GSize(59, 32);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
function srch() {
var adr = document.getElementById('adr').value; showAddress(adr); return false;
}
function chck(form) {
if(form.lm_point.value == "")
{
alert('Wpisz swoje położenie i kliknij napis "Znajdź na mapie"!');
return false;
}
else if (form.lm_name.value == "")
{
alert("Proszę wpisać nick!");
return false; }
else if (form.lm_email.value == "")
{
alert("Proszę wpisać e-mail!");
return false; }
return true;
}
function addPoint(point) {
if(point)
document.getElementById('point').value = point;
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " nie znaleziono!");
} else {
addPoint(point);
map.setCenter(point, 13);
map.addOverlay(new MarkerLight(latlng, {image: "http://maps.google.com/mapfiles/ms/micons/man.png"}));
marker.openInfoWindowHtml(address);
}
}
);
}
}
//-->
</script>
<?php
}
/**
* Page hook
*/
function lugmap_content($attr, $c = NULL) {
$output .= '<div id="lug-map">';
$output .= '<form action="" method="post" onSubmit="javascript: return chck(this)">';
$output .= '
<div id="map"></div>
<script type="text/javascript">
initialize(); </script>
';
$output .= '
<p>
<span>Pola oznaczone gwiazdką, są obowiązkowe.</span><br /><br />
<label for="lm_name">'.__("a","lug-map").' *: <input class="inpt" type="text" name="lm_name" /></label>
<label for="lm_org">'.__("b)","lug-map").' *: <input class="inpt" type="text" name="lm_org" /></label>
<label>'.__("c","lug-map").':</label><br /><input name="lm_dsc" class="inpt" maxchars="1900" /><br />
<label for="lm_email">'.__("d)","lug-map").' *: <input class="inpt" type="text" name="lm_email" /></label>
<!-- <label for="lm_web">'.__("LUG Web Page","lug-map").': <input class="inpt" type="text" name="lm_web" value="http://" /></label> -->
<label for="lm_adr">'.__("xxx","lug-map").' *: <input class="adr" id="adr" type="text" name="lm_adr" /></label>
<br />
<a href="#" id="srch" onClick="javascript: srch();" >'.__("Znajdź na mapie!","lug-map").'</a>
</p>
<input type="hidden" id="point" name="lm_point" />
<br />
<input type="submit" id="sbmt" class="button" value="'.__("Dodaj mnie!","lug-map").'" />
</form>';
$output .= '</div>';
return $output;
}
?>
Tomasz Kapica edytował(a) ten post dnia 11.06.09 o godzinie 23:20