1e3a5f4d

Визуализация новой карты - 4


Листинг 2 показывает соответствующий сегмент кода для обработки ID-действия.

Код листинга 2: Обработка ID-действия

else if("id".equals(action)) { String[] columns = new String[]{"NAME Nearest_Office", "City", "State", "a.location.sdo_point.x X", "a.location.sdo_point.y Y", "Headcount"};

//find out the office nearest to where user clicked on the map officeInfo = mv.identify(dataSrc, "field_offices a", //the table name columns, // columns in SELECT clause "location", // geometry column name srid, // spatial reference system id mapClickX, mapClickY //mouse click position ); Point2D officeLoc = null; if(officeInfo!=null) { // identify() returns a String[][] of row, column values // row 0 is the column name list, row 1 on are values // columns are named in the "columns" parameter // so here column 0 is Name, 1 is City, 2 is State, // 3 is X, and 4 is Y String x = officeInfo[1][3]; String y = officeInfo[1][4]; officeLoc = new Point2D.Double(Double.parseDouble(x), Double.parseDouble(y)); }

// mark user click on the map with a PIN marker Point2D p2 = mv.getUserPoint(mapClickX, mapClickY); mv.addPointFeature(p2.getX(), p2.getY(), srid, "M.CYAN PIN", //a PIN marker style null, null, null);

//add a leader line from user click to nearest office if(officeLoc!=null) mv.addLinearFeature(new double[]{p2.getX(), p2.getY(), officeLoc.getX(), officeLoc.getY()}, srid, "NEAREST_LINE_STY", null, null, false);

/* For identify: use previously generated map as backdrop and avoid rerendering all base themes. */ if(mv.getBackgroundImageURL()==null) mv.setBackgroundImageURL(mv.getGeneratedMapImageURL()); String[] enabledThemes = mv.getEnabledThemes(); mv.setAllThemesEnabled(false); //temporarily disable themes

mv.run(); // reissue map request to draw a PIN marker // reenable all themes mv.enableThemes(enabledThemes);

mv.removeAllPointFeatures(); // clean up PIN marker mv.removeAllLinearFeatures(); // clean up leader line as well } // end id action




Начало  Назад  Вперед