Changeset 2283 in osm for utils/josm


Ignore:
Timestamp:
2007-03-19T12:21:40+01:00 (18 years ago)
Author:
frsantos
Message:

Keep Yahoo logo in images

Location:
utils/josm/plugins/ywms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • utils/josm/plugins/ywms/resources/ymap.html

    r2264 r2283  
    3434        window.resizeTo(width,height);
    3535    </script>
    36     <script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=YahooDemo"></script>
     36    <script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.4&appid=z7qRk3_V34HAbY_SkC7u7GAgG5nDTblw.cuL1OS5LWGwkIIUeGjg4qsnJDPpmhoF"></script>
    3737  </head>
    3838 
     
    6262          // other map types work as well but only satellite allowed for use with OSM!
    6363          var map = new YMap(document.getElementById("map"), YAHOO_MAP_SAT);
     64          map.removeZoomScale();
    6465          var zac = map.getBestZoomAndCenter(points);
    6566          var level = zac.zoomLevel;
     67           
     68           // funny Yahoo bug seems to return 0 if your section is too small
     69           if( level == 0 ) level = 1;
     70           if (level>1) level--;
     71           
     72           map.drawZoomAndCenter(zac.YGeoPoint,level);
    6673
    67           // funny Yahoo bug seems to return 0 if your section is too small
    68           if (level==0) level=1;
    69 
    70           map.drawZoomAndCenter(zac.YGeoPoint,level);
     74                  // Get the on-screen coordinates of the points
     75                  xy0 = map.convertLatLonXY(points[0]);
     76                  xy1 = map.convertLatLonXY(points[1]);
     77                 
     78                  // Create a new size for the map. This makes the need of clipping the image unnecesary.
     79                  new_width  = Math.abs( xy0.x - xy1.x);
     80                  new_height = Math.abs( xy0.y - xy1.y);
     81                 
     82                  // Apply the new width-height
     83          mapDiv.style.width  = new_width;
     84          mapDiv.style.height = new_height;
     85          map.resizeTo( new YSize(new_width, new_height));
     86         
     87                  /// DEBUG: colour the interesting area
     88                  var cPT2 = new YGeoPoint(tllat, tllon);
     89                  var cPT3 = new YGeoPoint(tllat, brlon);
     90                  var cPT4 = new YGeoPoint(brlat, brlon);
     91                  var cPT5 = new YGeoPoint(brlat, tllon);
     92                  // args: array of pts, color, width, alpha
     93                  var poly1 = new YPolyline([cPT2,cPT3,cPT4,cPT5, cPT2],'blue',7,0.7);
     94                  //map.addOverlay(poly1);
     95                 
    7196          var bounds = map.getBoundsLatLon();
    7297
    7398          // Dumps the actual bounding box
    7499          dump("bbox=" + bounds.LonMin + "," + bounds.LatMin + "," + bounds.LonMax + "," + bounds.LatMax + "\n");
     100          dump("new_width=" + new_width + "\n");
     101          dump("new_height=" + new_height + "\n");
    75102      }
    76103    </script>
  • utils/josm/plugins/ywms/src/org/openstreetmap/josm/plugins/ywms/ImageLoader.java

    r2264 r2283  
    5353        private URL yahooUrl;
    5454        double[] orig_bbox = null;
    55         double[] final_bbox = null;
    56         int width = -1;
    57         int height = -1;
     55    int width = -1;
     56    int height = -1;
     57    int final_width = -1;
     58    int final_height = -1;
    5859        Image image;
    5960        List<String> firefoxFiles = new ArrayList<String>();
     
    128129                {
    129130                        System.out.println("YWMS::" + line);
    130                     if( line.startsWith("bbox=") )
    131                     {
    132                         final_bbox = getBbox(line);
    133                         // System.out.println("YWMS::BBOX: (" + final_bbox[0] + "," + final_bbox[1] + "), (" + final_bbox[2] + "," + final_bbox[3] + ")");
    134                     }
     131                if( line.startsWith("new_width=") )
     132                {
     133                    final_width = (int)Math.round( Double.parseDouble( line.substring(10)) );
     134                }
     135                else if( line.startsWith("new_height=") )
     136                {
     137                    final_height = (int)Math.round( Double.parseDouble( line.substring(11)) );
     138                }
    135139                    else if( line.startsWith(GECKO_DEBUG_LINE))
    136140                    {
     
    168172                }
    169173
    170                 if( final_bbox == null && imageFilePpm == null && !firefoxFiles.isEmpty() )
     174                if( final_width == -1 && imageFilePpm == null && !firefoxFiles.isEmpty() )
    171175                {
    172176                        throw new ImageLoaderException("Is there any other firefox window open with same profile?");
    173177                }
    174                 if( final_bbox == null )
    175                 {
    176                         throw new ImageLoaderException("Couldn't find bounding box. Is browser.dom.window.dump.enabled set in Firefox config?");
     178                if( final_width == -1)
     179                {
     180                        throw new ImageLoaderException("Couldn't find new dimension. Is browser.dom.window.dump.enabled set in Firefox config?");
    177181                }
    178182                if( imageFilePpm == null )
     
    221225        private void resizeImage()
    222226        {
    223                 int calcwidth = (int)Math.round((final_bbox[2] - final_bbox[0]) * width / (orig_bbox[2] - orig_bbox[0]));
    224                 int calcheight = (int)Math.round((final_bbox[3] - final_bbox[1]) * height / (orig_bbox[3] - orig_bbox[1]));
    225 
    226                 int cropWidth = (calcwidth - width) / 2;
    227                 int cropHeight = (calcheight - height) / 2;
    228        
    229227                Toolkit tk = Toolkit.getDefaultToolkit();
    230         // save("/tmp/image_orig.jpg");
    231         image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(0, 0, width, height)));
    232         image = tk.createImage (new FilteredImageSource (image.getSource(), new ReplicateScaleFilter(calcwidth, calcheight)));
    233         image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(cropWidth, cropHeight, width, height)));
    234                 // BufferedImage img = (BufferedImage)image.getScaledInstance(calcwidth, calcwidth, BufferedImage.SCALE_DEFAULT);
    235                 // image = img.getSubimage(cropl, cropt, width, height);
     228        //save("/tmp/image_orig.png");
     229        image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(0, 0, final_width, final_height)));
     230        //save("/tmp/image_crop.png");
     231        image = tk.createImage (new FilteredImageSource (image.getSource(), new ReplicateScaleFilter(width, height)));
     232        //save("/tmp/image_scale.png");
    236233        }
    237234
     
    265262         * @throws IOException When error saving the file
    266263         */
    267         public void save(String fileName) throws IOException
    268         {
    269         FileOutputStream fileStream = new FileOutputStream(fileName);
    270         ImageIO.write(getBufferedImage(), "png", fileStream);
    271         fileStream.close();
     264        public void save(String fileName)
     265        {
     266        try
     267        {
     268            FileOutputStream fileStream = new FileOutputStream(fileName);
     269            ImageIO.write(getBufferedImage(), "png", fileStream);
     270            fileStream.close();
     271        }
     272        catch(Exception e)
     273        {
     274            e.printStackTrace();
     275        }
    272276        }
    273277       
Note: See TracChangeset for help on using the changeset viewer.