use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class IconLayerGenerator method generate.
@Override
public void generate(TiledMap map, MapContent content) {
List<PointValue> points = new ArrayList<PointValue>();
IconRectCalculator rectCalculator = new IconRectCalculator(icon);
IntersectionCalculator intersectionCalculator = new IntersectionCalculator() {
@Override
public boolean intersects(Node a, Node b) {
return a.getPointValue().getIconRect().intersects(b.getPointValue().getIconRect());
}
};
Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), rectCalculator, intersectionCalculator);
for (SiteDTO site : sites) {
if (meetsCriteria(site)) {
AiLatLng geoPoint = getPoint(site);
if (geoPoint != null || clusterer.isMapped(site)) {
Point point = null;
if (geoPoint != null) {
point = map.fromLatLngToPixel(geoPoint);
}
points.add(new PointValue(site, point, point == null ? null : rectCalculator.iconRect(point), getValue(site, layer.getIndicatorIds())));
} else {
content.getUnmappedSites().add(site.getId());
}
}
}
List<Cluster> clusters = clusterer.cluster(map, points);
createMarkersFrom(clusters, map, content);
IconLayerLegend legend = new IconLayerLegend();
legend.setDefinition(layer);
content.addLegend(legend);
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class GeoDigestRenderer method renderSites.
private void renderSites(StringBuilder html, DatabaseModel databaseModel, Collection<Integer> siteIds) {
if (!siteIds.isEmpty()) {
for (Integer siteId : siteIds) {
SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
SiteDTO siteDTO = siteResult.getData().get(0);
ActivityDTO activityDTO = databaseModel.getModel().getSchemaDTO().getActivityById(siteDTO.getActivityId());
// Check to see if this activity is visible to the user...
if (activityDTO != null) {
List<SiteHistory> histories = findSiteHistory(siteId, databaseModel.getModel().getUserDigest().getFrom());
for (SiteHistory history : histories) {
html.append("<span class='geo-site' style='margin-left:10px;'>• ");
html.append(I18N.MESSAGES.geoDigestSiteMsg(history.getUser().getEmail(), history.getUser().getName(), activityDTO.getName(), siteDTO.getLocationName()));
Date targetDate = databaseModel.getModel().getUserDigest().getDate();
Date creationDate = new Date(history.getTimeCreated());
if (DateCalc.isOnToday(targetDate, creationDate)) {
html.append(I18N.MESSAGES.geoDigestSiteMsgDateToday(creationDate));
} else if (DateCalc.isOnYesterday(targetDate, creationDate)) {
html.append(I18N.MESSAGES.geoDigestSiteMsgDateYesterday(creationDate));
} else {
html.append(I18N.MESSAGES.geoDigestSiteMsgDateOther(creationDate));
}
html.append("</span><br>");
}
}
}
}
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class KmlDataServlet method writeDocument.
protected void writeDocument(PrintWriter out, int activityId) throws SAXException, TransformerConfigurationException {
XmlBuilder xml = new XmlBuilder(new StreamResult(out));
List<SiteDTO> sites = querySites(activityId);
xml.startDocument();
KMLNamespace kml = new KMLNamespace(xml);
kml.startKml();
ActivityFormDTO activity = dispatcher.execute(new GetActivityForm(activityId));
kml.startDocument();
kml.startStyle().at("id", "noDirectionsStyle");
kml.startBalloonStyle();
kml.text("$[description]");
xml.close();
xml.close();
for (SiteDTO pm : sites) {
if (pm.hasLatLong()) {
kml.startPlaceMark();
kml.styleUrl("#noDirectionsStyle");
kml.name(pm.getLocationName());
kml.startSnippet();
xml.cdata(renderSnippet(activity, pm));
// Snippet
xml.close();
kml.startDescription();
xml.cdata(renderDescription(activity, pm));
// Description
xml.close();
kml.startTimeSpan();
if (pm.getDate1() != null) {
kml.begin(pm.getDate1().atMidnightInMyTimezone());
kml.end(pm.getDate2().atMidnightInMyTimezone());
// Timespan
xml.close();
}
kml.startPoint();
kml.coordinates(pm.getLongitude(), pm.getLatitude());
// Point
xml.close();
// Placemark
xml.close();
}
}
// Document
xml.close();
// kml
xml.close();
xml.endDocument();
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class PieMapMarkerTest method testPies.
@Test
public void testPies() {
Dimension dimension = new Dimension(DimensionType.Indicator);
dimension.setCategoryColor(101, 255);
dimension.setCategoryColor(102, 0x00FF00);
dimension.setCategoryColor(103, 0x0000FF);
SiteDTO site1 = new SiteDTO();
site1.setId(1);
site1.setX(0d);
site1.setY(0d);
site1.setIndicatorValue(101, 50d);
site1.setIndicatorValue(102, 40d);
site1.setIndicatorValue(103, 10d);
List<SiteDTO> sites = new ArrayList<SiteDTO>();
sites.add(site1);
PiechartMapLayer layer = new PiechartMapLayer();
layer.addIndicatorId(101);
layer.addIndicatorId(102);
layer.addIndicatorId(103);
// layer.getColorDimensions().add(dimension);
MapReportElement mapElement = new MapReportElement();
mapElement.addLayer(layer);
MapContent content = new MapContent();
TiledMap map = new TiledMap(640, 480, new AiLatLng(0, 0), 6);
Map<Integer, Indicator> indicators = Maps.newHashMap();
indicators.put(101, new Indicator());
indicators.put(102, new Indicator());
indicators.put(103, new Indicator());
PiechartLayerGenerator generator = new PiechartLayerGenerator(layer, indicators);
generator.setSites(sites);
generator.generate(map, content);
Assert.assertEquals(1, content.getMarkers().size());
PieMapMarker marker = (PieMapMarker) content.getMarkers().get(0);
Assert.assertEquals(3, marker.getSlices().size());
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class UpdateSiteTest method testUpdatePreservesAdminMemberships.
@Test
public void testUpdatePreservesAdminMemberships() throws CommandException {
Map<String, Object> changes = Maps.newHashMap();
changes.put("comments", "new comments");
execute(new UpdateSite(1, changes));
// retrieve the old one
SiteResult result = execute(GetSites.byId(1));
SiteDTO secondRead = result.getData().get(0);
assertThat(secondRead.getAdminEntity(1).getId(), equalTo(2));
assertThat(secondRead.getAdminEntity(2).getId(), equalTo(12));
}
Aggregations