Search in sources :

Example 1 with BaseMap

use of org.activityinfo.legacy.shared.model.BaseMap in project activityinfo by bedatadriven.

the class BaseMapDialog method loadBaseMaps.

private void loadBaseMaps() {
    listView.getStore().removeAll();
    listView.getStore().add(googleThumb(GoogleBaseMap.ROADMAP, I18N.CONSTANTS.googleRoadmap()));
    listView.getStore().add(googleThumb(GoogleBaseMap.SATELLITE, I18N.CONSTANTS.googleSatelliteMap()));
    listView.getStore().add(googleThumb(GoogleBaseMap.HYBRID, I18N.CONSTANTS.googleHybrid()));
    listView.getStore().add(googleThumb(GoogleBaseMap.TERRAIN, I18N.CONSTANTS.googleTerrainMap()));
    updateSelection();
    service.execute(new GetBaseMaps(), new MaskingAsyncMonitor(listView, I18N.CONSTANTS.loading()), new AsyncCallback<BaseMapResult>() {

        @Override
        public void onFailure(Throwable caught) {
            failLoadingBaseMaps();
        }

        @Override
        public void onSuccess(BaseMapResult result) {
            List<ModelData> thumbnails = new ArrayList<ModelData>();
            for (BaseMap baseMap : result.getBaseMaps()) {
                thumbnails.add(tileThumb(baseMap));
            }
            listView.getStore().add(thumbnails);
            updateSelection();
        }
    });
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) BaseModelData(com.extjs.gxt.ui.client.data.BaseModelData) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) BaseMapResult(org.activityinfo.legacy.shared.command.result.BaseMapResult) GetBaseMaps(org.activityinfo.legacy.shared.command.GetBaseMaps) ArrayList(java.util.ArrayList) List(java.util.List) BaseMap(org.activityinfo.legacy.shared.model.BaseMap) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) GoogleBaseMap(org.activityinfo.legacy.shared.reports.content.GoogleBaseMap)

Example 2 with BaseMap

use of org.activityinfo.legacy.shared.model.BaseMap 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);
    // Generate the actual content
    for (LayerGenerator layerGtor : layerGenerators) {
        layerGtor.generate(map, content);
    }
    content.setIndicators(toDTOs(indicators.values()));
    element.setContent(content);
}
Also used : DimensionType(org.activityinfo.legacy.shared.command.DimensionType) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) Extents(org.activityinfo.model.type.geo.Extents) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) BaseMap(org.activityinfo.legacy.shared.model.BaseMap) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) GoogleBaseMap(org.activityinfo.legacy.shared.reports.content.GoogleBaseMap) Filter(org.activityinfo.legacy.shared.command.Filter) AiLatLng(org.activityinfo.model.type.geo.AiLatLng)

Example 3 with BaseMap

use of org.activityinfo.legacy.shared.model.BaseMap in project activityinfo by bedatadriven.

the class ImageMapRenderer method drawBasemap.

protected void drawBasemap(MapReportElement element, TileHandler tileHandler) {
    TiledMap map = createTileMap(element);
    BaseMap baseMap = element.getContent().getBaseMap();
    try {
        if (baseMap instanceof TileBaseMap) {
            drawTiledBaseMap(tileHandler, map, baseMap);
        } else if (baseMap instanceof GoogleBaseMap) {
            drawTiledBaseMap(tileHandler, map, MapboxLayers.toTileBaseMap(baseMap));
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Exception drawing basemap", e);
    }
}
Also used : TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) TiledMap(org.activityinfo.server.report.generator.map.TiledMap) BaseMap(org.activityinfo.legacy.shared.model.BaseMap) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) IOException(java.io.IOException)

Example 4 with BaseMap

use of org.activityinfo.legacy.shared.model.BaseMap in project activityinfo by bedatadriven.

the class ItextReportRendererTest method googleMapsBaseMap.

@Test
public void googleMapsBaseMap() throws IOException {
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    TileBaseMap referenceBaseMap = new TileBaseMap();
    referenceBaseMap.setTileUrlPattern("http://www.activityinfo.org/resources/tile/admin.cd/{z}/{x}/{y}.png");
    referenceBaseMap.setName("Administrative Map");
    BaseMap[] baseMaps = new BaseMap[] { referenceBaseMap, GoogleBaseMap.HYBRID, GoogleBaseMap.ROADMAP, GoogleBaseMap.SATELLITE, GoogleBaseMap.TERRAIN };
    for (BaseMap baseMap : baseMaps) {
        BubbleMapMarker marker1 = new BubbleMapMarker();
        marker1.setLat(-2.45);
        marker1.setLng(28.8);
        marker1.setX(100);
        marker1.setY(100);
        marker1.setRadius(25);
        MapContent mapContent = new MapContent();
        mapContent.setFilterDescriptions(Collections.EMPTY_LIST);
        mapContent.setBaseMap(baseMap);
        mapContent.setZoomLevel(8);
        mapContent.setCenter(new Extents(-2.2, -2.1, 28.85, 28.9).center());
        mapContent.setMarkers(Arrays.asList((MapMarker) marker1));
        MapReportElement satelliteMap = new MapReportElement();
        satelliteMap.setTitle(baseMap.toString());
        satelliteMap.setContent(mapContent);
        report.addElement(satelliteMap);
    }
    // renderToPdf(report, "google map.pdf");
    // renderToHtml(report, "google map.html");
    renderToRtf(report, "google map.rtf");
}
Also used : TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) Extents(org.activityinfo.model.type.geo.Extents) BaseMap(org.activityinfo.legacy.shared.model.BaseMap) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) Test(org.junit.Test)

Example 5 with BaseMap

use of org.activityinfo.legacy.shared.model.BaseMap in project activityinfo by bedatadriven.

the class MapGenerator method findBaseMap.

private BaseMap findBaseMap(MapReportElement element, Collection<Indicator> indicators) {
    BaseMap baseMap = null;
    String baseMapId = element.getBaseMapId();
    if (element.getBaseMapId() == null || element.getBaseMapId().equals(MapReportElement.AUTO_BASEMAP)) {
        baseMapId = defaultBaseMap(indicators);
    }
    if (PredefinedBaseMaps.isPredefinedMap(baseMapId)) {
        baseMap = PredefinedBaseMaps.forId(baseMapId);
    } else {
        baseMap = getBaseMap(baseMapId);
    }
    return baseMap;
}
Also used : BaseMap(org.activityinfo.legacy.shared.model.BaseMap) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) GoogleBaseMap(org.activityinfo.legacy.shared.reports.content.GoogleBaseMap)

Aggregations

BaseMap (org.activityinfo.legacy.shared.model.BaseMap)5 TileBaseMap (org.activityinfo.legacy.shared.model.TileBaseMap)5 GoogleBaseMap (org.activityinfo.legacy.shared.reports.content.GoogleBaseMap)3 Extents (org.activityinfo.model.type.geo.Extents)2 BaseModelData (com.extjs.gxt.ui.client.data.BaseModelData)1 ModelData (com.extjs.gxt.ui.client.data.ModelData)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DimensionType (org.activityinfo.legacy.shared.command.DimensionType)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GetBaseMaps (org.activityinfo.legacy.shared.command.GetBaseMaps)1 BaseMapResult (org.activityinfo.legacy.shared.command.result.BaseMapResult)1 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)1 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 TiledMap (org.activityinfo.server.report.generator.map.TiledMap)1 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)1 Test (org.junit.Test)1