gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / OSMUtils.java @ 9465
History | View | Annotate | Download (2.77 KB)
1 |
package org.gvsig.online.swing.impl; |
---|---|
2 |
|
3 |
import java.net.URISyntaxException; |
4 |
import java.net.URL; |
5 |
import org.gvsig.fmap.dal.DALLocator; |
6 |
import org.gvsig.fmap.dal.DataStore; |
7 |
import org.gvsig.fmap.dal.DataStoreParameters; |
8 |
import org.gvsig.fmap.dal.exception.InitializeException; |
9 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
10 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
11 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
12 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
13 |
import org.slf4j.Logger; |
14 |
import org.slf4j.LoggerFactory; |
15 |
|
16 |
/*
|
17 |
* To change this license header, choose License Headers in Project Properties.
|
18 |
* To change this template file, choose Tools | Templates
|
19 |
* and open the template in the editor.
|
20 |
*/
|
21 |
/**
|
22 |
*
|
23 |
* @author jjdelcerro
|
24 |
*/
|
25 |
@SuppressWarnings("UseSpecificCatch") |
26 |
public class OSMUtils { |
27 |
|
28 |
private static final Logger LOGGER = LoggerFactory.getLogger(OSMUtils.class); |
29 |
|
30 |
private static final String FIELD_URI = "uri"; |
31 |
private static final String FIELD_SUFFIX = "suffix"; |
32 |
|
33 |
private static final String FIELD_MAX_RES_LEVEL = "maxResolutionLevel"; |
34 |
private static final String FIELD_NAME = "name"; |
35 |
|
36 |
private static final String FIELD_PARAMETERS = "parameters"; |
37 |
private static final String FIELD_DELETECACHE = "deletecache"; |
38 |
|
39 |
public static FLayer createOSMLayer() { //String name, URL host, String layers, String srs) { |
40 |
try {
|
41 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
42 |
DataStoreParameters parameters = dataman.createStoreParameters("OSM Raster");
|
43 |
URL selectedURL = new URL("https://tile.openstreetmap.org/"); |
44 |
try {
|
45 |
parameters.setDynValue(FIELD_URI, selectedURL.toURI()); |
46 |
} catch (URISyntaxException e1) { |
47 |
LOGGER.warn("Can't convert URI from " + selectedURL.toString(), e1);
|
48 |
throw new InitializeException(e1); |
49 |
} |
50 |
parameters.setDynValue(FIELD_SUFFIX, "png");
|
51 |
parameters.setDynValue(FIELD_NAME, "Mapnik");
|
52 |
try {
|
53 |
parameters.setDynValue(FIELD_MAX_RES_LEVEL, 18);
|
54 |
} catch (NumberFormatException e) { |
55 |
|
56 |
} |
57 |
|
58 |
DataStoreParameters tileParams = dataman.createStoreParameters("Tile Store");
|
59 |
tileParams.setDynValue(FIELD_PARAMETERS, parameters); |
60 |
tileParams.setDynValue(FIELD_DELETECACHE, false);
|
61 |
DataStore store = dataman.openStore("Tile Store", tileParams);
|
62 |
|
63 |
MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
64 |
FLayer layer = mapContextManager.createLayer("Mapnik", store);
|
65 |
|
66 |
return layer;
|
67 |
} catch (Throwable ex) { |
68 |
LOGGER.warn("Can't create OSM layer", ex);
|
69 |
return null; |
70 |
} |
71 |
} |
72 |
|
73 |
} |