|
15 | 15 | * You should have received a copy of the GNU Lesser General Public License along with
|
16 | 16 | * this program. If not, see <http://www.gnu.org/licenses/>.
|
17 | 17 | */
|
18 |
| -package org.oscim.android.test; |
19 |
| - |
20 |
| -import android.content.Context; |
21 |
| -import android.os.Bundle; |
22 |
| -import android.view.View; |
23 |
| -import android.widget.Toast; |
24 |
| -import android.widget.ToggleButton; |
25 |
| -import io.jeo.map.Style; |
26 |
| -import io.jeo.vector.VectorDataset; |
27 |
| -import org.oscim.backend.CanvasAdapter; |
28 |
| -import org.oscim.backend.canvas.Color; |
29 |
| -import org.oscim.layers.OSMIndoorLayer; |
30 |
| -import org.oscim.layers.tile.buildings.BuildingLayer; |
31 |
| -import org.oscim.layers.tile.vector.labeling.LabelLayer; |
32 |
| -import org.oscim.test.JeoTest; |
33 |
| -import org.oscim.theme.internal.VtmThemes; |
34 |
| -import org.oscim.theme.styles.TextStyle; |
35 |
| -import org.oscim.utils.IOUtils; |
36 |
| -import org.slf4j.Logger; |
37 |
| -import org.slf4j.LoggerFactory; |
38 |
| - |
39 |
| -import java.io.IOException; |
40 |
| -import java.io.InputStream; |
41 |
| -import java.net.URL; |
42 |
| -import java.net.URLConnection; |
43 |
| -import java.util.Arrays; |
44 |
| - |
45 |
| -public class JeoIndoorActivity extends BaseMapActivity { |
46 |
| - public static final Logger log = LoggerFactory.getLogger(JeoIndoorActivity.class); |
47 |
| - |
48 |
| - // from http://overpass-turbo.eu/s/2vp |
49 |
| - String PATH = "https://gist.githubusercontent.com/anonymous/09062103a66844a96048f25626078c8d/raw/1d3af6a5a55e9ea4adc9551fa633a051a44a5a9c/overpass.geojson"; |
50 |
| - |
51 |
| - private OSMIndoorLayer mIndoorLayer; |
52 |
| - |
53 |
| - public JeoIndoorActivity() { |
54 |
| - super(R.layout.jeo_indoor_map); |
55 |
| - } |
56 |
| - |
57 |
| - @Override |
58 |
| - public void onCreate(Bundle savedInstanceState) { |
59 |
| - super.onCreate(savedInstanceState); |
60 |
| - |
61 |
| - mMap.addTask(new Runnable() { |
62 |
| - @Override |
63 |
| - public void run() { |
64 |
| - showToast("load data"); |
65 |
| - InputStream is = null; |
66 |
| - try { |
67 |
| - // File file = new File(Environment.getExternalStorageDirectory() |
68 |
| - // .getAbsolutePath(), "osmindoor.json"); |
69 |
| - // is = new FileInputStream(file); |
70 |
| - |
71 |
| - URL url = new URL(PATH); |
72 |
| - URLConnection conn = url.openConnection(); |
73 |
| - is = conn.getInputStream(); |
74 |
| - loadJson(is); |
75 |
| - } catch (IOException e) { |
76 |
| - e.printStackTrace(); |
77 |
| - } finally { |
78 |
| - IOUtils.closeQuietly(is); |
79 |
| - } |
80 |
| - } |
81 |
| - }); |
82 |
| - |
83 |
| - mMap.setTheme(VtmThemes.DEFAULT); |
84 |
| - |
85 |
| - mMap.layers().add(new BuildingLayer(mMap, mBaseLayer)); |
86 |
| - mMap.layers().add(new LabelLayer(mMap, mBaseLayer)); |
87 |
| - |
88 |
| - // String file = Environment.getExternalStorageDirectory().getAbsolutePath(); |
89 |
| - // VectorDataset data = (VectorDataset) JeoTest.getJsonData(file + "/states.json", true); |
90 |
| - // Style style = JeoTest.getStyle(); |
91 |
| - // mMap.layers().add(new JeoVectorLayer(mMap, data, style)); |
92 |
| - } |
93 |
| - |
94 |
| - void loadJson(InputStream is) { |
95 |
| - showToast("got data"); |
96 |
| - |
97 |
| - VectorDataset data = JeoTest.readGeoJson(is); |
98 |
| - Style style = JeoTest.getStyle(); |
99 |
| - TextStyle textStyle = TextStyle.builder() |
100 |
| - .isCaption(true) |
101 |
| - .fontSize(16 * CanvasAdapter.getScale()).color(Color.BLACK) |
102 |
| - .strokeWidth(2.2f * CanvasAdapter.getScale()).strokeColor(Color.WHITE) |
103 |
| - .build(); |
104 |
| - mIndoorLayer = new OSMIndoorLayer(mMap, data, style, textStyle); |
105 |
| - mMap.layers().add(mIndoorLayer); |
106 |
| - |
107 |
| - showToast("data ready"); |
108 |
| - mMap.updateMap(true); |
109 |
| - |
110 |
| - mIndoorLayer.activeLevels[0] = true; |
111 |
| - shift(); |
112 |
| - } |
113 |
| - |
114 |
| - public void showToast(final String text) { |
115 |
| - final Context ctx = this; |
116 |
| - runOnUiThread(new Runnable() { |
117 |
| - @Override |
118 |
| - public void run() { |
119 |
| - Toast toast = Toast.makeText(ctx, text, Toast.LENGTH_SHORT); |
120 |
| - toast.show(); |
121 |
| - } |
122 |
| - }); |
123 |
| - } |
124 |
| - |
125 |
| - boolean mShift = true; |
126 |
| - |
127 |
| - public void shift() { |
128 |
| - if (!mShift) |
129 |
| - return; |
130 |
| - |
131 |
| - mMap.postDelayed(new Runnable() { |
132 |
| - |
133 |
| - @Override |
134 |
| - public void run() { |
135 |
| - for (int i = 0; i < 10; i++) { |
136 |
| - if (mIndoorLayer.activeLevels[i]) { |
137 |
| - mIndoorLayer.activeLevels[i] = false; |
138 |
| - mIndoorLayer.activeLevels[(i + 1) % 9] = true; |
139 |
| - mIndoorLayer.update(); |
140 |
| - break; |
141 |
| - } |
142 |
| - } |
143 |
| - shift(); |
144 |
| - } |
145 |
| - }, 200); |
146 |
| - |
147 |
| - } |
148 |
| - |
149 |
| - public void onClick(View v) { |
150 |
| - mShift = false; |
151 |
| - |
152 |
| - if (mIndoorLayer == null) |
153 |
| - return; |
154 |
| - |
155 |
| - int i = 0; |
156 |
| - |
157 |
| - if (v instanceof ToggleButton) { |
158 |
| - ToggleButton b = (ToggleButton) v; |
159 |
| - i = (b.getTextOn().charAt(0) - '0') + 1; |
160 |
| - } |
161 |
| - |
162 |
| - if (i < 0 || i > 9) |
163 |
| - i = 0; |
164 |
| - |
165 |
| - mIndoorLayer.activeLevels[i] ^= true; |
166 |
| - if (v instanceof ToggleButton) |
167 |
| - ((ToggleButton) v).setChecked(mIndoorLayer.activeLevels[i]); |
168 |
| - log.debug(Arrays.toString(mIndoorLayer.activeLevels)); |
169 |
| - mIndoorLayer.update(); |
170 |
| - } |
171 |
| - |
172 |
| - @Override |
173 |
| - protected void onStop() { |
174 |
| - super.onStop(); |
175 |
| - } |
176 |
| - |
177 |
| - @Override |
178 |
| - protected void onResume() { |
179 |
| - super.onResume(); |
180 |
| - |
181 |
| - /* ignore saved position */ |
182 |
| - //mMap.setMapPosition(49.417, 8.673, 1 << 17); |
183 |
| - mMap.setMapPosition(53.5620092, 9.9866457, 1 << 16); |
184 |
| - } |
185 |
| -} |
| 18 | +//package org.oscim.android.test; |
| 19 | +// |
| 20 | +//import android.content.Context; |
| 21 | +//import android.os.Bundle; |
| 22 | +//import android.view.View; |
| 23 | +//import android.widget.Toast; |
| 24 | +//import android.widget.ToggleButton; |
| 25 | +//import io.jeo.map.Style; |
| 26 | +//import io.jeo.vector.VectorDataset; |
| 27 | +//import org.oscim.backend.CanvasAdapter; |
| 28 | +//import org.oscim.backend.canvas.Color; |
| 29 | +//import org.oscim.layers.OSMIndoorLayer; |
| 30 | +//import org.oscim.layers.tile.buildings.BuildingLayer; |
| 31 | +//import org.oscim.layers.tile.vector.labeling.LabelLayer; |
| 32 | +//import org.oscim.test.JeoTest; |
| 33 | +//import org.oscim.theme.internal.VtmThemes; |
| 34 | +//import org.oscim.theme.styles.TextStyle; |
| 35 | +//import org.oscim.utils.IOUtils; |
| 36 | +//import org.slf4j.Logger; |
| 37 | +//import org.slf4j.LoggerFactory; |
| 38 | +// |
| 39 | +//import java.io.IOException; |
| 40 | +//import java.io.InputStream; |
| 41 | +//import java.net.URL; |
| 42 | +//import java.net.URLConnection; |
| 43 | +//import java.util.Arrays; |
| 44 | +// |
| 45 | +//public class JeoIndoorActivity extends BaseMapActivity { |
| 46 | +// public static final Logger log = LoggerFactory.getLogger(JeoIndoorActivity.class); |
| 47 | +// |
| 48 | +// // from http://overpass-turbo.eu/s/2vp |
| 49 | +// String PATH = "https://gist.githubusercontent.com/anonymous/09062103a66844a96048f25626078c8d/raw/1d3af6a5a55e9ea4adc9551fa633a051a44a5a9c/overpass.geojson"; |
| 50 | +// |
| 51 | +// private OSMIndoorLayer mIndoorLayer; |
| 52 | +// |
| 53 | +// public JeoIndoorActivity() { |
| 54 | +// super(R.layout.jeo_indoor_map); |
| 55 | +// } |
| 56 | +// |
| 57 | +// @Override |
| 58 | +// public void onCreate(Bundle savedInstanceState) { |
| 59 | +// super.onCreate(savedInstanceState); |
| 60 | +// |
| 61 | +// mMap.addTask(new Runnable() { |
| 62 | +// @Override |
| 63 | +// public void run() { |
| 64 | +// showToast("load data"); |
| 65 | +// InputStream is = null; |
| 66 | +// try { |
| 67 | +// // File file = new File(Environment.getExternalStorageDirectory() |
| 68 | +// // .getAbsolutePath(), "osmindoor.json"); |
| 69 | +// // is = new FileInputStream(file); |
| 70 | +// |
| 71 | +// URL url = new URL(PATH); |
| 72 | +// URLConnection conn = url.openConnection(); |
| 73 | +// is = conn.getInputStream(); |
| 74 | +// loadJson(is); |
| 75 | +// } catch (IOException e) { |
| 76 | +// e.printStackTrace(); |
| 77 | +// } finally { |
| 78 | +// IOUtils.closeQuietly(is); |
| 79 | +// } |
| 80 | +// } |
| 81 | +// }); |
| 82 | +// |
| 83 | +// mMap.setTheme(VtmThemes.DEFAULT); |
| 84 | +// |
| 85 | +// mMap.layers().add(new BuildingLayer(mMap, mBaseLayer)); |
| 86 | +// mMap.layers().add(new LabelLayer(mMap, mBaseLayer)); |
| 87 | +// |
| 88 | +// // String file = Environment.getExternalStorageDirectory().getAbsolutePath(); |
| 89 | +// // VectorDataset data = (VectorDataset) JeoTest.getJsonData(file + "/states.json", true); |
| 90 | +// // Style style = JeoTest.getStyle(); |
| 91 | +// // mMap.layers().add(new JeoVectorLayer(mMap, data, style)); |
| 92 | +// } |
| 93 | +// |
| 94 | +// void loadJson(InputStream is) { |
| 95 | +// showToast("got data"); |
| 96 | +// |
| 97 | +// VectorDataset data = JeoTest.readGeoJson(is); |
| 98 | +// Style style = JeoTest.getStyle(); |
| 99 | +// TextStyle textStyle = TextStyle.builder() |
| 100 | +// .isCaption(true) |
| 101 | +// .fontSize(16 * CanvasAdapter.getScale()).color(Color.BLACK) |
| 102 | +// .strokeWidth(2.2f * CanvasAdapter.getScale()).strokeColor(Color.WHITE) |
| 103 | +// .build(); |
| 104 | +// mIndoorLayer = new OSMIndoorLayer(mMap, data, style, textStyle); |
| 105 | +// mMap.layers().add(mIndoorLayer); |
| 106 | +// |
| 107 | +// showToast("data ready"); |
| 108 | +// mMap.updateMap(true); |
| 109 | +// |
| 110 | +// mIndoorLayer.activeLevels[0] = true; |
| 111 | +// shift(); |
| 112 | +// } |
| 113 | +// |
| 114 | +// public void showToast(final String text) { |
| 115 | +// final Context ctx = this; |
| 116 | +// runOnUiThread(new Runnable() { |
| 117 | +// @Override |
| 118 | +// public void run() { |
| 119 | +// Toast toast = Toast.makeText(ctx, text, Toast.LENGTH_SHORT); |
| 120 | +// toast.show(); |
| 121 | +// } |
| 122 | +// }); |
| 123 | +// } |
| 124 | +// |
| 125 | +// boolean mShift = true; |
| 126 | +// |
| 127 | +// public void shift() { |
| 128 | +// if (!mShift) |
| 129 | +// return; |
| 130 | +// |
| 131 | +// mMap.postDelayed(new Runnable() { |
| 132 | +// |
| 133 | +// @Override |
| 134 | +// public void run() { |
| 135 | +// for (int i = 0; i < 10; i++) { |
| 136 | +// if (mIndoorLayer.activeLevels[i]) { |
| 137 | +// mIndoorLayer.activeLevels[i] = false; |
| 138 | +// mIndoorLayer.activeLevels[(i + 1) % 9] = true; |
| 139 | +// mIndoorLayer.update(); |
| 140 | +// break; |
| 141 | +// } |
| 142 | +// } |
| 143 | +// shift(); |
| 144 | +// } |
| 145 | +// }, 200); |
| 146 | +// |
| 147 | +// } |
| 148 | +// |
| 149 | +// public void onClick(View v) { |
| 150 | +// mShift = false; |
| 151 | +// |
| 152 | +// if (mIndoorLayer == null) |
| 153 | +// return; |
| 154 | +// |
| 155 | +// int i = 0; |
| 156 | +// |
| 157 | +// if (v instanceof ToggleButton) { |
| 158 | +// ToggleButton b = (ToggleButton) v; |
| 159 | +// i = (b.getTextOn().charAt(0) - '0') + 1; |
| 160 | +// } |
| 161 | +// |
| 162 | +// if (i < 0 || i > 9) |
| 163 | +// i = 0; |
| 164 | +// |
| 165 | +// mIndoorLayer.activeLevels[i] ^= true; |
| 166 | +// if (v instanceof ToggleButton) |
| 167 | +// ((ToggleButton) v).setChecked(mIndoorLayer.activeLevels[i]); |
| 168 | +// log.debug(Arrays.toString(mIndoorLayer.activeLevels)); |
| 169 | +// mIndoorLayer.update(); |
| 170 | +// } |
| 171 | +// |
| 172 | +// @Override |
| 173 | +// protected void onStop() { |
| 174 | +// super.onStop(); |
| 175 | +// } |
| 176 | +// |
| 177 | +// @Override |
| 178 | +// protected void onResume() { |
| 179 | +// super.onResume(); |
| 180 | +// |
| 181 | +// /* ignore saved position */ |
| 182 | +// //mMap.setMapPosition(49.417, 8.673, 1 << 17); |
| 183 | +// mMap.setMapPosition(53.5620092, 9.9866457, 1 << 16); |
| 184 | +// } |
| 185 | +//} |
0 commit comments