Open wikiro opened 11 years ago
CloudMade - use yours API_KEY
public class CommonMap extends FlowPanel { private MapWidget mapWidget; public CommonMap(double lat, double lon, int zoom, int mapTypeId) { MapTypeControlOptions controlOptions = MapTypeControlOptions.newInstance(); controlOptions.setMapTypeIds(new String[] { "CloudMade", "MapQuest", "OSM", MapTypeId.ROADMAP.toString(), MapTypeId.HYBRID.toString(), MapTypeId.SATELLITE.toString(), MapTypeId.TERRAIN.toString()}); setStyleName("commonMap"); MapOptions options = MapOptions.newInstance(); options.setZoom(zoom); options.setCenter(LatLng.newInstance(lat, lon)); options.setMapTypeControlOptions(controlOptions); ZoomControlOptions zoomControlOptions = ZoomControlOptions.newInstance(); zoomControlOptions.setPosition(ControlPosition.RIGHT_CENTER); zoomControlOptions.setStyle(ZoomControlStyle.SMALL); options.setZoomControlOptions(zoomControlOptions); ImageMapType osmMapType = getOsmMapType(); ImageMapType mapQuestType = getMapQuestType(); ImageMapType cloudMade = getCloudMadeType(); mapWidget = new MapWidget(options); mapWidget.addStyleName("map"); mapWidget.getMapTypeRegistry().set("OSM", osmMapType); mapWidget.getMapTypeRegistry().set("MapQuest", mapQuestType); mapWidget.getMapTypeRegistry().set("CloudMade", cloudMade); add(mapWidget); if (mapTypeId == 2) { mapWidget.setMapTypeId("OSM"); } else { mapWidget.setMapTypeId(MapTypeId.ROADMAP.toString()); } } private ImageMapType getOsmMapType() { ImageMapTypeOptions opts = ImageMapTypeOptions.newInstance(); opts.setMaxZoom(20); opts.setMinZoom(1); opts.setName("OSM"); opts.setTileSize(Size.newInstance(256, 256)); opts.setTileUrl(new TileUrlCallBack() { public String getTileUrl(Point point, int zoom) { return "http://tile.openstreetmap.org/" + zoom + "/" + ((int) point.getX()) + "/" + ((int) point.getY()) + ".png"; } }); return ImageMapType.newInstance(opts); } private ImageMapType getMapQuestType() { ImageMapTypeOptions opts = ImageMapTypeOptions.newInstance(); opts.setMaxZoom(20); opts.setMinZoom(1); opts.setName("MapQuest"); opts.setTileSize(Size.newInstance(256, 256)); opts.setTileUrl(new TileUrlCallBack() { public String getTileUrl(Point point, int zoom) { return "http://otile1.mqcdn.com/tiles/1.0.0/osm/" + zoom + "/" + ((int) point.getX()) + "/" + ((int) point.getY()) + ".png"; } }); return ImageMapType.newInstance(opts); } private ImageMapType getCloudMadeType() { ImageMapTypeOptions opts = ImageMapTypeOptions.newInstance(); opts.setMaxZoom(20); opts.setMinZoom(1); opts.setName("CloudMade"); opts.setTileSize(Size.newInstance(256, 256)); opts.setTileUrl(new TileUrlCallBack() { public String getTileUrl(Point point, int zoom) { //return "http://b.tile.cloudmade.com/<YOUR_API_HERE>/997/256/" + zoom + "/" + ((int) point.getX()) + "/" + ((int) point.getY()) + ".png"; } }); return ImageMapType.newInstance(opts); } }
Thanks for the snippets :)
That is a nice feature add you have on you map. :)
CloudMade - use yours API_KEY