# Solarmap
## Introduction
## API
### GET
All params in the file apiparams.json can be set by adding &parameterType_parameter_name=value to the base url
e.g.
[http://sidc.be/spaceweatherservices-dev/applications/solarmap/index.php?&images_sun=AIA304&features_grid=1&regions_sidc_sunspot=1&regions_inaf_sunspot=1&regions_noaa_region=1&regions_noaa_returning=0&regions_noaa_plages=1&coronal_holes_sidc=1&cmes_cactus=1&features_width=400](http://sidc.be/spaceweatherservices-dev/applications/solarmap/index.php?&images_sun=AIA304&features_grid=1&regions_sidc_sunspot=1&regions_inaf_sunspot=1&regions_noaa_region=1&regions_noaa_returning=0&regions_noaa_plages=1&coronal_holes_sidc=1&cmes_cactus=1&features_width=400)

One special switch between svg output and html output is present:
&output=svg or &output=html default being html

### POST
A post request with config file can be made; output is always svg. The post request overrules the defaults.
E.g store a file extraparams.json with content
```
{
	"images": {
		"params": {
			"sun": {
				"default": "AIA193"
			}
		}
	},
	"features": {
		"params": {
			"width": {
				"default": 400
			},
			"height": {
				"default": 400
			},
			"grid": {
				"default": false
			}
		}
	}
}
```


and use
`curl -X POST -F file=@extraparams.json http://sidc.be/spaceweatherservices-dev/applications/solarmap/index.php>image.svg`

The extraparams.json overwrite the corresponding values in apiparams.config and those are passed to the renderer.

## Technical things to know

### Layers
The svg/html consists of layers each layer corresponds to the main key in the api_params.json; each param is displayed separately.
For each class that renders content the name is corresponding to this structure e.g. class region_sidc_sunspot and can be found in the file render_region.class.php.
The list of layers in the main svg is controlled in the class Layers in the file paramRenderer.php where a list of displayables is given.

## Add new layer
- Create class paramType_paramName in file render_paramType
- Add include in paramRenderer.php near the top
- The class should implement the interface Renderable as defined in paramRenderer.php
This has method 
* initialize -> to initialize the data
* render -> to render the data
* renderPanel -> to render (right hand) panel of the data, the panel data display should have the data id prepended by panel_ if javascript needs to interact with it
* renderToolTipPanel -> to render the tooltip panel of the data

## Tooltips technicalities
- Add attribute data-template with id of the data prepended by tooltip_ to each visible element that needs a tooltip when hovered over.
- Create in renderTooltipPanel a div with this id and set style="display:none"
- The library https://atomiks.github.io/tippyjs/ takes care of the rest with corresponding code in interactivity.js.

## Individual layers considerations
### Coronal holes
Request sends target_time to server, server responds with all coronal holes with existing lispan in  [target_time-16h, target_time+16h] the client filters only those detections closest to the target_time.

### SWAP image
A request on the SWAP database is made such that the (non-defective) image closest to the target time is found. It is verified that the image exists on disk.

### KSO filaments

A request to https://sso.kso.ac.at/prod/API/index.php?component=archive&pc=S107&psc=f&dts_start=".$start."&dts_end=".$end
is made where $start = target_time - 2h and $end = target_time + 2h

### regions_sidc_sunspot

A request to http://sidc.be/spaceweatherservices-private/applications/ESASSAproducts/stable/API/index.php?component=archive&pc=S123&psc=b&dts_start=".$start."&dts_end=".$end is made where $start = target_time - 6days and $end = target_time 

### regions_noaa 

A request to the internal database is made where $start = YMD of today :00 00 00 and $end=$start + 1d

### regions INAF/OACT

A request to the internal database is made in chunks of 1 day backwards starting from the $target_time. If a result is found it is returned. This search is done for at most 7 days backwards in time.
