Modify

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#6869 closed enhancement (fixed)

[patch] Added JMapViewerEventListener and getMeterPerPixel() to JMapViewer

Reported by: jhuntley Owned by: jhuntley
Priority: normal Milestone:
Component: Core Version: latest
Keywords: JMapViewer Cc: bastiK

Description

The scale can now be retrieved in real-time vs looking off referenced wiki pages:

http://wiki.openstreetmap.org/wiki/Height_and_width_of_a_map

I've updated the Demo application to demonstrate this feature.

I've also added a special eventlistener mechanism to the the JMapViewer so external UI components can register and receive notifications when the user interacts with the Map Viewer. Right now I'm only demoing with the zoom feature. However, I could see additional actions added for other operations in the Viewer. Please see demo.

I've tested the accuracy of the meter/pixel calculation with all the major airport runways in the US. The calculation is extremely close to scale. I can generate runway overlays for airports using this function. I may even have more enhancements coming later for adding object and shape overlays to the map.

I do you hope you consider this functionality for the project. I'm attaching the source. Thanks for your time.

Attachments (8)

Demo.java (6.3 KB ) - added by jhuntley 13 years ago.
JMapViewer.java (31.8 KB ) - added by jhuntley 13 years ago.
OsmMercator.java (6.3 KB ) - added by jhuntley 13 years ago.
JMapViewer.zip (148.8 KB ) - added by jhuntley 13 years ago.
jmapviewer.2.diff (23.8 KB ) - added by jhuntley 13 years ago.
jmapviewer.diff (23.7 KB ) - added by jhuntley 13 years ago.
jmapviewer.3.diff (17.7 KB ) - added by anonymous 13 years ago.
JMapViewer.2.zip (149.2 KB ) - added by jhuntley 13 years ago.

Download all attachments as: .zip

Change History (27)

by jhuntley, 13 years ago

Attachment: Demo.java added

by jhuntley, 13 years ago

Attachment: JMapViewer.java added

by jhuntley, 13 years ago

Attachment: OsmMercator.java added

comment:1 by bastiK, 13 years ago

Sounds good, can you make a patch?

comment:2 by bastiK, 13 years ago

Summary: Added JMapViewerEventListener and getMeterPerPixel() to JMapViewer[patch] Added JMapViewerEventListener and getMeterPerPixel() to JMapViewer

comment:3 by jhuntley, 13 years ago

Sounds good, can you make a patch? 

If you like, certainly. However, I am new to the project. I've been reading through your wiki here

https://josm.openstreetmap.de/wiki/DevelopersGuide/SVN_Account

Do I need any special permissions granted to my account? I guess you may have already taken care of this? Any info is greatly appreciated.

in reply to:  3 comment:4 by bastiK, 13 years ago

Replying to jhuntley:

Sounds good, can you make a patch? 

If you like, certainly. However, I am new to the project. I've been reading through your wiki here

https://josm.openstreetmap.de/wiki/DevelopersGuide/SVN_Account

Do I need any special permissions granted to my account? I guess you may have already taken care of this? Any info is greatly appreciated.

What I meant: Please attach a single file in diff format. You can use svn diff to generate the patch. Don't forget to svn add the new files. This makes it easier to discuss and apply the changes.

You don't necessarily need an account, we can check in the changes for you. Anyway, the jmapviewer component is in the osm repository. To apply your changes directly, you need an account for svn.openstreetmap.org/. The jmapviewer is an important part of JOSM, so it would be nice to discus any major changes in advance.

comment:5 by jhuntley, 13 years ago

As per your request, I'm attaching the diff with the latest enhancements. I'm also including a new build for those wanting to demo the updates.

by jhuntley, 13 years ago

Attachment: JMapViewer.zip added

in reply to:  5 comment:6 by bastiK, 13 years ago

Replying to jhuntley:

As per your request, I'm attaching the diff with the latest enhancements. I'm also including a new build for those wanting to demo the updates.

Thanks, there are some classes missing, e.g. JMVCommandEvent.

Why did you remove this section?

-        if (rectangles) {
-            for (MapRectangle rectangle : mapRectangleList) {
-                x_max = Math.max(x_max, OsmMercator.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax));
-                y_max = Math.max(y_max, OsmMercator.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax));
-                x_min = Math.min(x_min, OsmMercator.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax));
-                y_min = Math.min(y_min, OsmMercator.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax));
-            }
-        }

Your scale code might fail, when the size of the component is 10x10. No big deal, but the formula on the linked wiki page looks easier. :)

Paul

comment:7 by jhuntley, 13 years ago

Why did you remove this section? 

I'm sorry, I wasn't aware I had. I must have accidentally left it out in the merge between my branch and openstreetmap's. I'll fix. I'll add the missing class.

comment:8 by jhuntley, 13 years ago

1 sec, need to check JMapViewer.java.

by jhuntley, 13 years ago

Attachment: jmapviewer.2.diff added

comment:9 by jhuntley, 13 years ago

"jmapviewer.diff" should now contain all the appropriate updates.

comment:10 by bastiK, 13 years ago

The scale doesn't update when the map is moved. (Please don't use tabs, it's hard to read the patch otherwise.)

comment:11 by jhuntley, 13 years ago

The scale doesn't update when the map is moved.

The scale doesn't actually have to update when the map is moved or paned. The size of the map and zoom are still the same. The scale only changes if you zoom in and out.

Please don't use tabs, it's hard to read the patch otherwise.) 

Thought i had it set in the CodeStyle, guess not. I'll update to use spaces. Thanks,

by jhuntley, 13 years ago

Attachment: jmapviewer.diff added

comment:12 by jhuntley, 13 years ago

I've converted tabs to spaces . Settings should be correct in my IDE and the patch. I also opened the patch and checked and the tabs are all spaces now.

in reply to:  11 ; comment:13 by bastiK, 13 years ago

Replying to jhuntley:

The scale doesn't update when the map is moved.

The scale doesn't actually have to update when the map is moved or paned. The size of the map and zoom are still the same. The scale only changes if you zoom in and out.

At small scale, it changes. E.g. open http://www.openstreetmap.org/?lat=47.78&lon=11.82&zoom=6&layers=M and move the map up and down. You'll see the bar in the lower left gets smaller/larger.

in reply to:  13 ; comment:14 by jhuntley, 13 years ago

Replying to bastiK:

Replying to jhuntley:

The scale doesn't update when the map is moved.

The scale doesn't actually have to update when the map is moved or paned. The size of the map and zoom are still the same. The scale only changes if you zoom in and out.

At small scale, it changes. E.g. open http://www.openstreetmap.org/?lat=47.78&lon=11.82&zoom=6&layers=M and move the map up and down. You'll see the bar in the lower left gets smaller/larger.

I see what you are referring too, but the change is so subtle. I did have the demo updating like that, but I just didn't think the the difference was enough to warrant calculating every move. However, if you would prefer it that way, I can make the adjustment. Shouldn't take long.

in reply to:  14 comment:15 by bastiK, 13 years ago

Replying to jhuntley:

Replying to bastiK:

Replying to jhuntley:

The scale doesn't update when the map is moved.

The scale doesn't actually have to update when the map is moved or paned. The size of the map and zoom are still the same. The scale only changes if you zoom in and out.

At small scale, it changes. E.g. open http://www.openstreetmap.org/?lat=47.78&lon=11.82&zoom=6&layers=M and move the map up and down. You'll see the bar in the lower left gets smaller/larger.

I see what you are referring too, but the change is so subtle.

Not that subtle: if you start at the equator and move to Siberia, it grows by factor 5. Reason enough to not have a scale on the osm main site for years.

I did have the demo updating like that, but I just didn't think the the difference was enough to warrant calculating every move.

The computer won't mind.

However, if you would prefer it that way, I can make the adjustment. Shouldn't take long.

I don't want to nag and keep you busy, but wouldn't it be a nice addition to your event framework? :)

by anonymous, 13 years ago

Attachment: jmapviewer.3.diff added

comment:16 by jhuntley, 13 years ago

Hello Bastik, I've made the updates you've requested. The Demo now updates scale when you pan as well as zoom. Please use jmapviewer.3.diff for your patch. For some reason, I no longer have the option to replace when I attach files. Sorry for the list.

by jhuntley, 13 years ago

Attachment: JMapViewer.2.zip added

comment:17 by jhuntley, 13 years ago

The computer won't mind. 
I don't want to nag and keep you busy, but wouldn't it be a nice addition to your event framework? :) 

Haha, I like your sense of humor :P I was tinkering around with the demo some more, and I see what you're referring to. It does change quite a bit when you pan up and down. I don't mind helping out or the constructive criticisms for that matter. I'm very particular to the details as well. I understand. Let me know if you see any other issues.

comment:18 by bastiK, 13 years ago

Resolution: fixed
Status: newclosed

In [o26701]. (applied josm 6869 - scale and event listeners for JMapViewer (patch by Jason Huntley))

comment:19 by bastiK, 13 years ago

Removed unnecessary unit conversion and added "official" earth radius.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain jhuntley.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.