Ticket #2073 (closed defect: fixed)
Small correction of maptemplate.c to be able to use the shpxy when the geometry is a MULTIPOLYGON
| Reported by: | djay | Owned by: | sdlime |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.10.2 release |
| Component: | MapServer CGI | Version: | 4.10 |
| Severity: | normal | Keywords: | imagemap |
| Cc: | sdlime |
Description
I try to generate an imagemap from mapserver using a template which contain this line :
<area shape="polygon" coords="[shpxy precision=0 proj=image] " href="#?[gid]" title="[nom]" alt="[nom]" onmouseover="imagemap.displayData.bindWithArg(imagemap,'[gid]',this.title,'[value]',this)();" onmouseout="imagemap.hideData()"
style="border: 1px #eee solid;background-color: #aaa;" />
I made my mapfile and then I use this command to generate my static imagemap : wget -O /path/to/imagemap/imagemap.xml " http://127.0.0.1/cgi-bin/mapserv-4.10.1?map=/path/to/mapfiles/stat_imagemap_com.map&qlayer=clr&mode=nquery&searchmap=true
When I load the imagemap and the image generated I have a warning message in the firefox console about the fact that there are some error in the imagemap and more precisely the last coordinate of some area are not available.
So I've check the imagemap generated by the mapserv cgi program and I see that sometime, there are component with 3 coordinates, which sounds prety strange. Then I've checked all the imagemaps I've generate with the command line coted before, so I use this command : grep "[1-9]*,[1-9]*,[1-9]*" -rni /path/to/imagemap to detect wrong imagemaps.
I check my PostGIS MULTIPOLYGON using the summary function to see that everytime a MULTIPOLYGON have more than only one nested POLYGON then the corresponding area have a three coordinate "POINT". Furthermore, in case there are only two POLYGON in the MULTIPOLYGON, I see that this "POINT" is the concatenation of the last POINT of the first POLYGON and the first POINT of the last POLYGON. So I've correct the imagemap generated by hand even if this solution was not acceptable from my point of view, so I've decided to check the source code to see if I could quickly correct this strange behavior.
For the test I've made I have to use a geometry object which is a MULTIPOLYGON. In the ms-rfc-2.txt file there is a note about the fact that MULTIPOLYGON are translated into POLYGON, so I was unable to find any method to solve this problem only in the case that the geometry is a MULTIPOLYGON. So I've choosen to find a solution which could work in each case and don't break anything.
In fact even if my explanation it's (maybe too) long, the correction is quite simple and here it is :
- the only things to change are in the maptemplate.c file :
- the line 1144 should be (to avoid a possible buffer overflow) :
- pointFormatLength = strlen("xh") + strlen("xf") + strlen("yh") + strlen("yf") + strlen("cs") + 10 + 2;
- rather than
- pointFormatLength = strlen("xh") + strlen("xf") + strlen("yh") + strlen("yf") + strlen("cs") + 10 + 1;
- the line 1148 should be ;
- snprintf(pointFormat2, pointFormatLength, "%s%%.%dlf%s%s%%.%dlf%s ", xh, precision, xf, yh, precision, yf);
- rather than ;
- snprintf(pointFormat2, pointFormatLength, "%s%%.%dlf%s%s%%.%dlf%s", xh, precision, xf, yh, precision, yf);
- the line 1144 should be (to avoid a possible buffer overflow) :
Well that's all in fact.
I regenerate the imagemaps and now it works like charm.
Please forgive my realy poor english level .. :] And don't hesitate to tell me if I've made or say anything wrong.
Thanks in advance.

