OpenWaterFoundation / owf-app-infomapper-ng

Open Water Foundation InfoMapper web application for menu-driven maps and visualizations, using Angular
GNU General Public License v3.0
1 stars 2 forks source link

Multiple raster layers don't show both cell values and show legend label #352

Open smalers opened 3 years ago

smalers commented 3 years ago

The Colorado Agricultural Water Transfer website Municipalities map has two raster layers. Is it possible to show both raster layer cell values? The popup does seem to show the correct raster cell value when moving between the cells in different raster layers.

Also, is it possible to show the lend value next to the cell value in the popup. I can shorten the legend text if necessary. Showing the text will make it easier for users to interpret the cell values.

smalers commented 3 years ago

Here are some thoughts:

  1. Popups are controlled by mouse events. Moving the mouse generates an event that causes popup text to be changed.
  2. Is there a predictable order to mouse events for a stack of layers? For example, if a vector layer is on top of the map, does its event get triggered first, followed by raster layer events that are from underlying raster layers? If the call sequence is predictable, that would be helpful.
  3. Understanding the lifecycle of the popup could help handle the events. For example if the popup knows that it is for a vector, then that controls. Then code could reach back into data and get raster values at the mouse coordinate, including handling no-data values.
  4. If the popup lifecycle shows that there is no vector layer involved at a location, then it becomes an issue of negotiating the raster events. See point number 2. It may be necessary to track the pixel x and y that generated the event. If multiple raster events are trigged at the same pixel, then process cell values for all he rasters at that pixel. If the pixel is different, restart the string for the popup.
smalers commented 3 years ago

Here is an idea...

For the code that handles the popup, can it retain a list/array of triggering items with the raster cell that triggered that call? Then whenever there is an event handled, the code could go through that short array/list as follows:

  1. If the new event has a different cell, then clear the list and add itself to that list.
  2. If the event has the same cell, then add itself to the list.
  3. Use the list to format the raster part of the output.

This simple logic would handle multiple raster events triggered for the same raster cell regardless of order. The vector output would also need to be handled as before.

Nightsphere commented 3 years ago

I believe I was able to find a solution for this using a combination of the ideas above from Steve and some of my own. I've done all the testing I could think of on my end, but I'm not convinced it's flawless. I feel like that should be the outlook for everything however. I will wait to close until more rigorous testing has been done / more examples have been used.

smalers commented 3 years ago

This seems to be somewhat working. See the image below. I mentioned before adding the text label to the right of the raster number. That way it is easier to interpret the numbers. the label may need to be truncated so the popup does not get wide.

There does seem to be some lag where the popup does not update when the mouse is moved. I'm using the LandDevelopment.tif and Municipality.tif layers in the following repository: https://github.com/OpenWaterFoundation/owf-infomapper-coagtransfer-data-wwr/tree/main/Rasters

image

smalers commented 3 years ago

Now that I've been working with the graduated symbol, adding the label to the right of the value in the popup is more complicated. It makes sense to do it for categorized symbol but graduated might need more formatting. We might need to be able to handle properties in the format for the popup to look good like:

${cellValue} - year of development

This would also allow modifier to be used like ${cellValue}.format('%.4f') if floating point and want to control the number of digits. This would need to be specified in the event configuration somehow. We can discuss.

smalers commented 3 years ago

In reviewing the legend for recent graduated classification, I am seeing the following, but only after interacting with the map for a while? The behavior should be as follows:

  1. If one raster layer is selected, only that layer's information should be listed in the popup. In the case below, because the group only allows one layer to be selected/visible at time, it is a bug that the popup is showing multiple layer's in the popup.
  2. If multiple raster layers are selected, then the popup should show multiple values. For example, if in the following the group was configured to allow multiple rasters to be selected at the same time, then the popup should show multiple values. This is actually useful and I may configure a map to show multiple overlapping rasters at the same time.

It is also a bug that when moving into a clear area (no color from the legend), there should probably be no data shown in the popup but there are clearly cases where something is confused.

In either case, the popup should be driven by the number of selected (visible) raster layers. There may be a bug in the analysis for this map because the already developed cells black should not be grown onto but different densities are showing this. So, the bug allowed me to see something unexpected.

image


I changed the classification file to be as follows, with Nodata added (software should handle by ignoring case). Note also that a single raster is shown in the popup below (rather than 3 as in the previous example), so not sure what is going on. The intent is that if the raster value is "no data", it will show as totally transparent. The raster library must be doing this already by not trying to render anything in those cells but I think showing explicitly in the legend will avoid confusion. The popup does show "no data". I think we need to clarify in the documentation what the software behavior is. Does it automatically handle no data by showing transparent? If so, then allowing an item in the legend would be an optional thing and it may actually be of interest to color no data different than the default, such as solid black, especially when evaluating whether analysis logic is correct. Note that * in the classification file means "all other data value that have not been handled by other rules and are not 'no data'".

I suspect that the Nodata line I added is being ignored because I changed to a specific color and nothing showed. So, it would be nice if the special value Nodata was handled and did actually render with the specified color, and by default the color would be transparent for boundary and fill. It may be a bit confusing that legend for no data is nothing, but that makes sense because if were configured with, for example, light grey for the outline then the legend would be different from the map. However, I think the user could get through this especially if it were explained with map layer documentation.

Finally, I use the term "missing data" in time series rather than "no data". This difference in language is OK. The term "no data" seems to be built into GIS and raster lingo so we should stick with that.

# Category classification table for Municipal Land Development raster.
# - the value corresponds to raster data value for year
# - set colors to indicate red for most immediate development pressure
valueMin,valueMax,color,opacity,fillColor,fillOpacity,weight,label
# 2018 Current - Black (might change to gray)
-Infinity,<=2018,#000000,1.0,#000000,0.3,2,"<= ${valueMax}"
# 2019-2020 Near-term red
>=2019,<=2020,#ff0000,1.0,#ff0000,0.3,2,"${valueMin} - ${valueMax}"
# 2021-2025 red-orange
>=2021,<=2025,#ff4500,1.0,#ff4500,0.3,2,"${valueMin} - ${valueMax}"
# 2026-2030 orange
>=2026,<=2030,#ffa500,1.0,#ffa500,0.3,2,"${valueMin} - ${valueMax}"
# 2031-2035 orange-yellow
>=2031,<=2035,#f8d568,1.0,#f8d568,0.3,2,"${valueMin} - ${valueMax}"
# 2036-2040 yellow
>=2036,<=2040,#ffff00,1.0,#ffff00,0.3,2,"${valueMin} - ${valueMax}"
# 2041-2045 yellow-green
>=2041,<=2045,#adff2f,1.0,#adff2f,0.3,2,"${valueMin} - ${valueMax}"
# 2046-2050 green
>=2046,Infinity,#00ff00,1.0,#00ff00,0.3,2,">= ${valueMin}"
# No data
Nodata,Nodata,#ffffff,1.0,#ffffff,0.0,0,"No data"

image

Nightsphere commented 3 years ago

After some digging, the issue with displaying every raster layer in the popup even though selectBehavior is set to Single was found. It was a small conditional error, and has been updated so that only the layer currently being shown on the map displays in the popup. I'm looking into the Nodata issue next.

Nightsphere commented 3 years ago

Merge number 2 was done, and the nodata value for valueMin and valueMax is finished. Changing the colors in the classification file for nodata will display on the map and legend. I'll keep this issue open for now in case any hidden bugs reveal themselves with testing in the coming days.

smalers commented 3 years ago

I don't think things are totally working. In the following image, if I move the mouse from right (color) to left (on gray), the popup incorrectly continues to show the color value rather than gray value. It also shows the raster values for all the layers and not just the selected/visible layer.

If I move the mouse from bottom to top into the gray area (second image below), and select the "Medium Density" raster, the popup shows no data even though it clearly is 2018.

image

image

Nightsphere commented 3 years ago

New code has been added that takes care of the multiple issues above. Since this has given me a harder time than I initially thought, and the fact that other small bugs have popped up after previous updates, I will wait to close this until more testing has been done.