Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c3fac173

Přidáno uživatelem Ondřej Fibich před více než 5 roky(ů)

Issue #1105: map support fixes

Zobrazit rozdíly:

application/controllers/address_points.php
class Address_points_Controller extends Controller
{
const METHOD_GOOGLE = 1;
const METHOD_OSM_NOMINATIM = 1;
/**
* Index redirects to show all
......
$gps = "";
if (! empty ($ap->gps))
if ($ap->gps != NULL)
{
$gps_result = $ap->get_gps_coordinates($ap->id);
......
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = __('Address point detail');
$view->mapycz_enabled = TRUE;
$view->content = new View('address_points/show');
$view->content->address_point = $ap;
$view->content->members_grid = $members_grid;
......
$gpsx = NULL;
$gpsy = NULL;
if (!empty($ap->gps))
if ($ap->gps != NULL)
{
$gps_result = $ap->get_gps_coordinates($ap->id);
......
// success, we end
if ($address_point && strlen($address_point->gps))
{
$gps = explode(' ', $address_point->gps);
echo gps::real2degrees($gps[0], FALSE) . ' ';
echo gps::real2degrees($gps[1], FALSE);
echo $address_point->gps;
return;
}
......
if (!$street_number || $town == '' || $country == '')
return;
$data = self::get_geocode_from_google ($street, $street_number, $town, $country);
$data = self::get_geocode_from_nomanatim ($street, $street_number, $town, $country);
if (!$data)
return;
/* return only precise GPS coordinates
*
* Valid location types: ROOFTOP
*
* Valid location types: class=place
*/
$type = $data->results[0]->geometry->location_type;
if ($type != "ROOFTOP")
if ($data[0]->class != "place")
return;
echo gps::real2degrees(num::decimal_point($data->results[0]->geometry->location->lat), FALSE)." ".
gps::real2degrees(num::decimal_point($data->results[0]->geometry->location->lng), FALSE);
echo num::decimal_point($data[0]->lat)." ".num::decimal_point($data[0]->lon);
}
/**
......
// success, we end
if ($address_point && strlen($address_point->gps))
{
$gps = explode(' ', $address_point->gps);
echo gps::real2degrees($gps[0], FALSE) . ' ';
echo gps::real2degrees($gps[1], FALSE);
echo $address_point->gps;
return;
}
......
if (!$number || $town == '' || $country == '')
return;
$data = self::get_geocode_from_google ($street, $number, $town, $country);
$data = self::get_geocode_from_nomanatim ($street, $number, $town, $country);
if (!$data)
return;
/* return only precise GPS coordinates
*
* Valid location types: ROOFTOP
*
* Valid location types: class=place
*/
$type = $data->results[0]->geometry->location_type;
if ($type != "ROOFTOP")
if ($data[0]->class != "place")
return;
echo gps::real2degrees(num::decimal_point($data->results[0]->geometry->location->lat), FALSE)." ".
gps::real2degrees(num::decimal_point($data->results[0]->geometry->location->lng), FALSE);
echo num::decimal_point($data[0]->lat)." ".num::decimal_point($data[0]->lon);
}
}
......
* @param type $country
* @return type
*/
private function get_geocode_from_google($street, $street_number, $town, $country)
private function get_geocode_from_nomanatim($street, $street_number, $town, $country)
{
$address = $street." ".$street_number.",".$town.",".$country;
$URL = "http://maps.googleapis.com/maps/api/geocode/json?address="
.urlencode($address)."&sensor=false";
$json = file_get_contents($URL);
$opts = array(
"http" => array(
"method" => "GET",
"header" => "Referer: " . url_lang::current() . "\r\n"
)
);
$context = stream_context_create($opts);
$URL = "http://nominatim.openstreetmap.org/?q=".urlencode($address)
."&format=json&limit=1";
$json = file_get_contents($URL, FALSE, $context);
$data = json_decode($json);
if (!$data ||
!is_object($data) ||
$data->status != 'OK' ||
!isset($data->results[0]))
!is_array($data) ||
count($data) == 0 ||
!is_object($data[0]) ||
!isset($data[0]->lat) ||
!isset($data[0]->lon))
{
return FALSE;
}
......
$form->dropdown('method')
->options(array
(
self::METHOD_GOOGLE => __('Google API')
self::METHOD_OSM_NOMINATIM => __('OSM Nominatim')
));
$form->submit('Update');
......
// Google method
switch ($form_data['method'])
{
case self::METHOD_GOOGLE:
case self::METHOD_OSM_NOMINATIM:
$address_point_model = new Address_point_Model();
......
$town .= ', '.$address_point->zip_code;
// finds gps from google
$data = self::get_geocode_from_google (
// finds gps from Nominatim
$data = self::get_geocode_from_nomanatim (
$address_point->street,
$address_point->street_number,
$town,
......
if (!$data)
continue;
/* return only precise GPS coordinates
*
* Valid location types: class=place
*/
if ($data[0]->class != "place")
continue;
// updates GPS coords
$address_point_model->update_gps_coordinates(
$address_point->id,
num::decimal_point($data->results[0]->geometry->location->lat),
num::decimal_point($data->results[0]->geometry->location->lng)
num::decimal_point($data[0]->lat),
num::decimal_point($data[0]->lon)
);
$updated++;
application/controllers/devices.php
$gps = '';
if (!empty($device->address_point->gps))
if ($device->address_point->gps != NULL)
{
$gps_result = $device->address_point->get_gps_coordinates();
......
$view->title = __('Device').' '.$device->name;
$view->breadcrumbs = $breadcrumbs->html();
$view->action_logs = action_logs::object_last_modif($device, $device_id);
$view->mapycz_enabled = TRUE;
$view->content = new View('devices/show');
$view->content->device = $device;
$view->content->device_type = $device_type;
......
$gpsx = '';
$gpsy = '';
if (!empty($device->address_point->gps))
if ($device->address_point->gps != NULL)
{
$gps_result = $device->address_point->get_gps_coordinates();
application/controllers/members.php
}
// gps coordinates
if (!empty($member->address_point->gps))
if ($member->address_point->gps != NULL)
{
$gps_result = ORM::factory('address_point')->get_gps_coordinates(
$member->address_point->id
......
}
// gps coordinates
if (!empty($member->members_domicile->address_point->gps))
if ($member->members_domicile->address_point->gps != NULL)
{
$gps_result = ORM::factory('address_point')->get_gps_coordinates(
$member->members_domicile->address_point->id
......
$gpsx = '';
$gpsy = '';
if (!empty($member->address_point->gps))
if ($member->address_point->gps != NULL)
{
$gps_result = $member->address_point->get_gps_coordinates(
$member->address_point->id
......
$domicile_gpsx = '';
$domicile_gpsy = '';
if (!empty($member->members_domicile->address_point->gps))
if ($member->members_domicile->address_point->gps != NULL)
{
$gps_result = $member->address_point->get_gps_coordinates(
$member->members_domicile->address_point->id
application/models/address_point.php
$country_id, $town, $district, $street, $number, $zip)
{
$where = " AND country_id = '".intval($country_id).
"' AND town LIKE '".mysql_real_escape_string($town)."'".
" AND street LIKE '".mysql_real_escape_string($street)."'".
" AND street_number LIKE '".mysql_real_escape_string($number)."'".
" AND t.zip_code LIKE '".mysql_real_escape_string($zip)."'";
"' AND town LIKE '".$this->db->escape_str($town)."'".
" AND street LIKE '".$this->db->escape_str($street)."'".
" AND street_number LIKE '".$this->db->escape_str($number)."'".
" AND t.zip_code LIKE '".$this->db->escape_str($zip)."'";
if ($district)
{
$where .= " AND quarter LIKE '".mysql_real_escape_string($district)."'";
$where .= " AND quarter LIKE '".$this->db->escape_str($district)."'";
}
else
{
application/views/address_points/show.php
</table>
<?php if (!empty($gps)): ?>
<div id="ap_gmap" style="float: <?php echo ($this->popup ? 'left' : 'right');?>">
<a class="gmap" href="http://maps.google.com/maps?f=q&hl=<?php echo $lang ?>&geocode=&q=<?php echo $gpsx ?>,<?php echo $gpsy ?>&z=18&t=h&ie=UTF8" target="_blank">
<img alt="<?php echo __('Address point detail') ?>" src="http://maps.google.com/maps/api/staticmap?center=<?php echo $gpsx ?>,<?php echo $gpsy ?>&zoom=16&maptype=hybrid&size=400x300&markers=color:red%7C<?php echo $gpsx ?>,<?php echo $gpsy ?>&language<?php echo $lang ?>&sensor=false"/>
</a>
</div>
<div id="ap_gmap" style="float: <?php echo ($this->popup ? 'left' : 'right'); ?>; width:500px; height:300px"></div>
<div style="margin-bottom: 10px; float:left"></div>
<script type="text/javascript">
$(document).ready(function () {
mapycz_addr('ap_gmap', <?php echo $gpsx ?>, <?php echo $gpsy ?>);
});
</script>
<?php endif; ?>
<div style="clear: both"></div>
application/views/devices/show.php
</table>
<?php if (!empty($gps)): ?>
<div id="ap_gmap" style="float: <?php echo ($this->popup ? 'left' : 'right');?>">
<a class="gmap" href="http://maps.google.com/maps?f=q&hl=<?php echo $lang ?>&geocode=&q=<?php echo $gpsx ?>,<?php echo $gpsy ?>&z=18&t=h&ie=UTF8" target="_blank">
<img alt="<?php echo __('Address point detail') ?>" src="http://maps.google.com/maps/api/staticmap?center=<?php echo $gpsx ?>,<?php echo $gpsy ?>&zoom=18&maptype=hybrid&size=300x300&markers=color:red%7C<?php echo $gpsx ?>,<?php echo $gpsy ?>&sensor=false" style="float: right; margin-right: 10px;" />
</a>
<div id="ap_gmap" style="float: <?php echo ($this->popup ? 'left' : 'right');?>; width:400px;height:300px;">
</div>
<script type="text/javascript">
$(document).ready(function () {
mapycz_dev('ap_gmap', <?php echo $gpsx ?>, <?php echo $gpsy ?>);
});
</script>
<?php endif; ?>
<br class="clear" />
application/views/js/__pieces/gps.php
?>
var gps_get = null;
// try to find GPS for address point and set it (esed ad devices and members)
$("#street_id, #street_number, #town_id, #country_id").keyup(function ()
$("#street_id, #street_number, #town_id, #country_id").change(function ()
{
get_gps_by_address($("#street_id").val(), $("#street_number").val(),
$("#town_id").val(), $("#country_id").val(), function(data)
{
if (data != '')
{
var s = data.split(" ");
$("#gpsx").val(gps_dms_coord(s[0]));
$("#gpsy").val(gps_dms_coord(s[1]));
}
else
{
$("#gpsx").val("");
$("#gpsy").val("");
}
gps_get = null;
});
});
// try to find GPS for domicile address point and set it (used at members)
$("#domicile_street_id, #domicile_street_number, #domicile_town_id, #domicile_country_id").change(function ()
{
get_gps_by_address($("#domicile_street_id").val(),
$("#domicile_street_number").val(), $("#domicile_town_id").val(),
$("#domicile_country_id").val(), function(data)
{
var s = data.split(" ");
$("#domicile_gpsx").val(gps_dms_coord(s[0]));
$("#domicile_gpsy").val(gps_dms_coord(s[1]));
});
});
function get_gps_by_address(street_id, street_number, town_id, country_id, clb)
{
if (gps_get != null)
{
gps_get.abort();
gps_get = null;
}
if (!street_number ||!town_id || !country_id)
{
return false;
}
gps_get = $.get("<?php echo url_lang::base() ?>address_points/get_gps_by_address/",
{
"street_id": $("#street_id").val(),
"street_number": $("#street_number").val(),
"town_id": $("#town_id").val(),
"country_id": $("#country_id").val()
"street_id": street_id,
"street_number": street_number,
"town_id": town_id,
"country_id": country_id
}, function(data)
{
if (data != '')
{
var s = data.split(" ");
$("#gpsx").val(s[0]);
$("#gpsy").val(s[1]);
}
else
{
$("#gpsx").val("");
$("#gpsy").val("");
}
clb(data);
gps_get = null;
});
});
// triggers find of GPS
$("#street_id, #street_number, #town_id, #country_id").change(function ()
{
$(this).trigger('keyup');
});
// try to find GPS for domicile address point and set it (used at members)
$("#domicile_street_id, #domicile_street_number, #domicile_town_id, #domicile_country_id").keyup(function ()
{
$.get("<?php echo url_lang::base() ?>address_points/get_gps_by_address/",
{
"street_id": $("#domicile_street_id").val(),
"street_number": $("#domicile_street_number").val(),
"town_id": $("#domicile_town_id").val(),
"country_id": $("#domicile_country_id").val()
}, function(data)
{
var s = data.split(" ");
$("#domicile_gpsx").val(s[0]);
$("#domicile_gpsy").val(s[1]);
});
});
// triggers find of GPS
$("#domicile_street_id, #domicile_street_number, #domicile_town_id, #domicile_country_id").change(function ()
{
$(this).trigger('keyup');
});
return true;
}
application/views/js/__pieces/whisperer_gps.php
if (data !== '')
{
var s = data.split(" ");
$("#gpsx").val(s[0]);
$("#gpsy").val(s[1]);
$("#gpsx").val(gps_dms_coord(s[0]));
$("#gpsy").val(gps_dms_coord(s[1]));
// show on map
if ($("#ap_map").length)
......
var width = $('#ap_map .no_map').width();
var height = $('#ap_map .no_map').height();
var map = '<img src="http://maps.google.com/maps/api/staticmap?center='+s[0]+','+s[1]+'&zoom=13&maptype=normal&size='+width+'x'+height+'&markers=color:red%7C'+s[0]+','+s[1]+'&language<?php echo Config::get('lang')?>&sensor=false"></img>';
map = '<div class="ap_form_map_container"><a href="http://maps.google.com/maps?f=q&hl=<?php echo Config::get('lang') ?>&geocode=&q='+s[0]+','+s[1]+'&z=18&t=h&ie=UTF8" target="_blank">'+map+'</a></div>';
var map = '<img src="http://staticmap.openstreetmap.de/staticmap.php?center='+s[0]+','+s[1]+'&zoom=18&size=' + width + 'x' + height + '&maptype=mapnik" width="' + width + '" height="' + height + '"></img>';
map = '<div class="ap_form_map_container"><a href="http://mapy.cz/zakladni?x='+s[1]+'&y='+s[0]+'&z=18" target="_blank">'+map+'</a></div>';
$("#ap_map").html(map);
map_add_zoom_buttons($("#ap_map a"), 6, 20);
map_add_zoom_buttons($("#ap_map a"), 6, 18);
}
}
else
......
if (data !== '')
{
var s = data.split(" ");
$("#domicile_gpsx").val(s[0]);
$("#domicile_gpsy").val(s[1]);
$("#domicile_gpsx").val(gps_dms_coord(s[0]));
$("#domicile_gpsy").val(gps_dms_coord(s[1]));
// show on map
if ($("#domicile_ap_map").length)
......
var width = $('#domicile_ap_map .no_map').width();
var height = $('#domicile_ap_map .no_map').height();
var map = '<img src="http://maps.google.com/maps/api/staticmap?center='+s[0]+','+s[1]+'&zoom=13&maptype=normal&size='+width+'x'+height+'&markers=color:red%7C'+s[0]+','+s[1]+'&language<?php echo Config::get('lang')?>&sensor=false"></img>';
map = '<div class="ap_form_map_container"><a href="http://maps.google.com/maps?f=q&hl=<?php echo Config::get('lang') ?>&geocode=&q='+s[0]+','+s[1]+'&z=18&t=h&ie=UTF8" target="_blank">'+map+'</a></div>';
var map = '<img src="http://staticmap.openstreetmap.de/staticmap.php?center='+s[0]+','+s[1]+'&zoom=18&size=' + width + 'x' + height + '&maptype=mapnik" width="' + width + '" height="' + height + '"></img>';
map = '<div class="ap_form_map_container"><a href="http://mapy.cz/zakladni?x='+s[1]+'&y='+s[0]+'&z=18" target="_blank">'+map+'</a></div>';
$("#domicile_ap_map").html(map);
map_add_zoom_buttons($("#domicile_ap_map a"), 6, 20);
map_add_zoom_buttons($("#domicile_ap_map a"), 6, 18);
}
}
else
application/views/js/address_points_edit.php
<?php
/**
* GPS javascript view.
* During adding of address point, try to add GPS for selected country,
* street, street number and town and set it to GPS fields.
*
* @author Michal Kliment, Ondřej Fibich
*/
// IDE complementation
if (FALSE): ?><script type="text/javascript"><?php endif
?>
$(document).ready(function()
{
$("#gpsx, #gpsy").keyup(function ()
{
if ($("#gpsx").val() == '' || $("#gpsy").val() == '')
{
$.get("<?php echo url_lang::base() ?>address_points/get_gps_by_address",
{
"street": $("#street_id option:selected").text(),
"street_number": $("#street_number").val(),
"town": $("#town_id option:selected").text(),
"country": $("#country_id option:selected").text()
}, function(data)
{
var s = data.split(" ");
$("#gpsx").val(s[0]);
$("#gpsy").val(s[1]);
});
}
});
$("#gpsx, #gpsy").trigger("keyup");
});
application/views/js/address_points_show.php
<?php
/**
* Map in address point detail.
*
* @author Ondřej Fibich
*/
// IDE complementation
if (FALSE): ?><script type="text/javascript"><?php endif
?>
window.mapycz_addr = function (divId, gpsx, gpsy)
{
var center = SMap.Coords.fromWGS84(gpsy, gpsx);
var m = new SMap(JAK.gel(divId), center, 17);
m.addDefaultLayer(SMap.DEF_OPHOTO);
m.addDefaultLayer(SMap.DEF_BASE).enable();
var layerSwitch = new SMap.Control.Layer();
layerSwitch.addDefaultLayer(SMap.DEF_BASE);
layerSwitch.addDefaultLayer(SMap.DEF_OPHOTO);
m.addControl(layerSwitch, {left: "8px", top: "9px"});
m.addDefaultControls();
var markerLayer = new SMap.Layer.Marker();
markerLayer.addMarker(new SMap.Marker(center, "myMarker", {}));
m.addLayer(markerLayer);
markerLayer.enable();
};
application/views/js/base.php
$(anchor).hide('slow');
}
/*
* This function returns the GPS coordinate conversion string in DD to DMS.
*/
function gps_dms(lat, lng)
{
var flat = parseFloat(lat),
flng = parseFloat(lng),
latResult = gps_dms_coord(flat) + ((flat >= 0) ? 'N' : 'S'),
lngResult = gps_dms_coord(flng) + ((flng >= 0) ? 'E' : 'W');
return latResult + ' ' + lngResult;
}
function gps_dms_coord(val)
{
var valDeg, valMin, valSec, result;
val = Math.abs(val);
valDeg = Math.floor(val);
result = valDeg + "°";
valMin = Math.floor((val - valDeg) * 60);
result += valMin + "′";
valSec = Math.round((val - valDeg - valMin / 60) * 3600 * 1000) / 1000;
result += valSec + '″';
return result;
}
<?php
/*
application/views/js/devices_show.php
$("#"+name).addClass("dispNone");
}
});
window.mapycz_dev = function (divId, gpsx, gpsy)
{
var center = SMap.Coords.fromWGS84(gpsy, gpsx);
var m = new SMap(JAK.gel(divId), center, 17);
m.addDefaultLayer(SMap.DEF_BASE).enable();
m.addDefaultControls();
var markerLayer = new SMap.Layer.Marker();
markerLayer.addMarker(new SMap.Marker(center, "myMarker", {}));
m.addLayer(markerLayer);
markerLayer.enable();
};
application/views/main.php
<?php echo html::script('media/js/messages_cs', FALSE) ?>
<?php echo html::script('media/js/php.min', FALSE) ?>
<?php if (isset($google_jsapi_enabled)): ?><script type="text/javascript" src="https://www.google.com/jsapi"></script><?php endif ?>
<?php if (isset($mapycz_enabled)): ?><script type="text/javascript" src="https://api.mapy.cz/loader.js"></script><script type="text/javascript">Loader.load()</script><?php endif ?>
<?php if (TextEditor::$instance_counter): ?>
<?php echo html::script('media/js/tinymce/tiny_mce', FALSE) ?>
<script type="text/javascript"><!--
application/views/members/show.php
<table style="float: right">
<tr>
<td style="border: none; padding: 0;">
<a href="http://maps.google.com/maps?f=q&hl=<?php echo $lang ?>&geocode=&q=<?php echo $map_query ?>&z=18&t=h&ie=UTF8" target="_blank" style="float: right; text-decoration: none;">
<a href="http://mapy.cz?q=<?php echo urlencode($map_query) ?>&z=18" target="_blank" style="float: right; text-decoration: none;">
<?php echo html::image(array
(
'width' => 16,
......
<table style="float: right">
<tr>
<td style="border: none; padding: 0;">
<a href="http://maps.google.com/maps?f=q&hl=<?php echo $lang ?>&geocode=&q=<?php echo $map_domicile_query ?>&z=18&t=h&ie=UTF8" target="_blank" style="float: right; text-decoration: none;">
<a href="http://mapy.cz?q=<?php echo urlencode($map_domicile_query) ?>" target="_blank" style="float: right; text-decoration: none;">
<?php echo html::image(array
(
'width' => 16,

Také k dispozici: Unified diff