📄 draggingshapes.java
字号:
shape = new SurfaceSquare(LatLon.fromDegrees(45, -104), 1e5); this.setupFilledShape(shape, layer, Color.MAGENTA); // Create a circle over the States. shape = new SurfaceCircle(LatLon.fromDegrees(36, -104), 1e5); this.setupFilledShape(shape, layer, Color.GREEN); // Create a big polygon over Florida. double originLat = 28; double originLon = -82; ArrayList<LatLon> positions = new ArrayList<LatLon>(); positions.add(new LatLon(Angle.fromDegrees(originLat + 5.0), Angle.fromDegrees(originLon + 2.5))); positions.add(new LatLon(Angle.fromDegrees(originLat + 5.0), Angle.fromDegrees(originLon - 2.5))); positions.add(new LatLon(Angle.fromDegrees(originLat + 2.5), Angle.fromDegrees(originLon - 5.0))); positions.add(new LatLon(Angle.fromDegrees(originLat - 2.5), Angle.fromDegrees(originLon - 5.0))); positions.add(new LatLon(Angle.fromDegrees(originLat - 5.0), Angle.fromDegrees(originLon - 2.5))); positions.add(new LatLon(Angle.fromDegrees(originLat - 5.0), Angle.fromDegrees(originLon + 2.5))); positions.add(new LatLon(Angle.fromDegrees(originLat - 2.5), Angle.fromDegrees(originLon + 5.0))); positions.add(new LatLon(Angle.fromDegrees(originLat + 2.5), Angle.fromDegrees(originLon + 5.0))); positions.add(new LatLon(Angle.fromDegrees(originLat + 5.0), Angle.fromDegrees(originLon + 2.5))); shape = new SurfacePolygon(positions); this.setupFilledShape(shape, layer, Color.BLUE); // Test +180/-180 lon span Polyline positions = new ArrayList<LatLon>(); positions.add(new LatLon(Angle.fromDegrees(-10), Angle.fromDegrees(170))); positions.add(new LatLon(Angle.fromDegrees(-10), Angle.fromDegrees(-170))); shape = new SurfacePolyline(positions); this.setupLine(shape, layer, Color.RED); // Test +180/-180 lon span Polygon positions = new ArrayList<LatLon>(); positions.add(new LatLon(Angle.fromDegrees(20), Angle.fromDegrees(-170))); positions.add(new LatLon(Angle.fromDegrees(15), Angle.fromDegrees(170))); positions.add(new LatLon(Angle.fromDegrees(10), Angle.fromDegrees(-175))); positions.add(new LatLon(Angle.fromDegrees(5), Angle.fromDegrees(170))); positions.add(new LatLon(Angle.fromDegrees(0), Angle.fromDegrees(-170))); positions.add(new LatLon(Angle.fromDegrees(20), Angle.fromDegrees(-170))); shape = new SurfacePolygon(positions); this.setupFilledShape(shape, layer, Color.RED); // Polylines around San Juan County, WA Iterable<? extends LatLon> iterable = makeLatLon(SAN_JUAN_COUNTY_1); shape = new SurfacePolyline(iterable); this.setupLine(shape, layer, Color.YELLOW); iterable = makeLatLon(SAN_JUAN_COUNTY_2); shape = new SurfacePolyline(iterable); this.setupLine(shape, layer, Color.YELLOW); iterable = makeLatLon(SAN_JUAN_COUNTY_3); shape = new SurfacePolyline(iterable); this.setupLine(shape, layer, Color.YELLOW); // Polyline around Snohomish County, WA iterable = makeLatLon(SNOHOMISH_COUNTY); shape = new SurfacePolyline(iterable); this.setupLine(shape, layer, Color.YELLOW); return layer; } protected void setupFilledShape(AbstractSurfaceShape shape, SurfaceShapeLayer layer, Color color) { ShapeAttributes attributes = new BasicShapeAttributes(); attributes.setDrawInterior(true); attributes.setDrawOutline(true); attributes.setInteriorMaterial(new Material(color)); attributes.setOutlineMaterial(new Material(this.makeBrighter(color))); attributes.setInteriorOpacity(0.5); attributes.setOutlineOpacity(0.8); attributes.setOutlineWidth(3); shape.setAttributes(attributes); layer.addRenderable(shape); } protected void setupLine(AbstractSurfaceShape shape, SurfaceShapeLayer layer, Color color) { ShapeAttributes attributes = new BasicShapeAttributes(); attributes.setDrawInterior(false); attributes.setDrawOutline(true); attributes.setOutlineMaterial(new Material(color)); attributes.setOutlineOpacity(1); attributes.setOutlineWidth(3); shape.setAttributes(attributes); layer.addRenderable(shape); } private Color makeBrighter(Color color) { float[] hsbComponents = new float[3]; Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsbComponents); float hue = hsbComponents[0]; float saturation = hsbComponents[1]; float brightness = hsbComponents[2]; saturation /= 3f; brightness *= 3f; if (saturation < 0f) saturation = 0f; if (brightness > 1f) brightness = 1f; int rgbInt = Color.HSBtoRGB(hue, saturation, brightness); return new Color(rgbInt); } } private static Iterable<? extends LatLon> makeLatLon(double[] src, int offset, int length) { int numCoords = (int) Math.floor(length / 2.0); LatLon[] dest = new LatLon[numCoords]; for (int i = 0; i < numCoords; i++) { double lonDegrees = src[offset + 2 * i]; double latDegrees = src[offset + 2 * i + 1]; dest[i] = LatLon.fromDegrees(latDegrees, lonDegrees); } return Arrays.asList(dest); } private static Iterable<? extends LatLon> makeLatLon(double[] src) { return makeLatLon(src, 0, src.length); } // Boundary data for San Juan and Snohomish Counties take from // http://www.census.gov/geo/cob/bdy/co/co00ascii/co53_d00_ascii.zip private static final double[] SAN_JUAN_COUNTY_1 = { //-0.123026351250109E+03, 0.487022510493827E+02, -0.123025486000000E+03, 0.487179660000000E+02, -0.123019699000000E+03, 0.487213120000000E+02, -0.123009787000000E+03, 0.487222910000000E+02, -0.123007511000000E+03, 0.487188630000000E+02, -0.123005086000000E+03, 0.486943420000000E+02, -0.123014449000000E+03, 0.486849780000000E+02, -0.123021215000000E+03, 0.486814160000000E+02, -0.123042337000000E+03, 0.486756630000000E+02, -0.123041645000000E+03, 0.486786330000000E+02, -0.123035672000000E+03, 0.486853500000000E+02, -0.123036360000000E+03, 0.486900800000000E+02, -0.123047058000000E+03, 0.486957720000000E+02, -0.123070427000000E+03, 0.486999710000000E+02, -0.123040179000000E+03, 0.487172960000000E+02, -0.123025486000000E+03, 0.487179660000000E+02, }; private static final double[] SAN_JUAN_COUNTY_2 = { //-0.122948050323932E+03, 0.485739411234568E+02, -0.122906298643435E+03, 0.487142756789313E+02, -0.122894599000000E+03, 0.487150300000000E+02, -0.122883606017278E+03, 0.487133157521183E+02, -0.122879724954535E+03, 0.487127105384329E+02, -0.122875938000000E+03, 0.487121200000000E+02, -0.122836802504198E+03, 0.486993713019117E+02, -0.122834290842953E+03, 0.486985531083446E+02, -0.122833124000000E+03, 0.486981730000000E+02, -0.122831410808922E+03, 0.486973051154063E+02, -0.122825683629670E+03, 0.486944037865925E+02, -0.122808804479515E+03, 0.486858529865323E+02, -0.122805788100163E+03, 0.486843249204562E+02, -0.122802545000000E+03, 0.486826820000000E+02, -0.122800267000000E+03, 0.486796200000000E+02, -0.122761393485795E+03, 0.486676429790988E+02, -0.122744791626046E+03, 0.486625279071718E+02, -0.122743049000000E+03, 0.486619910000000E+02, -0.122742776245752E+03, 0.486616237548803E+02, -0.122742082000000E+03, 0.486606890000000E+02, -0.122755031000000E+03, 0.486495120000000E+02, -0.122762709974974E+03, 0.486457601003223E+02, -0.122774165127982E+03, 0.486401631834124E+02, -0.122783875000000E+03, 0.486354190000000E+02, -0.122792147000000E+03, 0.486335020000000E+02, -0.122806316669653E+03, 0.486217713784910E+02, -0.122807583040252E+03, 0.486207229903106E+02, -0.122809622000000E+03, 0.486190350000000E+02, -0.122809583303260E+03, 0.486188448346238E+02, -0.122808864000000E+03, 0.486153100000000E+02, -0.122799010000000E+03, 0.486046830000000E+02, -0.122798770000000E+03, 0.486023520000000E+02, -0.122800217000000E+03, 0.486016900000000E+02, -0.122801521572817E+03, 0.486000752686420E+02, -0.122804869000000E+03, 0.485959320000000E+02, -0.122804736685678E+03, 0.485955635328447E+02, -0.122802617338743E+03, 0.485896616038081E+02, -0.122801096000000E+03, 0.485854250000000E+02, -0.122796913105296E+03, 0.485828999845133E+02, -0.122787753320193E+03, 0.485773706559316E+02, -0.122786586000000E+03, 0.485766660000000E+02, -0.122771206000000E+03, 0.485624260000000E+02, -0.122770349000000E+03, 0.485581060000000E+02, -0.122772384000000E+03, 0.485521430000000E+02, -0.122782618000000E+03, 0.485451910000000E+02, -0.122788503000000E+03, 0.485303930000000E+02, -0.122787596684858E+03, 0.485246062248558E+02, -0.122787347000000E+03, 0.485230120000000E+02, -0.122777467000000E+03, 0.485177990000000E+02, -0.122779073275586E+03, 0.485091830812273E+02, -0.122779124000000E+03, 0.485089110000000E+02, -0.122799155517055E+03, 0.484953208059023E+02, -0.122799759583816E+03, 0.484949109824973E+02, -0.122800414000000E+03, 0.484944670000000E+02, -0.122809344417182E+03, 0.484907496395120E+02, -0.122816332000000E+03, 0.484878410000000E+02, -0.122816392492828E+03, 0.484876896530700E+02, -0.122817912000000E+03, 0.484838880000000E+02, -0.122818113811431E+03, 0.484811078199731E+02, -0.122818435504082E+03, 0.484766761409594E+02, -0.122818482000648E+03, 0.484760355983364E+02, -0.122819730000000E+03, 0.484588430000000E+02, -0.122813100000000E+03, 0.484528560000000E+02, -0.122810699656295E+03, 0.484489394154454E+02, -0.122807708000000E+03, 0.484440580000000E+02, -0.122806716195520E+03, 0.484419671792455E+02, -0.122802509000000E+03, 0.484330980000000E+02, -0.122803004619265E+03, 0.484309676207466E+02, -0.122803326834080E+03, 0.484295826064757E+02, -0.122803521000000E+03, 0.484287480000000E+02, -0.122806510124273E+03, 0.484265382433425E+02, -0.122812173045928E+03, 0.484223518403418E+02, -0.122812208000000E+03, 0.484223260000000E+02, -0.122825307995692E+03, 0.484240652785748E+02, -0.122825803000000E+03, 0.484241310000000E+02, -0.122852542484940E+03, 0.484208474850799E+02, -0.122863360429977E+03, 0.484195190793902E+02, -0.122866475017092E+03, 0.484191366190217E+02, -0.122866865338919E+03, 0.484190886888710E+02, -0.122867939205531E+03, 0.484189568218194E+02, -0.122867996814560E+03, 0.484189497476327E+02, -0.122874135000000E+03, 0.484181960000000E+02, -0.122874527604161E+03, 0.484182203541858E+02, -0.122883759000000E+03, 0.484187930000000E+02, -0.122888474856222E+03, 0.484206350791676E+02, -0.122893646000000E+03, 0.484226550000000E+02, -0.122889016000000E+03, 0.484359470000000E+02, -0.122903214000000E+03, 0.484369790000000E+02, -0.122913888000000E+03, 0.484432310000000E+02, -0.122917771000000E+03, 0.484397810000000E+02, -0.122927683717092E+03, 0.484399602096806E+02, -0.122928004000000E+03, 0.484399660000000E+02, -0.122927964788402E+03, 0.484400111660268E+02, -0.122916460000000E+03, 0.484532630000000E+02, -0.122920099000000E+03, 0.484584280000000E+02, -0.122926901000000E+03, 0.484608740000000E+02, -0.122937881000000E+03, 0.484562210000000E+02, -0.122950555015899E+03, 0.484535630706048E+02, -0.122962009000000E+03, 0.484511610000000E+02, -0.123001288000000E+03, 0.484556628590224E+02, -0.123026267878952E+03, 0.484585258619868E+02, -0.123029013724265E+03, 0.484588405698076E+02, -0.123033178635901E+03, 0.484593179201736E+02, -0.123038888830654E+03, 0.484599723790898E+02, -0.123039156000000E+03, 0.484600030000000E+02, -0.123058154000000E+03, 0.484715220000000E+02,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -