2008/9/15 Petr Dlouhý <[EMAIL PROTECTED]>: > On Mon, 15 Sep 2008 05:15:01 +0200, andrzej zaborowski <[EMAIL PROTECTED]> > wrote: > >> Hi, >> I tried yesterday to decide what's the best way to support Yahoo! >> imagery with firefox 3 (or rather without ff 2). First I checked out >> the OpenLayers plugin from Francisco Santos and tried to see what was >> left to be done in it. I like the idea of the plugin but there seem >> to be unresolved design issues. >> >> Firstly, it does a switch from firefox to a java based browser for >> downloading. Aside from the size of the file, this browser is slower >> for me and causes josm to hang for a couple of seconds when loading >> yahoo for the first time. On the other hand scrolling the mapview >> doesn't spawn new processes like it would be with firefox so it's >> smoother. Perhaps it could be put into a thread of its own. >> >> Then the first thing that I found annoying was lack of progress >> indication when downloading, so the first patch attached makes the >> layer contents be displayed progressively as they're loaded. Then >> there's the issue with positioning and scalling the layer contents - >> the code to do this is disabled with a "TODO wrong calculations" >> comment. I found the calculations are actually correct but the whole >> idea of chaging the map view according to the layer requirements is >> bad. In this case it causes infinite recurrency because updating the >> view causes the open layer update (possibly download of new tiles) and >> a map view update again. Then it also implies restricting josm map >> view to only the zoom levels supported by the openlayer, I think this >> will be absolutely unusable. >> >> So I had an idea to reuse GeorefImage from WMSPlugin and store the >> openlayer contents and scale and position them when necessary. But >> then I checked out the latest WMSPlugin and found that some yahoo >> imagery support was added there with seemingly all the things I >> needed, even the download is done in a separate thread and tiles are >> downloaded automatically. I installed gnome-web-photo 0.5 and it >> basically works, with firefox 3 and wmsplugin, but the tiles were >> displayed wrongly. It took a lot of wrapping my head around it to >> understand out why (basically firefox 3 / gnome-web-photo alwyas >> return images enlarged to some constant window width and we have no >> way to communicate the downloaded yahoo image width from browser back >> to josm). I managed to work around it and while there are new gecko >> processes spawned all the time (like with ywms) it is quite usable and >> works with firefox 3. The third attached patch is the work around. >> > > Hello, I the author of the changes in WMSPlugin. There is much more info > about the changes in this list. Unfortunately, the patches didn't go through > the mailing list, so I don't know, what you changed. You have the same
Oops. This time attached as .txt as Dirk suggests, maybe it works. I noticed I also changed the "ImageSize" to 1000 to get possibly better resolution at low zoom, it's not related to rest of the patch. > problem with badly displayed tiles, as Dirk has. The web page is affecting > the result image size by changing it's size (by window.resizeTo), and it Yes, resizeTo still works on the new gecko but it seems gnome-web-photo 0.5 cannot know what the final width is and needs to assume some default fixed amount, gnome-web-photo --help gives this: -w, --width=W The desired width of the image (default: 1024) and the resulting .png's are always 1024px wide by default, the yahoo image is aligned to left and the rest of the png is filled with white. This coincides with what I saw when I tried to re-add MOZ_FORCE_PAINT_AFTER_ONLOAD support in ff3 - I couldn't find a way to get the exact size, although I gave up too quickly, probably. Regards
Index: src/org/openstreetmap/josm/plugins/openLayers/ShowOpenLayersAction.java =================================================================== --- src/org/openstreetmap/josm/plugins/openLayers/ShowOpenLayersAction.java (revision 10660) +++ src/org/openstreetmap/josm/plugins/openLayers/ShowOpenLayersAction.java (working copy) @@ -9,7 +9,7 @@ public class ShowOpenLayersAction extends JosmAction { public ShowOpenLayersAction(String name) { - super(name, "OpenLayers", "Show layer" + name, 0, 0, false); + super(name, "OpenLayers", "Show layer " + name, 0, 0, false); } public void actionPerformed(ActionEvent e) { Index: src/org/openstreetmap/josm/plugins/openLayers/Browser.java =================================================================== --- src/org/openstreetmap/josm/plugins/openLayers/Browser.java (revision 10660) +++ src/org/openstreetmap/josm/plugins/openLayers/Browser.java (working copy) @@ -27,9 +27,11 @@ Dimension oldSize = null; - public Browser(String uri) { + public Browser(String uri, MyHtmlBlockPanel.ViewUpdateListener vul) { super(); + view_update_listener = vul; + UserAgentContext ucontext = new CacheableUserAgentContext(); rcontext = new SimpleHtmlRendererContext(this, ucontext); addNotify(); @@ -98,12 +100,22 @@ return null; } + MyHtmlBlockPanel.ViewUpdateListener view_update_listener; /** * Overrided to hide hardcoded scrollbars and insets */ @Override protected HtmlBlockPanel createHtmlBlockPanel(UserAgentContext ucontext, HtmlRendererContext rcontext) { - return new MyHtmlBlockPanel(java.awt.Color.WHITE, true, ucontext, rcontext, this); + return new MyHtmlBlockPanel(java.awt.Color.WHITE, true, + ucontext, rcontext, this, view_update_listener); } + + /** + * Get page loading status from the bottom status bar. + */ + public String getStatus() { + /* TODO */ + return "Tile loaded"; + } } Index: src/org/openstreetmap/josm/plugins/openLayers/MyHtmlBlockPanel.java =================================================================== --- src/org/openstreetmap/josm/plugins/openLayers/MyHtmlBlockPanel.java (revision 10660) +++ src/org/openstreetmap/josm/plugins/openLayers/MyHtmlBlockPanel.java (working copy) @@ -17,6 +17,11 @@ private static final long serialVersionUID = -4778865358510293592L; + public interface ViewUpdateListener { + void region_update(int x, int y, int w, int h); + } + ViewUpdateListener view_update_listener; + /** * Constructor * @param background @@ -25,8 +30,10 @@ * @param rcontext * @param frameContext */ - public MyHtmlBlockPanel(Color background, boolean opaque, UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext) { + public MyHtmlBlockPanel(Color background, boolean opaque, UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext, + ViewUpdateListener vul) { super(background, opaque, pcontext, rcontext, frameContext); + view_update_listener = vul; } /** @@ -47,4 +54,9 @@ this.validateAll(); this.repaint(); } -} \ No newline at end of file + + public void repaint(int x, int y, int width, int height) { + super.repaint(x, y, width, height); + view_update_listener.region_update(x, y, width, height); + } +} Index: src/org/openstreetmap/josm/plugins/openLayers/OpenLayersLayer.java =================================================================== --- src/org/openstreetmap/josm/plugins/openLayers/OpenLayersLayer.java (revision 10660) +++ src/org/openstreetmap/josm/plugins/openLayers/OpenLayersLayer.java (working copy) @@ -24,7 +24,9 @@ * @author Francisco R. Santos <[EMAIL PROTECTED]> * */ -public class OpenLayersLayer extends Layer implements PreferenceChangedListener, PropertyChangeListener { +public class OpenLayersLayer extends Layer + implements PreferenceChangedListener, PropertyChangeListener, + MyHtmlBlockPanel.ViewUpdateListener { private Browser browser; @@ -33,9 +35,10 @@ */ public OpenLayersLayer() { super("OpenLayers"); - - this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html"); - + + this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html", + this); + if( Main.map != null ) { LatLon bottomLeft = Main.map.mapView.getLatLon(0,Main.map.mapView.getHeight()); @@ -129,18 +132,18 @@ LatLon bottomLeft = Main.map.mapView.getLatLon(0,Main.map.mapView.getHeight()); LatLon topRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0); Object value = browser.executeScript("zoomMapToExtent(" + bottomLeft.lon() + "," + bottomLeft.lat() + "," + topRight.lon() + "," + topRight.lat() + ")"); - if( value != null && false) - { - // TODO wrong calculations - + if (value != null && false) { + // TODO: should not be touching Main.map.mapView here as this + // causes endless recurrency - should do the scalling ourselves + // Get actual extent from browser NativeArray array = (NativeArray)value; double left = ((Double)array.get(0, null)).doubleValue(); double bottom = ((Double)array.get(1, null)).doubleValue(); double right = ((Double)array.get(2, null)).doubleValue(); double top = ((Double)array.get(3, null)).doubleValue(); - bottomLeft = new LatLon( bottom, left ); - topRight = new LatLon( top, right); + bottomLeft = new LatLon(bottom, left); + topRight = new LatLon(top, right); BoundingXYVisitor v = new BoundingXYVisitor(); v.visit(Main.proj.latlon2eastNorth(bottomLeft)); @@ -149,4 +152,12 @@ Main.map.mapView.recalculateCenterScale(v); } } + + public void region_update(int x, int y, int w, int h) { + String status = browser.getStatus(); + + org.openstreetmap.josm.Main.map.mapView.repaint(x, y, w, h); + + org.openstreetmap.josm.Main.map.statusLine.setHelpText(status); + } }
Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 0) +++ META-INF/MANIFEST.MF (revision 0) @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Created-By: 1.5.0_13-b05 (Sun Microsystems Inc.) +Plugin-Class: org.openstreetmap.josm.plugins.openLayers.OpenLayersPlugin +Plugin-Description: OpenLayers downloader layer for tracing over +Plugin-Version: 1337 +Plugin-Date: 2007-10-26T09:40:20.516999Z +Author: Francisco R. Santos <[EMAIL PROTECTED]> + Index: Makefile =================================================================== --- Makefile (revision 0) +++ Makefile (revision 0) @@ -0,0 +1,29 @@ +OLJAR=ol.jar +CPATH=src +JPATH=$(CPATH)/org/openstreetmap/josm/plugins/openLayers + +all: $(OLJAR) + +$(JPATH)/OpenLayersPlugin.class: $(JPATH)/*.java $(CPATH)/org/lobobrowser + javac -cp $(CPATH) $(JPATH)/*.java + +$(OLJAR): META-INF/MANIFEST.MF $(JPATH)/OpenLayersPlugin.class + OBJS=`echo $(JPATH)/*.class` && \ + ln -sf $(CPATH)/{com,edu,net,presets,styles,org,*.xml} . && \ + cp -ua $(CPATH)/images/* images/ && \ + jar -cvfm ol.jar META-INF/MANIFEST.MF images resources \ + $${OBJS//$(CPATH)\//} com edu net presets styles \ + ehcache-failsafe.xml org/apache org/lobobrowser org/mozilla org/w3c + +install: $(OLJAR) + mkdir -p ~/.josm/plugins + cp $^ ~/.josm/plugins/ + +uninstall: + rm -rf ~/.josm/plugins/$(OLJAR) + +clean: + rm -rf $(JPATH)/*.class $(OLJAR) + +$(CPATH)/org/lobobrowser: lib/*.jar /usr/lib/josm/josm.jar + for f in $^; do unzip -n "$$f" -d $(CPATH); done
Index: src/wmsplugin/WMSLayer.java =================================================================== --- src/wmsplugin/WMSLayer.java (revision 10666) +++ src/wmsplugin/WMSLayer.java (working copy) @@ -52,7 +52,7 @@ public int messageNum = 5; //limit for messages per layer protected boolean stopAfterPaint = false; - protected int ImageSize = 500; + protected int ImageSize = 1000; protected int dax = 10; protected int day = 10; protected int minZoom = 3; Index: src/wmsplugin/YAHOOGrabber.java =================================================================== --- src/wmsplugin/YAHOOGrabber.java (revision 10666) +++ src/wmsplugin/YAHOOGrabber.java (working copy) @@ -61,7 +61,7 @@ public void run() { Image img; - + width = (int) ((b.max.lon() - b.min.lon()) * pixelPerDegree); height = (int) ((b.max.lat() - b.min.lat()) * pixelPerDegree); @@ -80,7 +80,8 @@ } Process browser = browse(url.toString());; image.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); - img = ImageIO.read(browser.getInputStream()).getScaledInstance(width, height, Image.SCALE_FAST); + img = grab(browser, width, height, + b.max.lat()); } image.image.getGraphics().drawImage(img, 0 , 0, null); @@ -102,7 +103,30 @@ } } + static protected Image grab(Process browser, int width, int height, + double lat) throws IOException { + BufferedImage img; + double ratio; + /* + * Calculate the pixel aspect ratio: + * 1 deg lon in meters / 1 deg lat in meters. + * (should multiply by 40075.02 / 40007.86 - equatorial + * to meridional circumference, but don't know if Yahoo! + * takes that into account) + */ + ratio = Math.cos(Math.toRadians(lat)); + /* + * gnome-web-photo + gecko gives us an image with height + * matching the picture's height and width of some broswer + * default value, with the image aligned to left. + */ + img = ImageIO.read(browser.getInputStream()); + width = (int) + (img.getWidth() * width / ratio / img.getHeight()) + 1; + return img.getScaledInstance(width, height, Image.SCALE_SMOOTH); + } + protected Process browse(String url) throws IOException { ArrayList<String> cmdParams = new ArrayList<String>(); Index: resources/ymap.html =================================================================== --- resources/ymap.html (revision 10666) +++ resources/ymap.html (working copy) @@ -1,10 +1,6 @@ <html> <head> <script type="text/javascript"> - //var bbox = ""; - //var width = 800; - //var height = 800; - // Parse query string and set variables var url = location.href; var queryStringPos = url.indexOf("?"); @@ -12,7 +8,7 @@ { url = url.substring(queryStringPos + 1); var variables = url.split ("&"); - for (i = 0; i < variables.length; i++) + for (i = 0; i < variables.length; i++) { if( !variables[i] ) continue; @@ -24,15 +20,10 @@ { dump("YWMS ERROR: no queryString\n"); } - - // Limit size to current window's, to avoid memory problems - //width = Math.min(width, screen.width); - //height = Math.min(height, screen.height); - </script> <script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=z7qRk3_V34HAbY_SkC7u7GAgG5nDTblw.cuL1OS5LWGwkIIUeGjg4qsnJDPpmhoF"></script> </head> - + <body style="margin: 0px"> <div id="map"></div> <script type="text/javascript"> @@ -59,7 +50,7 @@ map.removeZoomScale(); var zac = map.getBestZoomAndCenter(points); var level = zac.zoomLevel; - + // funny Yahoo bug seems to return 0 if your section is too small if( level == 0 ) level = 1; if (level>1) level--; @@ -73,34 +64,17 @@ // This is hack to bug in getBestZoomAndCenter function cx = map.convertXYLatLon(new YCoordPoint((xy0.x+xy1.x)/2, (xy0.y+xy1.y)/2)); map.drawZoomAndCenter(cx,level) - - dump(xy0.x + " " + xy0.y + " " + xy1.x + " " + xy1.y + "\n"); - dump(tllat + " " + tllon + " " + brlat + " " + brlon + "\n"); - dump((brlat + tllat)/2 + " " + (brlon + tllon)/2 + "\n"); - + // Create a new size for the map. This makes the need of clipping the image unnecessary. - new_width = Math.abs( xy0.x - xy1.x); - new_height = Math.abs( xy0.y - xy1.y); - + new_width = Math.abs(xy0.x - xy1.x); + new_height = Math.abs(xy0.y - xy1.y); + // Apply the new width-height mapDiv.style.width = new_width; mapDiv.style.height = new_height; - map.resizeTo( new YSize(new_width, new_height)); - window.moveTo(0,0); + map.resizeTo(new YSize(new_width, new_height)); + window.moveTo(0, 0); window.resizeTo(new_width, new_height); - - - - /* - /// DEBUG: colour the interesting area - var cPT2 = new YGeoPoint(tllat, tllon); - var cPT3 = new YGeoPoint(tllat, brlon); - var cPT4 = new YGeoPoint(brlat, brlon); - var cPT5 = new YGeoPoint(brlat, tllon); - // args: array of pts, color, width, alpha - var poly1 = new YPolyline([cPT2,cPT3,cPT4,cPT5, cPT2],'blue',7,0.7); - map.addOverlay(poly1); - */ } </script> </body>
_______________________________________________ josm-dev mailing list josm-dev@openstreetmap.org http://lists.openstreetmap.org/listinfo/josm-dev