Re: [OpenMap Users] Possible bug in Layer subclasses

From: Don Dietrick <dietrick_at_bbn.com>
Date: Mon, 27 Sep 2004 10:47:23 -0400

I take that back, MapBean.setProjection(proj) should work fine to reset
the MapBean's projection on the layers, the MapBean doesn't check if
the new projection is the same as the one it has. So you should be
able to call mapBean.setProjection(getProjection()) to get everything
reset.

- Don

On Sep 27, 2004, at 10:41 AM, Don Dietrick wrote:

>
> On Sep 27, 2004, at 10:28 AM, Sperlongano Brian M NPRI wrote:
>
>> Yeah, this is exactly what I was trying to do. Unfortunately, Dan is
>> right with regards to the setProjection() call as far as I can
>> tell... some layers won't work properly because the projection is
>> stored as a class variable in the layer and not passed by reference
>> around to the various functions that use the projection. I haven't
>> been able to actually verify this would break layers, but I assume it
>> would, and since I'm working on a generic component, I can't take a
>> chance.
>>
>> As a workaround, I made some changes to ImageServer, with the
>> modified version attached. It seems to work for me, although there's
>> probably a chance that I'm fouling things up in a way that I don't
>> understand.
>>
>> Essentially, before rendering each layer I save a copy of the
>> projection using getProjection(), and then after rendering, I set the
>> projection back using projectionChanged(). I originally tried to do
>> this using setProjection(), but this did not actually cause the layer
>> to repaint.
>
> That's because the MapBean doesn't know about the ImageServer
> projection, and thinks you've just given it the projection it already
> has.
>
> I'll add a method to the MapBean that forces it to distribute the
> provided projection to the layers. Because setProjection() is called
> in the renderDataForProjection() method, they will react correctly to
> getting another projection from the MapBean.
>
> MapBeans and Layers won't do work if they don't think the projection
> they have is any different then the last one they got.
>
> - Don
>
>> You could also do this outside of ImageServer using the same method,
>> storing and re-setting the projection, so if there's a reason why
>> this would mess up ImageServer I would think it would be reasonable
>> to do it the same way in user-space.
>>
>> Code changes are below and attached. Hope this helps someone.
>>
>> -Brian
>>
>> (In file ImageServer.java, function byte[] createImage(Projection,
>> int, int, int)
>>
>> BEFORE:
>>
>> for (int i = layers.length - 1; i >= 0; i--) {
>>
>> if ((includedLayerMask & (0x00000001 << i)) != 0) {
>> if (Debug.debugging("imageserver")) {
>> Debug.output("ImageServer: image request adding layer
>> graphics from : "
>> + layers[i].getName());
>> }
>> layers[i].renderDataForProjection(proj, graphics);
>> } else {
>> if (Debug.debugging("imageserver")) {
>> Debug.output("ImageServer: skipping layer graphics from :
>> "
>> + layers[i].getName());
>> }
>> }
>> }
>>
>> AFTER:
>>
>> Projection tempProj; //temp projection storage
>>
>> for (int i = layers.length - 1; i >= 0; i--) {
>>
>> if ((includedLayerMask & (0x00000001 << i)) != 0) {
>> if (Debug.debugging("imageserver")) {
>> Debug.output("ImageServer: image request adding layer
>> graphics from : "
>> + layers[i].getName());
>> }
>> tempProj = layers[i].getProjection(); //store existing
>> projection
>> layers[i].renderDataForProjection(proj, graphics);
>> layers[i].projectionChanged(new ProjectionEvent(this, tempProj));
>> //set projection back
>> } else {
>> if (Debug.debugging("imageserver")) {
>> Debug.output("ImageServer: skipping layer graphics from :
>> "
>> + layers[i].getName());
>> }
>> }
>> }
>>
>>
>> -----Original Message-----
>> From: Hudson Brian R Contr AFRL/IFSF [mailto:Brian.Hudson_at_rl.af.mil]
>> Sent: Friday, September 24, 2004 4:14 PM
>> To: Sperlongano Brian M NPRI
>> Subject: RE: [OpenMap Users] Possible bug in Layer subclasses
>>
>>
>> Hey,
>>
>> I was trying to host a ImageServer off of the same layers that were
>> visible in a MapBean and had the same problems.
>>
>> Once someone would start sending requests to the ImageServer the
>> layers on the MpaBean would go haywire.
>>
>> I had to have this working in a very short amount of time so I made
>> it so those layers served to ImageServer clients were separate from
>> those layers being shown on the MapBean. This solution is far from
>> ideal (doubles the memory more or less)/
>>
>> I'd like to see this problem resolved as well.
>>
>> Brian Hudson
>>
>>
>>
>>
>> -----Original Message-----
>> From: owner-openmap-users_at_bbn.com
>> [mailto:owner-openmap-users_at_bbn.com] On Behalf Of Sperlongano Brian M
>> NPRI
>> Sent: Friday, September 24, 2004 3:35 PM
>> To: 'openmap-users_at_bbn.com'
>> Subject: [OpenMap Users] Possible bug in Layer subclasses
>>
>>
>> Hello all,
>>
>> I believe I have found a bug in the way layer rendering is
>> implemented. I was using the ImageServer class to generate
>> off-screen images for printing, and what I discovered was that the
>> way ImageServer works is to call the renderDataForProjection() method
>> on each of a set of layers onto a Graphics object.
>>
>> One of the things that these implementations do (at least for
>> OMGraphicHandlerLayer and GraticuleLayer, probably all of them) is to
>> set the passed in projection as the new projection.
>>
>> As an example of this, here is a clip from OMGraphicHandlerLayer:
>>
>> public synchronized void renderDataForProjection(Projection proj,
>> Graphics g) {
>> if (proj == null) {
>> Debug.error("Layer(" + getName() +
>> ").renderDataForProjection: null
>> projection!");
>> return;
>> } else if (!proj.equals(getProjection())) {
>> setProjection(proj.makeClone());
>> setList(prepare());
>> }
>> paint(g);
>> }
>>
>> Note the line that says "setProjection(proj.makeClone())".
>>
>> Now, if were were only using the layers on a MapBean, this would be
>> fine. The problem comes when we use existing layers to render to
>> projections other than the ones on the current map. Thus, say I have
>> a 200x200 MapBean, but I wish to (off-screen) render a 400x400
>> version of the same map. I would create a Projection object with
>> those parameters, and then pass it through renderDataForProjection.
>> The Layer would then render my 400x400 map no problem. However, it
>> would also store my 400x400 projection as the current projection.
>> This results in display artifacts being shown in the container
>> containing the MapBean.
>>
>> It seems to me that the offending setProjection() lines should be
>> removed. I commented out those lines in the layers I use and the bug
>> seems to go away AND the map seemed to function all the same.
>>
>> The other option would be to make sure that any class that used Layer
>> in this manner (such as ImageServer) be modified to save the current
>> Projection, render, and the set the old projection back, but this is
>> clearly a less-desireable solution.
>>
>> -Brian
>>
>> Brian Sperlongano
>> Computer Engineer
>> NUWCDIVNPT
>> --
>> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
>> with the following text in the BODY of the message "unsubscribe
>> openmap-users"]
>>
>>
>
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Don Dietrick, dietrick_at_bbn.com
> BBN Technologies, Cambridge, MA
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
> --
> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]
>
>


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, dietrick_at_bbn.com
BBN Technologies, Cambridge, MA
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Mon Sep 27 2004 - 10:47:46 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:06 EDT