Skip to content

Commit

Permalink
Merge pull request #39 from nworr/proj4-update
Browse files Browse the repository at this point in the history
update proj4php call with updated version
  • Loading branch information
nworr authored Dec 1, 2023
2 parents 6592555 + 9373171 commit bd8fb96
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions mapBuilder/classes/mapBuilderView.listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ function onmainviewGetMaps ($event) {
// Get original extent from ini file if set
if(array_key_exists('extent', $readConfigPath)){
// Reproject extent in ini file from EPSG:4326 to EPSG:3857.
$proj4 = new Proj4php();
$sourceProj = new Proj4phpProj('EPSG:4326', $proj4);
$destProj = new Proj4phpProj('EPSG:3857', $proj4);

if (! class_exists('Proj4phpProj') ) {
// proj4php > 2.0
$proj4 = new \proj4php\Proj4php();
$sourceProj = new \proj4php\Proj('EPSG:4326', $proj4);
$destProj = new \proj4php\Proj('EPSG:3857', $proj4);
} else {
$proj4 = new Proj4php();
$sourceProj = new Proj4Proj('EPSG:4326', $proj4);
$destProj = new Proj4Proj('EPSG:3857', $proj4);
}
$extentArraySource = explode(",", $readConfigPath['extent']);

// Is extent valid ?
Expand All @@ -33,9 +39,14 @@ function onmainviewGetMaps ($event) {
$extentArraySource = array_map('floatval', $extentArraySource);

// Handle WGS84 bounds
$sourceMinPt = new proj4phpPoint( max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06) );
$sourceMaxPt = new proj4phpPoint( min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06) );

if (! class_exists('Proj4phpPoint') ) {
// proj4php >2.0
$sourceMinPt = new \proj4php\Point(max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06));
$sourceMaxPt = new \proj4php\Point(min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06));
} else {
$sourceMinPt = new Proj4phpPoint(max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06));
$sourceMaxPt = new Proj4phpPoint(min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06));
}
try {
$destMinPt = $proj4->transform($sourceProj,$destProj,$sourceMinPt);
$destMaxPt = $proj4->transform($sourceProj,$destProj,$sourceMaxPt);
Expand Down

0 comments on commit bd8fb96

Please sign in to comment.