Tooltips on icons
Schuyler Erle
schuyler at NOCAT.NET
Tue Mar 29 07:26:34 PST 2005
* On 29-Mar-2005 at 2:09AM PST, Aaron Craig said:
>
> Is it possible to get a tooltip to pop up with some text taken from a
> field in my Postgis database when the user puts her mouse over an icon
> in a layer?
There's nothing built in to MapServer that I know of. I'm working on a
solution that uses Python MapScript and Cheetah templates to output an
image map that could be used to add JS mouseover hooks. The heart of
the code looks something like this:
def points_to_pixels (self, pts):
"""The points_to_pixels() method takes a list of (point, link)
tuples, and returns a list of dicts. Each entry in the returned dict
has an 'x' and 'y' key representing the point's location in pixel
space, and 'url' key containing the link."""
map = self.map
result = []
width = map.extent.maxx - map.extent.minx
height = map.extent.maxy - map.extent.miny
x_res = map.width / width
y_res = map.height / height
"""Each point is converted to pixel space by subtracting the
coordinate from the spatial map edge, multiplying by the pixel
resolution (in pixels/spatial unit), and rounding to the nearest
integer. If the point would wind up off the map, it is omitted from
the returned list. Also, points without matching links (e.g. the link
evaluates to false) are discarded."""
for pt, url in pts:
if not url:
continue
x = int((pt.x - map.extent.minx) * x_res + .5)
y = int((map.extent.maxy - pt.y) * y_res + .5)
if x >= 0 and x <= map.width and \
y >= 0 and y <= map.height:
result.append({ 'x': x, 'y': y, 'url': url })
return result
The result list gets passed to a Cheetah template to generate the
actual image map. I hope the code is reasonably self-explanatory. The
project I'm working on is something of a port of the subset of
mapserv's functionality to Python MapScript in order to make things
like this possible. I'll post to the list when the (GPL'ed) code is
available.
SDE
More information about the MapServer-users
mailing list