Beispiel für ein GridLayer-Overlay

Der folgende Code zeigt, wie ein GridLayer-Overlay erstellt und in einer Anforderung für eine benannte Karte verwendet wird.

Beachten Sie die Verwendung von CustomInflectionCollection, wobei die Farben für jede Flexion angegeben sind.

Alternativ können Sie ComputedInflectionCollection mit einer Start- und Endfarbe und einer Anzahl von Flexionen verwenden. Die Farbe wird ebenmäßig über die Anzahl der Flexionen verteilt.

Eine Erklärung der GridLayer-Elemente finden Sie unter GridLayer-Elemente.

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();
        }
    }

}