On Fri, May 4, 2012 at 8:23 AM, Keith Wiley wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I want to place a "legend" on the map, effectively an image which stays at a particular pixel-location in the view, without being tied to geographic coordinates (and which doesn't scale with zoom). I didn't see an example that does this.<br>
</blockquote><div><br></div><div style>I asked a similar question not too long ago and the one suggestion I got back was that some combination of css could probably work. Maybe you could look for an example of how to do the google watermark or attribution I think it's called.</div>
<div style><br></div><div style>I have to confess that from my perspective css is convoluted and complicated with pieces of the puzzle getting spread through several files -- so it can be difficult to track through all the relevant pieces and get everything figured out -- but maybe that's just me. And maybe that's just the price you pay for developing apps that run inside a web browser.</div>
<div style><br></div><div style>In my case I wasn't just dropping a static image on the screen, I needed to update the contents (the color, the label text, rotation, etc.) I'm sure there is still a css-based solution out there I could pursue, but for the short term I did the first thing that made sense to me that I could figure out on my own.</div>
<div style><br></div><div style>So bear with me here -- personally when it comes to drawing things in open-layers, I've had (by far) the most luck using points. And then specifying a point type (such as circle, square, or my own custom icon -- which is easy to define.) I've also done this for placing "external graphics" and that's worked out quite well. Once the icon/graphic is placed, I can update the label, rotate it, move it, change color, etc. by keeping track of the "style" for each point. I've messed around a bit with polygon features for trying to draw simple things, but I always come back to using points with custom icons or external graphics.</div>
<div style><br></div><div style>To actually place the object in a fixed screen location, I do something like the following (which is a combination of copy/paste out of my own code and manual typing):</div><div style><br>
</div>
<div style> var pt = new OpenLayers.Geometry.Point(screen_x, screen_y); </div><div style> var pos = map.getLonLatFromPixel( pt );</div><div style> var myfeature = myLayer.getFeatureByFid("feature");</div>
<div style> # (note that earlier when I created myfeature and added it to myLayer I placed it at 0, 0 and assigned it a unqiue fid)</div><div style> myfeature.move( pos )</div><div style><br></div><div style>I've done a little work with the ordering of operations when the map recenters which helps the objects to appear fixed, but I haven't played around with keeping them fixed during a zoom -- I know there are move & zoom call backs so presumably you could always reposition your objects ahead of when the map gets redrawn so they always appear fixed on screen. Points and external graphics maintain a fixed pixel size independent of zooming so that's another reason they are nice to use instead of polygons with each individual vertex defined in world coordinate space.</div>
<div style><br></div><div style>Another thing I played with for a different app was to create an empty map with lon/lat coordinates that match the screen pixel space (i.e. 0,0 to screen.width, screen.height). That then gives you a fixed area to work in so you can do "game" like things -- placing graphics with sensible x, y coordinates, rotating, translating them.</div>
<div style><br></div><div style>What would be interesting is if there was a way to overlay a "map" with this simple screen-matching coordinate system on top of a world map in order to do fixed objects on top of the map, but I haven't seen a way to do that. Open-layers is cool and powerful and I'm very grateful for it's existence -- but it does weave a tangled web of class inheritance and it's always a challenge to dig through layer after layer of class documentation to try to see if a particular feature or function or piece of data even exists and if so, how to leverage it.</div>
<div style><br></div><div style>I'm just learning openlayers myself here, so I'd love to hear feedback if there are better ways to do this stuff.</div><div style><br></div><div><span style>Curt</span> </div></div>
-- <br><div><div>Curtis Olson:</div><div><a href="http://www.atiak.com" target="_blank">http://www.atiak.com</a> - <a href="http://aem.umn.edu/~uav/" target="_blank">http://aem.umn.edu/~uav/</a></div><div><a href="http://www.flightgear.org" target="_blank">http://www.flightgear.org</a> - <a href="http://gallinazo.flightgear.org" target="_blank">http://gallinazo.flightgear.org</a></div>
</div><br>