Skip to content

Commit

Permalink
Add support of aircraft icon color change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ysurac committed Sep 29, 2015
1 parent 415d0f9 commit 58018a8
Show file tree
Hide file tree
Showing 76 changed files with 127 additions and 5 deletions.
Empty file added cache/.keep
Empty file.
61 changes: 61 additions & 0 deletions getImages.php
@@ -0,0 +1,61 @@
<?php

function hexToRGB($hex) {
$hex = str_replace("#", "", $hex);
$color = array();
if (strlen($hex) == 3) {
$color['r'] = hexdec(substr($hex, 0, 1) . $r);
$color['g'] = hexdec(substr($hex, 1, 1) . $g);
$color['b'] = hexdec(substr($hex, 2, 1) . $b);
} else if (strlen($hex) == 6) {
$color['r'] = hexdec(substr($hex, 0, 2));
$color['g'] = hexdec(substr($hex, 2, 2));
$color['b'] = hexdec(substr($hex, 4, 2));
}
return $color;
}


if (!isset($_GET['color']) || $_GET['color'] == '') {
exit(0);
}
$color = $_GET['color'];
if (!isset($_GET['filename']) || !preg_match('/^[a-z0-9-]+\.png$/', strtolower($_GET['filename']))) {
echo "Incorrect filename";
exit(0);
}
$filename = $_GET['filename'];
if (file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.'cache/'.$color.'-'.$filename)) {
header('Content-type: image/png');
readfile(dirname(__FILE__).DIRECTORY_SEPARATOR.'cache/'.$color.'-'.$filename);
exit(0);
}
$original = dirname(__FILE__).DIRECTORY_SEPARATOR.'images/aircrafts/new/'.$filename;
if (!file_exists($original)) {
echo "File not found";
}

if (extension_loaded('gd') && function_exists('gd_info')) {
$image = imagecreatefrompng($original);
$index = imagecolorexact($image,26,49,81);
$c = hexToRGB($color);
imagecolorset($image,$index,$c['r'],$c['g'],$c['b']);
/*
$ig = imagecolorat($image, 0, 0);
imagecolortransparent($image, $ig);
*/

header('Content-type: image/png');
imagealphablending($image, false);
imagesavealpha($image, true);
imagepng($image);
if (is_writable('cache')) {
imagepng($image,dirname(__FILE__).DIRECTORY_SEPARATOR.'cache/'.$color.'-'.$filename);
}
imagedestroy($image);
} else {
header('Content-type: image/png');
if ($color == 'FF0000') readfile(dirname(__FILE__).DIRECTORY_SEPARATOR.'images/aircrafts/selected/'.$filename);
else readfile(dirname(__FILE__).DIRECTORY_SEPARATOR.'images/aircrafts/'.$filename);
}
?>
Binary file added images/aircrafts/new/A124.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/A225.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/A320.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/A330.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/A340.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/A380.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/A400.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/AN12.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/AS20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/B2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/B73X.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/B74X.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/B752.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/B76X.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/B77X.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/B787.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/C17.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/C172.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/C680.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/CL35.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/CL41.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/CNBR.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/DHC1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/DR40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/E145.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/aircrafts/new/E170.png
Binary file added images/aircrafts/new/E190.png
Binary file added images/aircrafts/new/E300.png
Binary file added images/aircrafts/new/F100.png
Binary file added images/aircrafts/new/F104.png
Binary file added images/aircrafts/new/F14.png
Binary file added images/aircrafts/new/F15.png
Binary file added images/aircrafts/new/F16X.png
Binary file added images/aircrafts/new/F22.png
Binary file added images/aircrafts/new/F35.png
Binary file added images/aircrafts/new/G21T.png
Binary file added images/aircrafts/new/GL6T.png
Binary file added images/aircrafts/new/GLID.png
Binary file added images/aircrafts/new/HAR.png
Binary file added images/aircrafts/new/J4.png
Binary file added images/aircrafts/new/JS1.png
Binary file added images/aircrafts/new/K35R.png
Binary file added images/aircrafts/new/L10.png
Binary file added images/aircrafts/new/L14.png
Binary file added images/aircrafts/new/LJ60.png
Binary file added images/aircrafts/new/LJ75.png
Binary file added images/aircrafts/new/MD11.png
Binary file added images/aircrafts/new/ME09.png
Binary file added images/aircrafts/new/MG15.png
Binary file added images/aircrafts/new/MIR2.png
Binary file added images/aircrafts/new/MRF1.png
Binary file added images/aircrafts/new/N340.png
Binary file added images/aircrafts/new/NG5.png
Binary file added images/aircrafts/new/NIM.png
Binary file added images/aircrafts/new/P38.png
Binary file added images/aircrafts/new/P51.png
Binary file added images/aircrafts/new/PA12.png
Binary file added images/aircrafts/new/PA28.png
Binary file added images/aircrafts/new/PP3.png
Binary file added images/aircrafts/new/R721.png
Binary file added images/aircrafts/new/S434.png
Binary file added images/aircrafts/new/S51.png
Binary file added images/aircrafts/new/SHIP.png
Binary file added images/aircrafts/new/T144.png
Binary file added images/aircrafts/new/T37.png
Binary file added images/aircrafts/new/T6.png
Binary file added images/aircrafts/new/UH1.png
Binary file added images/aircrafts/new/WA40.png
Binary file added images/aircrafts/new/YK52.png
Binary file added images/aircrafts/new/default.png
Binary file added images/aircrafts/new/helico.png
9 changes: 9 additions & 0 deletions index.php
Expand Up @@ -77,6 +77,15 @@
<option value="MapQuest-Aerial"<?php if ($MapType == 'MapQuest-Aerial') print ' selected'; ?>>MapQuest-Aerial</option>
</select>
</li>
<?php
if (extension_loaded('gd') && function_exists('gd_info')) {
?>
<li>Aircraft icon color :
<input type="color" name="aircraftcolor" id="html5colorpicker" onchange="iconColor(aircraftcolor.value);" value="#<?php if (isset($_COOKIE['IconColor'])) print $_COOKIE['IconColor']; elseif (isset($globalAircraftIconColor)) print $globalAircraftIconColor; else print '1a3151'; ?>">
</li>
<?php
}
?>
</ul>
</form>
<p>Any change in settings reload page</p>
Expand Down
24 changes: 24 additions & 0 deletions install/index.php
Expand Up @@ -455,6 +455,25 @@
<label for="aircraftsize">Size of aircraft icon on map (default to 30px if zoom > 7 else 15px), empty to default</label>
<input type="number" name="aircraftsize" id="aircraftsize" value="<?php if (isset($globalAircraftSize)) echo $globalAircraftSize; ?>" />
</p>
<p>
<?php
if (extension_loaded('gd') && function_exists('gd_info')) {
?>
<label for="aircrafticoncolor">Color of aircraft icon on map</label>
<input type="color" name="aircrafticoncolor" id="aircrafticoncolor" value="#<?php if (isset($globalAircraftIconColor)) echo $globalAircraftIconColo; else echo '1a3151'; ?>" />
<?php
if (!is_writable('cache')) {
?>
<b>The directory cache is not writable, aircraft icon will not be cached</b>
<?php
}
} else {
?>
<b>PHP GD is not installed, you can t change color of aircraft icon on map</b>
<?php
}
?>
</p>
</fieldset>

<input type="submit" name="submit" value="Create/Update database & write setup" />
Expand Down Expand Up @@ -642,6 +661,11 @@
} else {
$settings = array_merge($settings,array('globalMapAltitudeColor' => 'FALSE'));
}

if (isset($_POST['aircrafticoncolor'])) {
$aircrafticoncolor = filter_input(INPUT_POST,'aircrafticoncolor',FILTER_SANITIZE_STRING);
$settings = array_merge($settings,array('globalAircraftIconColor' => substr($aircrafticoncolor,1)));
}

$mappopup = filter_input(INPUT_POST,'mappopup',FILTER_SANITIZE_STRING);
if ($mappopup == 'mappopup') {
Expand Down
38 changes: 33 additions & 5 deletions js/map.js.php
Expand Up @@ -76,6 +76,10 @@
//initialize the layer group for the aircrft markers
var layer_data = L.layerGroup();

var southWest = L.latLng(-90,-180),
northEast = L.latLng(90,180);
bounds = L.latLngBounds(southWest,northEast);

//a few title layers
<?php
if (isset($_COOKIE['MapType'])) $MapType = $_COOKIE['MapType'];
Expand Down Expand Up @@ -108,6 +112,7 @@
?>
L.tileLayer('https://otile{s}-s.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', {
maxZoom: 18,
continuousWorld: false,
subdomains: "1234",
noWrap: true,
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
Expand Down Expand Up @@ -438,20 +443,29 @@ function getLiveData()
if (feature.properties.callsign != ""){ markerLabel += feature.properties.callsign+'<br />'; }
if (feature.properties.departure_airport_code != "" || feature.properties.arrival_airport_code != ""){ markerLabel += '<span class="nomobile">'+feature.properties.departure_airport_code+' - '+feature.properties.arrival_airport_code+'</span>'; }
<?php
if (isset($_COOKIE['IconColor'])) $IconColor = $_COOKIE['IconColor'];
elseif (isset($globalAircraftIconColor)) $IconColor = $globalAircraftIconColor;
else $IconColor = '1a3151';
if (!isset($ident) && !isset($flightaware_id)) {
?>
info.update(feature.properties);

//console.log(document.getElementById('aircraft_ident').className);
if (document.getElementById('aircraft_ident').className == feature.properties.callsign) {
var iconURLpath = '<?php print $globalURL; ?>/images/aircrafts/selected/'+feature.properties.aircraft_shadow;
//var iconURLpath = '<?php print $globalURL; ?>/images/aircrafts/selected/'+feature.properties.aircraft_shadow;
var iconURLpath = '<?php print $globalURL; ?>/getImages.php?color=FF0000&filename='+feature.properties.aircraft_shadow;
var iconURLShadowpath = '<?php print $globalURL; ?>/getImages.php?color=8D93B9&filename='+feature.properties.aircraft_shadow;
} else {
var iconURLpath = '<?php print $globalURL; ?>/images/aircrafts/'+feature.properties.aircraft_shadow;
//var iconURLpath = '<?php print $globalURL; ?>/images/aircrafts/'+feature.properties.aircraft_shadow;
var iconURLpath = '<?php print $globalURL; ?>/getImages.php?color=<?php print $IconColor; ?>&filename='+feature.properties.aircraft_shadow;
var iconURLShadowpath = '<?php print $globalURL; ?>/getImages.php?color=8D93B9&filename='+feature.properties.aircraft_shadow;
}
<?php
} else {
?>
var iconURLpath = '<?php print $globalURL; ?>/images/aircrafts/'+feature.properties.aircraft_shadow;
//var iconURLpath = '<?php print $globalURL; ?>/images/aircrafts/'+feature.properties.aircraft_shadow;
var iconURLpath = '<?php print $globalURL; ?>/getImages.php?color=<?php print $IconColor; ?>&filename='+feature.properties.aircraft_shadow;
var iconURLShadowpath = '<?php print $globalURL; ?>/getImages.php?color=8D93B9&filename='+feature.properties.aircraft_shadow;

<?php
}
Expand All @@ -466,6 +480,9 @@ function getLiveData()
iconUrl: iconURLpath,
iconSize: [<?php print $globalAircraftSize; ?>, <?php print $globalAircraftSize; ?>],
iconAnchor: [<?php print $globalAircraftSize/2; ?>, <?php print $globalAircraftSize; ?>]
shadowUrl: iconURLShadowpath,
shadowSize: [<?php print $globalAircraftSize; ?>, <?php print $globalAircraftSize; ?>],
shadowAnchor: [<?php print ($globalAircraftSize/2)+1; ?>, <?php print $globalAircraftSize; ?>]
})
})
<?php
Expand All @@ -490,11 +507,14 @@ function getLiveData()
alt: feature.properties.callsign,
icon: L.icon({
iconUrl: iconURLpath,
shadowUrl: iconURLShadowpath,
iconSize: [30, 30],
iconAnchor: [15, 30]
shadowSize: [30,30],
iconAnchor: [15, 30],
shadowAnchor: [16,30]
})
})
<?php
<?php
if ((isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'false') || (!isset($_COOKIE['flightpopup']) && isset($globalMapPopup) && !$globalMapPopup)) {
?>

Expand All @@ -513,6 +533,9 @@ function getLiveData()
alt: feature.properties.callsign,
icon: L.icon({
iconUrl: iconURLpath,
shadowUrl: iconURLShadowpath,
shadowSize: [15,15],
shadowAnchor: [8,15],
iconSize: [15, 15],
iconAnchor: [7, 15]
})
Expand Down Expand Up @@ -1471,6 +1494,11 @@ function mapType(selectObj) {
window.location.reload();
}

function iconColor(color) {
document.cookie = 'IconColor='+color.substring(1)+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
window.location.reload();
}


function getCookie(cname) {
var name = cname + "=";
Expand Down

0 comments on commit 58018a8

Please sign in to comment.