use of org.activityinfo.shared.report.model.layers.MapLayer in project activityinfo by bedatadriven.
the class ReportJsonFactory method encodeLayers.
public JsonArray encodeLayers(List<MapLayer> layers) {
JsonArray jsonLayers = new JsonArray();
for (int i = 0; i < layers.size(); i++) {
MapLayer layer = layers.get(i);
JsonObject jsonLayer = new JsonObject();
if (layer instanceof BubbleMapLayer) {
jsonLayer.addProperty("layerType", layer.getTypeName());
jsonLayer.add("colorDimensions", encodeDimensionList(((BubbleMapLayer) layer).getColorDimensions()));
jsonLayer.addProperty("bubbleColor", ((BubbleMapLayer) layer).getBubbleColor());
jsonLayer.addProperty("labelColor", ((BubbleMapLayer) layer).getLabelColor());
jsonLayer.addProperty("minRadius", ((BubbleMapLayer) layer).getMinRadius());
jsonLayer.addProperty("maxRadius", ((BubbleMapLayer) layer).getMaxRadius());
jsonLayer.addProperty("alpha", ((BubbleMapLayer) layer).getAlpha());
jsonLayer.addProperty("scaling", ((BubbleMapLayer) layer).getScaling().toString());
} else if (layer instanceof PiechartMapLayer) {
jsonLayer.addProperty("layerType", layer.getTypeName());
jsonLayer.add("slices", encodeSlicesList(((PiechartMapLayer) layer).getSlices()));
jsonLayer.addProperty("minRadius", ((PiechartMapLayer) layer).getMinRadius());
jsonLayer.addProperty("maxRadius", ((PiechartMapLayer) layer).getMaxRadius());
jsonLayer.addProperty("alpha", ((PiechartMapLayer) layer).getAlpha());
jsonLayer.addProperty("scaling", ((PiechartMapLayer) layer).getScaling().toString());
} else if (layer instanceof IconMapLayer) {
jsonLayer.addProperty("layerType", layer.getTypeName());
jsonLayer.add("activityIds", encodeIntegerList(((IconMapLayer) layer).getActivityIds()));
jsonLayer.addProperty("icon", ((IconMapLayer) layer).getIcon());
}
jsonLayer.addProperty("isVisible", layer.isVisible());
jsonLayer.add("indicatorIds", encodeIntegerList(layer.getIndicatorIds()));
// jsonLayer.addProperty("labelSequence", layer.getLabelSequence()
// .next());
// jsonLayer.addProperty("cluster", (Boolean) layer.isClustered());
jsonLayer.addProperty("name", layer.getName());
jsonLayer.add("filter", encodeFilter(layer.getFilter()));
jsonLayers.add(jsonLayer);
}
return jsonLayers;
}
use of org.activityinfo.shared.report.model.layers.MapLayer in project activityinfo by bedatadriven.
the class MapEditor method createLayersOptionsPanel.
protected void createLayersOptionsPanel() {
optionsPanel = new LayerOptionsPanel(dispatcher);
optionsPanel.setVisible(false);
optionsPanel.addListener(Events.Hide, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
mapPanel.setZoomControlOffsetX(ZOOM_CONTROL_LEFT_MARGIN);
}
});
optionsPanel.addListener(Events.Show, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
mapPanel.setZoomControlOffsetX(LayerOptionsPanel.WIDTH + ZOOM_CONTROL_LEFT_MARGIN);
}
});
optionsPanel.addValueChangeHandler(new ValueChangeHandler<MapLayer>() {
@Override
public void onValueChange(ValueChangeEvent<MapLayer> event) {
reportEventBus.fireChange();
}
});
add(optionsPanel, new AbsoluteData(0, CONTROL_TOP_MARGIN));
}
use of org.activityinfo.shared.report.model.layers.MapLayer in project activityinfo by bedatadriven.
the class MapGenerator method queryIndicators.
private Map<Integer, Indicator> queryIndicators(MapReportElement element) {
// Get relevant indicators for the map markers
Set<Integer> indicatorIds = new HashSet<Integer>();
for (MapLayer maplayer : element.getLayers()) {
indicatorIds.addAll(maplayer.getIndicatorIds());
}
Map<Integer, Indicator> indicators = Maps.newHashMap();
for (Integer indicatorId : indicatorIds) {
indicators.put(indicatorId, indicatorDAO.findById(indicatorId));
}
return indicators;
}
use of org.activityinfo.shared.report.model.layers.MapLayer in project activityinfo by bedatadriven.
the class MapGenerator method generate.
@Override
public void generate(User user, MapReportElement element, Filter inheritedFilter, DateRange dateRange) {
Filter filter = GeneratorUtils.resolveElementFilter(element, dateRange);
Filter effectiveFilter = inheritedFilter == null ? filter : new Filter(inheritedFilter, filter);
MapContent content = new MapContent();
content.setFilterDescriptions(generateFilterDescriptions(filter, Collections.<DimensionType>emptySet(), user));
Map<Integer, Indicator> indicators = queryIndicators(element);
// Set up layer generators
List<LayerGenerator> layerGenerators = new ArrayList<LayerGenerator>();
for (MapLayer layer : element.getLayers()) {
if (layer.isVisible()) {
LayerGenerator layerGtor = createGenerator(layer, indicators);
layerGtor.query(getDispatcher(), effectiveFilter);
layerGenerators.add(layerGtor);
}
}
// FIRST PASS: calculate extents and margins
int width = element.getWidth();
int height = element.getHeight();
AiLatLng center;
int zoom;
Extents extents = Extents.emptyExtents();
Margins margins = new Margins(0);
for (LayerGenerator layerGtor : layerGenerators) {
extents.grow(layerGtor.calculateExtents());
margins.grow(layerGtor.calculateMargins());
}
content.setExtents(extents);
if (element.getCenter() == null) {
// Now we're ready to calculate the zoom level
// and the projection
zoom = TileMath.zoomLevelForExtents(extents, width, height);
center = extents.center();
} else {
center = element.getCenter();
zoom = element.getZoomLevel();
}
content.setCenter(center);
// Retrieve the basemap and clamp zoom level
BaseMap baseMap = findBaseMap(element, indicators.values());
if (zoom < baseMap.getMinZoom()) {
zoom = baseMap.getMinZoom();
}
if (zoom > baseMap.getMaxZoom()) {
zoom = baseMap.getMaxZoom();
}
if (zoom > element.getMaximumZoomLevel()) {
zoom = element.getMaximumZoomLevel();
}
TiledMap map = new TiledMap(width, height, center, zoom);
content.setBaseMap(baseMap);
content.setZoomLevel(zoom);
if (baseMap == null) {
baseMap = TileBaseMap.createNullMap(element.getBaseMapId());
LOGGER.log(Level.SEVERE, "Could not find base map id=" + element.getBaseMapId());
}
// Generate the actual content
for (LayerGenerator layerGtor : layerGenerators) {
layerGtor.generate(map, content);
}
content.setIndicators(toDTOs(indicators.values()));
element.setContent(content);
}
use of org.activityinfo.shared.report.model.layers.MapLayer in project activityinfo by bedatadriven.
the class ReportJsonFactory method decodeLayers.
public List<MapLayer> decodeLayers(JsonArray layers) {
Iterator<JsonElement> it = layers.iterator();
List<MapLayer> mapLayers = new ArrayList<MapLayer>();
while (it.hasNext()) {
JsonObject jsonLayer = it.next().getAsJsonObject();
if ("Bubble".equals(jsonLayer.get("type"))) {
BubbleMapLayer layer = new BubbleMapLayer();
JsonArray colorDimensions = jsonLayer.get("colorDimensions").getAsJsonArray();
if (colorDimensions.size() > 0) {
layer.setColorDimensions(decodeDimensionList(colorDimensions));
}
JsonElement bubbleColor = jsonLayer.get("bubbleColor");
if (bubbleColor != null) {
layer.setBubbleColor(bubbleColor.getAsString());
}
JsonElement labelColor = jsonLayer.get("labelColor");
if (labelColor != null) {
layer.setLabelColor(labelColor.getAsString());
}
JsonElement minRadius = jsonLayer.get("minRadius");
if (minRadius != null) {
layer.setMinRadius(minRadius.getAsInt());
}
JsonElement maxRadius = jsonLayer.get("maxRadius");
if (maxRadius != null) {
layer.setMaxRadius(maxRadius.getAsInt());
}
JsonElement alpha = jsonLayer.get("alpha");
if (alpha != null) {
layer.setAlpha(alpha.getAsDouble());
}
JsonElement scaling = jsonLayer.get("scaling");
if (scaling != null) {
layer.setScaling(ScalingType.valueOf(scaling.getAsString()));
}
layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
Iterator<JsonElement> itr = indicators.iterator();
while (itr.hasNext()) {
layer.addIndicator(itr.next().getAsInt());
}
if (jsonLayer.get("cluster").getAsBoolean()) {
layer.setClustering(new AutomaticClustering());
} else {
layer.setClustering(new NoClustering());
}
layer.setName(jsonLayer.get("name").getAsString());
layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
mapLayers.add(layer);
} else if ("Piechart".equals(jsonLayer.get("type"))) {
PiechartMapLayer layer = new PiechartMapLayer();
JsonElement minRadius = jsonLayer.get("minRadius");
if (minRadius != null) {
layer.setMinRadius(minRadius.getAsInt());
}
JsonElement maxRadius = jsonLayer.get("maxRadius");
if (maxRadius != null) {
layer.setMaxRadius(maxRadius.getAsInt());
}
JsonElement alpha = jsonLayer.get("alpha");
if (alpha != null) {
layer.setAlpha(alpha.getAsDouble());
}
JsonElement scaling = jsonLayer.get("scaling");
if (scaling != null) {
layer.setScaling(ScalingType.valueOf(scaling.getAsString()));
}
layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
Iterator<JsonElement> itr = indicators.iterator();
while (itr.hasNext()) {
layer.addIndicatorId(itr.next().getAsInt());
}
if (jsonLayer.get("cluster").getAsBoolean()) {
layer.setClustering(new AutomaticClustering());
} else {
layer.setClustering(new NoClustering());
}
layer.setName(jsonLayer.get("name").getAsString());
layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
mapLayers.add(layer);
} else if ("Bubble".equals(jsonLayer.get("type"))) {
IconMapLayer layer = new IconMapLayer();
JsonArray activityIds = jsonLayer.get("activityIds").getAsJsonArray();
Iterator<JsonElement> activityIrtator = activityIds.iterator();
while (activityIrtator.hasNext()) {
layer.addActivityId(activityIrtator.next().getAsInt());
}
JsonElement icon = jsonLayer.get("icon");
if (icon != null) {
layer.setIcon(icon.getAsString());
}
layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
Iterator<JsonElement> itr = indicators.iterator();
while (itr.hasNext()) {
layer.addIndicatorId(itr.next().getAsInt());
}
if (jsonLayer.get("cluster").getAsBoolean()) {
layer.setClustering(new AutomaticClustering());
} else {
layer.setClustering(new NoClustering());
}
layer.setName(jsonLayer.get("name").getAsString());
layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
mapLayers.add(layer);
}
}
return mapLayers;
}
Aggregations