GridStyle

GridStyle est un Style qui prend une liste d'inflexions pour GridLayer. Chaque inflexion est constituée d'une valeur, d'une couleur et, en option, d'une description.

Exemple SOAP

La requête SOAP suivante crée une carte avec une GridLayer dont le style est conforme à GridStyle (la couleur et la valeur de chaque inflexion sont fournies dans une liste d'inflexions).


package com.pb;

import com.mapinfo.midev.service.mappingcommon.v1.AggregationMethod;
import com.mapinfo.midev.service.units.v1.Distance;
import com.mapinfo.midev.service.units.v1.DistanceUnit;
import com.mapinfo.midev.service.mapping.v1.GridLayer;
import com.mapinfo.midev.service.mappingcommon.v1.IDWInterpolator;
import com.mapinfo.midev.service.mapping.v1.Map;
import com.mapinfo.midev.service.mapping.v1.MapImage;
import com.mapinfo.midev.service.mapping.ws.v1.MappingService;
import com.mapinfo.midev.service.mapping.ws.v1.MappingServiceInterface;
import com.mapinfo.midev.service.table.v1.NamedTable;
import com.mapinfo.midev.service.geometries.v1.Point;
import com.mapinfo.midev.service.geometries.v1.Pos;
import com.mapinfo.midev.service.mapping.v1.RenderMapRequest;
import com.mapinfo.midev.service.mapping.v1.RenderMapResponse;
import com.mapinfo.midev.service.mapping.ws.v1.ServiceException;
import com.mapinfo.midev.service.mapping.v1.ZoomAndCenterMapView;
import com.mapinfo.midev.service.style.v1.GridStyle;
import com.mapinfo.midev.service.style.v1.Inflection;
import com.mapinfo.midev.service.style.v1.InflectionListType;

import javax.xml.ws.BindingProvider;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

public final class GridStyleInflectionExample {
	private static final File DESTINATION_PATH = new File("c:/temp/GridStyleInflectionExample.png"); // where the map image will be saved
	private static final String MIME_TYPE = "image/png";        // MIME type of the map image
	private static final String STATE_CAP_TABLE_NAME = "/Samples/NamedTables/USA_CAPS";

	private static final String USERNAME = "admin";     // the username to access the Mapping Service
	private static final String PASSWORD = "admin";     // the password to access the Mapping Service

	public static void main(String[] args) throws ServiceException, IOException {
		MappingService mappingService = new MappingService();
		MappingServiceInterface mappingServiceInterface = mappingService.getMappingServiceInterface();

		// set credentials to access the service
		java.util.Map<String, Object> requestContext = ((BindingProvider) mappingServiceInterface).getRequestContext();
		requestContext.put(BindingProvider.USERNAME_PROPERTY, USERNAME);
		requestContext.put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);

		RenderMapRequest renderMapRequest = new RenderMapRequest();

		GridLayer gridLayer = new GridLayer();
			{
				NamedTable stateCapTable = new NamedTable();
				stateCapTable.setName(STATE_CAP_TABLE_NAME);

				gridLayer.setTable(stateCapTable);
			}

			{
				InflectionListType inflectionListType = new InflectionListType();

				List<Inflection> inflections = inflectionListType.getInflection();

				Inflection inflection;

				inflection = new Inflection();
				inflection.setValue(5000);
				inflection.setColor("yellow");
				inflections.add(inflection);

				inflection = new Inflection();
				inflection.setValue(20000);
				inflection.setColor("green");
				inflections.add(inflection);

				inflection = new Inflection();
				inflection.setValue(50000);
				inflection.setColor("blue");
				inflections.add(inflection);

				inflection = new Inflection();
				inflection.setValue(100000);
				inflection.setColor("red");
				inflections.add(inflection);

				inflection = new Inflection();
				inflection.setValue(200000);
				inflection.setColor("white");
				inflections.add(inflection);

				GridStyle gridStyle = new GridStyle();
				gridStyle.setInflectionList(inflectionListType);

				gridLayer.setStyle(gridStyle);
			}

			{
				Distance cellWidth = new Distance();
				cellWidth.setValue(18.1);
				cellWidth.setUom(DistanceUnit.MILE);
				gridLayer.setCellWidth(cellWidth);
			}

				gridLayer.setValueExpression("Pop_1990");

				gridLayer.setSpatialExpression("Obj");

			{
				IDWInterpolator interpolator = new IDWInterpolator();
				interpolator.setSearchRadius(1810);
				interpolator.setExponent(2);
				interpolator.setMaxPoints(20);
				interpolator.setAggregationMethod(AggregationMethod.AVERAGE);
				gridLayer.setInterpolator(interpolator);
			}

			{
				Map map = new Map();
				map.getLayer().add(gridLayer);
				renderMapRequest.setMap(map);
			}

			{
				ZoomAndCenterMapView mapView = new ZoomAndCenterMapView();
				Point center = new Point();
				center.setSrsName("epsg:4267");
				Pos pos = new Pos();
				pos.setX(-97);
				pos.setY(36);
				center.setPos(pos);
				mapView.setMapCenter(center);
				Distance zoom = new Distance();
				zoom.setValue(3350);
				zoom.setUom(DistanceUnit.MILE);
				mapView.setZoomLevel(zoom);

				mapView.setWidth(800);
				mapView.setHeight(600);

				renderMapRequest.setMapView(mapView);
			}

			{
				renderMapRequest.setImageMimeType(MIME_TYPE);
			}

			renderMapRequest.setReturnImage(true);

			RenderMapResponse renderMapResponse = mappingServiceInterface.renderMap(renderMapRequest);

			MapImage mapImage = renderMapResponse.getMapImage();

			byte[] imagePng = mapImage.getImage();

			OutputStream os = new FileOutputStream(DESTINATION_PATH);
			os.write(imagePng);
			os.close();
	}
}
				
			

Exemple REST

L'exemple suivant est un objet JSON décrivant GridStyle InflectionList pour une requête REST.


{
	"inflectionList": {
		"inflection": [{
			"color": "yellow",
			"description": "",
			"value": 5000
		},
		{
			"color": "green",
			"description": "",
			"value": 20000
		},
		{
			"color": "blue",
			"description": "",
			"value": 50000
		},
		{
			"color": "red",
			"description": "",
			"value": 100000
		},
		{
			"color": "white",
			"description": "",
			"value": 200000
		}]
	}
}