use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class WikipediaBoundingBoxLayerWorker method handleBackground.
@Override
protected List<LayerRecord> handleBackground() {
BoundingBox boundingBox = this.boundingBox;
GeometryFactory geometryFactory = this.geometryFactory;
final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
if (coordinateSystem instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projCs = (ProjectedCoordinateSystem) coordinateSystem;
geometryFactory = projCs.getGeographicCoordinateSystem().getGeometryFactory();
boundingBox = boundingBox.convert(geometryFactory);
}
final List<LayerRecord> results = (List) this.geoNamesService.getWikipediaArticles(boundingBox);
for (final Record record : results) {
final String title = record.getValue("title");
final String wikipediaUrl = record.getValue("wikipediaUrl");
final String thumbnailImage = record.getValue("thumbnailImg");
final Point point = record.getGeometry();
String text;
if (thumbnailImage != null) {
text = "<html><b>" + title + "</b><br /><img src=\"" + thumbnailImage + "\" /><br /></html>";
} else {
text = "<html><b>" + title + "</b><br /></html>";
}
// if (viewport instanceof ComponentViewport2D) {
// final ComponentViewport2D componentViewport =
// (ComponentViewport2D)viewport;
// componentViewport.addHotSpot(geometryFactory, point, text, "http://"
// + wikipediaUrl);
// }
}
return results;
}
use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class AbstractOverlay method hasSnapPoint.
protected boolean hasSnapPoint() {
this.snapPoint = null;
this.snapEventX = MouseOverlay.getEventX();
this.snapEventY = MouseOverlay.getEventY();
this.snapCentre = MouseOverlay.getEventPoint();
final double snapCentreX = this.snapCentre.getX();
final double snapCentreY = this.snapCentre.getY();
final double maxDistance = this.viewport.getHotspotMapUnits();
final BoundingBox boundingBox = this.snapCentre.getBoundingBox().expand(maxDistance);
final GeometryFactory geometryFactory = getViewportGeometryFactory2d();
final Map<Point, Set<CloseLocation>> snapLocations = new HashMap<>();
final List<AbstractRecordLayer> layers = getSnapLayers();
for (final AbstractRecordLayer layer : layers) {
final List<LayerRecord> records = layer.getRecordsBackground(boundingBox);
for (final LayerRecord record : records) {
if (layer.isVisible(record)) {
final Geometry recordGeometry = record.getGeometry();
final CloseLocation closeLocation = this.map.findCloseLocation(geometryFactory, layer, record, recordGeometry, snapCentreX, snapCentreY, maxDistance);
if (closeLocation != null) {
final Point closePoint = closeLocation.getViewportPoint();
Maps.addToSet(snapLocations, closePoint, closeLocation);
}
}
}
}
return setSnapLocations(snapLocations);
}
use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method mouseClicked.
@Override
public void mouseClicked(final MouseEvent event) {
if (modeAddGeometryClick(event)) {
} else if (SwingUtil.isLeftButtonAndNoModifiers(event) && event.getClickCount() == 2) {
final List<LayerRecord> records = new ArrayList<>();
final BoundingBox boundingBox = getHotspotBoundingBox();
final Geometry boundary = boundingBox.toPolygon().prepare();
addRecords(records, getProject(), boundary);
final int size = records.size();
if (size == 0) {
} else if (size < 10) {
for (final LayerRecord record : records) {
final AbstractRecordLayer layer = record.getLayer();
layer.showForm(record);
}
event.consume();
} else {
JOptionPane.showMessageDialog(this, "There are too many " + size + " selected to view. Maximum 10. Select fewer records or move mouse to middle of geometry.", "Too Many Selected Records", JOptionPane.ERROR_MESSAGE);
event.consume();
}
}
}
use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method splitLineKeyPress.
// K key to split a record
protected boolean splitLineKeyPress(final KeyEvent e) {
final int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_K) {
if (!isOverlayAction(ACTION_ADD_GEOMETRY) && hasMouseOverLocation()) {
for (final CloseLocation mouseLocation : getMouseOverLocations()) {
final LayerRecord record = mouseLocation.getRecord();
final AbstractRecordLayer layer = record.getLayer();
layer.splitRecord(record, mouseLocation);
}
e.consume();
return true;
}
}
return false;
}
use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class MapPanel method propertyChange.
@SuppressWarnings("unchecked")
@Override
public void propertyChange(final PropertyChangeEvent event) {
final Object source = event.getSource();
final String propertyName = event.getPropertyName();
final Object oldValue = event.getOldValue();
final Object newValue = event.getNewValue();
if (AbstractRecordLayer.RECORDS_SELECTED.equals(propertyName)) {
final List<LayerRecord> oldRecords = (List<LayerRecord>) oldValue;
this.selectedRecordsIndex.removeRecords(oldRecords);
final List<LayerRecord> newRecords = (List<LayerRecord>) newValue;
this.selectedRecordsIndex.addRecords(newRecords);
} else if (source == this.project) {
if ("viewBoundingBox".equals(propertyName)) {
final BoundingBox boundingBox = (BoundingBox) newValue;
setBoundingBox(boundingBox);
} else if ("geometryFactory".equals(propertyName)) {
final GeometryFactory oldGeometryFactory = (GeometryFactory) oldValue;
final GeometryFactory newGeometryFactory = (GeometryFactory) newValue;
setGeometryFactory(oldGeometryFactory, newGeometryFactory);
}
} else if (source == this.viewport) {
if ("geometryFactory".equals(propertyName)) {
final GeometryFactory oldGeometryFactory = (GeometryFactory) oldValue;
final GeometryFactory newGeometryFactory = (GeometryFactory) newValue;
setGeometryFactory(oldGeometryFactory, newGeometryFactory);
} else if ("boundingBox".equals(propertyName)) {
final BoundingBox boundingBox = this.viewport.getBoundingBox();
setBoundingBox(boundingBox);
} else if ("unitsPerPixel".equals(propertyName)) {
repaint();
}
} else if (source == this.baseMapOverlay) {
if ("layer".equals(propertyName)) {
final Layer layer = (Layer) newValue;
if (this.baseMapLayerField != null) {
if (layer == null) {
this.baseMapLayerField.setSelectedItem(0);
} else {
this.baseMapLayerField.setSelectedItem(layer);
}
}
}
} else if (source == this.baseMapLayers) {
if ("layers".equals(propertyName)) {
if (this.baseMapOverlay != null) {
final Layer selectedLayer = this.baseMapOverlay.getLayer();
final Layer newLayer = (Layer) newValue;
if (selectedLayer != newLayer) {
if (selectedLayer != null) {
final LayerGroup selectedLayerParent = selectedLayer.getLayerGroup();
if (selectedLayer.isDeleted() || selectedLayerParent != null && selectedLayerParent != this.baseMapLayers) {
this.baseMapOverlay.setLayer(null);
}
}
if (newLayer != null && newLayer.isVisible()) {
this.baseMapOverlay.setLayer(newLayer);
this.baseMapLayerField.setSelectedItem(newLayer);
if (selectedLayer != null) {
selectedLayer.setVisible(false);
}
}
}
}
}
} else if (source instanceof Layer) {
final Layer layer = (Layer) source;
if (layer.getParent() == this.baseMapLayers) {
if ("visible".equals(propertyName)) {
final boolean visible = layer.isVisible();
if (visible) {
this.baseMapLayerField.setSelectedItem(layer);
} else if (!this.baseMapLayers.isHasVisibleLayer()) {
this.baseMapLayerField.setSelectedIndex(0);
}
}
}
} else if (source instanceof LayerRecord) {
final LayerRecord record = (LayerRecord) source;
if (propertyName.equals(record.getGeometryFieldName())) {
if (record.isSelected()) {
final Geometry oldGeometry = (Geometry) oldValue;
if (oldGeometry == null) {
final BoundingBox boundingBox = record.getGeometry().getBoundingBox();
this.selectedRecordsIndex.removeItem(boundingBox, record);
} else {
final BoundingBox boundingBox = oldGeometry.getBoundingBox();
this.selectedRecordsIndex.removeItem(boundingBox, record);
}
this.selectedRecordsIndex.addRecord(record);
}
}
}
repaint();
}
Aggregations