// Maximum number of Geocoding calls to the Google Maps API.
const MAX_GMAPS_RPC_CALLS = 5;
+ static public function buildStaticMapURL($latitude, $longitude, $color, $separator = '&')
+ {
+ $parameters = array(
+ 'size' => '300x100',
+ 'markers' => 'color:' . $color . '|' . $latitude . ',' . $longitude,
+ 'zoom' => '12',
+ 'sensor' => 'false'
+ );
+ global $globals;
+
+ return Platal::globals()->maps->static_map . '?' . http_build_query($parameters, '', $separator);
+ }
+
public function getGeocodedAddress(Address $address, $defaultLanguage = null, $forceLanguage = false) {
$this->prepareAddress($address);
$textAddress = $this->getTextToGeocode($address->text);
checkCurrentAddress());
}
-function addressChanged(prefid)
+function addressChanged(prefid, color)
{
+ var text = $('#' + prefid + '_cont').find("[name*='[text]']").val();
$('#' + prefid + '_cont').find('[name*=changed]').val("1");
+ $.xpost('map_url/', { text:text, color:color }, function(data) {
+ $('.static_map_url').find('img').attr('src', data);
+ });
}
function deleteGeocoding(prefid, hrpid)
function handlers()
{
return array(
- 'map' => $this->make_hook('map', AUTH_COOKIE)
+ 'map' => $this->make_hook('map', AUTH_COOKIE),
+ 'map_url' => $this->make_hook('map_url', AUTH_COOKIE)
);
}
self::prepare_map($page);
}
}
+
+ function handler_map_url($page)
+ {
+ pl_content_headers('text/plain');
+
+ if (Post::has('text')) {
+ $address = new Address(array('text' => Post::t('text')));
+ $gmapsGeocoder = new GMapsGeocoder();
+ $gmapsGeocoder->getGeocodedAddress($address);
+ echo GMapsGeocoder::buildStaticMapURL($address->latitude, $address->longitude, Post::t('color'));
+ }
+
+ exit();
+ }
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2011 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * 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 *
+ ***************************************************************************/
+
+function smarty_insert_getStaticMapURL(array $data)
+{
+ return GMapsGeocoder::buildStaticMapURL($data['latitude'], $data['longitude'], $data['color'], '&');
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
<tr{if t($class)} class="{$class}"{/if}>
<td>
{/if}
- <textarea name="{$prefname}[text]" cols="30" rows="4" onkeyup="addressChanged('{$prefid}')">{$address.text}</textarea>
+ <textarea name="{$prefname}[text]" cols="30" rows="4" onchange="addressChanged('{$prefid}','{$profile->promoColor()}')">{$address.text}</textarea>
<input type="hidden" name="{$prefname}[postalText]" value="{$address.postalText}" />
<input type="hidden" name="{$prefname}[types]" value="{$address.types}" />
<input type="hidden" name="{$prefname}[formatted_address]" value="{$address.formatted_address}" />
</td>
<td>
{/if}
- {if t($address.latitude)}
- <img src="{#globals.maps.static_map#}?size=300x100&markers=color:{$profile->promoColor()}%7C{$address.latitude},{$address.longitude}&zoom=12&sensor=false"
- alt="Position de l'adresse" />
+ <div class="static_map_url" {if !t($address.latitude)}style="display: none"{/if}>
+ <img src="{insert name="getStaticMapURL" latitude=$address.latitude longitude=$address.longitude color=$profile->promoColor()}" alt="Position de l'adresse" />
{if t($geocoding_removal)}
<br />
<small id="{$prefid}_geocoding_removal">
{/if}
</small>
{/if}
- {/if}
+ </div>
{if t($validation)}
</div>
<div style="clear: both"></div>