Ticket #1572: wmsplugin-yahoo.txt

File wmsplugin-yahoo.txt, 5.3 KB (added by stoecker, 18 years ago)
Line 
1Index: src/wmsplugin/WMSLayer.java
2===================================================================
3--- src/wmsplugin/WMSLayer.java (revision 10666)
4+++ src/wmsplugin/WMSLayer.java (working copy)
5@@ -52,7 +52,7 @@
6
7 public int messageNum = 5; //limit for messages per layer
8 protected boolean stopAfterPaint = false;
9- protected int ImageSize = 500;
10+ protected int ImageSize = 1000;
11 protected int dax = 10;
12 protected int day = 10;
13 protected int minZoom = 3;
14Index: src/wmsplugin/YAHOOGrabber.java
15===================================================================
16--- src/wmsplugin/YAHOOGrabber.java (revision 10666)
17+++ src/wmsplugin/YAHOOGrabber.java (working copy)
18@@ -61,7 +61,7 @@
19
20 public void run() {
21 Image img;
22-
23+
24 width = (int) ((b.max.lon() - b.min.lon()) * pixelPerDegree);
25 height = (int) ((b.max.lat() - b.min.lat()) * pixelPerDegree);
26
27@@ -80,7 +80,8 @@
28 }
29 Process browser = browse(url.toString());;
30 image.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
31- img = ImageIO.read(browser.getInputStream()).getScaledInstance(width, height, Image.SCALE_FAST);
32+ img = grab(browser, width, height,
33+ b.max.lat());
34 }
35 image.image.getGraphics().drawImage(img, 0 , 0, null);
36
37@@ -102,7 +103,30 @@
38 }
39 }
40
41+ static protected Image grab(Process browser, int width, int height,
42+ double lat) throws IOException {
43+ BufferedImage img;
44+ double ratio;
45
46+ /*
47+ * Calculate the pixel aspect ratio:
48+ * 1 deg lon in meters / 1 deg lat in meters.
49+ * (should multiply by 40075.02 / 40007.86 - equatorial
50+ * to meridional circumference, but don't know if Yahoo!
51+ * takes that into account)
52+ */
53+ ratio = Math.cos(Math.toRadians(lat));
54+ /*
55+ * gnome-web-photo + gecko gives us an image with height
56+ * matching the picture's height and width of some broswer
57+ * default value, with the image aligned to left.
58+ */
59+ img = ImageIO.read(browser.getInputStream());
60+ width = (int)
61+ (img.getWidth() * width / ratio / img.getHeight()) + 1;
62+ return img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
63+ }
64+
65 protected Process browse(String url) throws IOException {
66 ArrayList<String> cmdParams = new ArrayList<String>();
67
68Index: resources/ymap.html
69===================================================================
70--- resources/ymap.html (revision 10666)
71+++ resources/ymap.html (working copy)
72@@ -1,10 +1,6 @@
73 <html>
74 <head>
75 <script type="text/javascript">
76- //var bbox = "";
77- //var width = 800;
78- //var height = 800;
79-
80 // Parse query string and set variables
81 var url = location.href;
82 var queryStringPos = url.indexOf("?");
83@@ -12,7 +8,7 @@
84 {
85 url = url.substring(queryStringPos + 1);
86 var variables = url.split ("&");
87- for (i = 0; i < variables.length; i++)
88+ for (i = 0; i < variables.length; i++)
89 {
90 if( !variables[i] )
91 continue;
92@@ -24,15 +20,10 @@
93 {
94 dump("YWMS ERROR: no queryString\n");
95 }
96-
97- // Limit size to current window's, to avoid memory problems
98- //width = Math.min(width, screen.width);
99- //height = Math.min(height, screen.height);
100-
101 </script>
102 <script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=z7qRk3_V34HAbY_SkC7u7GAgG5nDTblw.cuL1OS5LWGwkIIUeGjg4qsnJDPpmhoF"></script>
103 </head>
104-
105+
106 <body style="margin: 0px">
107 <div id="map"></div>
108 <script type="text/javascript">
109@@ -59,7 +50,7 @@
110 map.removeZoomScale();
111 var zac = map.getBestZoomAndCenter(points);
112 var level = zac.zoomLevel;
113-
114+
115 // funny Yahoo bug seems to return 0 if your section is too small
116 if( level == 0 ) level = 1;
117 if (level>1) level--;
118@@ -73,34 +64,17 @@
119 // This is hack to bug in getBestZoomAndCenter function
120 cx = map.convertXYLatLon(new YCoordPoint((xy0.x+xy1.x)/2, (xy0.y+xy1.y)/2));
121 map.drawZoomAndCenter(cx,level)
122-
123- dump(xy0.x + " " + xy0.y + " " + xy1.x + " " + xy1.y + "\n");
124- dump(tllat + " " + tllon + " " + brlat + " " + brlon + "\n");
125- dump((brlat + tllat)/2 + " " + (brlon + tllon)/2 + "\n");
126-
127+
128 // Create a new size for the map. This makes the need of clipping the image unnecessary.
129- new_width = Math.abs( xy0.x - xy1.x);
130- new_height = Math.abs( xy0.y - xy1.y);
131-
132+ new_width = Math.abs(xy0.x - xy1.x);
133+ new_height = Math.abs(xy0.y - xy1.y);
134+
135 // Apply the new width-height
136 mapDiv.style.width = new_width;
137 mapDiv.style.height = new_height;
138- map.resizeTo( new YSize(new_width, new_height));
139- window.moveTo(0,0);
140+ map.resizeTo(new YSize(new_width, new_height));
141+ window.moveTo(0, 0);
142 window.resizeTo(new_width, new_height);
143-
144-
145-
146- /*
147- /// DEBUG: colour the interesting area
148- var cPT2 = new YGeoPoint(tllat, tllon);
149- var cPT3 = new YGeoPoint(tllat, brlon);
150- var cPT4 = new YGeoPoint(brlat, brlon);
151- var cPT5 = new YGeoPoint(brlat, tllon);
152- // args: array of pts, color, width, alpha
153- var poly1 = new YPolyline([cPT2,cPT3,cPT4,cPT5, cPT2],'blue',7,0.7);
154- map.addOverlay(poly1);
155- */
156 }
157 </script>
158 </body>