Load geojson file in constructor

This commit is contained in:
Andreas Kristiansen
2025-12-20 15:53:05 +01:00
parent 5537f6ed43
commit 5375f03fb8
2 changed files with 14 additions and 8 deletions

View File

@@ -66,11 +66,17 @@ class Geojson {
];
private $qra;
private $geojsonFile = null;
private $geojsonData = null;
public function __construct() {
public function __construct($dxcc = null) {
$CI =& get_instance();
$CI->load->library('qra');
$this->qra = $CI->qra;
if ($dxcc !== null) {
$this->geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson";
$this->geojsonData = $this->loadGeoJsonFile($geojsonFile);
}
}
// ============================================================================
@@ -114,14 +120,16 @@ class Geojson {
return null;
}
$geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson";
$geojsonData = $this->loadGeoJsonFile($geojsonFile);
if ($this->geojsonFile === null) {
$this->geojsonFile = "assets/json/geojson/states_{$dxcc}.geojson";
$this->geojsonData = $this->loadGeoJsonFile($this->geojsonFile);
}
if ($geojsonData === null) {
if ($this->geojsonData === null) {
return null;
}
return $this->findFeatureContainingPoint($lat, $lng, $geojsonData);
return $this->findFeatureContainingPoint($lat, $lng, $this->geojsonData);
}
/**