Opened 20 years ago

Closed 17 years ago

#745 closed defect (fixed)

HTML legend ignores map_layer_class_* changes

Reported by: dmorissette Owned by: dmorissette
Priority: high Milestone: 5.0 release
Component: MapServer C Library Version: 4.3
Severity: normal Keywords:
Cc: emiliom@…

Description (last modified by dmorissette)

Emilio Mayorga wrote:
> 
> Daniel Morissette wrote:
> 
>> Emilio Mayorga wrote:
>>
>>> I'm trying to impact the output of an HTML legend by using URL CGI 
>>> arguments. For example, if in my map file there is a layer with these 
>>> elements:
>>> NAME  "countries"
>>> GROUP "political"
>>> I want to change the group to "admin" on the fly using this URL CGI 
>>> snippet:
>>> &mode=legend&map_countries_group=admin
>>>
>>> However, the HTML legend seems to be completely unresponsive to 
>>> changes passed via the map_<layer name>_<layer subelement> syntax 
>>> (I've tried various changes). Is that so, or am I doing something wrong?
>>>
>>
>> I had a quick look at the code and I see no reason why the HTML legend 
>> would react differently to those layer changes than the other modes. 
>> Are you able to change the group value when using browse mode? Which 
>> version of MapServer are you using? Maybe that's a bug from an older 
>> version?
> 
> 
> Thanks for looking into it. I'm using Mapserver 4.0, on RedHat 8 (sorry, 
> I forgot to mention that). I've tried changing different layer elements 
> (not just group), with no success. I just tried making a layer change 
> while on map mode (map_countries_class_size=10). Here's the URL:
>
http://basin.ocean.washington.edu/cgi-bin/mapserv?mode=map&map=/var/www/html/mapserv/mapache/eng/mapache.map&mapext=-89.7117+14.0558+-85.834+16.9558&mapsize=600+449&layers=countries+departam_ln&map_countries_class_size=10

> 
> 
> The change works. When I try the same change using legend mode with HTML 
> legend, it doesn't change the legend symbol for the "countries" layer. 
> Here's the URL:
>
http://basin.ocean.washington.edu/cgi-bin/mapserv?map=/var/www/html/mapserv/mapache/eng/mapache.map&mode=legend&mapext=0+0+1.134+0.85&mapsize=600+449&layers=countries+departam_ln&map_countries_class_size=10

> 
> 
> Here's the layer definition, though I've also tried this on other layers:
> LAYER # paises
>   NAME         countries
>   DATA         countries
>   GROUP        "political"
>   STATUS       OFF
>   TYPE         LINE
> 
>   CLASS
>     NAME       "Paises"
>     SYMBOL     "line5"
>     COLOR      0 0 0
>     SIZE       2
>   END
> 
>   METADATA
>     wmstitle    "Paises"
>     wms_order   "1"
>     meta_href   "/mapserv/mapache/data/ciatadm.html"
>   END
> 
>   PROJECTION
>     "proj=latlong"
>     "ellps=intl"
>     "no_defs"
>   END
> END
> 
> I tried it using browse mode, but I got an error: "mapserv(): Web 
> application error. No template provided". I don't have a template file 
> because I'm using the Landview/javascript framework.
> 
> Thanks!
> 
> -Emilio
> 
> PS. My unofficial ("pre-release") MapServer application is here:
> http://geo.garrobo.org/mapache/eng/ecosist_ind.html
>

Change History (12)

comment:1 by dmorissette, 20 years ago

I was able to reproduce the issue with the itasca_legend demo on our server:

http://www2.dmsolutions.ca/msapps/itasca_legend/demo_init.html
(select legend 3)

We can change the rivers colors on the map using
&map_dlgstln2_class_color=255+0+0 but the HTML legend is not affected:

http://www2.dmsolutions.ca/cgi-bin/mapserv_42?program=%2Fcgi-bin%2Fmapserv_42&map=%2Fhome%2Fmsapps%2Fitasca_legend%2Fdemo.map&layer=lakespy2&layer=dlgstln2&zoomsize=2&map_web_imagepath=%2Ftmp%2Fms_tmp%2F&map_web_imageurl=%2Fms_tmp%2F&map_web_template=demo_leg_nolayerlist.html&map_legend_template=legend3.html&map_dlgstln2_class_color=255+0+0

comment:2 by sdlime, 20 years ago

Status: newassigned
Actually I'm surprised it worked in browse/map mode. The syntax for changing 
class parameters has always been awkward cause you must tell mapserver which 
class to change. Class names and class numbers must be used to do this and the 
example didn't include them. Should be map_countries_class_Pines_size...

I'll look tonite...

Steve

comment:3 by dmorissette, 20 years ago

Actually, the docs said that when there is only one class or one layer then you
don't need the class/layer index and/or name, so the example is OK according to
docs.

The problem really seems to be that the legend ignores the changes but the map
takes them into account.

comment:4 by sdlime, 20 years ago

Should've remembered that shortcut syntax since I wrote it.

I tested tonite with the MapServer demo and it worked as expected with mode=map,
mode=browse and mode=legend. The mapfile structures are modified at runtime and
the code is not smart enough to know when or if those modifications were made. I
tried modifying color and size, no problem. I was using image legends as opposed
to the HTML legends. I can never tell with HTML legends if the might be a
caching issue.

See for example (the red color works):
 
http://maps.dnr.state.mn.us/cgi-bin/mapserv40?map_dlgstln2_class_color=255+0+0&layer=lakespy2&layer=dlgstln2&zoomsize=2&map=%2Fusr%2Flocal%2Fwww%2Fdocs%2Fmapserver_demos%2Fworkshop%2Fitasca.map&program=%2Fcgi-bin%2Fmapserv40&root=%2Fmapserver_demos%2Fworkshop&map_web_imagepath=%2Fusr%2Flocal%2Fwww%2Fdocs%2Ftmp%2F&map_web_imageurl=%2Ftmp%2F&map_web_template=itasca_basic.html
http://maps.dnr.state.mn.us/cgi-bin/mapserv40?map_dlgstln2_class_color=255+0+0&layer=lakespy2&layer=dlgstln2&zoomsize=2&map=%2Fusr%2Flocal%2Fwww%2Fdocs%2Fmapserver_demos%2Fworkshop%2Fitasca.map&program=%2Fcgi-bin%2Fmapserv40&root=%2Fmapserver_demos%2Fworkshop&map_web_imagepath=%2Fusr%2Flocal%2Fwww%2Fdocs%2Ftmp%2F&map_web_imageurl=%2Ftmp%2F&map_web_template=itasca_basic.html&mode=legend

What's interesting about Emilio's site is that legend isn't reflecting size=2
even with no URL-based changes, nor is the map. Changing to size=10 gets you
very strange symbolization. I don't think there's a problem with the URL-based
parameter handling. My guess is that there are caching issues causing Dan's
results and there's something else up with Emilio's setup, probably something
screwy with the line5 symbol. Could still be a bug in the legending code. Can
you post that symbol?

Steve

comment:5 by emiliom@…, 20 years ago

Thanks to both for looking into this. I did think the size=10 symbolization
looked weird. I took this symbol definition straight from a .sym file that came
with the Mapserver tutorial, symbols35.sym:
# 12
Symbol
NAME 'line5'
Type VECTOR
TRANSPARENT 0
Points
1 0
0 1
0 1
1 0
END
END

But I've tried changing different layer parameters on more than one layer with
the HTML legend, all without success. It's not just that layer & symbol. I was
too lazy to try mode=legend with an image legend.

comment:6 by sdlime, 20 years ago

Vector symbols are typically used for markers or polygon fills, not as brushes
for lines. If you truly want thick lines use a ellipse symbol (most likely a
circle). I'll try playing with this symbol and see what happens...

Steve

comment:7 by sdlime, 20 years ago

Status: assignednew
Works great with your symbol (still think it looks funny ;-)) on this end, both
for drawing lines and polygons. This is definitely a problem with the icon
caching mechanism in the processIcon function in maptemplate.c. The file names
use the class index but nothing about the information within the class so a new
icon is not created with the new values. The work around would be to not use
HTML legends if you need to modify class rendering parameters. The fix might be
complex:

  - add the ability to toggle icon caching, perhaps as an HTML legend tag option
 (e.g. [leg_icon cache="off"])
  - get smarter with icon names by somehow serializing the styles

The latter is probably impractical. Reassigning to Dan...
 

comment:8 by sdlime, 20 years ago

There is one other option, either setting a flag in a class object when things 
change or by inspecting the CGI input when building icons. The latter might be 
worth considering...

Steve

comment:9 by emiliom@…, 20 years ago

Thanks for the tips. I'm still pretty new to MapServer, so I didn't play with
the symbology too much. As for this problem, I'm using your LandView javascript
framework, together with a javascript layer selection tree tool (like Windows
Explorer), and HTML legends. My Mapserver site is going to be bilingual (English
& Spanish). I wanted to have a single map file, and be able to change layer,
class, or group names in all these tools from a single place, through javascript.

Anyways, I'll make do. Using image legends is any option, but HTML legends were
working just great for me now, except for the extra complexity I mentioned some
months ago, of having to use an <iframe> and quite a bit of DOM/javascript
manipulation to suck the html from the iframe and stuff it into a <div>. But
that's another topic....  Thanks for looking into this issue!

comment:10 by dmorissette, 20 years ago

Milestone: 4.4 release
To summarize, Steve wrote in comment #7 that the problem seems to be with the
caching of the legend icons. I'll try to address this for 4.4 if I can find the
time.

comment:11 by dmorissette, 17 years ago

Description: modified (diff)
Status: newassigned

comment:12 by dmorissette, 17 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r6491.

It was not possible to serialize the whole styleObj for use in building the icon filename, but I have modified processIcon() to at least include some key params from the frist 2 styles of the class when building the filenames.

Note: See TracTickets for help on using tickets.