Exemple de recouvrement de couche de grille

Le code suivant montre comment créer un recouvrement GridLayer et l'utiliser dans une requête pour obtenir une carte nommée.

Notez l'utilisation de CustomInflectionCollection, dans laquelle les couleurs sont indiquées pour chaque inflexion.

Sinon, vous pouvez utiliser ComputedInflectionCollection avec une couleur de début et de fin et un certain nombre d'inflexions. La couleur est répartie de manière uniforme sur le nombre d'inflexions.

Pour obtenir des explications sur les éléments GridLayer, reportez-vous à la section Éléments GridLayer.

public class RenderNamedMapWithGridLayerOverlay {

	public static void main(String[] args) {
        try {
            MappingServiceInterface mapping = Preference.getServiceinterface();
            Point mapCenter = BuildGeometry.buildPoint("mapinfo:coordsys 12, 62, 7, 0.0", 0, 0, null);
            MapView mapView = MappingView.getZoomAndCenterMapView(mapCenter,MappingUtility.buildDistance(19000, DistanceUnit.KILOMETER));

            NamedTable namedTable = new NamedTable();
            namedTable.setName("/Samples/NamedTables/WorldcapTable");
            
            Distance cellWidth = MappingUtility.buildDistance(50, DistanceUnit.MILE);
            
            IDWInterpolator interpolator = new IDWInterpolator();
            interpolator.setAggregationMethod(AggregationMethod.AVERAGE);
            interpolator.setExponent(2);
            interpolator.setMaxPoints(25);
            interpolator.setSearchRadius(100);
            
            CustomInflectionCollection inflectionCollection = new CustomInflectionCollection();
            inflectionCollection.setInflectionMethod(InflectionMethod.EQUAL_COUNT);
            inflectionCollection.setRoundBy(0.1);
            
            InflectionColorBinList inBinList = new InflectionColorBinList();
            
            InflectionColorBin red = new InflectionColorBin();            
            red.setColor("RED");
            inBinList.getInflectionColorBin().add(red);            
            
            InflectionColorBin yellow = new InflectionColorBin();            
            yellow.setColor("YELLOW");
            inBinList.getInflectionColorBin().add(yellow);
            
            InflectionColorBin green = new InflectionColorBin();            
            green.setColor("GREEN");
            inBinList.getInflectionColorBin().add(green);
            
            InflectionColorBin rgb = new InflectionColorBin();            
            rgb.setColor("rgb(0,255,255)");
            inBinList.getInflectionColorBin().add(rgb);
            
            InflectionColorBin blue = new InflectionColorBin();            
            blue.setColor("BLUE"); 
            inBinList.getInflectionColorBin().add(blue);
            
            inflectionCollection.setInflectionColorBinList(inBinList);

            //Creating GridEnvelope
            List<Pos> pointList = new ArrayList<Pos>(2); 
            pointList.add(BuildGeometry.buildPos(-1.6190368438028984E7, -5501153.098687401, null));
            pointList.add(BuildGeometry.buildPos(1.6606614137907444E7, 6743291.671893631, null));
            Envelope gridEnvelope = BuildGeometry.buildEnvelope("mapinfo:coordsys 12, 62, 7, 0.0", pointList);

            //Creating GridLayer
            Layer gridLayer	= MappingUtility.buildGridLayer(namedTable, null, cellWidth, "Cap_Pop", "Obj", interpolator, inflectionCollection, gridEnvelope);
           
            RenderNamedMapWithOverlayRequest  request = MappingServiceRequestBuilder.createRenderNamedMapOverlayRequest
            ("RenderNamedMapWithGridLayerOverlay","/Samples/NamedMaps/WorldMap", mapView, gridLayer);
            
            RenderNamedMapWithOverlayResponse response = mapping.renderNamedMapWithOverlay(request);
            
            PrintMappingResponse.printRenderNamedMapWithOverlayResponse(response);
        }
        catch (ServiceException se) {
        	PrintMappingResponse.printError(se);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

}