Ejemplo de superposición de capa de cuadrícula

El siguiente código muestra cómo crear una superposión de GridLayer y su uso en una solicitud de un mapa con nombre asignado.

Tenga en cuenta el uso de CustomInflectionCollection, mediante el cual se especifican los colores para cada inflexión.

Como alternativa, puede utilizar una ComputedInflectionCollection con un color de inicio y final y número de inflexiones. El color se esparce de manera uniforma en el número de inflexiones.

Consulte Elementos de GridLayer, para obtener una explicación de los elementos de 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();
        }
    }

}