World Wind Java Development 11--Load hot spot information (imitation Google Earth)

Source: Internet
Author: User

There is a photo layer in the GE layer, where you can see some of the images that we call hot information, as shown in:


Then look at the implementation of this article:

The effect is not very much like, actually realize this is very simple, refer to examples in the balloons can be very easy to achieve, here I myself encapsulated Balloonutil class easy to reuse, code is simple to add a note will no longer expand, directly attached source code, There is no understanding of the place can be message exchange ha.

/** * @Copyright 2014-2020 @??? **/package Edu.whu.vge.util;import Gov.nasa.worldwind.avlist.avkey;import Gov.nasa.worldwind.awt.worldwindowglcanvas;import Gov.nasa.worldwind.geom.position;import Gov.nasa.worldwind.layers.renderablelayer;import Gov.nasa.worldwind.render.abstractbrowserballoon;import Gov.nasa.worldwind.render.balloonattributes;import Gov.nasa.worldwind.render.basicballoonattributes;import Gov.nasa.worldwind.render.globebrowserballoon;import Gov.nasa.worldwind.render.pointplacemark;import Gov.nasa.worldwind.render.size;import Gov.nasa.worldwind.util.logging;import Gov.nasa.worldwind.util.WWIO;import Gov.nasa.worldwindx.examples.util.ballooncontroller;import Gov.nasa.worldwindx.examples.util.HotSpotController; Import java.io.inputstream;/** * @ Project Name: Smartscope * @ class Name: Balloonsutil * @ class Description: * @ Creator: Liu Shuo * @ created: February 3, 2015 4:56:26 * @ Modified NOTE: * @ Version: */public class balloonsutil{private double Balloonlat;//balloon latitude private double balloonlon;//balloon Longitude private Strin G Ballooncontentpath; //html file path private String balloonname; Balloon name protected Hotspotcontroller hotspotcontroller;protected Ballooncontroller ballooncontroller;/** * * Create a new instance Balloonsutil. * * @param balloonlat * @param balloonlon * @param ballooncontentpath * @param balloonname */public balloonsutil (double b Alloonlat, double balloonlon,string Ballooncontentpath, String balloonname) {super (); This.balloonlat = Balloonlat; This.balloonlon = Balloonlon;this.ballooncontentpath = Ballooncontentpath;this.balloonname = BalloonName;} /** * S * * @ method Name: Makebrowserballoon; * @ Method Description: Generate balloon tag layer; * @ parameter: @param windowglcanvas * @ parameter: @return * @ return type: Ren Derablelayer; * Creator: Liu Shuo; * @ creation Time: February 3, 2015 PM 5:01:03; * @throws */public renderablelayer makebrowserballoon (Worldwindowglcanvas Windowglcanvas) {// ??? Ballooncontrollerthis.hotspotcontroller = new Hotspotcontroller (windowglcanvas); this.ballooncontroller = new Ballooncontroller (Windowglcanvas); Renderablelayer layer = new Renderablelayer (); Layer.setname (Balloonname); STring htmlstring = Null;inputstream Contentstream = null;try{//Read html file contents Contentstream = Wwio.openfileorresourcestream (ballooncontentpath,null); htmlstring = wwio.readstreamtostring (Contentstream, null);} catch (Exception e) {e.printstacktrace ();} Finally{wwio.closestream (Contentstream, Ballooncontentpath);} if (htmlstring = = null) htmlstring = Logging.getmessage ("Generic. Exceptionattemptingtoreadfile ", ballooncontentpath);//Create a globebrowserballoonposition balloonposition = Position.fromdegrees (Balloonlat, Balloonlon); Abstractbrowserballoon balloon = new Globebrowserballoon (htmlstring,balloonposition);// Set the Globebrowserballoon property balloonattributes attrs = new Basicballoonattributes (); Attrs.setsize (New Size (Size.NATIVE_ DIMENSION, 0d, null,size.native_dimension, 0d, null)); Balloon.setattributes (attrs);// Associating Globebrowserballoon with Pointplacemark pointplacemark placemark = new Pointplacemark (balloonposition); Placemark.setlabeltext (balloonname);p lacemark.setvalue (Avkey.balloon, BALLOON); Layer.addreNderable (balloon); layer.addrenderable (placemark); return layer;} Public double Getballoonlat () {return balloonlat;} public void Setballoonlat (double balloonlat) {This.balloonlat = Balloonlat;} Public double Getballoonlon () {return balloonlon;} public void Setballoonlon (double balloonlon) {This.balloonlon = Balloonlon;} Public String Getballooncontentpath () {return ballooncontentpath;} public void Setballooncontentpath (String ballooncontentpath) {this.ballooncontentpath = Ballooncontentpath;} Public String Getballoonname () {return balloonname;} public void Setballoonname (String balloonname) {this.balloonname = Balloonname;}}

When calling, simply type the following code:

String Htmlpath = System.getproperty ("User.dir") + "\\src\\edu\\whu\\vge\\data\\whu.html"; Balloonsutil balloonsutil = new Balloonsutil (30.5271,114.3604, Htmlpath, "I am Here"); Wwpanel.getworldwindowglcanvas (). Getmodel (). Getlayers (). Add (Balloonsutil.makebrowserballoon (Wwpanel.getworldwindowglcanvas ()));
In addition, we enclose the code of the Whu.html Web page for your reference.


World Wind Java Development 11--Load hot spot information (imitation Google Earth)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.