← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1957: (GIS) Implemented blueprint: Ability to select imported organisation units by level.

 

------------------------------------------------------------
revno: 1957
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-10-29 13:24:12 +0200
message:
  (GIS) Implemented blueprint: Ability to select imported organisation units by level.
removed:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByParentOrganisationUnitAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByParentOrganisationUnitAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitsWithCoordinatesAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/pointShapefile.vm
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/polygonShapefile.vm
added:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByLevelAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByParentAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonByLevelAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonByParentAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFromFileAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByLevelAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByParentAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonPoint.vm
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonPolygon.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
  dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
  dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml
  dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java
  dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingStoreTest.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AddOrUpdateMapViewAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetAllMapViewsAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapViewAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapView.vm
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapViews.vm
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonminAggregatedMapValues.vm
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/config.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2010-10-13 13:00:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2010-10-29 11:24:12 +0000
@@ -66,10 +66,12 @@
 
     private String mapSourceType;
 
+    private String organisationUnitSelectionType;
+
     private String mapSource;
-    
-    private transient String parentOrganisationUnitName;
-    
+
+    private transient String organisationUnitSelectionTypeName;
+
     private String mapLegendType;
 
     private int method;
@@ -96,9 +98,9 @@
 
     public MapView( String name, String mapValueType, IndicatorGroup indicatorGroup, Indicator indicator,
         DataElementGroup dataElementGroup, DataElement dataElement, String mapDateType, PeriodType periodType,
-        Period period, String startDate, String endDate, String mapSourceType, String mapSource, String mapLegendType,
-        int method, int classes, String bounds, String colorLow, String colorHigh, MapLegendSet mapLegendSet,
-        String longitude, String latitude, int zoom )
+        Period period, String startDate, String endDate, String mapSourceType, String organisationUnitSelectionType,
+        String mapSource, String mapLegendType, int method, int classes, String bounds, String colorLow,
+        String colorHigh, MapLegendSet mapLegendSet, String longitude, String latitude, int zoom )
     {
         this.name = name;
         this.mapValueType = mapValueType;
@@ -112,6 +114,7 @@
         this.startDate = startDate;
         this.endDate = endDate;
         this.mapSourceType = mapSourceType;
+        this.organisationUnitSelectionType = organisationUnitSelectionType;
         this.mapSource = mapSource;
         this.mapLegendType = mapLegendType;
         this.method = method;
@@ -301,6 +304,16 @@
         this.mapSourceType = mapSourceType;
     }
 
+    public String getOrganisationUnitSelectionType()
+    {
+        return organisationUnitSelectionType;
+    }
+
+    public void setOrganisationUnitSelectionType( String organisationUnitSelectionType )
+    {
+        this.organisationUnitSelectionType = organisationUnitSelectionType;
+    }
+
     public String getMapSource()
     {
         return mapSource;
@@ -311,14 +324,14 @@
         this.mapSource = mapSource;
     }
 
-    public String getParentOrganisationUnitName()
+    public String getOrganisationUnitSelectionTypeName()
     {
-        return parentOrganisationUnitName;
+        return organisationUnitSelectionTypeName;
     }
 
-    public void setParentOrganisationUnitName( String parentOrganisationUnitName )
+    public void setOrganisationUnitSelectionTypeName( String organisationUnitSelectionTypeName )
     {
-        this.parentOrganisationUnitName = parentOrganisationUnitName;
+        this.organisationUnitSelectionTypeName = organisationUnitSelectionTypeName;
     }
 
     public String getMapLegendType()

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2010-10-19 20:24:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2010-10-29 11:24:12 +0000
@@ -60,35 +60,53 @@
     final String MAPLEGENDSET_TYPE_AUTOMATIC = "automatic";
 
     final String MAPLEGENDSET_TYPE_PREDEFINED = "predefined";
-    
+
     final String KEY_MAP_DATE_TYPE = "dateType";
 
     final String MAP_DATE_TYPE_FIXED = "fixed";
 
     final String MAP_DATE_TYPE_START_END = "start-end";
     
+    final String ORGANISATION_UNIT_SELECTION_TYPE_PARENT = "parent";
+    
+    final String ORGANISATION_UNIT_SELECTION_TYPE_LEVEL = "level";
+
     // -------------------------------------------------------------------------
     // DataMapValue
     // -------------------------------------------------------------------------
 
     Collection<AggregatedMapValue> getAggregatedDataMapValues( int dataElementId, int periodId, String mapLayerPath );
 
-    Collection<AggregatedMapValue> getDataElementMapValues( int dataElementId, Date startDate, Date endDate, int parentOrganisationUnitId );
-    
-    Collection<AggregatedMapValue> getDataElementMapValues( int dataElementId, int periodId, int parentOrganisationUnitId );
-    
+    Collection<AggregatedMapValue> getDataElementMapValues( int dataElementId, int periodId,
+        int parentOrganisationUnitId );
+
+    Collection<AggregatedMapValue> getDataElementMapValues( int dataElementId, Date startDate, Date endDate,
+        int parentOrganisationUnitId );
+
+    Collection<AggregatedMapValue> getDataElementMapValuesByLevel( int dataElementId, int periodId, int level );
+
+    Collection<AggregatedMapValue> getDataElementMapValuesByLevel( int dataElementId, Date startDate, Date endDate,
+        int level );
+
     // -------------------------------------------------------------------------
     // IndicatorMapValue
     // -------------------------------------------------------------------------
 
-    Collection<AggregatedMapValue> getAggregatedIndicatorMapValues( int indicatorId, Collection<Integer> periodIds, String mapLayerPath, String featureId );
+    Collection<AggregatedMapValue> getAggregatedIndicatorMapValues( int indicatorId, Collection<Integer> periodIds,
+        String mapLayerPath, String featureId );
 
-    Collection<AggregatedMapValue> getIndicatorMapValues( int indicatorId, Date startDate, Date endDate, int parentOrganisationUnitId );
-    
     Collection<AggregatedMapValue> getAggregatedIndicatorMapValues( int indicatorId, int periodId, String mapLayerPath );
 
     Collection<AggregatedMapValue> getIndicatorMapValues( int indicatorId, int periodId, int parentOrganisationUnitId );
 
+    Collection<AggregatedMapValue> getIndicatorMapValues( int indicatorId, Date startDate, Date endDate,
+        int parentOrganisationUnitId );
+
+    Collection<AggregatedMapValue> getIndicatorMapValuesByLevel( int dataElementId, int periodId, int level );
+
+    Collection<AggregatedMapValue> getIndicatorMapValuesByLevel( int dataElementId, Date startDate, Date endDate,
+        int level );
+
     // -------------------------------------------------------------------------
     // Map
     // -------------------------------------------------------------------------
@@ -96,7 +114,7 @@
     /**
      * Adds a Map.
      * 
-     * @param map, the Map to add.
+     * @param map , the Map to add.
      * @return a generated unique id of the added Map.
      */
     int addMap( Map map );
@@ -104,11 +122,11 @@
     /**
      * Adds a Map.
      * 
-     * @param name, Map description.
-     * @param mapLayerPath, the link to Geoserver.
-     * @param organisationUnitLevelId, the level of the organisation units into
+     * @param name , Map description.
+     * @param mapLayerPath , the link to Geoserver.
+     * @param organisationUnitLevelId , the level of the organisation units into
      *        which the map is devided.
-     * @param nameColumn, the shapefile column which holds the name of the
+     * @param nameColumn , the shapefile column which holds the name of the
      *        organisation unit.
      * @return a generated unique id of the added Map.
      */
@@ -118,11 +136,11 @@
      * Adds a map. If a map with the same mapLayerPath already exists, the map
      * will be updated.
      * 
-     * @param name, Map description.
-     * @param mapLayerPath, the link to Geoserver or GeoJSON file.
-     * @param organisationUnitLevelId, the level of the organisation units into
+     * @param name , Map description.
+     * @param mapLayerPath , the link to Geoserver or GeoJSON file.
+     * @param organisationUnitLevelId , the level of the organisation units into
      *        which the map is devided.
-     * @param nameColumn, the shapefile column which holds the name of the
+     * @param nameColumn , the shapefile column which holds the name of the
      *        organisation unit.
      */
     void addOrUpdateMap( String name, String mapLayerPath, int organisationUnitLevelId, String nameColumn );
@@ -130,21 +148,21 @@
     /**
      * Updates a Map.
      * 
-     * @param map, the Map to update.
+     * @param map , the Map to update.
      */
     void updateMap( Map map );
 
     /**
      * Deletes a Map.
      * 
-     * @param map, the Map to delete.
+     * @param map , the Map to delete.
      */
     void deleteMap( Map map );
 
     /**
      * Returns the Map with the given id.
      * 
-     * @param id, the id of the map.
+     * @param id , the id of the map.
      * @return the Map with the given id.
      */
     Map getMap( int id );
@@ -152,7 +170,7 @@
     /**
      * Returns the Map with the given map layer path.
      * 
-     * @param id, the id of the map.
+     * @param id , the id of the map.
      * @return a Map.
      */
     Map getMapByMapLayerPath( String mapLayerPath );
@@ -160,7 +178,7 @@
     /**
      * Returns a Collection<Map> of maps with the right type.
      * 
-     * @param type, the map type.
+     * @param type , the map type.
      * @return a Collection<Map>.
      */
     Collection<Map> getMapsByType( String type );
@@ -175,7 +193,7 @@
     /**
      * Returns a Collection of all Maps at the given level.
      * 
-     * @param organisationUnitLevel, the organisation unit level to return maps
+     * @param organisationUnitLevel , the organisation unit level to return maps
      *        at.
      * @return a Collection with all Maps at the given level.
      */
@@ -209,7 +227,7 @@
     /**
      * Adds a MapOrganisationUnitRelation.
      * 
-     * @param mapOrganisationUnitRelation, the MapOrganisationUnitRelation to
+     * @param mapOrganisationUnitRelation , the MapOrganisationUnitRelation to
      *        add.
      * @return a generated unique id of the added MapOrganisationUnitRelation.
      */
@@ -218,10 +236,10 @@
     /**
      * Adds a MapOrganisationUnitRelation.
      * 
-     * @param mapLayerPath, the map the MapOrganisationUnitRelation should be
+     * @param mapLayerPath , the map the MapOrganisationUnitRelation should be
      *        added to.
-     * @param organisationUnitId, an organisation unit in the database.
-     * @param featureId, the id of an organisation unit in the shapefile.
+     * @param organisationUnitId , an organisation unit in the database.
+     * @param featureId , the id of an organisation unit in the shapefile.
      * @return a generated unique id of the added MapOrganisationUnitRelation.
      */
     int addMapOrganisationUnitRelation( String mapLayerPath, int organisationUnitId, String featureId );
@@ -232,10 +250,10 @@
      * Adds a MapOrganisationUnitRelation. If it already exists, it will be
      * updated.
      * 
-     * @param mapLayerPath, the map the MapOrganisationUnitRelation should be
+     * @param mapLayerPath , the map the MapOrganisationUnitRelation should be
      *        added to.
-     * @param organisationUnitId, an organisation unit in the database.
-     * @param featureId, the id of an organisation unit in the shapefile.
+     * @param organisationUnitId , an organisation unit in the database.
+     * @param featureId , the id of an organisation unit in the shapefile.
      * @return a generated unique id of the added MapOrganisationUnitRelation.
      */
     void addOrUpdateMapOrganisationUnitRelation( String mapLayerPath, int organisationUnitId, String featureId );
@@ -243,7 +261,7 @@
     /**
      * Updates a MapOrganisationUnitRelation.
      * 
-     * @param mapOrganisationUnitRelation, the MapOrganisationUnitRelation to
+     * @param mapOrganisationUnitRelation , the MapOrganisationUnitRelation to
      *        update.
      */
     void updateMapOrganisationUnitRelation( MapOrganisationUnitRelation mapOrganisationUnitRelation );
@@ -251,7 +269,7 @@
     /**
      * Deletes a MapOrganisationUnitRelation.
      * 
-     * @param mapOrganisationUnitRelation, the MapOrganisationUnitRelation to
+     * @param mapOrganisationUnitRelation , the MapOrganisationUnitRelation to
      *        delete.
      */
     void deleteMapOrganisationUnitRelation( MapOrganisationUnitRelation mapOrganisationUnitRelation );
@@ -259,7 +277,7 @@
     /**
      * Returns a MapOrganisationUnitRelation.
      * 
-     * @param id, the id of the returned MapOrganisationUnitRelation.
+     * @param id , the id of the returned MapOrganisationUnitRelation.
      * @return the MapOrganisationUnitRelation with the given id.
      */
     MapOrganisationUnitRelation getMapOrganisationUnitRelation( int id );
@@ -267,8 +285,8 @@
     /**
      * Returns a Collection <MapOrganisationUnitRelation>.
      * 
-     * @param map, the foreign Map in the MapOrganisationUnitRelation.
-     * @param map, the foreign OrganisationUnit in the
+     * @param map , the foreign Map in the MapOrganisationUnitRelation.
+     * @param map , the foreign OrganisationUnit in the
      *        MapOrganisationUnitRelation.
      * @return a Collection<MapOrganisationUnitRelation> which contains the
      *         given Map and OrganisationUnit.
@@ -288,7 +306,7 @@
      * Returns a Collection of all MapOrganisationUnitRelations connected to the
      * given Map.
      * 
-     * @param map, the Map to which the MapOrganisationUnitRelations are
+     * @param map , the Map to which the MapOrganisationUnitRelations are
      *        connected.
      * @return a Collection of MapOrganisationUnitRelations connected to the
      *         given Map.
@@ -299,7 +317,7 @@
      * Returns a Collection of all existing MapOrganisationUnitRelations and the
      * MapOrganisationUnitRelations that are not yet created (no featureId).
      * 
-     * @param map, the Map to which the MapOrganisationUnitRelations are
+     * @param map , the Map to which the MapOrganisationUnitRelations are
      *        connected.
      * @return a Collection of MapOrganisationUnitRelations.
      */
@@ -309,7 +327,7 @@
      * Returns a Collection of all existing MapOrganisationUnitRelations and the
      * MapOrganisationUnitRelations that are not yet created (no featureId).
      * 
-     * @param mapLayerPath, the map to which the MapOrganisationUnitRelations
+     * @param mapLayerPath , the map to which the MapOrganisationUnitRelations
      *        are connected.
      * @return a Collection of MapOrganisationUnitRelations.
      */
@@ -366,7 +384,7 @@
     Collection<MapLegendSet> getMapLegendSetsByType( String type );
 
     MapLegendSet getMapLegendSetByIndicator( int indicatorId );
-    
+
     MapLegendSet getMapLegendSetByDataElement( int dataElementId );
 
     Collection<MapLegendSet> getAllMapLegendSets();
@@ -379,17 +397,19 @@
 
     int addMapView( MapView mapView );
 
-    int addMapView( String name, String mapValueType, int indicatorGroupId, int indicatorId,
-        int dataElementGroupId, int dataElementId, String periodTypeName, int periodId, String mapSourceType,
-        String mapSource, String mapLegendType, int method, int classes, String bounds, String colorLow,
-        String colorHigh, int mapLegendSetId, String longitude, String latitude, int zoom );
+    int addMapView( String name, String mapValueType, int indicatorGroupId, int indicatorId, int dataElementGroupId,
+        int dataElementId, String periodTypeName, int periodId, String mapSourceType,
+        String organisationUnitSelectionType, String mapSource, String mapLegendType, int method, int classes,
+        String bounds, String colorLow, String colorHigh, int mapLegendSetId, String longitude, String latitude,
+        int zoom );
 
     void updateMapView( MapView mapView );
 
     void addOrUpdateMapView( String name, String mapValueType, Integer indicatorGroupId, Integer indicatorId,
-        Integer dataElementGroupId, Integer dataElementId, String periodTypeName, Integer periodId,
-        String startDate, String endDate, String mapSource, String mapLegendType, int method, int classes, String bounds,
-        String colorLow, String colorHigh, Integer mapLegendSetId, String longitude, String latitude, int zoom );
+        Integer dataElementGroupId, Integer dataElementId, String periodTypeName, Integer periodId, String startDate,
+        String endDate, String organisationUnitSelectionType, String mapSource, String mapLegendType, int method,
+        int classes, String bounds, String colorLow, String colorHigh, Integer mapLegendSetId, String longitude,
+        String latitude, int zoom );
 
     void deleteMapView( MapView view );
 

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2010-10-19 20:24:19 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2010-10-29 11:24:12 +0000
@@ -55,6 +55,7 @@
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.MathUtils;
+import org.hisp.dhis.system.util.Timer;
 import org.hisp.dhis.user.UserSettingService;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -186,6 +187,43 @@
         return values;
     }
 
+    public Collection<AggregatedMapValue> getDataElementMapValuesByLevel( int dataElementId, int periodId, int level )
+    {
+        Period period = periodService.getPeriod( periodId );
+
+        return getDataElementMapValuesByLevel( dataElementId, period.getStartDate(), period.getEndDate(), level );
+    }
+
+    public Collection<AggregatedMapValue> getDataElementMapValuesByLevel( int dataElementId, Date startDate,
+        Date endDate, int level )
+    {
+        Collection<AggregatedMapValue> values = new HashSet<AggregatedMapValue>();
+
+        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level );
+
+        DataElement dataElement = dataElementService.getDataElement( dataElementId );
+
+        for ( OrganisationUnit organisationUnit : organisationUnits )
+        {
+            if ( organisationUnit.hasCoordinates() )
+            {
+                Double value = aggregationService.getAggregatedDataValue( dataElement, null, startDate, endDate,
+                    organisationUnit );
+
+                value = value != null ? value : 0; // TODO improve
+
+                AggregatedMapValue mapValue = new AggregatedMapValue();
+                mapValue.setOrganisationUnitId( organisationUnit.getId() );
+                mapValue.setOrganisationUnitName( organisationUnit.getName() );
+                mapValue.setValue( MathUtils.getRounded( value, 2 ) );
+
+                values.add( mapValue );
+            }
+        }
+
+        return values;
+    }
+
     // -------------------------------------------------------------------------
     // IndicatorMapValues
     // -------------------------------------------------------------------------
@@ -232,7 +270,6 @@
 
     public Collection<AggregatedMapValue> getIndicatorMapValues( int indicatorId, Date startDate, Date endDate,
         int parentOrganisationUnitId )
-
     {
         Collection<AggregatedMapValue> values = new HashSet<AggregatedMapValue>();
 
@@ -242,7 +279,43 @@
         for ( OrganisationUnit organisationUnit : parent.getChildren() )
         {
             if ( organisationUnit.hasCoordinates() )
-
+            {
+                Double value = aggregationService.getAggregatedIndicatorValue( indicator, startDate, endDate,
+                    organisationUnit );
+
+                value = value != null ? value : 0; // TODO improve
+
+                AggregatedMapValue mapValue = new AggregatedMapValue();
+                mapValue.setOrganisationUnitId( organisationUnit.getId() );
+                mapValue.setOrganisationUnitName( organisationUnit.getName() );
+                mapValue.setValue( MathUtils.getRounded( value, 2 ) );
+
+                values.add( mapValue );
+            }
+        }
+
+        return values;
+    }
+
+    public Collection<AggregatedMapValue> getIndicatorMapValuesByLevel( int indicatorId, int periodId, int level )
+    {
+        Period period = periodService.getPeriod( periodId );
+
+        return getIndicatorMapValuesByLevel( indicatorId, period.getStartDate(), period.getEndDate(), level );
+    }
+
+    public Collection<AggregatedMapValue> getIndicatorMapValuesByLevel( int indicatorId, Date startDate, Date endDate,
+        int level )
+    {
+        Collection<AggregatedMapValue> values = new HashSet<AggregatedMapValue>();
+
+        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level );
+
+        Indicator indicator = indicatorService.getIndicator( indicatorId );
+
+        for ( OrganisationUnit organisationUnit : organisationUnits )
+        {
+            if ( organisationUnit.hasCoordinates() )
             {
                 Double value = aggregationService.getAggregatedIndicatorValue( indicator, startDate, endDate,
                     organisationUnit );
@@ -765,8 +838,9 @@
 
     public int addMapView( String name, String mapValueType, int indicatorGroupId, int indicatorId,
         int dataElementGroupId, int dataElementId, String periodTypeName, int periodId, String mapSourceType,
-        String mapSource, String mapLegendType, int method, int classes, String bounds, String colorLow,
-        String colorHigh, int mapLegendSetId, String longitude, String latitude, int zoom )
+        String organisationUnitSelectionType, String mapSource, String mapLegendType, int method, int classes,
+        String bounds, String colorLow, String colorHigh, int mapLegendSetId, String longitude, String latitude,
+        int zoom )
     {
         MapView mapView = new MapView();
 
@@ -798,6 +872,7 @@
         mapView.setPeriodType( periodType );
         mapView.setPeriod( period );
         mapView.setMapSourceType( mapSourceType );
+        mapView.setOrganisationUnitSelectionType( organisationUnitSelectionType );
         mapView.setMapSource( mapSource );
         mapView.setMapLegendType( mapLegendType );
         mapView.setMethod( method );
@@ -820,8 +895,9 @@
 
     public void addOrUpdateMapView( String name, String mapValueType, Integer indicatorGroupId, Integer indicatorId,
         Integer dataElementGroupId, Integer dataElementId, String periodTypeName, Integer periodId, String startDate,
-        String endDate, String mapSource, String mapLegendType, int method, int classes, String bounds,
-        String colorLow, String colorHigh, Integer mapLegendSetId, String longitude, String latitude, int zoom )
+        String endDate, String organisationUnitSelectionType, String mapSource, String mapLegendType, int method,
+        int classes, String bounds, String colorLow, String colorHigh, Integer mapLegendSetId, String longitude,
+        String latitude, int zoom )
     {
         IndicatorGroup indicatorGroup = null;
 
@@ -870,6 +946,7 @@
             mapView.setStartDate( startDate );
             mapView.setEndDate( endDate );
             mapView.setMapSourceType( mapSourceType );
+            mapView.setOrganisationUnitSelectionType( organisationUnitSelectionType );
             mapView.setMapSource( mapSource );
             mapView.setMapLegendType( mapLegendType );
             mapView.setMethod( method );
@@ -887,8 +964,9 @@
         else
         {
             mapView = new MapView( name, mapValueType, indicatorGroup, indicator, dataElementGroup, dataElement,
-                mapDateType, periodType, period, startDate, endDate, mapSourceType, mapSource, mapLegendType, method,
-                classes, bounds, colorLow, colorHigh, mapLegendSet, longitude, latitude, zoom );
+                mapDateType, periodType, period, startDate, endDate, mapSourceType, organisationUnitSelectionType,
+                mapSource, mapLegendType, method, classes, bounds, colorLow, colorHigh, mapLegendSet, longitude,
+                latitude, zoom );
 
             addMapView( mapView );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml	2010-09-01 09:02:32 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml	2010-10-29 11:24:12 +0000
@@ -41,6 +41,8 @@
 		
 		<property name="mapSourceType"/>
 		
+		<property name="organisationUnitSelectionType"/>
+		
 		<property name="mapSource"/>
 		
 		<property name="mapLegendType"/>

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java	2010-08-30 13:58:52 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java	2010-10-29 11:24:12 +0000
@@ -219,7 +219,8 @@
         mappingService.addMap( mapA );
 
         MapView mapView = new MapView( "MapViewA", MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, indicator,
-            new DataElementGroup(), new DataElement(), MappingService.MAP_DATE_TYPE_FIXED, periodType, period, "", "", MappingService.MAP_SOURCE_TYPE_SHAPEFILE,
+            new DataElementGroup(), new DataElement(), MappingService.MAP_DATE_TYPE_FIXED, periodType, period, "", "",
+            MappingService.ORGANISATION_UNIT_SELECTION_TYPE_PARENT, MappingService.MAP_SOURCE_TYPE_SHAPEFILE,
             "sl_districts", MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, "1", "1", 1 );
 
         int idA = mappingService.addMapView( mapView );

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingStoreTest.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingStoreTest.java	2010-08-30 13:58:52 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingStoreTest.java	2010-10-29 11:24:12 +0000
@@ -162,8 +162,8 @@
 
         MapView mapView = new MapView( "MapViewA", MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, indicator,
             new DataElementGroup(), new DataElement(), MappingService.MAP_DATE_TYPE_FIXED, periodType, period, "", "",
-            MappingService.MAP_SOURCE_TYPE_SHAPEFILE, "sl_districts", MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1,
-            "", "A", "B", mapLegendSet, "1", "1", 1 );
+            MappingService.ORGANISATION_UNIT_SELECTION_TYPE_PARENT, MappingService.MAP_SOURCE_TYPE_SHAPEFILE,
+            "sl_districts", MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, "1", "1", 1 );
 
         int idA = mappingStore.addMapView( mapView );
 

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AddOrUpdateMapViewAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AddOrUpdateMapViewAction.java	2010-09-01 09:02:32 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AddOrUpdateMapViewAction.java	2010-10-29 11:24:12 +0000
@@ -123,6 +123,13 @@
         this.endDate = endDate;
     }
 
+    private String organisationUnitSelectionType;
+
+    public void setOrganisationUnitSelectionType( String organisationUnitSelectionType )
+    {
+        this.organisationUnitSelectionType = organisationUnitSelectionType;
+    }
+
     private String mapSource;
 
     public void setMapSource( String mapSource )
@@ -208,8 +215,8 @@
         throws Exception
     {
         mappingService.addOrUpdateMapView( name, mapValueType, indicatorGroupId, indicatorId, dataElementGroupId,
-            dataElementId, periodTypeId, periodId, startDate, endDate, mapSource, mapLegendType, method,
-            classes, bounds, colorLow, colorHigh, mapLegendSetId, longitude, latitude, zoom );
+            dataElementId, periodTypeId, periodId, startDate, endDate, organisationUnitSelectionType, mapSource,
+            mapLegendType, method, classes, bounds, colorLow, colorHigh, mapLegendSetId, longitude, latitude, zoom );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetAllMapViewsAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetAllMapViewsAction.java	2010-10-20 14:10:39 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetAllMapViewsAction.java	2010-10-29 11:24:12 +0000
@@ -30,10 +30,13 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.mapping.MapView;
 import org.hisp.dhis.mapping.MappingService;
 import org.hisp.dhis.mapping.comparator.MapViewNameComparator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 
 import com.opensymphony.xwork2.Action;
@@ -75,7 +78,7 @@
     {
         return object;
     }
-    
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -83,20 +86,38 @@
     public String execute()
     {
         object = new ArrayList<MapView>( mappingService.getMapViewsByMapSourceType() );
-        
+
         Collections.sort( object, new MapViewNameComparator() );
-        
+
         for ( MapView mapView : object )
         {
             if ( mapView != null && mapView.getMapSourceType().equals( MappingService.MAP_SOURCE_TYPE_DATABASE ) )
             {
-                OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(
-                    Integer.parseInt( mapView.getMapSource() ) );
-                
-                mapView.setParentOrganisationUnitName( organisationUnit.getName() );
+                if ( mapView.getOrganisationUnitSelectionType() == null
+                    || mapView.getOrganisationUnitSelectionType().trim().isEmpty()
+                    || mapView.getOrganisationUnitSelectionType().equals(
+                        MappingService.ORGANISATION_UNIT_SELECTION_TYPE_PARENT ) )
+                {
+                    mapView.setOrganisationUnitSelectionType( MappingService.ORGANISATION_UNIT_SELECTION_TYPE_PARENT );
+                    
+                    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( Integer
+                        .parseInt( mapView.getMapSource() ) );
+
+                    mapView.setOrganisationUnitSelectionTypeName( organisationUnit.getName() );
+                }
+
+                else if ( mapView.getOrganisationUnitSelectionType().equals(
+                    MappingService.ORGANISATION_UNIT_SELECTION_TYPE_LEVEL ) )
+                {
+                    OrganisationUnitLevel level = organisationUnitService.getOrganisationUnitLevelByLevel( Integer
+                        .parseInt( mapView.getMapSource() ) );
+
+                    mapView.setOrganisationUnitSelectionTypeName( level.getName() );
+
+                }
             }
         }
-        
+
         return SUCCESS;
     }
 }
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByLevelAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByLevelAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByLevelAction.java	2010-10-29 11:24:12 +0000
@@ -0,0 +1,124 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.aggregation.AggregatedMapValue;
+import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.system.util.DateUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Jan Henrik Overland
+ * @version $Id$
+ */
+public class GetDataMapValuesByLevelAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    
+    private MappingService mappingService;
+
+    public void setMappingService( MappingService mappingService )
+    {
+        this.mappingService = mappingService;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private Integer periodId;
+
+    public void setPeriodId( Integer periodId )
+    {
+        this.periodId = periodId;
+    }
+
+    private String startDate;
+    
+    public void setStartDate( String startDate )
+    {
+        this.startDate = startDate;
+    }
+
+    private String endDate;
+
+    public void setEndDate( String endDate )
+    {
+        this.endDate = endDate;
+    }
+
+    private Integer level;
+
+    public void setLevel( Integer level )
+    {
+        this.level = level;
+    }    
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Collection<AggregatedMapValue> object;
+
+    public Collection<AggregatedMapValue> getObject()
+    {
+        return object;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+    
+    public String execute()
+        throws Exception
+    {
+        if ( periodId != null ) // Period
+        {
+            object = mappingService.getDataElementMapValues( id, periodId, level );
+        }
+        else // Start and end date
+        {
+            object = mappingService.getDataElementMapValues( id, DateUtils.getMediumDate( startDate ), DateUtils.getMediumDate( endDate ), level );
+        }
+        
+        return SUCCESS;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByParentAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByParentAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByParentAction.java	2010-10-29 11:24:12 +0000
@@ -0,0 +1,124 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.aggregation.AggregatedMapValue;
+import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.system.util.DateUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Jan Henrik Overland
+ * @version $Id$
+ */
+public class GetDataMapValuesByParentAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    
+    private MappingService mappingService;
+
+    public void setMappingService( MappingService mappingService )
+    {
+        this.mappingService = mappingService;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private Integer periodId;
+
+    public void setPeriodId( Integer periodId )
+    {
+        this.periodId = periodId;
+    }
+
+    private String startDate;
+    
+    public void setStartDate( String startDate )
+    {
+        this.startDate = startDate;
+    }
+
+    private String endDate;
+
+    public void setEndDate( String endDate )
+    {
+        this.endDate = endDate;
+    }
+
+    private Integer parentId;    
+
+    public void setParentId( Integer parentId )
+    {
+        this.parentId = parentId;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Collection<AggregatedMapValue> object;
+
+    public Collection<AggregatedMapValue> getObject()
+    {
+        return object;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+    
+    public String execute()
+        throws Exception
+    {
+        if ( periodId != null ) // Period
+        {
+            object = mappingService.getDataElementMapValues( id, periodId, parentId );
+        }
+        else // Start and end date
+        {
+            object = mappingService.getDataElementMapValues( id, DateUtils.getMediumDate( startDate ), DateUtils.getMediumDate( endDate ), parentId );
+        }
+        
+        return SUCCESS;
+    }
+}

=== removed file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByParentOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByParentOrganisationUnitAction.java	2010-08-31 09:13:46 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataMapValuesByParentOrganisationUnitAction.java	1970-01-01 00:00:00 +0000
@@ -1,124 +0,0 @@
-package org.hisp.dhis.mapping.action;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-
-import org.hisp.dhis.aggregation.AggregatedMapValue;
-import org.hisp.dhis.mapping.MappingService;
-import org.hisp.dhis.system.util.DateUtils;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Jan Henrik Overland
- * @version $Id$
- */
-public class GetDataMapValuesByParentOrganisationUnitAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-    
-    private MappingService mappingService;
-
-    public void setMappingService( MappingService mappingService )
-    {
-        this.mappingService = mappingService;
-    }
-    
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Integer id;
-
-    public void setId( Integer id )
-    {
-        this.id = id;
-    }
-
-    private Integer periodId;
-
-    public void setPeriodId( Integer periodId )
-    {
-        this.periodId = periodId;
-    }
-
-    private Integer parentId;    
-
-    public void setParentId( Integer parentId )
-    {
-        this.parentId = parentId;
-    }
-
-    private String startDate;
-    
-    public void setStartDate( String startDate )
-    {
-        this.startDate = startDate;
-    }
-
-    private String endDate;
-
-    public void setEndDate( String endDate )
-    {
-        this.endDate = endDate;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Collection<AggregatedMapValue> object;
-
-    public Collection<AggregatedMapValue> getObject()
-    {
-        return object;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-    
-    public String execute()
-        throws Exception
-    {
-        if ( periodId != null ) // Period
-        {
-            object = mappingService.getDataElementMapValues( id, periodId, parentId );
-        }
-        else // Start and end date
-        {
-            object = mappingService.getDataElementMapValues( id, DateUtils.getMediumDate( startDate ), DateUtils.getMediumDate( endDate ), parentId );
-        }
-        
-        return SUCCESS;
-    }
-}

=== removed file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java	2010-05-17 21:05:26 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java	1970-01-01 00:00:00 +0000
@@ -1,85 +0,0 @@
-package org.hisp.dhis.mapping.action;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.io.InputStream;
-
-import org.hisp.dhis.external.location.LocationManager;
-import org.hisp.dhis.mapping.MappingService;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Lars Helge Overland
- * @version $Id$
- */
-public class GetGeoJsonAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    @Autowired
-    private LocationManager locationManager;
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private String name;
-
-    public void setName( String name )
-    {
-        this.name = name;
-    }
-
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
-    private InputStream inputStream;
-
-    public InputStream getInputStream()
-    {
-        return inputStream;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-        throws Exception
-    {        
-        inputStream = locationManager.getInputStream( name, MappingService.GEOJSON_DIR );
-        
-        return SUCCESS;
-    }
-}

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonByLevelAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonByLevelAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonByLevelAction.java	2010-10-29 11:24:12 +0000
@@ -0,0 +1,98 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.system.filter.OrganisationUnitWithCoordinatesFilter;
+import org.hisp.dhis.system.util.FilterUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Jan Henrik Overland
+ * @version $Id$
+ */
+public class GetGeoJsonByLevelAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer level;
+
+    public void setLevel( Integer level )
+    {
+        this.level = level;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private Collection<OrganisationUnit> object;
+
+    public Collection<OrganisationUnit> getObject()
+    {
+        return object;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        object = organisationUnitService.getOrganisationUnitsAtLevel( level );
+        
+        FilterUtils.filter( object, new OrganisationUnitWithCoordinatesFilter() );
+        
+        if ( object != null && object.size() > 0 )
+        {
+            return object.iterator().next().getFeatureType();
+        }
+        
+        return NONE;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonByParentAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonByParentAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonByParentAction.java	2010-10-29 11:24:12 +0000
@@ -0,0 +1,95 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.system.filter.OrganisationUnitWithCoordinatesFilter;
+import org.hisp.dhis.system.util.FilterUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Jan Henrik Overland
+ * @version $Id$
+ */
+public class GetGeoJsonByParentAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer parentId;
+
+    public void setParentId( Integer id )
+    {
+        this.parentId = id;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private Collection<OrganisationUnit> object;
+
+    public Collection<OrganisationUnit> getObject()
+    {
+        return object;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );
+        
+        object = new HashSet<OrganisationUnit>( parent.getChildren() );
+        
+        FilterUtils.filter( object, new OrganisationUnitWithCoordinatesFilter() );
+        
+        return parent.getChildrenFeatureType();
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFromFileAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFromFileAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFromFileAction.java	2010-10-29 11:24:12 +0000
@@ -0,0 +1,85 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.InputStream;
+
+import org.hisp.dhis.external.location.LocationManager;
+import org.hisp.dhis.mapping.MappingService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class GetGeoJsonFromFileAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private LocationManager locationManager;
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private String name;
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private InputStream inputStream;
+
+    public InputStream getInputStream()
+    {
+        return inputStream;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {        
+        inputStream = locationManager.getInputStream( name, MappingService.GEOJSON_DIR );
+        
+        return SUCCESS;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByLevelAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByLevelAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByLevelAction.java	2010-10-29 11:24:12 +0000
@@ -0,0 +1,124 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.aggregation.AggregatedMapValue;
+import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.system.util.DateUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Jan Henrik Overland
+ * @version $Id$
+ */
+public class GetIndicatorMapValuesByLevelAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    
+    private MappingService mappingService;
+
+    public void setMappingService( MappingService mappingService )
+    {
+        this.mappingService = mappingService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private Integer periodId;
+
+    public void setPeriodId( Integer periodId )
+    {
+        this.periodId = periodId;
+    }
+    
+    private String startDate;
+    
+    public void setStartDate( String startDate )
+    {
+        this.startDate = startDate;
+    }
+
+    private String endDate;
+
+    public void setEndDate( String endDate )
+    {
+        this.endDate = endDate;
+    }
+
+    private Integer level;
+
+    public void setLevel( Integer level )
+    {
+        this.level = level;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Collection<AggregatedMapValue> object;
+
+    public Collection<AggregatedMapValue> getObject()
+    {
+        return object;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+    
+    public String execute()
+        throws Exception
+    {
+        if ( periodId != null ) // Period
+        {
+            object = mappingService.getIndicatorMapValuesByLevel( id, periodId, level );
+        }
+        else // Start and end date
+        {
+            object = mappingService.getIndicatorMapValuesByLevel( id, DateUtils.getMediumDate( startDate ), DateUtils.getMediumDate( endDate ), level );
+        }
+        
+        return SUCCESS;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByParentAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByParentAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByParentAction.java	2010-10-29 11:24:12 +0000
@@ -0,0 +1,124 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.aggregation.AggregatedMapValue;
+import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.system.util.DateUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Jan Henrik Overland
+ * @version $Id$
+ */
+public class GetIndicatorMapValuesByParentAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    
+    private MappingService mappingService;
+
+    public void setMappingService( MappingService mappingService )
+    {
+        this.mappingService = mappingService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private Integer periodId;
+
+    public void setPeriodId( Integer periodId )
+    {
+        this.periodId = periodId;
+    }
+    
+    private String startDate;
+    
+    public void setStartDate( String startDate )
+    {
+        this.startDate = startDate;
+    }
+
+    private String endDate;
+
+    public void setEndDate( String endDate )
+    {
+        this.endDate = endDate;
+    }
+
+    private Integer parentId;    
+
+    public void setParentId( Integer parentId )
+    {
+        this.parentId = parentId;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Collection<AggregatedMapValue> object;
+
+    public Collection<AggregatedMapValue> getObject()
+    {
+        return object;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+    
+    public String execute()
+        throws Exception
+    {
+        if ( periodId != null ) // Period
+        {
+            object = mappingService.getIndicatorMapValues( id, periodId, parentId );
+        }
+        else // Start and end date
+        {
+            object = mappingService.getIndicatorMapValues( id, DateUtils.getMediumDate( startDate ), DateUtils.getMediumDate( endDate ), parentId );
+        }
+        
+        return SUCCESS;
+    }
+}

=== removed file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByParentOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByParentOrganisationUnitAction.java	2010-08-31 09:13:46 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetIndicatorMapValuesByParentOrganisationUnitAction.java	1970-01-01 00:00:00 +0000
@@ -1,124 +0,0 @@
-package org.hisp.dhis.mapping.action;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-
-import org.hisp.dhis.aggregation.AggregatedMapValue;
-import org.hisp.dhis.mapping.MappingService;
-import org.hisp.dhis.system.util.DateUtils;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Jan Henrik Overland
- * @version $Id$
- */
-public class GetIndicatorMapValuesByParentOrganisationUnitAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-    
-    private MappingService mappingService;
-
-    public void setMappingService( MappingService mappingService )
-    {
-        this.mappingService = mappingService;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Integer id;
-
-    public void setId( Integer id )
-    {
-        this.id = id;
-    }
-
-    private Integer periodId;
-
-    public void setPeriodId( Integer periodId )
-    {
-        this.periodId = periodId;
-    }
-
-    private Integer parentId;    
-
-    public void setParentId( Integer parentId )
-    {
-        this.parentId = parentId;
-    }
-    
-    private String startDate;
-    
-    public void setStartDate( String startDate )
-    {
-        this.startDate = startDate;
-    }
-
-    private String endDate;
-
-    public void setEndDate( String endDate )
-    {
-        this.endDate = endDate;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Collection<AggregatedMapValue> object;
-
-    public Collection<AggregatedMapValue> getObject()
-    {
-        return object;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-    
-    public String execute()
-        throws Exception
-    {
-        if ( periodId != null ) // Period
-        {
-            object = mappingService.getIndicatorMapValues( id, periodId, parentId );
-        }
-        else // Start and end date
-        {
-            object = mappingService.getIndicatorMapValues( id, DateUtils.getMediumDate( startDate ), DateUtils.getMediumDate( endDate ), parentId );
-        }
-        
-        return SUCCESS;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapViewAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapViewAction.java	2010-10-13 13:00:43 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapViewAction.java	2010-10-29 11:24:12 +0000
@@ -32,6 +32,7 @@
 import org.hisp.dhis.mapping.MapView;
 import org.hisp.dhis.mapping.MappingService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 
 import com.opensymphony.xwork2.Action;
@@ -44,7 +45,7 @@
     implements Action
 {
     private static final Log log = LogFactory.getLog( GetMapViewAction.class );
-    
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -95,15 +96,30 @@
         object = mappingService.getMapView( id );
 
         log.info( "Getting map view: " + object );
-        
+
         if ( object != null && object.getMapSourceType().equals( MappingService.MAP_SOURCE_TYPE_DATABASE ) )
         {
-            OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(
-                Integer.parseInt( object.getMapSource() ) );
-            
-            log.info( "Getting map view for organisation unit: " + object + " for map source: " + object.getMapSource() );
-            
-            object.setParentOrganisationUnitName( organisationUnit.getName() );
+            if ( object.getOrganisationUnitSelectionType() == null
+                || object.getOrganisationUnitSelectionType().trim().isEmpty()
+                || object.getOrganisationUnitSelectionType().equals(
+                    MappingService.ORGANISATION_UNIT_SELECTION_TYPE_PARENT ) )
+            {
+                object.setOrganisationUnitSelectionType( MappingService.ORGANISATION_UNIT_SELECTION_TYPE_PARENT );
+                
+                OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( Integer
+                    .parseInt( object.getMapSource() ) );
+
+                object.setOrganisationUnitSelectionTypeName( organisationUnit.getName() );
+            }
+
+            else if ( object.getOrganisationUnitSelectionType().equals(
+                MappingService.ORGANISATION_UNIT_SELECTION_TYPE_PARENT ) )
+            {
+                OrganisationUnitLevel level = organisationUnitService.getOrganisationUnitLevelByLevel( Integer
+                    .parseInt( object.getMapSource() ) );
+
+                object.setOrganisationUnitSelectionTypeName( level.getName() );
+            }
         }
 
         return SUCCESS;

=== removed file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitsWithCoordinatesAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitsWithCoordinatesAction.java	2010-08-28 10:27:45 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitsWithCoordinatesAction.java	1970-01-01 00:00:00 +0000
@@ -1,95 +0,0 @@
-package org.hisp.dhis.mapping.action;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.system.filter.OrganisationUnitWithCoordinatesFilter;
-import org.hisp.dhis.system.util.FilterUtils;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Jan Henrik Overland
- * @version $Id$
- */
-public class GetOrganisationUnitsWithCoordinatesAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private OrganisationUnitService organisationUnitService;
-
-    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
-    {
-        this.organisationUnitService = organisationUnitService;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Integer parentId;
-
-    public void setParentId( Integer id )
-    {
-        this.parentId = id;
-    }
-    
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
-    private Collection<OrganisationUnit> object;
-
-    public Collection<OrganisationUnit> getObject()
-    {
-        return object;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-        throws Exception
-    {
-        OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );
-        
-        object = new HashSet<OrganisationUnit>( parent.getChildren() );
-        
-        FilterUtils.filter( object, new OrganisationUnitWithCoordinatesFilter() );
-        
-        return parent.getChildrenFeatureType();
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2010-10-20 14:10:39 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2010-10-29 11:24:12 +0000
@@ -64,8 +64,13 @@
         <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
     </bean>
 
-    <bean id="org.hisp.dhis.mapping.action.GetDataMapValuesByParentOrganisationUnitAction"
-        class="org.hisp.dhis.mapping.action.GetDataMapValuesByParentOrganisationUnitAction" scope="prototype">
+    <bean id="org.hisp.dhis.mapping.action.GetDataMapValuesByParentAction"
+        class="org.hisp.dhis.mapping.action.GetDataMapValuesByParentAction" scope="prototype">
+        <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
+    </bean>
+
+    <bean id="org.hisp.dhis.mapping.action.GetDataMapValuesByLevelAction"
+        class="org.hisp.dhis.mapping.action.GetDataMapValuesByLevelAction" scope="prototype">
         <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
     </bean>
 
@@ -79,8 +84,13 @@
         <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
     </bean>
 
-    <bean id="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByParentOrganisationUnitAction"
-        class="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByParentOrganisationUnitAction" scope="prototype">
+    <bean id="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByParentAction"
+        class="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByParentAction" scope="prototype">
+        <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
+    </bean>
+
+    <bean id="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByLevelAction"
+        class="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByLevelAction" scope="prototype">
         <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
     </bean>
 
@@ -348,19 +358,26 @@
 
 	<!-- GeoJson -->
 
-	<bean id="org.hisp.dhis.mapping.action.GetGeoJsonAction" class="org.hisp.dhis.mapping.action.GetGeoJsonAction"
+    <bean id="org.hisp.dhis.mapping.action.GetGeoJsonByParentAction"
+        class="org.hisp.dhis.mapping.action.GetGeoJsonByParentAction"
+        scope="prototype">
+        <property name="organisationUnitService"
+            ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+    </bean>
+
+    <bean id="org.hisp.dhis.mapping.action.GetGeoJsonByLevelAction"
+        class="org.hisp.dhis.mapping.action.GetGeoJsonByLevelAction"
+        scope="prototype">
+        <property name="organisationUnitService"
+            ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+    </bean>
+
+	<bean id="org.hisp.dhis.mapping.action.GetGeoJsonFromFileAction" class="org.hisp.dhis.mapping.action.GetGeoJsonFromFileAction"
 		scope="prototype"/>
 
 	<bean id="org.hisp.dhis.mapping.action.GetGeoJsonFilesAction"
 		class="org.hisp.dhis.mapping.action.GetGeoJsonFilesAction" scope="prototype"/>
 
-	<bean id="org.hisp.dhis.mapping.action.GetOrganisationUnitsWithCoordinatesAction"
-		class="org.hisp.dhis.mapping.action.GetOrganisationUnitsWithCoordinatesAction"
-		scope="prototype">
-		<property name="organisationUnitService"
-			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
-	</bean>
-
 	<!-- Export Map -->
 
 	<bean id="org.hisp.dhis.mapping.action.ExportImageAction" class="org.hisp.dhis.mapping.action.ExportImageAction"

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2010-10-18 20:10:30 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2010-10-29 11:24:12 +0000
@@ -79,8 +79,14 @@
                 /dhis-web-mapping/jsonminAggregatedMapValues.vm</result>
         </action>
         
-        <action name="getDataMapValuesByParentOrganisationUnit"
-            class="org.hisp.dhis.mapping.action.GetDataMapValuesByParentOrganisationUnitAction">
+        <action name="getDataMapValuesByParent"
+            class="org.hisp.dhis.mapping.action.GetDataMapValuesByParentAction">
+            <result name="success" type="velocity-json">
+                /dhis-web-mapping/jsonminAggregatedMapValues.vm</result>
+        </action>
+        
+        <action name="getDataMapValuesByLevel"
+            class="org.hisp.dhis.mapping.action.GetDataMapValuesByLevelAction">
             <result name="success" type="velocity-json">
                 /dhis-web-mapping/jsonminAggregatedMapValues.vm</result>
         </action>
@@ -97,8 +103,14 @@
                 /dhis-web-mapping/jsonminAggregatedMapValues.vm</result>
         </action>
 		
-		<action name="getIndicatorMapValuesByParentOrganisationUnit"
-            class="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByParentOrganisationUnitAction">
+		<action name="getIndicatorMapValuesByParent"
+            class="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByParentAction">
+            <result name="success" type="velocity-json">
+                /dhis-web-mapping/jsonminAggregatedMapValues.vm</result>
+        </action>
+        
+        <action name="getIndicatorMapValuesByLevel"
+            class="org.hisp.dhis.mapping.action.GetIndicatorMapValuesByLevelAction">
             <result name="success" type="velocity-json">
                 /dhis-web-mapping/jsonminAggregatedMapValues.vm</result>
         </action>
@@ -371,16 +383,24 @@
 
 		<!-- GeoJson -->
 
-		<action name="getGeoJson"
-			class="org.hisp.dhis.mapping.action.GetOrganisationUnitsWithCoordinatesAction">
-			<result name="Point" type="velocity-json">/dhis-web-mapping/pointShapefile.vm</result>
-			<result name="Polygon" type="velocity-json">/dhis-web-mapping/polygonShapefile.vm</result>
-			<result name="MultiPolygon" type="velocity-json">/dhis-web-mapping/polygonShapefile.vm</result>
-			<result name="None" type="velocity-json">/dhis-web-mapping/polygonShapefile.vm</result>
+		<action name="getGeoJsonByParent"
+			class="org.hisp.dhis.mapping.action.GetGeoJsonByParentAction">
+			<result name="Point" type="velocity-json">/dhis-web-mapping/geojsonPoint.vm</result>
+			<result name="Polygon" type="velocity-json">/dhis-web-mapping/geojsonPolygon.vm</result>
+			<result name="MultiPolygon" type="velocity-json">/dhis-web-mapping/geojsonPolygon.vm</result>
+			<result name="None" type="velocity-json">/dhis-web-mapping/geojsonPolygon.vm</result>
 		</action>
 
+        <action name="getGeoJsonByLevel"
+            class="org.hisp.dhis.mapping.action.GetGeoJsonByLevelAction">
+            <result name="Point" type="velocity-json">/dhis-web-mapping/geojsonPoint.vm</result>
+            <result name="Polygon" type="velocity-json">/dhis-web-mapping/geojsonPolygon.vm</result>
+            <result name="MultiPolygon" type="velocity-json">/dhis-web-mapping/geojsonPolygon.vm</result>
+            <result name="None" type="velocity-json">/dhis-web-mapping/geojsonPolygon.vm</result>
+        </action>
+
 		<action name="getGeoJsonFromFile"
-            class="org.hisp.dhis.mapping.action.GetGeoJsonAction">
+            class="org.hisp.dhis.mapping.action.GetGeoJsonFromFileAction">
 			<result name="success" type="stream">
 				<param name="contentType">application/json</param>
 				<param name="inputName">inputStream</param>

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonPoint.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonPoint.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonPoint.vm	2010-10-29 11:24:12 +0000
@@ -0,0 +1,2 @@
+#set( $size = $object.size() )
+{"type":"FeatureCollection","features":[#foreach($unit in $object){"type":"Feature","id":"${unit.id}","geometry":{"type":"Point","coordinates":$!encoder.jsEncode( $!{unit.validCoordinates} )},"properties":{"id":"$!{unit.id}","name":"$!encoder.jsEncode( ${unit.name} )","hasChildrenWithCoordinates":$!{unit.hasChildrenWithCoordinates()},"type":"Facility"}}#if( $velocityCount < $size ),#end #end ],"crs":{"type":"EPSG","properties":{"code":"4326"}}}
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonPolygon.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonPolygon.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonPolygon.vm	2010-10-29 11:24:12 +0000
@@ -0,0 +1,2 @@
+#set( $size = $object.size() )
+{"type":"FeatureCollection","features":[#foreach($unit in $object){"type":"Feature","id":"districts.1","geometry":{"type":"MultiPolygon","coordinates":$!encoder.jsEncode( $!{unit.validCoordinates} )},"properties":{"id":"$!{unit.id}","name":"$!encoder.jsEncode( ${unit.name} )","hasChildrenWithCoordinates":$!{unit.hasChildrenWithCoordinates()}}}#if( $velocityCount < $size ),#end #end],"crs":{"type":"EPSG","properties":{"code":"4326"}}}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapView.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapView.vm	2010-10-13 13:00:43 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapView.vm	2010-10-29 11:24:12 +0000
@@ -13,8 +13,9 @@
     "startDate": "$!encoder.jsEncode( ${object.startDate} )",
     "endDate": "$!encoder.jsEncode( ${object.endDate} )",
     "mapSourceType": "$!encoder.jsEncode( ${object.mapSourceType} )",
+    "organisationUnitSelectionType": "$!encoder.jsEncode( ${object.organisationUnitSelectionType} )",
     "mapSource": "$!encoder.jsEncode( ${object.mapSource} )",
-    "parentOrganisationUnitName": "$!encoder.jsEncode( ${object.parentOrganisationUnitName} )",
+    "organisationUnitSelectionTypeName": "$!encoder.jsEncode( ${object.organisationUnitSelectionTypeName} )",
     "mapLegendType": "$!encoder.jsEncode( ${object.mapLegendType} )",
     "method": "$!{object.method}",
     "classes": "$!{object.classes}",

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapViews.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapViews.vm	2010-10-20 14:10:39 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapViews.vm	2010-10-29 11:24:12 +0000
@@ -9,14 +9,15 @@
     "indicatorId": "$!{mapView.indicator.id}",
     "dataElementGroupId": "$!{mapView.dataElementGroup.id}",
     "dataElementId": "$!{mapView.dataElement.id}",
-    "mapDateType": "$!encoder.jsEncode( ${object.mapDateTypeNullSafe} )",
+    "mapDateType": "$!encoder.jsEncode( ${mapView.mapDateTypeNullSafe} )",
     "periodTypeId": "$!encoder.jsEncode( ${mapView.periodType.name} )",
     "periodId": "$!{mapView.period.id}",
-    "startDate": "$!encoder.jsEncode( ${object.startDate} )",
-    "endDate": "$!encoder.jsEncode( ${object.endDate} )",
+    "startDate": "$!encoder.jsEncode( ${mapView.startDate} )",
+    "endDate": "$!encoder.jsEncode( ${mapView.endDate} )",
     "mapSourceType": "$!encoder.jsEncode( ${mapView.mapSourceType} )",
+    "organisationUnitSelectionType": "$!encoder.jsEncode( ${mapView.organisationUnitSelectionType} )",
     "mapSource": "$!encoder.jsEncode( ${mapView.mapSource} )",
-    "parentOrganisationUnitName": "$!encoder.jsEncode( ${mapView.parentOrganisationUnitName} )",
+    "organisationUnitSelectionTypeName": "$!encoder.jsEncode( ${mapView.organisationUnitSelectionTypeName} )",
     "mapLegendType": "$!encoder.jsEncode( ${mapView.mapLegendType} )",
     "method": "$!{mapView.method}",
     "classes": "$!{mapView.classes}",

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonminAggregatedMapValues.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonminAggregatedMapValues.vm	2010-05-11 15:21:26 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonminAggregatedMapValues.vm	2010-10-29 11:24:12 +0000
@@ -1,1 +1,1 @@
-#set( $size = $object.size() ){"mapvalues":[#foreach( $value in $object ){"orgUnitId":"$!{value.organisationUnitId}","orgUnitName":"$!{value.organisationUnitName}","periodId":"$!{value.periodId}","value":"$!{value.value}"}#if( $velocityCount < $size ),#end#end]}
\ No newline at end of file
+#set( $size = $object.size() ){"mapvalues":[#foreach( $value in $object ){"orgUnitId":"$!{value.organisationUnitId}","orgUnitName":"$!{value.organisationUnitName}","value":"$!{value.value}"}#if( $velocityCount < $size ),#end#end]}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/config.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/config.js	2010-10-21 15:51:37 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/config.js	2010-10-29 11:24:12 +0000
@@ -57,6 +57,8 @@
 	map_value_type_dataelement: 'dataelement',
     map_date_type_fixed: 'fixed',
     map_date_type_start_end: 'start-end',
+    map_selection_type_parent: 'parent',
+    map_selection_type_level: 'level',
     
 //  MapFish
 

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2010-10-21 15:51:37 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2010-10-29 11:24:12 +0000
@@ -103,7 +103,7 @@
         url: GLOBALS.conf.path_mapping + 'getAllMapViews' + GLOBALS.conf.type,
         root: 'mapViews',
         fields: ['id', 'name', 'mapValueType', 'indicatorGroupId', 'indicatorId', 'dataElementGroupId', 'dataElementId', 'mapDateType', 'periodTypeId',
-            'periodId', 'startDate', 'endDate', 'mapSourceType', 'mapSource', 'parentOrganisationUnitName', 'mapLegendType', 'method', 'classes',
+            'periodId', 'startDate', 'endDate', 'mapSourceType', 'organisationUnitSelectionType', 'mapSource', 'organisationUnitSelectionTypeName', 'mapLegendType', 'method', 'classes',
             'bounds', 'colorLow', 'colorHigh', 'mapLegendSetId', 'longitude', 'latitude', 'zoom'],
         sortInfo: {field: 'name', direction: 'ASC'},
         autoLoad: false,
@@ -454,6 +454,7 @@
                             periodId: formValues.periodId,
                             startDate: formValues.startDate,
                             endDate: formValues.endDate,
+                            organisationUnitSelectionType: formValues.organisationUnitSelectionType,
                             mapSource:formValues.mapSource,
                             mapLegendType: formValues.mapLegendType,
                             method: formValues.method,
@@ -481,7 +482,7 @@
         id: 'deleteview_p',
 		bodyStyle: 'border:0px solid #fff',
         items:
-        [   
+        [
             { html: '<div class="window-field-label-first">' + i18n_view + '</div>' },
 			deleteMapViewComboBox,
 			{
@@ -571,7 +572,10 @@
 				layoutOnTabChange: true,
                 deferredRender: false,
                 plain: true,
-                defaults: {layout: 'fit', bodyStyle: 'padding:8px; border:0px'},
+                defaults: {
+                    layout: 'fit',
+                    bodyStyle: 'padding:8px; border:0px'
+                },
                 listeners: {
                     tabchange: function(panel, tab)
                     {
@@ -586,8 +590,7 @@
                         }
                     }
                 },
-                items:
-                [
+                items: [
                     {
                         title: '<span class="panel-tab-title">' + i18n_new + '</span>',
                         id: 'view0',

=== removed file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/pointShapefile.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/pointShapefile.vm	2010-10-11 17:55:45 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/pointShapefile.vm	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-#set( $size = $object.size() )
-{"type":"FeatureCollection","features":[ #foreach ( $unit in $object ) {"type":"Feature","id":"${unit.id}","geometry":{"type":"Point","coordinates":$!encoder.jsEncode( $!{unit.validCoordinates} )},"properties":{"id":"$!{unit.id}","name":"$!encoder.jsEncode( ${unit.name} )","hasChildrenWithCoordinates":$!{unit.hasChildrenWithCoordinates()},"type":"Facility"}}#if( $velocityCount < $size ),#end #end ],"crs":{"type":"EPSG","properties":{"code":"4326"}}}
\ No newline at end of file

=== removed file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/polygonShapefile.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/polygonShapefile.vm	2010-10-11 17:55:45 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/polygonShapefile.vm	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-#set( $size = $object.size() )
-{"type":"FeatureCollection","features":[ #foreach ( $unit in $object ) {"type":"Feature","id":"districts.1","geometry":{"type":"MultiPolygon","coordinates":$!encoder.jsEncode( $!{unit.validCoordinates} )},"properties":{"id":"$!{unit.id}","name":"$!encoder.jsEncode( ${unit.name} )","hasChildrenWithCoordinates":$!{unit.hasChildrenWithCoordinates()}}}#if( $velocityCount < $size ),#end #end],"crs":{"type":"EPSG","properties":{"code":"4326"}}}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js	2010-10-21 15:51:37 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js	2010-10-29 11:24:12 +0000
@@ -62,8 +62,6 @@
 
 	bounds: false,
 
-    parentId: false,
-
     mapView: false,
 
     mapData: false,
@@ -74,15 +72,11 @@
     
     selectFeatures: false,
     
+    organisationUnitSelectionType: false,
+    
     initComponent: function() {
     
-        this.legend = {
-            type: GLOBALS.conf.map_legend_type_automatic,
-            method: GLOBALS.conf.classify_by_equal_intervals,
-            classes: 5
-        };
-        
-        this.valueType = GLOBALS.conf.map_value_type_indicator;
+        this.initProperties();
         
         this.createItems();
         
@@ -148,6 +142,36 @@
         return [colorA, colorB];
     },
     
+    initProperties: function() {
+        this.legend = {
+            type: GLOBALS.conf.map_legend_type_automatic,
+            method: GLOBALS.conf.classify_by_equal_intervals,
+            classes: 5
+        };
+        
+        this.organisationUnitSelectionType = {
+            value: GLOBALS.conf.map_selection_type_parent,
+			parent: null,
+			level: null,
+            setParent: function(p) {
+                this.value = GLOBALS.conf.map_selection_type_parent;
+				this.parent = p;
+            },
+            setLevel: function(p) {
+                this.value = GLOBALS.conf.map_selection_type_level;
+				this.level = p;
+            },
+            isParent: function() {
+                return this.value == GLOBALS.conf.map_selection_type_parent;
+            },
+            isLevel: function() {
+                return this.value == GLOBALS.conf.map_selection_type_level;
+            }			
+        };
+        
+        this.valueType = GLOBALS.conf.map_value_type_indicator;
+    },
+    
     createItems: function() {
         this.items = [
         {
@@ -530,7 +554,7 @@
         {
             xtype: 'textfield',
             id: 'map_tf',
-            fieldLabel: i18n_parent_orgunit,
+            fieldLabel: 'Org. units',
             typeAhead: true,
             editable: false,
             valueField: 'id',
@@ -542,6 +566,7 @@
 			labelSeparator: GLOBALS.conf.labelseparator,
             selectOnFocus: true,
             width: GLOBALS.conf.combo_width,
+            node: {attributes: {hasChildrenWithCoordinates: false}},
             listeners: {
                 'focus': {
                     scope: this,
@@ -550,76 +575,170 @@
                             var value, rawvalue;
                             var w = new Ext.Window({
                                 id: 'orgunit_w',
-                                title: 'Select parent organisation unit',
-                                closeAction: 'hide',
+                                title: 'Select organisation units',
+                                closeAction: 'close',
+                                layout: 'fit',
                                 autoScroll: true,
-                                width: 280,
-                                autoHeight: true,
-                                height: 'auto',
-                                boxMaxHeight: 500,
+                                width: 276,
+                                height: GLOBALS.util.getMultiSelectHeight() + 82,
+                                boxMaxHeight: GLOBALS.util.getMultiSelectHeight() + 82,
                                 items: [
                                     {
-                                        xtype: 'treepanel',
-                                        id: 'orgunit_tp',
-                                        bodyStyle: 'padding:7px',
-                                        height: GLOBALS.util.getMultiSelectHeight(),
-                                        autoScroll: true,
-                                        loader: new Ext.tree.TreeLoader({
-                                            dataUrl: GLOBALS.conf.path_mapping + 'getOrganisationUnitChildren' + GLOBALS.conf.type
-                                        }),
-                                        root: {
-                                            id: TOPLEVELUNIT.id,
-                                            text: TOPLEVELUNIT.name,
-                                            hasChildrenWithCoordinates: TOPLEVELUNIT.hasChildrenWithCoordinates,
-                                            nodeType: 'async',
-                                            draggable: false,
-                                            expanded: true
+                                        xtype: 'tabpanel',
+                                        activeTab: 0,
+                                        layoutOnTabChange: false,
+                                        deferredRender: false,
+                                        plain: true,
+                                        listeners: {
+                                            tabchange: function(panel, tab) {
+                                                if (tab.id == 'maptab0') {
+                                                    w.setHeight(GLOBALS.util.getMultiSelectHeight() + 82);
+                                                    w.syncSize();
+                                                }
+                                                else if (tab.id == 'maptab1') {
+                                                    w.setHeight(152);
+                                                    w.syncSize();
+                                                }
+                                            }
                                         },
-                                        listeners: {
-                                            'click': {
-                                                fn: function(n) {
-                                                    if (n.hasChildNodes()) {
-                                                        tf.setValue(n.attributes.text);
-                                                        tf.value = n.attributes.id;
-                                                        tf.node = n;
-                                                    }
-                                                }
-                                            },
-                                            'expandnode': {
-                                                fn: function(n) {
-                                                    Ext.getCmp('orgunit_w').syncSize();
-                                                }
-                                            },
-                                            'collapsenode': {
-                                                fn: function(n) {
-                                                    Ext.getCmp('orgunit_w').syncSize();
-                                                }
-                                            }
-                                        }
-                                    },
-                                    {
-                                        xtype: 'panel',
-                                        layout: 'table',
                                         items: [
                                             {
-                                                xtype: 'button',
-                                                text: 'Select',
-                                                width: 133,
-                                                scope: this,
-                                                handler: function() {
-                                                    if (tf.getValue() && tf.getValue() != this.parentId) {
-                                                        this.loadFromDatabase(tf.value);
+                                                title: '<span class="panel-tab-title">Parent organisation unit</span>',
+                                                id: 'maptab0',
+                                                items: [
+                                                    {
+                                                        xtype: 'treepanel',
+                                                        id: 'orgunit_tp',
+                                                        bodyStyle: 'padding:7px',
+                                                        height: GLOBALS.util.getMultiSelectHeight(),
+                                                        autoScroll: true,
+                                                        loader: new Ext.tree.TreeLoader({
+                                                            dataUrl: GLOBALS.conf.path_mapping + 'getOrganisationUnitChildren' + GLOBALS.conf.type
+                                                        }),
+                                                        root: {
+                                                            id: TOPLEVELUNIT.id,
+                                                            text: TOPLEVELUNIT.name,
+                                                            hasChildrenWithCoordinates: TOPLEVELUNIT.hasChildrenWithCoordinates,
+                                                            nodeType: 'async',
+                                                            draggable: false,
+                                                            expanded: true
+                                                        },
+                                                        listeners: {
+                                                            'click': {
+                                                                scope: this,
+                                                                fn: function(n) {
+                                                                    if (n.hasChildNodes()) {
+                                                                        tf.setValue(n.attributes.text);
+                                                                        tf.value = n.attributes.id;
+                                                                        tf.node = n;
+                                                                    }
+                                                                 }
+                                                            },
+                                                            'expandnode': {
+                                                                fn: function(n) {
+                                                                    Ext.getCmp('orgunit_w').syncSize();
+                                                                }
+                                                            },
+                                                            'collapsenode': {
+                                                                fn: function(n) {
+                                                                    Ext.getCmp('orgunit_w').syncSize();
+                                                                }
+                                                            }
+                                                        }
+                                                    },
+                                                    {
+                                                        xtype: 'panel',
+                                                        layout: 'table',
+                                                        items: [
+                                                            {
+                                                                xtype: 'button',
+                                                                text: 'Select',
+                                                                width: 130,
+                                                                scope: this,
+                                                                handler: function() {
+                                                                    if (tf.getValue()) {
+                                                                        this.organisationUnitSelectionType.setParent(tf.value);
+                                                                        this.loadFromDatabase(tf.value);
+                                                                    }
+                                                                    Ext.getCmp('orgunit_w').close();
+                                                                }
+                                                            },
+                                                            {
+                                                                xtype: 'button',
+                                                                text: 'Cancel',
+                                                                width: 130,
+                                                                handler: function() {
+                                                                    Ext.getCmp('orgunit_w').close();
+                                                                }
+                                                            }
+                                                        ]
                                                     }
-                                                    Ext.getCmp('orgunit_w').hide();
-                                                }
+                                                ]
                                             },
                                             {
-                                                xtype: 'button',
-                                                text: 'Cancel',
-                                                width: 133,
-                                                handler: function() {
-                                                    Ext.getCmp('orgunit_w').hide();
-                                                }
+                                                title: '<span class="panel-tab-title">Level</span>',
+                                                id: 'maptab1',
+                                                items: [
+                                                    {
+                                                        xtype: 'panel',
+                                                        bodyStyle: 'padding:8px',
+                                                        items: [
+                                                            { html: '<div class="window-field-label-first">Level</div>' },
+                                                            {
+                                                                xtype: 'combo',
+                                                                id: 'maporganisationunitlevel_cb',
+                                                                typeAhead: true,
+                                                                editable: false,
+                                                                valueField: 'level',
+                                                                displayField: 'name',
+                                                                mode: 'remote',
+                                                                forceSelection: true,
+                                                                triggerAction: 'all',
+                                                                emptyText: GLOBALS.conf.emptytext,
+                                                                labelSeparator: GLOBALS.conf.labelseparator,
+                                                                selectOnFocus: true,
+                                                                width: GLOBALS.conf.combo_width,
+                                                                store: GLOBALS.stores.organisationUnitLevel,
+                                                                listeners: {
+                                                                    'select': function(cb) {
+                                                                        tf.setValue(cb.getRawValue());
+                                                                        tf.value = cb.getValue();
+                                                                    }
+                                                                }                                                                        
+                                                            }
+                                                        ]
+                                                    },
+                                                    
+                                                    { html: '<br>' },
+                                                    
+                                                    {
+                                                        xtype: 'panel',
+                                                        layout: 'table',
+                                                        items: [
+                                                            {
+                                                                xtype: 'button',
+                                                                text: 'Select',
+                                                                width: 130,
+                                                                scope: this,
+                                                                handler: function() {
+                                                                    if (tf.value) {
+                                                                        this.organisationUnitSelectionType.setLevel(tf.value);
+                                                                        this.loadFromDatabase(tf.value);
+                                                                    }
+                                                                    Ext.getCmp('orgunit_w').close();
+                                                                }
+                                                            },
+                                                            {
+                                                                xtype: 'button',
+                                                                text: 'Cancel',
+                                                                width: 130,
+                                                                handler: function() {
+                                                                    Ext.getCmp('orgunit_w').close();
+                                                                }
+                                                            }
+                                                        ]
+                                                    }
+                                                ]
                                             }
                                         ]
                                     }
@@ -853,6 +972,8 @@
     },
     
     createSelectFeatures: function() {
+        var scope = this;
+        
         var onHoverSelect = function onHoverSelect(feature) {
             if (ACTIVEPANEL == GLOBALS.conf.thematicMap) {
                 Ext.getCmp('featureinfo_l').setText('<div style="color:black">' + feature.attributes[choropleth.mapData.nameColumn] + '</div><div style="color:#555">' + feature.attributes.value + '</div>', false);
@@ -879,6 +1000,7 @@
                     
                     Ext.getCmp('map_tf').setValue(feature.data.name);
                     Ext.getCmp('map_tf').value = feature.attributes.id;
+                    scope.organisationUnitSelectionType.setParent(feature.attributes.id);
                     choropleth.loadFromDatabase(feature.attributes.id, true);
                 }
                 else {
@@ -1043,6 +1165,14 @@
             Ext.getCmp('map_cb').showField();
             Ext.getCmp('map_tf').hideField();
         }
+		
+		if (this.mapView.organisationUnitSelectionType == GLOBALS.conf.map_selection_type_parent ||
+			this.mapView.organisationUnitSelectionType == null) {
+				this.organisationUnitSelectionType.setParent(this.mapView.mapSource);
+		}
+		else if (this.mapView.organisationUnitSelectionType == GLOBALS.conf.map_selection_type_level) {
+			this.organisationUnitSelectionType.setLevel(this.mapView.mapSource);
+		}
     },
     
     setMapView: function() {
@@ -1100,7 +1230,7 @@
         this.prepareMapViewLegend();
         
         function predefinedMapLegendSetStoreCallback() {
-            Ext.getCmp('maplegendset_cb').setValue(this  .mapView.mapLegendSetId);
+            Ext.getCmp('maplegendset_cb').setValue(this.mapView.mapLegendSetId);
             this.applyPredefinedLegend(true);
         }
         
@@ -1134,7 +1264,7 @@
         this.prepareMapViewMap();
 
         if (MAPSOURCE == GLOBALS.conf.map_source_type_database) {
-            Ext.getCmp('map_tf').setValue(this.mapView.parentOrganisationUnitName);
+            Ext.getCmp('map_tf').setValue(this.mapView.organisationUnitSelectionTypeName);
             Ext.getCmp('map_tf').value = this.mapView.mapSource;
             this.loadFromDatabase(this.mapView.mapSource);
         }
@@ -1182,48 +1312,6 @@
 		});
 	},
     
-    loadFromDatabase: function(id, isDrillDown) {
-        function load() {
-            MASK.msg = i18n_loading_geojson;
-            MASK.show();
-            
-            this.parentId = id;
-            this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJson.action?parentId=' + this.parentId);
-        }
-        
-        if (isDrillDown) {
-            load.call(this);
-        }
-        else if (id != this.parentId || this.mapView) {
-            if (!this.mapView) {
-                if (!Ext.getCmp('map_tf').node.attributes.hasChildrenWithCoordinates) {
-                    Ext.message.msg(false, i18n_no_coordinates_found);
-                    Ext.getCmp('map_tf').setValue(Ext.getCmp('orgunit_tp').getNodeById(this.parentId).attributes.text);                    
-                    Ext.getCmp('map_tf').value = this.parentId;
-                    Ext.getCmp('map_tf').node = Ext.getCmp('orgunit_tp').getNodeById(this.parentId);
-                    return;
-                }
-            }
-            load.call(this);
-        }
-    },
-    
-    loadFromFile: function(url) {
-        if (url != this.newUrl) {
-            this.newUrl = url;
-
-            if (MAPSOURCE == GLOBALS.conf.map_source_type_geojson) {
-                this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJsonFromFile.action?name=' + url);
-            }
-			else if (MAPSOURCE == GLOBALS.conf.map_source_type_shapefile) {
-				this.setUrl(GLOBALS.conf.path_geoserver + GLOBALS.conf.wfs + url + GLOBALS.conf.output);
-			}
-        }
-        else {
-            this.classify(false, true);
-        }
-    },
-    
     validateForm: function(exception) {
         if (Ext.getCmp('mapvaluetype_cb').getValue() == GLOBALS.conf.map_value_type_indicator) {
             if (!Ext.getCmp('indicator_cb').getValue()) {
@@ -1284,7 +1372,7 @@
                 }
                 return false;
             }
-        }            
+        }
         
         return true;
     },
@@ -1300,6 +1388,7 @@
             periodId: Ext.getCmp('period_cb').getValue() || '',
             startDate: Ext.getCmp('startdate_df').getValue() || '',
             endDate: Ext.getCmp('enddate_df').getValue() || '',
+            organisationUnitSelectionType: this.organisationUnitSelectionType.value,
             mapSource: MAPSOURCE == GLOBALS.conf.map_source_type_database ? Ext.getCmp('map_tf').value : Ext.getCmp('map_cb').getValue(),
             mapLegendType: Ext.getCmp('maplegendtype_cb').getValue(),
             method: this.legend.type == GLOBALS.conf.map_legend_type_automatic ? Ext.getCmp('method_cb').getValue() : '',
@@ -1314,19 +1403,48 @@
         };
     },
     
-    applyValues: function() {
-        var options = {};
-        this.indicator = 'value';
-        options.indicator = this.indicator;
-        options.method = Ext.getCmp('method_cb').getValue();
-        options.numClasses = Ext.getCmp('numClasses_cb').getValue();
-        options.colors = this.getColors();
-        
-        this.coreComp.updateOptions(options);
-        this.coreComp.applyClassification();
-        this.classificationApplied = true;
-        
-        MASK.hide();
+    loadFromDatabase: function(id, isDrillDown) {
+        function load() {
+            MASK.msg = i18n_loading_geojson;
+            MASK.show();
+			
+            if (this.organisationUnitSelectionType.isParent()) {
+                this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJsonByParent.action?parentId=' + id);
+            }
+            else if (this.organisationUnitSelectionType.isLevel()) {
+                this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJsonByLevel.action?level=' + id);
+            }
+        }
+        
+        if (isDrillDown || this.mapView) {
+            load.call(this);
+        }
+        else {
+            if (this.organisationUnitSelectionType.isParent() && !Ext.getCmp('map_tf').node.attributes.hasChildrenWithCoordinates) {
+                Ext.message.msg(false, i18n_no_coordinates_found);
+                Ext.getCmp('map_tf').setValue(Ext.getCmp('orgunit_tp').getNodeById(this.organisationUnitSelectionType.parent).attributes.text);                    
+                Ext.getCmp('map_tf').value = this.organisationUnitSelectionType.parent;
+                Ext.getCmp('map_tf').node = Ext.getCmp('orgunit_tp').getNodeById(this.organisationUnitSelectionType.parent);
+                return;
+            }
+            load.call(this);
+        }
+    },
+    
+    loadFromFile: function(url) {
+        if (url != this.newUrl) {
+            this.newUrl = url;
+
+            if (MAPSOURCE == GLOBALS.conf.map_source_type_geojson) {
+                this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJsonFromFile.action?name=' + url);
+            }
+			else if (MAPSOURCE == GLOBALS.conf.map_source_type_shapefile) {
+				this.setUrl(GLOBALS.conf.path_geoserver + GLOBALS.conf.wfs + url + GLOBALS.conf.output);
+			}
+        }
+        else {
+            this.classify(false, true);
+        }
     },
 
     classify: function(exception, position) {
@@ -1362,14 +1480,16 @@
             }
             
             var dataUrl = this.valueType == GLOBALS.conf.map_value_type_indicator ?
-                'getIndicatorMapValuesByParentOrganisationUnit' : 'getDataMapValuesByParentOrganisationUnit';
+                (this.organisationUnitSelectionType.isParent() ? 'getIndicatorMapValuesByParent' : 'getIndicatorMapValuesByLevel') :
+                    (this.organisationUnitSelectionType.isLevel() ? 'getDataMapValuesByParent' : 'getDataMapValuesByLevel');
             
             var params = {
                 id: this.valueType == GLOBALS.conf.map_value_type_indicator ? Ext.getCmp('indicator_cb').getValue() : Ext.getCmp('dataelement_cb').getValue(),
                 periodId: MAPDATETYPE == GLOBALS.conf.map_date_type_fixed ? Ext.getCmp('period_cb').getValue() : null,
                 startDate: MAPDATETYPE == GLOBALS.conf.map_date_type_start_end ? new Date(Ext.getCmp('startdate_df').getValue()).format('Y-m-d') : null,
                 endDate: MAPDATETYPE == GLOBALS.conf.map_date_type_start_end ? new Date(Ext.getCmp('enddate_df').getValue()).format('Y-m-d') : null,
-                parentId: this.parentId
+                parentId: this.organisationUnitSelectionType.parent,
+                level: this.organisationUnitSelectionType.level
             };
                 
             Ext.Ajax.request({
@@ -1504,6 +1624,21 @@
         }
     },
     
+    applyValues: function() {
+        var options = {};
+        this.indicator = 'value';
+        options.indicator = this.indicator;
+        options.method = Ext.getCmp('method_cb').getValue();
+        options.numClasses = Ext.getCmp('numClasses_cb').getValue();
+        options.colors = this.getColors();
+        
+        this.coreComp.updateOptions(options);
+        this.coreComp.applyClassification();
+        this.classificationApplied = true;
+        
+        MASK.hide();
+    },
+    
     onRender: function(ct, position) {
         mapfish.widgets.geostat.Choropleth.superclass.onRender.apply(this, arguments);
         if (this.loadMask) {

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js	2010-10-21 15:51:37 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js	2010-10-29 11:24:12 +0000
@@ -62,8 +62,6 @@
 
 	bounds: false,
 
-    parentId: false,
-
     mapView: false,
 
     mapData: false,
@@ -72,19 +70,13 @@
     
     valueType: false,
     
-    stores: false,
-    
     selectFeatures: false,
     
+    organisationUnitSelectionType: false,
+    
     initComponent: function() {
-        
-        this.legend = {
-            type: GLOBALS.conf.map_legend_type_automatic,
-            method: GLOBALS.conf.classify_by_equal_intervals,
-            classes: 5
-        };
-        
-        this.valueType = GLOBALS.conf.map_value_type_indicator;
+    
+        this.initProperties();
         
         this.createItems();
         
@@ -118,6 +110,36 @@
         return [colorA, colorB];
     },
     
+    initProperties: function() {
+        this.legend = {
+            type: GLOBALS.conf.map_legend_type_automatic,
+            method: GLOBALS.conf.classify_by_equal_intervals,
+            classes: 5
+        };
+        
+        this.organisationUnitSelectionType = {
+            value: GLOBALS.conf.map_selection_type_parent,
+			parent: null,
+			level: null,
+            setParent: function(p) {
+                this.value = GLOBALS.conf.map_selection_type_parent;
+				this.parent = p;
+            },
+            setLevel: function(p) {
+                this.value = GLOBALS.conf.map_selection_type_level;
+				this.level = p;
+            },
+            isParent: function() {
+                return this.value == GLOBALS.conf.map_selection_type_parent;
+            },
+            isLevel: function() {
+                return this.value == GLOBALS.conf.map_selection_type_level;
+            }			
+        };
+        
+        this.valueType = GLOBALS.conf.map_value_type_indicator;
+    },
+    
     createItems: function() {
         this.items = [
         {
@@ -141,6 +163,7 @@
                     scope: this,
                     fn: function(cb) {
                         this.mapView = GLOBALS.stores.mapView.getAt(GLOBALS.stores.mapView.find('id', cb.getValue())).data;
+                        
                         this.legend.type = this.mapView.mapLegendType;
                         this.legend.method = this.mapView.method || this.legend.method;
                         this.legend.classes = this.mapView.classes || this.legend.classes;
@@ -499,7 +522,7 @@
         {
             xtype: 'textfield',
             id: 'map_tf2',
-            fieldLabel: i18n_parent_orgunit,
+            fieldLabel: 'Org. units',
             typeAhead: true,
             editable: false,
             valueField: 'id',
@@ -511,6 +534,7 @@
 			labelSeparator: GLOBALS.conf.labelseparator,
             selectOnFocus: true,
             width: GLOBALS.conf.combo_width,
+            node: {attributes: {hasChildrenWithCoordinates: false}},
             listeners: {
                 'focus': {
                     scope: this,
@@ -519,76 +543,170 @@
                             var value, rawvalue;
                             var w = new Ext.Window({
                                 id: 'orgunit_w2',
-                                title: 'Select parent organisation unit',
-                                closeAction: 'hide',
+                                title: 'Select organisation units',
+                                closeAction: 'close',
+                                layout: 'fit',
                                 autoScroll: true,
-                                width: 280,
-                                autoHeight: true,
-                                height: 'auto',
-                                boxMaxHeight: 500,
+                                width: 276,
+                                height: GLOBALS.util.getMultiSelectHeight() + 82,
+                                boxMaxHeight: GLOBALS.util.getMultiSelectHeight() + 82,
                                 items: [
                                     {
-                                        xtype: 'treepanel',
-                                        id: 'orgunit_tp2',
-                                        bodyStyle: 'padding:7px',
-                                        height: GLOBALS.util.getMultiSelectHeight(),
-                                        autoScroll: true,
-                                        loader: new Ext.tree.TreeLoader({
-                                            dataUrl: GLOBALS.conf.path_mapping + 'getOrganisationUnitChildren' + GLOBALS.conf.type
-                                        }),
-                                        root: {
-                                            id: TOPLEVELUNIT.id,
-                                            text: TOPLEVELUNIT.name,
-                                            hasChildrenWithCoordinates: TOPLEVELUNIT.hasChildrenWithCoordinates,
-                                            nodeType: 'async',
-                                            draggable: false,
-                                            expanded: true
+                                        xtype: 'tabpanel',
+                                        activeTab: 0,
+                                        layoutOnTabChange: false,
+                                        deferredRender: false,
+                                        plain: true,
+                                        listeners: {
+                                            tabchange: function(panel, tab) {
+                                                if (tab.id == 'maptab0_2') {
+                                                    w.setHeight(GLOBALS.util.getMultiSelectHeight() + 82);
+                                                    w.syncSize();
+                                                }
+                                                else if (tab.id == 'maptab1_2') {
+                                                    w.setHeight(152);
+                                                    w.syncSize();
+                                                }
+                                            }
                                         },
-                                        listeners: {
-                                            'click': {
-                                                fn: function(n) {
-                                                    if (n.hasChildNodes()) {
-                                                        tf.setValue(n.attributes.text);
-                                                        tf.value = n.attributes.id;
-                                                        tf.node = n;
-                                                    }
-                                                }
-                                            },
-                                            'expandnode': {
-                                                fn: function(n) {
-                                                    Ext.getCmp('orgunit_w2').syncSize();
-                                                }
-                                            },
-                                            'collapsenode': {
-                                                fn: function(n) {
-                                                    Ext.getCmp('orgunit_w2').syncSize();
-                                                }
-                                            }
-                                        }
-                                    },
-                                    {
-                                        xtype: 'panel',
-                                        layout: 'table',
                                         items: [
                                             {
-                                                xtype: 'button',
-                                                text: 'Select',
-                                                width: 133,
-                                                scope: this,
-                                                handler: function() {
-                                                    if (tf.getValue() && tf.getValue() != this.parentId) {
-                                                        this.loadFromDatabase(tf.value);
+                                                title: '<span class="panel-tab-title">Parent organisation unit</span>',
+                                                id: 'maptab0_2',
+                                                items: [
+                                                    {
+                                                        xtype: 'treepanel',
+                                                        id: 'orgunit_tp2',
+                                                        bodyStyle: 'padding:7px',
+                                                        height: GLOBALS.util.getMultiSelectHeight(),
+                                                        autoScroll: true,
+                                                        loader: new Ext.tree.TreeLoader({
+                                                            dataUrl: GLOBALS.conf.path_mapping + 'getOrganisationUnitChildren' + GLOBALS.conf.type
+                                                        }),
+                                                        root: {
+                                                            id: TOPLEVELUNIT.id,
+                                                            text: TOPLEVELUNIT.name,
+                                                            hasChildrenWithCoordinates: TOPLEVELUNIT.hasChildrenWithCoordinates,
+                                                            nodeType: 'async',
+                                                            draggable: false,
+                                                            expanded: true
+                                                        },
+                                                        listeners: {
+                                                            'click': {
+                                                                scope: this,
+                                                                fn: function(n) {
+                                                                    if (n.hasChildNodes()) {
+                                                                        tf.setValue(n.attributes.text);
+                                                                        tf.value = n.attributes.id;
+                                                                        tf.node = n;
+                                                                    }
+                                                                 }
+                                                            },
+                                                            'expandnode': {
+                                                                fn: function(n) {
+                                                                    Ext.getCmp('orgunit_w2').syncSize();
+                                                                }
+                                                            },
+                                                            'collapsenode': {
+                                                                fn: function(n) {
+                                                                    Ext.getCmp('orgunit_w2').syncSize();
+                                                                }
+                                                            }
+                                                        }
+                                                    },
+                                                    {
+                                                        xtype: 'panel',
+                                                        layout: 'table',
+                                                        items: [
+                                                            {
+                                                                xtype: 'button',
+                                                                text: 'Select',
+                                                                width: 130,
+                                                                scope: this,
+                                                                handler: function() {
+                                                                    if (tf.getValue()) {
+                                                                        this.organisationUnitSelectionType.setParent(tf.value);
+                                                                        this.loadFromDatabase(tf.value);
+                                                                    }
+                                                                    Ext.getCmp('orgunit_w2').close();
+                                                                }
+                                                            },
+                                                            {
+                                                                xtype: 'button',
+                                                                text: 'Cancel',
+                                                                width: 130,
+                                                                handler: function() {
+                                                                    Ext.getCmp('orgunit_w2').close();
+                                                                }
+                                                            }
+                                                        ]
                                                     }
-                                                    Ext.getCmp('orgunit_w2').hide();
-                                                }
+                                                ]
                                             },
                                             {
-                                                xtype: 'button',
-                                                text: 'Cancel',
-                                                width: 133,
-                                                handler: function() {
-                                                    Ext.getCmp('orgunit_w2').hide();
-                                                }
+                                                title: '<span class="panel-tab-title">Level</span>',
+                                                id: 'maptab1_2',
+                                                items: [
+                                                    {
+                                                        xtype: 'panel',
+                                                        bodyStyle: 'padding:8px',
+                                                        items: [
+                                                            { html: '<div class="window-field-label-first">Level</div>' },
+                                                            {
+                                                                xtype: 'combo',
+                                                                id: 'maporganisationunitlevel_cb2',
+                                                                typeAhead: true,
+                                                                editable: false,
+                                                                valueField: 'level',
+                                                                displayField: 'name',
+                                                                mode: 'remote',
+                                                                forceSelection: true,
+                                                                triggerAction: 'all',
+                                                                emptyText: GLOBALS.conf.emptytext,
+                                                                labelSeparator: GLOBALS.conf.labelseparator,
+                                                                selectOnFocus: true,
+                                                                width: GLOBALS.conf.combo_width,
+                                                                store: GLOBALS.stores.organisationUnitLevel,
+                                                                listeners: {
+                                                                    'select': function(cb) {
+                                                                        tf.setValue(cb.getRawValue());
+                                                                        tf.value = cb.getValue();
+                                                                    }
+                                                                }                                                                        
+                                                            }
+                                                        ]
+                                                    },
+                                                    
+                                                    { html: '<br>' },
+                                                    
+                                                    {
+                                                        xtype: 'panel',
+                                                        layout: 'table',
+                                                        items: [
+                                                            {
+                                                                xtype: 'button',
+                                                                text: 'Select',
+                                                                width: 130,
+                                                                scope: this,
+                                                                handler: function() {
+                                                                    if (tf.value) {
+                                                                        this.organisationUnitSelectionType.setLevel(tf.value);
+                                                                        this.loadFromDatabase(tf.value);
+                                                                    }
+                                                                    Ext.getCmp('orgunit_w2').close();
+                                                                }
+                                                            },
+                                                            {
+                                                                xtype: 'button',
+                                                                text: 'Cancel',
+                                                                width: 130,
+                                                                handler: function() {
+                                                                    Ext.getCmp('orgunit_w2').close();
+                                                                }
+                                                            }
+                                                        ]
+                                                    }
+                                                ]
                                             }
                                         ]
                                     }
@@ -822,8 +940,15 @@
     },
     
     createSelectFeatures: function() {
+        var scope = this;
+        
         var onHoverSelect = function onHoverSelect(feature) {
-            Ext.getCmp('featureinfo_l').setText('<div style="color:black">' + feature.attributes[proportionalSymbol.mapData.nameColumn] + '</div><div style="color:#555">' + feature.attributes.value + '</div>', false);
+            if (ACTIVEPANEL == GLOBALS.conf.thematicMap2) {
+                Ext.getCmp('featureinfo_l').setText('<div style="color:black">' + feature.attributes[proportionalSymbol.mapData.nameColumn] + '</div><div style="color:#555">' + feature.attributes.value + '</div>', false);
+            }
+            else if (ACTIVEPANEL == GLOBALS.conf.organisationUnitAssignment) {
+                Ext.getCmp('featureinfo_l').setText('<div style="color:black">' + feature.attributes[mapping.mapData.nameColumn] + '</div>', false);
+            }
         };
         
         var onHoverUnselect = function onHoverUnselect(feature) {
@@ -835,7 +960,7 @@
             var x = east_panel.x - 210;
             var y = east_panel.y + 41;
             
-            if (MAPSOURCE == GLOBALS.conf.map_source_type_database) {
+            if (ACTIVEPANEL == GLOBALS.conf.thematicMap2 && MAPSOURCE == GLOBALS.conf.map_source_type_database) {
                 if (feature.attributes.hasChildrenWithCoordinates) {
                     if (lfw) {
                         lfw.destroy();
@@ -843,12 +968,41 @@
                     
                     Ext.getCmp('map_tf2').setValue(feature.data.name);
                     Ext.getCmp('map_tf2').value = feature.attributes.id;
+                    scope.organisationUnitSelectionType.setParent(feature.attributes.id);
                     proportionalSymbol.loadFromDatabase(feature.attributes.id, true);
                 }
                 else {
                     Ext.message.msg(false, i18n_no_coordinates_found);
                 }
             }
+            
+            if (ACTIVEPANEL == GLOBALS.conf.organisationUnitAssignment && MAPSOURCE != GLOBALS.conf.map_source_type_database) {
+                if (selectFeaturePopup) {
+                    selectFeaturePopup.destroy();
+                }
+                
+                var popup = new Ext.Window({
+                    title: '<span class="panel-title">Assign organisation unit</span>',
+                    width: 180,
+                    height: 65,
+                    layout: 'fit',
+                    plain: true,
+                    html: '<div class="window-orgunit-text">' + feature.attributes[mapping.mapData.nameColumn] + '</div>',
+                    x: x,
+                    y: y,
+                    listeners: {
+                        'close': {
+                            fn: function() {
+                                mapping.relation = false;
+                            }
+                        }
+                    }
+                });
+                
+                selectFeaturePopup = popup;		
+                popup.show();
+                mapping.relation = feature.attributes[mapping.mapData.nameColumn];
+            }
         };
         
         this.selectFeatures = new OpenLayers.Control.newSelectFeature(
@@ -865,7 +1019,7 @@
     
     prepareMapViewValueType: function() {
         var obj = {};
-        
+
         if (this.valueType == GLOBALS.conf.map_value_type_indicator) {
             Ext.getCmp('indicatorgroup_cb2').showField();
             Ext.getCmp('indicator_cb2').showField();
@@ -979,6 +1133,14 @@
             Ext.getCmp('map_cb2').showField();
             Ext.getCmp('map_tf2').hideField();
         }
+		
+		if (this.mapView.organisationUnitSelectionType == GLOBALS.conf.map_selection_type_parent ||
+			this.mapView.organisationUnitSelectionType == null) {
+				this.organisationUnitSelectionType.setParent(this.mapView.mapSource);
+		}
+		else if (this.mapView.organisationUnitSelectionType == GLOBALS.conf.map_selection_type_level) {
+			this.organisationUnitSelectionType.setLevel(this.mapView.mapSource);
+		}
     },
     
     setMapView: function() {
@@ -1021,7 +1183,7 @@
                 this.setMapViewLegend();
             }});
         }
-        
+
         if (obj.stores.valueTypeGroup.isLoaded) {
             valueTypeGroupStoreCallback.call(this);
         }
@@ -1070,7 +1232,7 @@
         this.prepareMapViewMap();
 
         if (MAPSOURCE == GLOBALS.conf.map_source_type_database) {
-            Ext.getCmp('map_tf2').setValue(this.mapView.parentOrganisationUnitName);
+            Ext.getCmp('map_tf2').setValue(this.mapView.organisationUnitSelectionTypeName);
             Ext.getCmp('map_tf2').value = this.mapView.mapSource;
             this.loadFromDatabase(this.mapView.mapSource);
         }
@@ -1117,48 +1279,6 @@
 			}
 		});
 	},
-
-    loadFromDatabase: function(id, isDrillDown) {
-        function load() {
-            MASK.msg = i18n_loading_geojson;
-            MASK.show();
-            
-            this.parentId = id;
-            this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJson.action?parentId=' + this.parentId);
-        }
-        
-        if (isDrillDown) {
-            load.call(this);
-        }
-        else if (id != this.parentId || this.mapView) {
-            if (!this.mapView) {
-                if (!Ext.getCmp('map_tf2').node.attributes.hasChildrenWithCoordinates) {
-                    Ext.message.msg(false, i18n_no_coordinates_found);
-                    Ext.getCmp('map_tf2').setValue(Ext.getCmp('orgunit_tp2').getNodeById(this.parentId).attributes.text);                    
-                    Ext.getCmp('map_tf2').value = this.parentId;
-                    Ext.getCmp('map_tf2').node = Ext.getCmp('orgunit_tp2').getNodeById(this.parentId);
-                    return;
-                }
-            }
-            load.call(this);
-        }
-    },
-    
-    loadFromFile: function(url) {
-        if (url != this.newUrl) {
-            this.newUrl = url;
-
-            if (MAPSOURCE == GLOBALS.conf.map_source_type_geojson) {
-                this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJsonFromFile.action?name=' + url);
-            }
-			else if (MAPSOURCE == GLOBALS.conf.map_source_type_shapefile) {
-				this.setUrl(GLOBALS.conf.path_geoserver + GLOBALS.conf.wfs + url + GLOBALS.conf.output);
-			}
-        }
-        else {
-            this.classify(false, true);
-        }
-    },
     
     validateForm: function(exception) {
         if (Ext.getCmp('mapvaluetype_cb2').getValue() == GLOBALS.conf.map_value_type_indicator) {
@@ -1220,7 +1340,7 @@
                 }
                 return false;
             }
-        }            
+        }
         
         return true;
     },
@@ -1236,8 +1356,8 @@
             periodId: Ext.getCmp('period_cb2').getValue() || '',
             startDate: Ext.getCmp('startdate_df2').getValue() || '',
             endDate: Ext.getCmp('enddate_df2').getValue() || '',
-            mapSource: MAPSOURCE == GLOBALS.conf.map_source_type_database ?
-                Ext.getCmp('map_tf2').value : Ext.getCmp('map_cb2').getValue(),
+            organisationUnitSelectionType: this.organisationUnitSelectionType.value,
+            mapSource: MAPSOURCE == GLOBALS.conf.map_source_type_database ? Ext.getCmp('map_tf2').value : Ext.getCmp('map_cb2').getValue(),
             mapLegendType: Ext.getCmp('maplegendtype_cb2').getValue(),
             method: this.legend.type == GLOBALS.conf.map_legend_type_automatic ? Ext.getCmp('method_cb2').getValue() : '',
             classes: this.legend.type == GLOBALS.conf.map_legend_type_automatic ? Ext.getCmp('numClasses_cb2').getValue() : '',
@@ -1251,19 +1371,48 @@
         };
     },
     
-    applyValues: function() {
-        var options = {};
-        this.indicator = 'value';
-        options.indicator = this.indicator;
-        options.method = Ext.getCmp('method_cb2').getValue();
-        options.numClasses = Ext.getCmp('numClasses_cb2').getValue();
-        options.colors = this.getColors();
-        
-        this.coreComp.updateOptions(options);
-        this.coreComp.applyClassification();
-        this.classificationApplied = true;
-        
-        MASK.hide();
+    loadFromDatabase: function(id, isDrillDown) {
+        function load() {
+            MASK.msg = i18n_loading_geojson;
+            MASK.show();
+			
+            if (this.organisationUnitSelectionType.isParent()) {
+                this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJsonByParent.action?parentId=' + id);
+            }
+            else if (this.organisationUnitSelectionType.isLevel()) {
+                this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJsonByLevel.action?level=' + id);
+            }
+        }
+        
+        if (isDrillDown || this.mapView) {
+            load.call(this);
+        }
+        else {
+            if (this.organisationUnitSelectionType.isParent() && !Ext.getCmp('map_tf2').node.attributes.hasChildrenWithCoordinates) {
+                Ext.message.msg(false, i18n_no_coordinates_found);
+                Ext.getCmp('map_tf2').setValue(Ext.getCmp('orgunit_tp2').getNodeById(this.organisationUnitSelectionType.parent).attributes.text);                    
+                Ext.getCmp('map_tf2').value = this.organisationUnitSelectionType.parent;
+                Ext.getCmp('map_tf2').node = Ext.getCmp('orgunit_tp2').getNodeById(this.organisationUnitSelectionType.parent);
+                return;
+            }
+            load.call(this);
+        }
+    },
+    
+    loadFromFile: function(url) {
+        if (url != this.newUrl) {
+            this.newUrl = url;
+
+            if (MAPSOURCE == GLOBALS.conf.map_source_type_geojson) {
+                this.setUrl(GLOBALS.conf.path_mapping + 'getGeoJsonFromFile.action?name=' + url);
+            }
+			else if (MAPSOURCE == GLOBALS.conf.map_source_type_shapefile) {
+				this.setUrl(GLOBALS.conf.path_geoserver + GLOBALS.conf.wfs + url + GLOBALS.conf.output);
+			}
+        }
+        else {
+            this.classify(false, true);
+        }
     },
 
     classify: function(exception, position) {
@@ -1279,7 +1428,7 @@
         if (this.validateForm(exception)) {
             MASK.msg = i18n_aggregating_map_values;
             MASK.show();
-            
+
             if (!position) {
                 MAP.zoomToExtent(this.layer.getDataExtent());
             }
@@ -1299,14 +1448,16 @@
             }
             
             var dataUrl = this.valueType == GLOBALS.conf.map_value_type_indicator ?
-                'getIndicatorMapValuesByParentOrganisationUnit' : 'getDataMapValuesByParentOrganisationUnit';
+                (this.organisationUnitSelectionType.isParent() ? 'getIndicatorMapValuesByParent' : 'getIndicatorMapValuesByLevel') :
+                    (this.organisationUnitSelectionType.isLevel() ? 'getDataMapValuesByParent' : 'getDataMapValuesByLevel');
             
             var params = {
                 id: this.valueType == GLOBALS.conf.map_value_type_indicator ? Ext.getCmp('indicator_cb2').getValue() : Ext.getCmp('dataelement_cb2').getValue(),
                 periodId: MAPDATETYPE == GLOBALS.conf.map_date_type_fixed ? Ext.getCmp('period_cb2').getValue() : null,
                 startDate: MAPDATETYPE == GLOBALS.conf.map_date_type_start_end ? new Date(Ext.getCmp('startdate_df2').getValue()).format('Y-m-d') : null,
                 endDate: MAPDATETYPE == GLOBALS.conf.map_date_type_start_end ? new Date(Ext.getCmp('enddate_df2').getValue()).format('Y-m-d') : null,
-                parentId: this.parentId
+                parentId: this.organisationUnitSelectionType.parent,
+                level: this.organisationUnitSelectionType.level
             };
                 
             Ext.Ajax.request({
@@ -1441,6 +1592,21 @@
         }
     },
     
+    applyValues: function() {
+        var options = {};
+        this.indicator = 'value';
+        options.indicator = this.indicator;
+        options.method = Ext.getCmp('method_cb2').getValue();
+        options.numClasses = Ext.getCmp('numClasses_cb2').getValue();
+        options.colors = this.getColors();
+        
+        this.coreComp.updateOptions(options);
+        this.coreComp.applyClassification();
+        this.classificationApplied = true;
+        
+        MASK.hide();
+    },
+    
     onRender: function(ct, position) {
         mapfish.widgets.geostat.Symbol.superclass.onRender.apply(this, arguments);
         if (this.loadMask) {
@@ -1464,4 +1630,4 @@
     }   
 });
 
-Ext.reg('proportionalSymbol', mapfish.widgets.geostat.Symbol);
\ No newline at end of file
+Ext.reg('choropleth', mapfish.widgets.geostat.Symbol);
\ No newline at end of file