Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve geo coordinates map picker #274

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Classes/Evaluation/LatitudeEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function evaluateFieldValue($value)
{
// test if we have any latitude
if ($value && $value !== '') {
$value = EvalcoordinatesUtility::formatLatitude($value);
return EvalcoordinatesUtility::formatLatitude($value);
}
return $value;
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Classes/Evaluation/LongitudeEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function evaluateFieldValue($value)
{
// test if we have any longitude
if ($value && $value != '') {
$value = EvalcoordinatesUtility::formatLongitude($value);
return EvalcoordinatesUtility::formatLongitude($value);
}
return $value;
return null;
}

/**
Expand Down
15 changes: 8 additions & 7 deletions Classes/FormEngine/FieldControl/LocationMapWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ public function render(): array

if ($row['latitude'] || $row['longitude'] == '') {
// remove all after first slash in address (top, floor ...)
$address = preg_replace('/^([^\/]*).*$/', '$1', $row['address']) . ' ';
$address .= $row['city'];
$address = preg_replace('/^([^\/]*).*$/', '$1', $row['address']);
$city = $row['zip'] . ' ' . $row['city']; // zip is currently ignored by osm
$address .= ', '. $city;
// if we have at least some address part (saves geocoding calls)
if ($address) {
// base url
$geoCodeUrlBase = 'https://nominatim.openstreetmap.org/search/';
$geoCodeUrlAddress = $address;
$geoCodeUrlCityOnly = $row['city'];
$geoCodeUrlAddress = trim((string)$address, ' ,');
$geoCodeUrlCityOnly = trim((string)$city, ' ,');
// urlparams for nominatim which are fixed.
$geoCodeUrlQuery = '?format=json&addressdetails=1&limit=1&polygon_svg=1';
$geoCodeUrlQuery = '?format=json&addressdetails=1&limit=1';
// replace newlines with spaces; remove multiple spaces
$geoCodeUrl = trim(preg_replace('/\s\s+/', ' ', $geoCodeUrlBase . $geoCodeUrlAddress . $geoCodeUrlQuery));
$geoCodeUrlShort = trim(preg_replace('/\s\s+/', ' ', $geoCodeUrlBase . $geoCodeUrlCityOnly . $geoCodeUrlQuery));
$geoCodeUrl = trim(preg_replace('/\s\s+/', ' ', $geoCodeUrlBase . urlencode($geoCodeUrlAddress) . $geoCodeUrlQuery));
$geoCodeUrlShort = trim(preg_replace('/\s\s+/', ' ', $geoCodeUrlBase . urlencode($geoCodeUrlCityOnly) . $geoCodeUrlQuery));
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That whole part in the LocationMapWizard breaks geocoding completely, at least for me.
And there is also no need to include the zip, as your comment says: it should be ignored. But it isn't, in my experience.
So we keep the version which works for now.

Expand Down
12 changes: 6 additions & 6 deletions Classes/Utility/EvalcoordinatesUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
class EvalcoordinatesUtility
{
const LATITUDE_UPPER = '90.000000000000';
const LONGITUDE_UPPER = '180.000000000000';
const LATITUDE_UPPER = '90.00000000';
const LONGITUDE_UPPER = '180.00000000';

/**
* @param $coordinate
Expand Down Expand Up @@ -66,11 +66,11 @@ protected static function validate($coordinate, string $upperRange): string
// remove all points from decimal-part
$decimalPart = preg_replace("/[^\d]/", '', $decimalPart);

// fill up with zeros or shorten to match our goal of decimal(14,12) in DB
if (\strlen($decimalPart) >= 12) {
$decimalPart = substr($decimalPart, 0, 12);
// fill up with zeros or shorten to match our goal of decimal(11,8) in DB
if (\strlen($decimalPart) >= 8) {
$decimalPart = substr($decimalPart, 0, 8);
} else {
$decimalPart = str_pad($decimalPart, 12, '0', STR_PAD_RIGHT);
$decimalPart = str_pad($decimalPart, 8, '0', STR_PAD_RIGHT);
}

// concatenate the whole string to a well-formed longitude and return
Expand Down
4 changes: 2 additions & 2 deletions Configuration/TCA/tt_address.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@
'label' => 'LLL:EXT:tt_address/Resources/Private/Language/locallang_db.xlf:tt_address.latitude',
'config' => [
'type' => 'input',
'eval' => 'null,' . \FriendsOfTYPO3\TtAddress\Evaluation\LatitudeEvaluation::class,
'eval' => \FriendsOfTYPO3\TtAddress\Evaluation\LatitudeEvaluation::class,
'default' => null,
'behaviour' => [
'allowLanguageSynchronization' => true,
Expand All @@ -569,7 +569,7 @@
'label' => 'LLL:EXT:tt_address/Resources/Private/Language/locallang_db.xlf:tt_address.longitude',
'config' => [
'type' => 'input',
'eval' => 'null,' . \FriendsOfTYPO3\TtAddress\Evaluation\LongitudeEvaluation::class,
'eval' => \FriendsOfTYPO3\TtAddress\Evaluation\LongitudeEvaluation::class,
'default' => null,
'fieldControl' => [
'locationMap' => [
Expand Down
4 changes: 2 additions & 2 deletions Resources/Public/Backend/LocationMapWizard/leafletBackend.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
top: 6vh;
left: 10vw;
opacity: 0;
box-shadow: 0px 2px 15px #000000;
box-shadow: 0 2px 15px #000000;
transition: opacity 1500ms;
z-index: -1;
}
Expand Down Expand Up @@ -36,4 +36,4 @@
font-size: 20px;
padding: 5px 15px;
text-align: center;
}
}
29 changes: 29 additions & 0 deletions Resources/Public/Icons/actions-geo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/LeafletBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Icons', 'TYPO3/CMS/TtAddress/leaflet-core-1
// Geocode only first time
// Geocode only if lat OR lon is empty AND wie have geocoding url
// this saves geocoding calls
if ((LeafBE.$latitude == null || LeafBE.$longitude == null) && LeafBE.$geoCodeUrl != null) {
if (((!LeafBE.$latitude || !LeafBE.$longitude) || (LeafBE.$latitude == 0 && LeafBE.$longitude == 0)) && LeafBE.$geoCodeUrl != null) {
function geocode(callback) {
var temp = $.getJSON(LeafBE.$geoCodeUrl, function (data) {
if (data.length == 0) {
Expand Down
8 changes: 1 addition & 7 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,10 @@
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][\FriendsOfTYPO3\TtAddress\Evaluation\LatitudeEvaluation::class] = '';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][\FriendsOfTYPO3\TtAddress\Evaluation\LongitudeEvaluation::class] = '';

// Register icons
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class)->registerIcon(
'location-map-wizard',
\TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class,
['source' => 'EXT:tt_address/Resources/Public/Contrib/layers-2x.png']
);

$icons = [
'apps-pagetree-folder-contains-tt-address' => 'page-tree-module.svg',
'tt-address-plugin' => 'ContentElementWizard.svg',
'location-map-wizard' => 'actions-geo.svg',
];
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
foreach ($icons as $identifier => $path) {
Expand Down
4 changes: 2 additions & 2 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ CREATE TABLE tt_address (
twitter varchar(255) DEFAULT '',
facebook varchar(255) DEFAULT '',
linkedin varchar(255) DEFAULT '',
latitude decimal(14,12) default NULL,
longitude decimal(15,12) default NULL,
latitude decimal(11,8) default NULL,
longitude decimal(11,8) default NULL,

image tinyblob,
categories int(11) DEFAULT '0' NOT NULL,
Expand Down