├── LICENSE ├── README ├── README.md ├── UCSDGraphs.iml ├── data ├── airports │ └── routesUA.dat ├── graders │ ├── mod1 │ │ ├── graph1.txt │ │ ├── graph1.txt.degrees │ │ ├── graph2.txt │ │ ├── graph2.txt.degrees │ │ ├── graph3.txt │ │ ├── graph3.txt.degrees │ │ ├── graph4.txt │ │ ├── graph4.txt.degrees │ │ ├── graph5.txt │ │ ├── graph6.txt │ │ ├── routesUA.dat │ │ ├── routesUA.dat.degrees │ │ ├── routesUA.dat.twoaway │ │ ├── ucsd.map │ │ ├── ucsd.map.degrees │ │ └── ucsd.map.twoaway │ ├── mod2 │ │ ├── map1.txt │ │ ├── map1.txt.answer │ │ ├── map2.txt │ │ ├── map2.txt.answer │ │ ├── map3.txt │ │ ├── map3.txt.answer │ │ ├── ucsd.map │ │ └── ucsd.map.answer │ └── mod3 │ │ ├── map1.txt │ │ ├── map1.txt.answer │ │ ├── map2.txt │ │ ├── map2.txt.answer │ │ ├── map3.txt │ │ ├── map3.txt.answer │ │ ├── ucsd.map │ │ └── ucsd.map.answer ├── intersections │ ├── hollywood_large.intersections │ ├── hollywood_small.intersections │ ├── new_york.intersections │ ├── newbury_small.intersections │ ├── newbury_verysmall.intersections │ ├── san_diego.intersections │ └── ucsd.intersections ├── maps │ ├── hollywood_large.map │ ├── hollywood_small.map │ ├── mapfiles.list │ ├── new_york.map │ ├── newbury_small.map │ ├── newbury_verysmall.map │ ├── san_diego.map │ ├── ucsd.map │ └── utc.map ├── mazes │ └── maze1.maze └── testdata │ └── simpletest.map ├── libs ├── java-json.jar ├── javax.json-1.0.4.jar └── jsoup-1.12.1.jar └── src ├── application ├── CLabel.java ├── DataSet.java ├── GeoLabel.java ├── MapApp.java ├── MarkerManager.java ├── RouteVisualization.java ├── SelectManager.java ├── TestApp.java ├── controllers │ ├── FetchController.java │ └── RouteController.java └── services │ ├── GeneralService.java │ └── RouteService.java ├── basicgraph ├── DegreeGrader.java ├── Graph.java ├── GraphAdjList.java ├── GraphAdjMatrix.java └── GraphGrader.java ├── geography ├── GeographicPoint.java └── RoadSegment.java ├── gmapsfx ├── ArrayTester.java ├── GoogleMapView.java ├── MapComponentInitializedListener.java ├── MapNotInitializedException.java ├── MapReadyListener.java ├── javascript │ ├── IJavascriptRuntime.java │ ├── IWebEngine.java │ ├── JavaFxWebEngine.java │ ├── JavascriptArray.java │ ├── JavascriptEnum.java │ ├── JavascriptFunction.java │ ├── JavascriptFunctionLine.java │ ├── JavascriptObject.java │ ├── JavascriptRuntime.java │ ├── event │ │ ├── EventHandlers.java │ │ ├── GFXEventHandler.java │ │ ├── MapStateEventType.java │ │ ├── StateEventHandler.java │ │ ├── UIEventHandler.java │ │ └── UIEventType.java │ └── object │ │ ├── Animation.java │ │ ├── GMapObjectType.java │ │ ├── GMapPoint.java │ │ ├── GoogleMap.java │ │ ├── InfoWindow.java │ │ ├── InfoWindowOptions.java │ │ ├── LatLong.java │ │ ├── LatLongBounds.java │ │ ├── MVCArray.java │ │ ├── MapOptions.java │ │ ├── MapShape.java │ │ ├── MapTypeIdEnum.java │ │ ├── Marker.java │ │ ├── MarkerOptions.java │ │ ├── MarkerShape.java │ │ ├── Polyline.java │ │ ├── PolylineOptions.java │ │ ├── Projection.java │ │ └── Size.java ├── service │ ├── elevation │ │ ├── ElevationResult.java │ │ ├── ElevationService.java │ │ ├── ElevationServiceCallback.java │ │ ├── ElevationStatus.java │ │ ├── LocationElevationRequest.java │ │ └── PathElevationRequest.java │ └── geocoding │ │ └── GeocodingService.java ├── shapes │ ├── ArcBuilder.java │ ├── Circle.java │ ├── CircleOptions.java │ ├── FillableMapShapeOptions.java │ ├── MapShapeOptions.java │ ├── Polygon.java │ ├── PolygonOptions.java │ ├── Polyline.java │ ├── PolylineOptions.java │ ├── Rectangle.java │ ├── RectangleOptions.java │ └── StrokePosition.java └── zoom │ ├── MaxZoomResult.java │ ├── MaxZoomService.java │ ├── MaxZoomServiceCallback.java │ └── MaxZoomStatus.java ├── html ├── index.html ├── main.js ├── routing.css └── visual.js ├── mapmaker ├── DataFetcher.java └── MapMaker.java ├── roadgraph ├── AStarGrader.java ├── CorrectAnswer.java ├── DijkstraGrader.java ├── MapGraph.java ├── MapGraphNode.java └── SearchGrader.java ├── util └── GraphLoader.java └── week3example ├── Maze.java ├── MazeLoader.java └── MazeNode.java /README: -------------------------------------------------------------------------------- 1 | /------------------------------------------------------------------------- 2 | / Starter Code and GUI Application for Course 3 in the 3 | / Java Programming: Object Oriented Design of 4 | / Data Structures Specialization: 5 | / 6 | / Advanced Data Structures in Java 7 | / https://www.coursera.org/learn/advanced-data-structures 8 | / 9 | / Authored by UCSD MOOC Team: 10 | / Mia Minnes, Christine Alvarado, Leo Porter, Alec Brickner 11 | / and Adam Setters 12 | / 13 | / Date: 12/16/2015 14 | /------------------------------------------------------------------------- 15 | 16 | ---------------------------------------------------------[ DESCRIPTION ]-- 17 | 18 | The files provided are skeleton code, as well as grading previews and 19 | testing files to be used in completing the course programming 20 | assignments. Additionally, you are provided a runnable JavaFX program 21 | which will help to test and demonstrate your implementations. 22 | 23 | -------------------------------------------------------[ FILES BY WEEK ]-- 24 | 25 | Below are the files introduced in each week and used in each week 26 | of the course. See file for description... 27 | 28 | Week 1 : Introduction to the course and graphs 29 | ============================================== 30 | basicgraph.Graph.java 31 | basicgraph.GraphAdjList.java 32 | basicgraph.GraphAdjMatrix.java 33 | 34 | Week 2 : Class design and simple graph search 35 | ================================================== 36 | roadgraph.MapGraph.java 37 | week2example.Maze.java 38 | week2example.MazeLoader.java 39 | week2example.MazeNode.java 40 | 41 | Utility files 42 | ============= 43 | geography.GeographicPoint.java 44 | geography.RoadSegment.java 45 | util.GraphLoader.java 46 | 47 | ---------------------------------------------------------------[ SETUP ]-- 48 | 49 | Importing Project into eclipse: 50 | 1. Create a new Java Project in your workspace 51 | 2. Import the starter files: 52 | File -> Import -> Select "File System" -> Next -> Browse and set 53 | root directory to folder contents of zip were extracted to -> Finish 54 | 55 | Feel free to use another IDE or manually compile and run your programs. 56 | If you need help, google is your friend. 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fastest Route Finder with BFS, Dijkstra(getting speed limit data from web) and also A Star Algorithms included. 2 | _this was the final homework for UCSD's Advanced Data Structures in Java._ 3 | 4 | A basic shortest path finder between given two points. Dijkstra has the extra feature of getting data from web, to name it from opensourcemap, if the current coordinates does not have the info of maxspeed then continues to scan around 300 radius uses the closest info. 5 | Preferred 6 | 7+ Language Level 7 | SDK 1.8 because of javafx library 8 | jUnit 9 | and libs 10 | 11 | > ### **Example:** 12 | 13 | Given part of text is just a snapshot of some part. 14 | 15 | -------------------------------------------------------------------------------- /UCSDGraphs.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /data/graders/mod1/graph1.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 0 1 3 | 1 2 4 | 2 3 5 | 3 4 6 | 4 5 7 | 5 6 8 | 6 7 9 | 7 8 10 | 8 9 11 | -------------------------------------------------------------------------------- /data/graders/mod1/graph1.txt.degrees: -------------------------------------------------------------------------------- 1 | 2 2 2 2 2 2 2 2 1 1 2 | -------------------------------------------------------------------------------- /data/graders/mod1/graph2.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 0 1 3 | 1 2 4 | 2 3 5 | 3 4 6 | 4 5 7 | 5 6 8 | 6 7 9 | 7 8 10 | 8 9 11 | 1 0 12 | 2 1 13 | 3 2 14 | 4 3 15 | 5 4 16 | 6 5 17 | 7 6 18 | 8 7 19 | 9 8 20 | -------------------------------------------------------------------------------- /data/graders/mod1/graph2.txt.degrees: -------------------------------------------------------------------------------- 1 | 4 4 4 4 4 4 4 4 2 2 2 | -------------------------------------------------------------------------------- /data/graders/mod1/graph3.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 0 1 3 | 0 2 4 | 0 3 5 | 0 4 6 | 0 5 7 | 0 6 8 | 0 7 9 | 0 8 10 | 0 9 11 | 1 0 12 | 2 0 13 | 3 0 14 | 4 0 15 | 5 0 16 | 6 0 17 | 7 0 18 | 8 0 19 | 9 0 20 | -------------------------------------------------------------------------------- /data/graders/mod1/graph3.txt.degrees: -------------------------------------------------------------------------------- 1 | 18 2 2 2 2 2 2 2 2 2 2 | -------------------------------------------------------------------------------- /data/graders/mod1/graph4.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 0 1 3 | 0 2 4 | 0 3 5 | 0 4 6 | 0 5 7 | 0 6 8 | 0 7 9 | 0 8 10 | 0 9 11 | 1 0 12 | 2 0 13 | 3 0 14 | 4 0 15 | 5 0 16 | 6 0 17 | 7 0 18 | 8 0 19 | 9 0 20 | -------------------------------------------------------------------------------- /data/graders/mod1/graph4.txt.degrees: -------------------------------------------------------------------------------- 1 | 18 2 2 2 2 2 2 2 2 2 2 | -------------------------------------------------------------------------------- /data/graders/mod1/graph5.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 0 1 3 | 0 2 4 | 0 3 5 | 0 4 6 | 0 5 7 | 1 6 8 | 2 7 9 | 3 8 10 | 4 9 11 | 5 10 12 | -------------------------------------------------------------------------------- /data/graders/mod1/graph6.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 0 1 3 | 0 2 4 | 0 3 5 | 0 4 6 | 0 5 7 | 1 6 8 | 2 7 9 | 3 8 10 | 4 9 11 | 5 10 12 | -------------------------------------------------------------------------------- /data/graders/mod1/routesUA.dat.degrees: -------------------------------------------------------------------------------- 1 | 323 319 281 279 217 176 143 98 42 42 39 36 36 34 34 32 32 30 29 26 26 26 24 22 22 20 19 18 18 18 18 18 18 17 16 16 16 16 16 14 14 14 14 14 14 14 14 14 14 14 14 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 2 | -------------------------------------------------------------------------------- /data/graders/mod1/routesUA.dat.twoaway: -------------------------------------------------------------------------------- 1 | 6 2 | 20 3 | 29 4 | 31 5 | 33 6 | 41 7 | 42 8 | 50 9 | 65 10 | 68 11 | 70 12 | 73 13 | 83 14 | 86 15 | 89 16 | 112 17 | 113 18 | 115 19 | 124 20 | 26 21 | 130 22 | 163 23 | 164 24 | 167 25 | 51 26 | 172 27 | 174 28 | 131 29 | 132 30 | 133 31 | 182 32 | 183 33 | 184 34 | 185 35 | 186 36 | 187 37 | 188 38 | 27 39 | 189 40 | 190 41 | 191 42 | 72 43 | 30 44 | 43 45 | 192 46 | 193 47 | 194 48 | 195 49 | 138 50 | 196 51 | 197 52 | 198 53 | 199 54 | 200 55 | 201 56 | 28 57 | 8 58 | 202 59 | 203 60 | 140 61 | 204 62 | 205 63 | 206 64 | 207 65 | 141 66 | 9 67 | 208 68 | 44 69 | 209 70 | 210 71 | 211 72 | 212 73 | 142 74 | 143 75 | 213 76 | 214 77 | 215 78 | 58 79 | 144 80 | 216 81 | 217 82 | 218 83 | 219 84 | 220 85 | 145 86 | 146 87 | 221 88 | 80 89 | 222 90 | 223 91 | 224 92 | 225 93 | 1 94 | 226 95 | 227 96 | 148 97 | 228 98 | 229 99 | 230 100 | 231 101 | 232 102 | 233 103 | 234 104 | 235 105 | 236 106 | 237 107 | 238 108 | 152 109 | 239 110 | 240 111 | 241 112 | 242 113 | 153 114 | 34 115 | 10 116 | 243 117 | 244 118 | 245 119 | 246 120 | 247 121 | 248 122 | 14 123 | 249 124 | 154 125 | 156 126 | 250 127 | 251 128 | 252 129 | 253 130 | 254 131 | 255 132 | 256 133 | 62 134 | 257 135 | 258 136 | 259 137 | 260 138 | 45 139 | 6 140 | 11 141 | 15 142 | 18 143 | 19 144 | 31 145 | 32 146 | 42 147 | 50 148 | 65 149 | 68 150 | 78 151 | 83 152 | 84 153 | 88 154 | 89 155 | 97 156 | 109 157 | 113 158 | 114 159 | 116 160 | 119 161 | 122 162 | 26 163 | 157 164 | 129 165 | 159 166 | 130 167 | 164 168 | 168 169 | 361 170 | 51 171 | 171 172 | 172 173 | 176 174 | 177 175 | 132 176 | 7 177 | 133 178 | 262 179 | 184 180 | 185 181 | 187 182 | 27 183 | 323 184 | 72 185 | 43 186 | 277 187 | 336 188 | 337 189 | 195 190 | 339 191 | 341 192 | 138 193 | 279 194 | 139 195 | 281 196 | 200 197 | 356 198 | 359 199 | 201 200 | 360 201 | 28 202 | 202 203 | 140 204 | 366 205 | 286 206 | 141 207 | 9 208 | 208 209 | 367 210 | 368 211 | 369 212 | 44 213 | 287 214 | 288 215 | 289 216 | 210 217 | 333 218 | 370 219 | 212 220 | 292 221 | 142 222 | 143 223 | 213 224 | 214 225 | 371 226 | 372 227 | 58 228 | 373 229 | 144 230 | 374 231 | 375 232 | 376 233 | 145 234 | 146 235 | 377 236 | 91 237 | 296 238 | 80 239 | 378 240 | 223 241 | 224 242 | 225 243 | 1 244 | 297 245 | 379 246 | 147 247 | 226 248 | 298 249 | 227 250 | 148 251 | 230 252 | 380 253 | 301 254 | 232 255 | 92 256 | 234 257 | 381 258 | 306 259 | 150 260 | 152 261 | 382 262 | 261 263 | 240 264 | 307 265 | 241 266 | 308 267 | 153 268 | 34 269 | 10 270 | 245 271 | 246 272 | 247 273 | 310 274 | 311 275 | 248 276 | 383 277 | 384 278 | 14 279 | 249 280 | 154 281 | 385 282 | 386 283 | 156 284 | 387 285 | 250 286 | 251 287 | 388 288 | 252 289 | 389 290 | 390 291 | 391 292 | 392 293 | 253 294 | 254 295 | 62 296 | 257 297 | 260 298 | 45 299 | 393 300 | 394 301 | 6 302 | 22 303 | 41 304 | 50 305 | 65 306 | 78 307 | 86 308 | 89 309 | 113 310 | 128 311 | 26 312 | 164 313 | 51 314 | 7 315 | 133 316 | 262 317 | 27 318 | 190 319 | 43 320 | 336 321 | 354 322 | 200 323 | 28 324 | 8 325 | 395 326 | 202 327 | 397 328 | 399 329 | 85 330 | 206 331 | 141 332 | 287 333 | 209 334 | 143 335 | 214 336 | 218 337 | 145 338 | 146 339 | 91 340 | 80 341 | 222 342 | 223 343 | 1 344 | 226 345 | 298 346 | 148 347 | 230 348 | 232 349 | 92 350 | 304 351 | 234 352 | 238 353 | 261 354 | 240 355 | 241 356 | 242 357 | 404 358 | 34 359 | 10 360 | 246 361 | 247 362 | 248 363 | 14 364 | 405 365 | 406 366 | 251 367 | 407 368 | 62 369 | 408 370 | 257 371 | 45 372 | 95 373 | 0 374 | 6 375 | 15 376 | 25 377 | 32 378 | 33 379 | 42 380 | 46 381 | 50 382 | 52 383 | 53 384 | 61 385 | 68 386 | 83 387 | 86 388 | 89 389 | 3 390 | 110 391 | 111 392 | 113 393 | 115 394 | 116 395 | 118 396 | 120 397 | 122 398 | 124 399 | 26 400 | 129 401 | 130 402 | 160 403 | 164 404 | 361 405 | 51 406 | 172 407 | 173 408 | 131 409 | 132 410 | 7 411 | 133 412 | 265 413 | 184 414 | 185 415 | 90 416 | 269 417 | 270 418 | 274 419 | 27 420 | 189 421 | 72 422 | 332 423 | 43 424 | 192 425 | 335 426 | 340 427 | 138 428 | 279 429 | 280 430 | 139 431 | 284 432 | 200 433 | 358 434 | 201 435 | 28 436 | 8 437 | 202 438 | 140 439 | 366 440 | 286 441 | 403 442 | 141 443 | 9 444 | 368 445 | 44 446 | 287 447 | 210 448 | 211 449 | 413 450 | 142 451 | 143 452 | 363 453 | 213 454 | 214 455 | 293 456 | 58 457 | 144 458 | 417 459 | 216 460 | 376 461 | 219 462 | 145 463 | 146 464 | 377 465 | 91 466 | 295 467 | 296 468 | 80 469 | 222 470 | 223 471 | 224 472 | 297 473 | 419 474 | 226 475 | 298 476 | 227 477 | 148 478 | 228 479 | 230 480 | 380 481 | 92 482 | 302 483 | 303 484 | 304 485 | 234 486 | 305 487 | 235 488 | 306 489 | 150 490 | 364 491 | 151 492 | 152 493 | 240 494 | 241 495 | 308 496 | 420 497 | 365 498 | 153 499 | 34 500 | 10 501 | 243 502 | 247 503 | 310 504 | 311 505 | 248 506 | 14 507 | 249 508 | 421 509 | 422 510 | 423 511 | 154 512 | 314 513 | 315 514 | 155 515 | 156 516 | 250 517 | 424 518 | 252 519 | 267 520 | 253 521 | 254 522 | 93 523 | 94 524 | 319 525 | 256 526 | 62 527 | 257 528 | 258 529 | 259 530 | 425 531 | 260 532 | 45 533 | 95 534 | 6 535 | 12 536 | 22 537 | 42 538 | 50 539 | 65 540 | 86 541 | 89 542 | 112 543 | 113 544 | 120 545 | 13 546 | 123 547 | 26 548 | 164 549 | 51 550 | 132 551 | 7 552 | 133 553 | 188 554 | 27 555 | 190 556 | 72 557 | 43 558 | 336 559 | 284 560 | 200 561 | 28 562 | 8 563 | 395 564 | 140 565 | 85 566 | 342 567 | 206 568 | 141 569 | 9 570 | 287 571 | 209 572 | 411 573 | 142 574 | 143 575 | 214 576 | 215 577 | 418 578 | 218 579 | 145 580 | 146 581 | 91 582 | 80 583 | 222 584 | 223 585 | 225 586 | 1 587 | 426 588 | 226 589 | 298 590 | 227 591 | 148 592 | 230 593 | 231 594 | 232 595 | 304 596 | 234 597 | 427 598 | 236 599 | 306 600 | 238 601 | 261 602 | 240 603 | 241 604 | 242 605 | 404 606 | 34 607 | 247 608 | 248 609 | 14 610 | 249 611 | 154 612 | 406 613 | 428 614 | 251 615 | 254 616 | 62 617 | 257 618 | 260 619 | 429 620 | 45 621 | 95 622 | -------------------------------------------------------------------------------- /data/graders/mod1/ucsd.map.degrees: -------------------------------------------------------------------------------- 1 | 6 6 6 6 5 3 2 2 2 2 2 1 1 1 1 1 1 2 | -------------------------------------------------------------------------------- /data/graders/mod1/ucsd.map.twoaway: -------------------------------------------------------------------------------- 1 | 16 2 | 3 3 | 8 4 | 3 5 | 3 6 | 11 7 | 6 8 | -------------------------------------------------------------------------------- /data/graders/mod2/map1.txt: -------------------------------------------------------------------------------- 1 | 0 0 1 1 "Road 1" edge 2 | 1 1 2 2 "Road 2" edge 3 | 2 2 3 3 "Road 3" edge 4 | 3 3 4 4 "Road 4" edge 5 | 4 4 5 5 "Road 5" edge 6 | 5 5 6 6 "Road 6" edge 7 | -------------------------------------------------------------------------------- /data/graders/mod2/map1.txt.answer: -------------------------------------------------------------------------------- 1 | 7 2 | 6 3 | 0.0 0.0 4 | 1.0 1.0 5 | 2.0 2.0 6 | 3.0 3.0 7 | 4.0 4.0 8 | 5.0 5.0 9 | 6.0 6.0 10 | -------------------------------------------------------------------------------- /data/graders/mod2/map2.txt: -------------------------------------------------------------------------------- 1 | 0 0 1 1 "Road 1" edge 2 | 1 1 2 2 "Road 2" edge 3 | 2 2 3 3 "Road 3" edge 4 | 3 3 4 4 "Road 4" edge 5 | 4 4 5 5 "Road 5" edge 6 | 5 5 6 6 "Road 6" edge 7 | -------------------------------------------------------------------------------- /data/graders/mod2/map2.txt.answer: -------------------------------------------------------------------------------- 1 | 7 2 | 6 3 | -------------------------------------------------------------------------------- /data/graders/mod2/map3.txt: -------------------------------------------------------------------------------- 1 | 0 0 0 1 "Road 1" edge 2 | 0 1 0 0 "Road 1" edge 3 | 0 1 0 2 "Road 2" edge 4 | 0 2 0 1 "Road 2" edge 5 | 0 2 1 2 "Road 3" edge 6 | 1 2 0 2 "Road 3" edge 7 | 1 2 2 2 "Road 4" edge 8 | 2 2 1 2 "Road 4" edge 9 | 2 2 2 1 "Road 5" edge 10 | 2 1 2 2 "Road 5" edge 11 | 2 1 2 0 "Road 6" edge 12 | 2 0 2 1 "Road 6" edge 13 | 2 0 1 0 "Road 7" edge 14 | 1 0 2 0 "Road 7" edge 15 | 1 0 0 0 "Road 8" edge 16 | 0 0 1 0 "Road 8" edge 17 | -------------------------------------------------------------------------------- /data/graders/mod2/map3.txt.answer: -------------------------------------------------------------------------------- 1 | 8 2 | 16 3 | 0.0 0.0 4 | 0.0 1.0 5 | 0.0 2.0 6 | 1.0 2.0 7 | -------------------------------------------------------------------------------- /data/graders/mod2/ucsd.map.answer: -------------------------------------------------------------------------------- 1 | 17 2 | 24 3 | 32.8756538 -117.2435715 4 | 32.8757495 -117.2430819 5 | 32.8741164 -117.2382689 6 | 32.8742087 -117.2381344 7 | -------------------------------------------------------------------------------- /data/graders/mod3/map1.txt: -------------------------------------------------------------------------------- 1 | 0 0 1 1 "Road 1" edge 2 | 1 1 2 2 "Road 2" edge 3 | 2 2 3 3 "Road 3" edge 4 | 3 3 4 4 "Road 4" edge 5 | 4 4 5 5 "Road 5" edge 6 | 5 5 6 6 "Road 6" edge 7 | 0 0 -1 0 "Road 7" edge 8 | -1 0 -2 0 "Road 8" edge 9 | -2 0 -3 0 "Road 9" edge 10 | -------------------------------------------------------------------------------- /data/graders/mod3/map1.txt.answer: -------------------------------------------------------------------------------- 1 | 0.0 0.0 2 | 1.0 1.0 3 | 2.0 2.0 4 | 3.0 3.0 5 | 4.0 4.0 6 | 5.0 5.0 7 | 6.0 6.0 8 | -------------------------------------------------------------------------------- /data/graders/mod3/map2.txt: -------------------------------------------------------------------------------- 1 | 1 1 4 1 "main" edge 2 | 4 1 1 1 "main" edge 3 | 4 1 4 2 "state" edge 4 | 4 2 4 1 "state" edge 5 | 4 1 7 3 "front" edge 6 | 7 3 4 1 "front" edge 7 | 4 1 5 1 "main" edge 8 | 5 1 4 1 "main" edge 9 | 4 1 4 0 "state" edge 10 | 4 0 4 1 "state" edge 11 | 4 0 5 1 "short" edge 12 | 5 1 4 0 "short" edge 13 | 4 0 4 -1 "state" edge 14 | 4 -1 4 0 "state" edge 15 | 4 -1 8 -1 "south" edge 16 | 8 -1 4 -1 "south" edge 17 | 5 1 6.5 0 "first" edge 18 | 6.5 0 5 1 "first" edge 19 | 6.5 0 8 -1 "next" edge 20 | 8 -1 6.5 0 "next" edge 21 | 7 3 8 -1 "high" edge 22 | 8 -1 7 3 "high" edge 23 | -------------------------------------------------------------------------------- /data/graders/mod3/map2.txt.answer: -------------------------------------------------------------------------------- 1 | 7.0 3.0 2 | 4.0 1.0 3 | 4.0 0.0 4 | 4.0 -1.0 5 | -------------------------------------------------------------------------------- /data/graders/mod3/map3.txt: -------------------------------------------------------------------------------- 1 | 0 0 -1 1 "Zig" edge 2 | -1 1 1 2 "Zag" edge 3 | 1 2 0 3 "Left" edge 4 | 0 3 4 4 "Mid" edge 5 | 0 0 2 2 "Right" edge 6 | 2 2 4 4 "Right" edge 7 | 4 4 0 4 "Upper" edge 8 | -------------------------------------------------------------------------------- /data/graders/mod3/map3.txt.answer: -------------------------------------------------------------------------------- 1 | 0.0 0.0 2 | 4.0 4.0 3 | 0.0 4.0 4 | -------------------------------------------------------------------------------- /data/graders/mod3/ucsd.map.answer: -------------------------------------------------------------------------------- 1 | 32.8709815 -117.2434254 2 | 32.8710666 -117.2432407 3 | 32.8715162 -117.2422525 4 | 32.8717705 -117.2419172 5 | 32.8726064 -117.2418224 6 | 32.8741164 -117.2382689 7 | 32.8742087 -117.2381344 8 | -------------------------------------------------------------------------------- /data/intersections/hollywood_small.intersections: -------------------------------------------------------------------------------- 1 | Lat: 34.108928, Lon: -118.3379696 Lat: 34.1085487, Lon: -118.337979 2 | Lat: 34.1089619, Lon: -118.3391174 Lat: 34.1076423, Lon: -118.3390137 3 | Lat: 34.1089619, Lon: -118.3391174 Lat: 34.1092817, Lon: -118.3391165 4 | Lat: 34.1089619, Lon: -118.3391174 Lat: 34.1087853, Lon: -118.3386925 5 | Lat: 34.1089619, Lon: -118.3391174 Lat: 34.10908, Lon: -118.3400346 6 | Lat: 34.1093056, Lon: -118.3379235 Lat: 34.1087853, Lon: -118.3386925 7 | Lat: 34.1093056, Lon: -118.3379235 Lat: 34.1093731, Lon: -118.3385801 8 | Lat: 34.1082145, Lon: -118.3444277 Lat: 34.1093925, Lon: -118.3400463 9 | Lat: 34.1092817, Lon: -118.3391165 Lat: 34.1089619, Lon: -118.3391174 10 | Lat: 34.1092817, Lon: -118.3391165 Lat: 34.1097672, Lon: -118.3391194 11 | Lat: 34.1092817, Lon: -118.3391165 Lat: 34.1093925, Lon: -118.3400463 12 | Lat: 34.1074342, Lon: -118.3400377 Lat: 34.1079022, Lon: -118.3410223 13 | Lat: 34.1076423, Lon: -118.3390137 Lat: 34.1089619, Lon: -118.3391174 14 | Lat: 34.1087853, Lon: -118.3386925 Lat: 34.1093056, Lon: -118.3379235 15 | Lat: 34.1087853, Lon: -118.3386925 Lat: 34.1085487, Lon: -118.337979 16 | Lat: 34.1087853, Lon: -118.3386925 Lat: 34.1089619, Lon: -118.3391174 17 | Lat: 34.1093925, Lon: -118.3400463 Lat: 34.10908, Lon: -118.3400346 18 | Lat: 34.1093925, Lon: -118.3400463 Lat: 34.1082145, Lon: -118.3444277 19 | Lat: 34.1093925, Lon: -118.3400463 Lat: 34.1092817, Lon: -118.3391165 20 | Lat: 34.1081907, Lon: -118.337113 Lat: 34.1085487, Lon: -118.337979 21 | Lat: 34.1097672, Lon: -118.3391194 Lat: 34.1092817, Lon: -118.3391165 22 | Lat: 34.1076233, Lon: -118.3411896 Lat: 34.1079022, Lon: -118.3410223 23 | Lat: 34.1076233, Lon: -118.3411896 Lat: 34.1065619, Lon: -118.3423929 24 | Lat: 34.1076233, Lon: -118.3411896 Lat: 34.1041261, Lon: -118.3393876 25 | Lat: 34.1093731, Lon: -118.3385801 Lat: 34.1093056, Lon: -118.3379235 26 | Lat: 34.1067247, Lon: -118.3391392 Lat: 34.10908, Lon: -118.3400346 27 | Lat: 34.1085487, Lon: -118.337979 Lat: 34.108928, Lon: -118.3379696 28 | Lat: 34.1085487, Lon: -118.337979 Lat: 34.1081907, Lon: -118.337113 29 | Lat: 34.1085487, Lon: -118.337979 Lat: 34.1087853, Lon: -118.3386925 30 | Lat: 34.10908, Lon: -118.3400346 Lat: 34.1093925, Lon: -118.3400463 31 | Lat: 34.10908, Lon: -118.3400346 Lat: 34.1089619, Lon: -118.3391174 32 | Lat: 34.10908, Lon: -118.3400346 Lat: 34.1079022, Lon: -118.3410223 33 | Lat: 34.10908, Lon: -118.3400346 Lat: 34.1067247, Lon: -118.3391392 34 | Lat: 34.1041261, Lon: -118.3393876 Lat: 34.1076233, Lon: -118.3411896 35 | Lat: 34.1065619, Lon: -118.3423929 Lat: 34.1076233, Lon: -118.3411896 36 | Lat: 34.1079022, Lon: -118.3410223 Lat: 34.10908, Lon: -118.3400346 37 | Lat: 34.1079022, Lon: -118.3410223 Lat: 34.1076233, Lon: -118.3411896 38 | Lat: 34.1079022, Lon: -118.3410223 Lat: 34.1074342, Lon: -118.3400377 39 | -------------------------------------------------------------------------------- /data/intersections/newbury_verysmall.intersections: -------------------------------------------------------------------------------- 1 | Lat: 34.1842502, Lon: -118.94923 Lat: 34.1842742, Lon: -118.947663 2 | Lat: 34.1842502, Lon: -118.94923 Lat: 34.1832868, Lon: -118.9491068 3 | Lat: 34.1842502, Lon: -118.94923 Lat: 34.184898, Lon: -118.949349 4 | Lat: 34.185952, Lon: -118.949513 Lat: 34.1842742, Lon: -118.947663 5 | Lat: 34.185952, Lon: -118.949513 Lat: 34.184898, Lon: -118.949349 6 | Lat: 34.185952, Lon: -118.949513 Lat: 34.191625, Lon: -118.950069 7 | Lat: 34.1832868, Lon: -118.9491068 Lat: 34.1842502, Lon: -118.94923 8 | Lat: 34.184898, Lon: -118.949349 Lat: 34.1849616, Lon: -118.9485947 9 | Lat: 34.184898, Lon: -118.949349 Lat: 34.1842502, Lon: -118.94923 10 | Lat: 34.184898, Lon: -118.949349 Lat: 34.185952, Lon: -118.949513 11 | Lat: 34.182935, Lon: -118.945212 Lat: 34.1842902, Lon: -118.9456633 12 | Lat: 34.186876, Lon: -118.944755 Lat: 34.1842902, Lon: -118.9456633 13 | Lat: 34.1842742, Lon: -118.947663 Lat: 34.1842902, Lon: -118.9456633 14 | Lat: 34.1842742, Lon: -118.947663 Lat: 34.1842502, Lon: -118.94923 15 | Lat: 34.1842742, Lon: -118.947663 Lat: 34.185952, Lon: -118.949513 16 | Lat: 34.191625, Lon: -118.950069 Lat: 34.185952, Lon: -118.949513 17 | Lat: 34.1842902, Lon: -118.9456633 Lat: 34.182935, Lon: -118.945212 18 | Lat: 34.1842902, Lon: -118.9456633 Lat: 34.186876, Lon: -118.944755 19 | Lat: 34.1842902, Lon: -118.9456633 Lat: 34.1842742, Lon: -118.947663 20 | Lat: 34.1849616, Lon: -118.9485947 Lat: 34.184898, Lon: -118.949349 21 | -------------------------------------------------------------------------------- /data/intersections/ucsd.intersections: -------------------------------------------------------------------------------- 1 | Lat: 32.8756538, Lon: -117.2435715 Lat: 32.8757495, Lon: -117.2430819 2 | Lat: 32.8756538, Lon: -117.2435715 Lat: 32.8755247, Lon: -117.2437787 3 | Lat: 32.8756538, Lon: -117.2435715 Lat: 32.8766947, Lon: -117.2436925 4 | Lat: 32.8755247, Lon: -117.2437787 Lat: 32.875336, Lon: -117.244034 5 | Lat: 32.8755247, Lon: -117.2437787 Lat: 32.8756538, Lon: -117.2435715 6 | Lat: 32.8757495, Lon: -117.2430819 Lat: 32.8741164, Lon: -117.2382689 7 | Lat: 32.8757495, Lon: -117.2430819 Lat: 32.8765435, Lon: -117.2435225 8 | Lat: 32.8757495, Lon: -117.2430819 Lat: 32.8756538, Lon: -117.2435715 9 | Lat: 32.8765435, Lon: -117.2435225 Lat: 32.8757495, Lon: -117.2430819 10 | Lat: 32.8747713, Lon: -117.2360131 Lat: 32.8742087, Lon: -117.2381344 11 | Lat: 32.8741164, Lon: -117.2382689 Lat: 32.8728698, Lon: -117.2379406 12 | Lat: 32.8741164, Lon: -117.2382689 Lat: 32.8757495, Lon: -117.2430819 13 | Lat: 32.8741164, Lon: -117.2382689 Lat: 32.8742087, Lon: -117.2381344 14 | Lat: 32.873833, Lon: -117.2435847 Lat: 32.8756538, Lon: -117.2435715 15 | Lat: 32.8762498, Lon: -117.2438229 Lat: 32.8755247, Lon: -117.2437787 16 | Lat: 32.8771038, Lon: -117.2360337 Lat: 32.8741164, Lon: -117.2382689 17 | Lat: 32.8742087, Lon: -117.2381344 Lat: 32.8747713, Lon: -117.2360131 18 | Lat: 32.8742087, Lon: -117.2381344 Lat: 32.8769858, Lon: -117.2359995 19 | Lat: 32.8742087, Lon: -117.2381344 Lat: 32.8741164, Lon: -117.2382689 20 | Lat: 32.8769858, Lon: -117.2359995 Lat: 32.8771038, Lon: -117.2360337 21 | Lat: 32.8728698, Lon: -117.2379406 Lat: 32.8725007, Lon: -117.2380045 22 | Lat: 32.8728698, Lon: -117.2379406 Lat: 32.8724213, Lon: -117.2379297 23 | Lat: 32.8724053, Lon: -117.2377174 Lat: 32.8742087, Lon: -117.2381344 24 | Lat: 32.875336, Lon: -117.244034 Lat: 32.8755247, Lon: -117.2437787 25 | -------------------------------------------------------------------------------- /data/maps/mapfiles.list: -------------------------------------------------------------------------------- 1 | ucsd.map 2 | utc.map 3 | san_diego.map 4 | hollywood_large.map 5 | new_york.map -------------------------------------------------------------------------------- /data/mazes/maze1.maze: -------------------------------------------------------------------------------- 1 | 4 4 2 | 3 | * 4 | ** 5 | -------------------------------------------------------------------------------- /data/testdata/simpletest.map: -------------------------------------------------------------------------------- 1 | 1.0 1.0 4.0 1.0 "main" "city street" 2 | 4.0 1.0 4.0 2.0 "state" "city street" 3 | 4.0 1.0 4.0 0.0 "state" "city street" 4 | 4.0 1.0 5.0 1.0 "main" "city street" 5 | 4.0 1.0 7.0 3.0 "front" "city street" 6 | 4.0 0.0 4.0 -1.0 "state" "city street" 7 | 4.0 0.0 5.0 1.0 "short" "connector" 8 | 7.0 3.0 8.0 -1.0 "high" "residential" 9 | 8.0 -1.0 4.0 -1.0 "south" "residential" 10 | 5.0 1.0 6.5 0.0 "first" "residential" 11 | 6.5 0.0 8.0 -1.0 "next" "residential" 12 | 4.0 1.0 1.0 1.0 "main" "city street" 13 | 4.0 2.0 4.0 1.0 "state" "city street" 14 | 4.0 0.0 4.0 1.0 "state" "city street" 15 | 5.0 1.0 4.0 1.0 "main" "city street" 16 | 7.0 3.0 4.0 1.0 "front" "city street" 17 | 8.0 -1.0 7.0 3.0 "high" "residential" 18 | 4.0 -1.0 8.0 -1.0 "south" "residential" 19 | 6.5 0.0 5.0 1.0 "first" "residential" 20 | 8.0 -1.0 6.5 0.0 "next" "residential" 21 | 4.0 -1.0 4.0 0.0 "state" "city street" 22 | 5.0 1.0 4.0 0.0 "short" "connector" -------------------------------------------------------------------------------- /libs/java-json.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salimt/GoogleMaps-Find-Fastest-Route-Algorithms/20405a7f2b0842b32968acf6d6157fa90a2bfa7b/libs/java-json.jar -------------------------------------------------------------------------------- /libs/javax.json-1.0.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salimt/GoogleMaps-Find-Fastest-Route-Algorithms/20405a7f2b0842b32968acf6d6157fa90a2bfa7b/libs/javax.json-1.0.4.jar -------------------------------------------------------------------------------- /libs/jsoup-1.12.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salimt/GoogleMaps-Find-Fastest-Route-Algorithms/20405a7f2b0842b32968acf6d6157fa90a2bfa7b/libs/jsoup-1.12.1.jar -------------------------------------------------------------------------------- /src/application/CLabel.java: -------------------------------------------------------------------------------- 1 | package application; 2 | 3 | import javafx.beans.property.ObjectProperty; 4 | import javafx.beans.property.SimpleObjectProperty; 5 | import javafx.scene.Node; 6 | import javafx.scene.control.Label; 7 | import javafx.scene.paint.Color; 8 | import javafx.scene.paint.Paint; 9 | 10 | /** 11 | * Label which has an object property associated with it 12 | * 13 | * @author UCSD MOOC development team 14 | * 15 | * @param Type of object associated with label 16 | */ 17 | 18 | public class CLabel extends Label { 19 | private ObjectProperty item = new SimpleObjectProperty(this, "item"); 20 | private static final Paint RED = Color.web("#9E092F"); 21 | private static final Paint GREEN = Color.web("#099E78"); 22 | 23 | // CONSTRUCTORS 24 | public CLabel() { 25 | super(); 26 | } 27 | 28 | public CLabel(String text, T item) { 29 | super(text); 30 | 31 | if(item != null) 32 | setItem(item); 33 | else 34 | setItem(null); 35 | } 36 | 37 | public CLabel(String text, Node graphic, T item) { 38 | super(text, graphic); 39 | if(item != null) 40 | setItem(item); 41 | else 42 | setItem(null); 43 | 44 | } 45 | 46 | 47 | /** 48 | * Used to update item when new item is set. 49 | * 50 | * @param item 51 | * @param empty 52 | */ 53 | protected void updateView(T item, boolean empty) { 54 | if(item != null) { 55 | setText(item.toString()); 56 | setTextFill(GREEN); 57 | } 58 | else { 59 | // TODO -- could change this to be more generic 60 | setText("Choose Point"); 61 | setTextFill(RED); 62 | } 63 | } 64 | 65 | public final ObjectProperty itemProperty(){ return item; } 66 | 67 | 68 | public T getItem(){ 69 | return item.get(); 70 | } 71 | 72 | public void setItem(T newItem) { 73 | item.set(newItem); 74 | updateView(item.get(), true); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/application/DataSet.java: -------------------------------------------------------------------------------- 1 | package application; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import geography.GeographicPoint; 8 | import util.GraphLoader; 9 | 10 | /** 11 | * Class to wrap the graph, current .map file map, and 12 | * other pertinent information about the map data sets 13 | * 14 | * @author UCSD MOOC development team 15 | * 16 | */ 17 | public class DataSet { 18 | String filePath; 19 | roadgraph.MapGraph graph; 20 | Set intersections; 21 | private HashMap> roads; 22 | boolean currentlyDisplayed; 23 | 24 | public DataSet (String path) { 25 | this.filePath = path; 26 | graph = null; 27 | roads = null; 28 | currentlyDisplayed = false; 29 | } 30 | 31 | public void setGraph(roadgraph.MapGraph graph) { 32 | this.graph = graph; 33 | } 34 | 35 | public void setRoads(HashMap> roads) { this.roads = roads; } 36 | public roadgraph.MapGraph getGraph(){ return graph; } 37 | 38 | /** Return the intersections in this graph. 39 | * In order to keep it consistent, if getVertices in the graph returns something 40 | * other than null (i.e. it's been implemented) we get the vertices from 41 | * the graph itself. But if the graph hasn't been implemented, we return 42 | * the set of intersections we separately maintain specifically for this purpose. 43 | * @return The set of road intersections (vertices in the graph) 44 | */ 45 | public Set getIntersections() { 46 | Set intersectionsFromGraph = graph.getVertices(); 47 | if (intersectionsFromGraph == null) { 48 | return intersections; 49 | } 50 | else { 51 | return intersectionsFromGraph; 52 | } 53 | } 54 | 55 | public HashMap> getRoads() { return this.roads; } 56 | 57 | public void initializeGraph() { 58 | graph = new roadgraph.MapGraph(); 59 | roads = new HashMap>(); 60 | intersections = new HashSet(); 61 | //TODO: change to use intersections for points in graph. 62 | GraphLoader.loadRoadMap(filePath, graph, roads, intersections); 63 | } 64 | 65 | public String getFilePath() { 66 | return this.filePath; 67 | } 68 | 69 | 70 | public Object[] getPoints() { 71 | Set pointSet = roads.keySet(); 72 | return pointSet.toArray(); 73 | } 74 | 75 | public boolean isDisplayed() { 76 | return this.currentlyDisplayed; 77 | } 78 | 79 | public void setDisplayed(boolean value) { 80 | this.currentlyDisplayed = value; 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /src/application/GeoLabel.java: -------------------------------------------------------------------------------- 1 | /** Small class to store a GeographicPoint 2 | * as a label 3 | * @author UCSD MOOC development team 4 | * 5 | */ 6 | 7 | package application; 8 | 9 | import javafx.beans.property.ObjectProperty; 10 | import javafx.scene.paint.Color; 11 | import javafx.scene.paint.Paint; 12 | 13 | public class GeoLabel { 14 | 15 | private geography.GeographicPoint point; 16 | private static final Paint RED = Color.web("#9E092F"); 17 | private static final Paint GREEN = Color.web("#099E78"); 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/application/RouteVisualization.java: -------------------------------------------------------------------------------- 1 | /** Class to aid with route visualization for search 2 | * 3 | * @author UCSD MOOC development team 4 | * 5 | */ 6 | 7 | package application; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import gmapsfx.javascript.IJavascriptRuntime; 13 | import gmapsfx.javascript.JavascriptArray; 14 | import gmapsfx.javascript.JavascriptRuntime; 15 | import gmapsfx.javascript.object.GoogleMap; 16 | import gmapsfx.javascript.object.LatLong; 17 | import gmapsfx.javascript.object.LatLongBounds; 18 | import gmapsfx.javascript.object.Marker; 19 | import gmapsfx.javascript.object.MarkerOptions; 20 | import javafx.concurrent.Task; 21 | import javafx.scene.control.Button; 22 | import netscape.javascript.JSObject; 23 | 24 | public class RouteVisualization { 25 | List points; 26 | ArrayList markerList; 27 | MarkerManager manager; 28 | JavascriptArray markers; 29 | IJavascriptRuntime runtime; 30 | 31 | 32 | 33 | 34 | public RouteVisualization(MarkerManager manager) { 35 | points = new ArrayList(); 36 | markerList = new ArrayList(); 37 | this.manager = manager; 38 | 39 | } 40 | 41 | public void acceptPoint(geography.GeographicPoint point) { 42 | points.add(point); 43 | 44 | // System.out.println("accepted point : " + point); 45 | } 46 | 47 | 48 | 49 | public void startVisualization() { 50 | 51 | LatLongBounds bounds = new LatLongBounds(); 52 | List latLongs = new ArrayList(); 53 | JavascriptArray jsArray = new JavascriptArray(); 54 | manager.hideIntermediateMarkers(); 55 | manager.hideDestinationMarker(); 56 | // manager.disableRouteButtons(true); 57 | 58 | // create JavascriptArray of points 59 | for(geography.GeographicPoint point : points) { 60 | LatLong ll = new LatLong(point.getX(), point.getY()); 61 | MarkerOptions options = MarkerManager.createDefaultOptions(ll); 62 | Marker newMarker = new Marker(options); 63 | jsArray.push(newMarker); 64 | markerList.add(newMarker); 65 | bounds.extend(ll); 66 | } 67 | 68 | // fit map bounds to visualization 69 | manager.getMap().fitBounds(bounds); 70 | 71 | // get javascript runtime and execute animation 72 | runtime = JavascriptRuntime.getInstance(); 73 | String command = runtime.getFunction("visualizeSearch", manager.getMap(), jsArray); 74 | // System.out.println(command); 75 | 76 | runtime.execute(command); 77 | 78 | // MapApp.showInfoAlert("Nodes visited :" , latLongs.size() +" nodes were visited in the search"); 79 | manager.disableVisButton(true); 80 | // manager.disableRouteButtons(false); 81 | 82 | 83 | } 84 | 85 | public void clearMarkers() { 86 | for(Marker marker : markerList) { 87 | marker.setVisible(false); 88 | } 89 | } 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/application/SelectManager.java: -------------------------------------------------------------------------------- 1 | /** Class to manage items selected in the GUI 2 | * 3 | * @author UCSD MOOC development team 4 | * 5 | */ 6 | 7 | package application; 8 | import application.services.GeneralService; 9 | import geography.GeographicPoint; 10 | import gmapsfx.javascript.object.Marker; 11 | 12 | public class SelectManager { 13 | private CLabel pointLabel; 14 | private CLabel startLabel; 15 | private CLabel destinationLabel; 16 | private Marker startMarker; 17 | private Marker destinationMarker; 18 | private Marker selectedMarker; 19 | private MarkerManager markerManager; 20 | private DataSet dataSet; 21 | 22 | 23 | public SelectManager() { 24 | startMarker = null; 25 | destinationMarker = null; 26 | selectedMarker = null; 27 | pointLabel = null; 28 | startLabel = null; 29 | destinationLabel = null; 30 | dataSet = null; 31 | } 32 | 33 | 34 | public void resetSelect() { 35 | markerManager.setSelectMode(true); 36 | } 37 | public void clearSelected() { 38 | selectedMarker = null; 39 | pointLabel.setItem(null); 40 | } 41 | 42 | public void setAndDisplayData(DataSet data) { 43 | setDataSet(data); 44 | //TODO - maybe if markerManager!= null? 45 | if(markerManager != null) { 46 | markerManager.displayDataSet(); 47 | } 48 | else { 49 | System.err.println("Error : Marker Manager is null."); 50 | } 51 | } 52 | 53 | public void setMarkerManager(MarkerManager manager) { this.markerManager = manager; } 54 | public void setPoint(GeographicPoint point, Marker marker) { 55 | // System.out.println("inSetPoint.. passed : " + point); 56 | pointLabel.setItem(point); 57 | selectedMarker = marker; 58 | } 59 | public void setDataSet(DataSet dataSet) { 60 | this.dataSet = dataSet; 61 | if(markerManager != null) { 62 | markerManager.setDataSet(dataSet); 63 | } 64 | } 65 | 66 | public void setPointLabel(CLabel label) { this.pointLabel = label; } 67 | public void setStartLabel(CLabel label) { this.startLabel = label; } 68 | public void setDestinationLabel(CLabel label) { this.destinationLabel = label; } 69 | 70 | public GeographicPoint getPoint() { return pointLabel.getItem(); } 71 | 72 | 73 | public GeographicPoint getStart(){return startLabel.getItem();} 74 | public GeographicPoint getDestination(){return destinationLabel.getItem();} 75 | public void setStart() { 76 | if(pointLabel.getItem() != null) { 77 | GeographicPoint point = pointLabel.getItem(); 78 | startLabel.setItem(point); 79 | markerManager.setStart(point); 80 | } 81 | } 82 | 83 | public void setDestination() { 84 | if(pointLabel.getItem() != null) { 85 | GeographicPoint point = pointLabel.getItem(); 86 | destinationLabel.setItem(point); 87 | markerManager.setDestination(point); 88 | } 89 | } 90 | 91 | 92 | 93 | } -------------------------------------------------------------------------------- /src/application/TestApp.java: -------------------------------------------------------------------------------- 1 | /** Basic Class to test UI components 2 | * 3 | * @author UCSD MOOC development team 4 | * 5 | */ 6 | package application; 7 | 8 | import gmapsfx.GoogleMapView; 9 | import gmapsfx.MapComponentInitializedListener; 10 | import gmapsfx.javascript.object.GoogleMap; 11 | import gmapsfx.javascript.object.LatLong; 12 | import gmapsfx.javascript.object.MapOptions; 13 | import gmapsfx.javascript.object.MapTypeIdEnum; 14 | import gmapsfx.shapes.Polyline; 15 | import javafx.application.Application; 16 | import javafx.scene.Scene; 17 | import javafx.scene.layout.BorderPane; 18 | import javafx.stage.Stage; 19 | 20 | public class TestApp extends Application 21 | implements MapComponentInitializedListener { 22 | protected GoogleMapView mapComponent; 23 | protected GoogleMap map; 24 | 25 | @Override 26 | public void start(Stage primaryStage) throws Exception { 27 | mapComponent = new GoogleMapView(); 28 | mapComponent.addMapInitializedListener(this); 29 | 30 | BorderPane bp = new BorderPane(); 31 | Scene scene = new Scene(bp); 32 | bp.setCenter(mapComponent); 33 | primaryStage.setScene(scene); 34 | primaryStage.show(); 35 | } 36 | 37 | public void mapInitialized() { 38 | LatLong center = new LatLong(34.0219, -118.4814); 39 | 40 | MapOptions options = new MapOptions(); 41 | options.center(center) 42 | .mapMarker(false) 43 | .mapType(MapTypeIdEnum.ROADMAP) 44 | //maybe set false 45 | .mapTypeControl(true) 46 | .overviewMapControl(false) 47 | .panControl(true) 48 | .rotateControl(false) 49 | .scaleControl(false) 50 | .streetViewControl(false) 51 | .zoom(8) 52 | .zoomControl(true); 53 | 54 | map = mapComponent.createMap(options); 55 | 56 | Polyline p = new Polyline(); 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/application/controllers/RouteController.java: -------------------------------------------------------------------------------- 1 | package application.controllers; 2 | 3 | import application.CLabel; 4 | import application.MapApp; 5 | import application.MarkerManager; 6 | import application.SelectManager; 7 | import application.services.RouteService; 8 | import javafx.scene.control.Button; 9 | import javafx.scene.control.RadioButton; 10 | import javafx.scene.control.ToggleGroup; 11 | 12 | import java.util.List; 13 | 14 | public class RouteController { 15 | // Strings for slider labels 16 | public static final int BFS = 3; 17 | public static final int A_STAR = 2; 18 | public static final int DIJ = 1; 19 | public static final int DISABLE = 0; 20 | public static final int START = 1; 21 | public static final int DESTINATION = 2; 22 | 23 | private int selectedToggle = DIJ; 24 | 25 | private RouteService routeService; 26 | private Button displayButton; 27 | private Button hideButton; 28 | private Button startButton; 29 | private Button resetButton; 30 | private Button destinationButton; 31 | private Button visualizationButton; 32 | 33 | private ToggleGroup group; 34 | private CLabel startLabel; 35 | private CLabel endLabel; 36 | private CLabel pointLabel; 37 | private SelectManager selectManager; 38 | private MarkerManager markerManager; 39 | 40 | 41 | 42 | public RouteController(RouteService routeService, Button displayButton, Button hideButton, 43 | Button resetButton, Button startButton, Button destinationButton, 44 | ToggleGroup group, List searchOptions, Button visualizationButton, 45 | CLabel startLabel, CLabel endLabel, 46 | CLabel pointLabel, SelectManager manager, MarkerManager markerManager) { 47 | // save parameters 48 | this.routeService = routeService; 49 | this.displayButton = displayButton; 50 | this.hideButton = hideButton; 51 | this.startButton = startButton; 52 | this.resetButton = resetButton; 53 | this.destinationButton = destinationButton; 54 | this.group = group; 55 | this.visualizationButton = visualizationButton; 56 | 57 | // maybe don't need references to labels; 58 | this.startLabel = startLabel; 59 | this.endLabel = endLabel; 60 | this.pointLabel = pointLabel; 61 | this.selectManager = manager; 62 | this.markerManager = markerManager; 63 | 64 | setupDisplayButtons(); 65 | setupRouteButtons(); 66 | setupVisualizationButton(); 67 | setupLabels(); 68 | setupToggle(); 69 | //routeService.displayRoute("data/sampleroute.map"); 70 | } 71 | 72 | 73 | private void setupDisplayButtons() { 74 | displayButton.setOnAction(e -> { 75 | if(startLabel.getItem() != null && endLabel.getItem() != null) { 76 | routeService.displayRoute(startLabel.getItem(), endLabel.getItem(), selectedToggle); 77 | } 78 | else { 79 | MapApp.showErrorAlert("Route Display Error", "Make sure to choose points for both start and destination."); 80 | } 81 | }); 82 | 83 | hideButton.setOnAction(e -> { 84 | routeService.hideRoute(); 85 | }); 86 | 87 | //TODO -- implement 88 | resetButton.setOnAction( e -> { 89 | 90 | routeService.reset(); 91 | }); 92 | } 93 | 94 | private void setupVisualizationButton() { 95 | visualizationButton.setOnAction( e -> { 96 | markerManager.startVisualization(); 97 | }); 98 | } 99 | 100 | private void setupRouteButtons() { 101 | startButton.setOnAction(e -> { 102 | //System.out.println(); 103 | selectManager.setStart(); 104 | }); 105 | 106 | destinationButton.setOnAction( e-> { 107 | selectManager.setDestination(); 108 | }); 109 | } 110 | 111 | 112 | private void setupLabels() { 113 | 114 | 115 | } 116 | 117 | private void setupToggle() { 118 | group.selectedToggleProperty().addListener( li -> { 119 | if(group.getSelectedToggle().getUserData().equals("Dijkstra")) { 120 | selectedToggle = DIJ; 121 | } 122 | else if(group.getSelectedToggle().getUserData().equals("A*")) { 123 | selectedToggle = A_STAR; 124 | } 125 | else if(group.getSelectedToggle().getUserData().equals("BFS")) { 126 | selectedToggle = BFS; 127 | } 128 | else { 129 | System.err.println("Invalid radio button selection"); 130 | } 131 | }); 132 | } 133 | 134 | 135 | 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/application/services/GeneralService.java: -------------------------------------------------------------------------------- 1 | package application.services; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.regex.Pattern; 6 | 7 | import application.DataSet; 8 | import application.MapApp; 9 | import application.MarkerManager; 10 | import application.SelectManager; 11 | import gmapsfx.GoogleMapView; 12 | import gmapsfx.javascript.object.GoogleMap; 13 | import gmapsfx.javascript.object.LatLong; 14 | import gmapsfx.javascript.object.LatLongBounds; 15 | import javafx.concurrent.Task; 16 | import javafx.scene.control.Alert; 17 | import javafx.scene.control.Button; 18 | import javafx.scene.control.ComboBox; 19 | import mapmaker.MapMaker; 20 | 21 | // class for map and general application services (file IO, etc.) 22 | public class GeneralService { 23 | // private static boolean singleton = false; 24 | private int currentState; 25 | private SelectManager selectManager; 26 | private GoogleMap map; 27 | private MarkerManager markerManager; 28 | 29 | 30 | 31 | private static final String DATA_FILE_PATTERN = "[\\w_]+.map"; 32 | private static final String DATA_FILE_DIR_STR = "data/maps/"; 33 | 34 | private List filenames; 35 | DataSet dataSet; 36 | 37 | public GeneralService(GoogleMapView mapComponent, SelectManager selectManager, MarkerManager markerManager) { 38 | // get map from GoogleMapView 39 | this.map = mapComponent.getMap(); 40 | this.selectManager = selectManager; 41 | this.markerManager = markerManager; 42 | this.markerManager.setMap(map); 43 | filenames = new ArrayList(); 44 | 45 | // uncomment to click map and print coordinates 46 | /*mapComponent.addUIEventHandler(UIEventType.click, (JSObject obj) -> { 47 | System.out.println(obj.getMember("latLng")); 48 | });*/ 49 | } 50 | 51 | 52 | // writes geographic data flat file 53 | // parameters arr contains the coordinates of the bounds for the map region 54 | public boolean writeDataToFile(String filename, float[] arr) { 55 | MapMaker mm = new MapMaker(arr); 56 | 57 | // parse data and write to filename 58 | if(mm.parseData(filename)) { 59 | return true; 60 | } 61 | 62 | return false; 63 | } 64 | 65 | public static String getDataSetDirectory() { return GeneralService.DATA_FILE_DIR_STR; } 66 | 67 | // gets current bounds of map view 68 | public float[] getBoundsArray() { 69 | LatLong sw, ne; 70 | LatLongBounds bounds = map.getBounds(); 71 | 72 | sw = bounds.getSouthWest(); 73 | ne = bounds.getNorthEast(); 74 | 75 | // [S, W, N, E] 76 | return new float[] {(float) sw.getLatitude(), (float) sw.getLongitude(), 77 | (float) ne.getLatitude(), (float) ne.getLongitude()}; 78 | } 79 | 80 | public void addDataFile(String filename) { 81 | filenames.add(filename); 82 | } 83 | 84 | public void displayIntersections(DataSet dataset) { 85 | // remove old data set markers 86 | if(markerManager == null){ 87 | System.out.println("failure!"); 88 | } 89 | if(markerManager.getDataSet() != null) { 90 | markerManager.clearMarkers(); 91 | markerManager.getDataSet().setDisplayed(false); 92 | } 93 | 94 | // display new data set 95 | selectManager.setAndDisplayData(dataset); 96 | dataset.setDisplayed(true); 97 | 98 | } 99 | 100 | public float boundsSize() { 101 | float[] bounds = getBoundsArray(); 102 | return (bounds[2] - bounds[0]) * (bounds[3] - bounds[1]); 103 | } 104 | 105 | public boolean checkBoundsSize(double limit) { 106 | if (boundsSize() > limit) { 107 | return false; 108 | } 109 | return true; 110 | } 111 | 112 | /** 113 | * Check if file name matches pattern [filename].map 114 | * 115 | * @param str - path to check 116 | * @return string to use as path 117 | */ 118 | public String checkDataFileName(String str) { 119 | if(Pattern.matches(DATA_FILE_PATTERN, str)) { 120 | return DATA_FILE_DIR_STR + str; 121 | } 122 | return null; 123 | } 124 | 125 | public void runFetchTask(String fName, ComboBox cb, Button button) { 126 | float[] arr = getBoundsArray(); 127 | 128 | Task task = new Task() { 129 | @Override 130 | public String call() { 131 | if(writeDataToFile(fName, arr)) { 132 | return fName; 133 | } 134 | 135 | return "z" + fName; 136 | 137 | } 138 | }; 139 | 140 | 141 | 142 | Alert fetchingAlert = MapApp.getInfoAlert("Loading : ", "Fetching data for current map area..."); 143 | task.setOnSucceeded( e -> { 144 | if(task.getValue().equals(fName)) { 145 | addDataFile(fName); 146 | 147 | cb.getItems().add(new DataSet(fName)); 148 | if(fetchingAlert.isShowing()) { 149 | fetchingAlert.close(); 150 | } 151 | MapApp.showInfoAlert("Fetch completed : ", "Data set : \"" + fName + "\" written to file!"); 152 | // System.out.println("Fetch Task Succeeded"); 153 | 154 | } 155 | else { 156 | // System.out.println("Something went wrong, data not written to file : Task succeeded but fName returned differently"); 157 | 158 | } 159 | 160 | button.setDisable(false); 161 | 162 | }); 163 | 164 | 165 | task.setOnFailed( e -> { 166 | 167 | }); 168 | 169 | task.setOnRunning(e -> { 170 | button.setDisable(true); 171 | fetchingAlert.showAndWait(); 172 | }); 173 | 174 | 175 | Thread fetchThread = new Thread(task); 176 | fetchThread.start(); 177 | } 178 | 179 | 180 | 181 | public List getDataFiles() { 182 | return filenames; 183 | } 184 | 185 | public static String getFileRegex() { 186 | return GeneralService.DATA_FILE_PATTERN; 187 | } 188 | 189 | 190 | public void setState(int state) { 191 | currentState = state; 192 | } 193 | 194 | 195 | public double getState() { return currentState; } 196 | 197 | 198 | } 199 | 200 | -------------------------------------------------------------------------------- /src/basicgraph/GraphAdjList.java: -------------------------------------------------------------------------------- 1 | package basicgraph; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** A class that implements a directed graph. 9 | * The graph may have self-loops, parallel edges. 10 | * Vertices are labeled by integers 0 .. n-1 11 | * and may also have String labels. 12 | * The edges of the graph are not labeled. 13 | * Representation of edges via adjacency lists. 14 | * 15 | * @author UCSD MOOC development team and YOU 16 | * 17 | */ 18 | public class GraphAdjList extends Graph { 19 | 20 | 21 | private Map> adjListsMap; 22 | 23 | /** 24 | * Create a new empty Graph 25 | */ 26 | public GraphAdjList () { 27 | adjListsMap = new HashMap>(); 28 | } 29 | 30 | /** 31 | * Implement the abstract method for adding a vertex. 32 | */ 33 | public void implementAddVertex() { 34 | int v = getNumVertices(); 35 | ArrayList neighbors = new ArrayList(); 36 | adjListsMap.put(v, neighbors); 37 | } 38 | 39 | /** 40 | * Implement the abstract method for adding an edge. 41 | * @param v the index of the start point for the edge. 42 | * @param w the index of the end point for the edge. 43 | */ 44 | public void implementAddEdge(int v, int w) { 45 | (adjListsMap.get(v)).add(w); 46 | 47 | } 48 | 49 | /** 50 | * Implement the abstract method for finding all 51 | * out-neighbors of a vertex. 52 | * If there are multiple edges between the vertex 53 | * and one of its out-neighbors, this neighbor 54 | * appears once in the list for each of these edges. 55 | * 56 | * @param v the index of vertex. 57 | * @return List a list of indices of vertices. 58 | */ 59 | public List getNeighbors(int v) { 60 | return new ArrayList(adjListsMap.get(v)); 61 | } 62 | 63 | /** 64 | * Implement the abstract method for finding all 65 | * in-neighbors of a vertex. 66 | * If there are multiple edges from another vertex 67 | * to this one, the neighbor 68 | * appears once in the list for each of these edges. 69 | * 70 | * @param v the index of vertex. 71 | * @return List a list of indices of vertices. 72 | */ 73 | public List getInNeighbors(int v) { 74 | List inNeighbors = new ArrayList(); 75 | for (int u : adjListsMap.keySet()) { 76 | //iterate through all edges in u's adjacency list and 77 | //add u to the inNeighbor list of v whenever an edge 78 | //with startpoint u has endpoint v. 79 | for (int w : adjListsMap.get(u)) { 80 | if (v == w) { 81 | inNeighbors.add(u); 82 | } 83 | } 84 | } 85 | return inNeighbors; 86 | } 87 | 88 | 89 | /** 90 | * Implement the abstract method for finding all 91 | * vertices reachable by two hops from v. 92 | * 93 | * @param v the index of vertex. 94 | * @return List a list of indices of vertices. 95 | */ 96 | public List getDistance2(int v) { 97 | // XXX: Implement this method in week 2 98 | List distances = new ArrayList <>(); 99 | 100 | for(Integer n: getNeighbors(v)) 101 | distances.addAll(getNeighbors(n)); 102 | 103 | return distances; 104 | } 105 | 106 | /** 107 | * Generate string representation of adjacency list 108 | * @return the String 109 | */ 110 | public String adjacencyString() { 111 | String s = "Adjacency list"; 112 | s += " (size " + getNumVertices() + "+" + getNumEdges() + " integers):"; 113 | 114 | for (int v : adjListsMap.keySet()) { 115 | s += "\n\t"+v+": "; 116 | for (int w : adjListsMap.get(v)) { 117 | s += w+", "; 118 | } 119 | } 120 | return s; 121 | } 122 | 123 | 124 | 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/basicgraph/GraphAdjMatrix.java: -------------------------------------------------------------------------------- 1 | package basicgraph; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** A class that implements a directed graph. 7 | * The graph may have self-loops, parallel edges. 8 | * Vertices are labeled by integers 0 .. n-1 9 | * and may also have String labels. 10 | * The edges of the graph are not labeled. 11 | * Representation of edges via an adjacency matrix. 12 | * 13 | * @author UCSD MOOC development team and YOU 14 | * 15 | */ 16 | public class GraphAdjMatrix extends Graph { 17 | 18 | private final int defaultNumVertices = 5; 19 | private int[][] adjMatrix; 20 | 21 | /** Create a new empty Graph */ 22 | public GraphAdjMatrix () { 23 | adjMatrix = new int[defaultNumVertices][defaultNumVertices]; 24 | } 25 | 26 | /** 27 | * Implement the abstract method for adding a vertex. 28 | * If need to increase dimensions of matrix, double them 29 | * to amortize cost. 30 | */ 31 | public void implementAddVertex() { 32 | int v = getNumVertices(); 33 | if (v >= adjMatrix.length) { 34 | int[][] newAdjMatrix = new int[v*2][v*2]; 35 | for (int i = 0; i < adjMatrix.length; i ++) { 36 | for (int j = 0; j < adjMatrix.length; j ++) { 37 | newAdjMatrix[i][j] = adjMatrix[i][j]; 38 | } 39 | } 40 | adjMatrix = newAdjMatrix; 41 | } 42 | } 43 | 44 | /** 45 | * Implement the abstract method for adding an edge. 46 | * Allows for multiple edges between two points: 47 | * the entry at row v, column w stores the number of such edges. 48 | * @param v the index of the start point for the edge. 49 | * @param w the index of the end point for the edge. 50 | */ 51 | public void implementAddEdge(int v, int w) { 52 | adjMatrix[v][w] += 1; 53 | } 54 | 55 | /** 56 | * Implement the abstract method for finding all 57 | * out-neighbors of a vertex. 58 | * If there are multiple edges between the vertex 59 | * and one of its out-neighbors, this neighbor 60 | * appears once in the list for each of these edges. 61 | * 62 | * @param v the index of vertex. 63 | * @return List a list of indices of vertices. 64 | */ 65 | public List getNeighbors(int v) { 66 | List neighbors = new ArrayList(); 67 | for (int i = 0; i < getNumVertices(); i ++) { 68 | for (int j=0; j< adjMatrix[v][i]; j ++) { 69 | neighbors.add(i); 70 | } 71 | } 72 | return neighbors; 73 | } 74 | 75 | /** 76 | * Implement the abstract method for finding all 77 | * in-neighbors of a vertex. 78 | * If there are multiple edges from another vertex 79 | * to this one, the neighbor 80 | * appears once in the list for each of these edges. 81 | * 82 | * @param v the index of vertex. 83 | * @return List a list of indices of vertices. 84 | */ 85 | public List getInNeighbors(int v) { 86 | List inNeighbors = new ArrayList(); 87 | for (int i = 0; i < getNumVertices(); i ++) { 88 | for (int j=0; j< adjMatrix[i][v]; j++) { 89 | inNeighbors.add(i); 90 | } 91 | } 92 | return inNeighbors; 93 | } 94 | 95 | /** 96 | * Implement the abstract method for finding all 97 | * vertices reachable by two hops from v. 98 | * Use matrix multiplication to record length 2 paths. 99 | * 100 | * @param v the index of vertex. 101 | * @return List a list of indices of vertices. 102 | */ 103 | public List getDistance2(int v) { 104 | // XXX Implement this method in week 2 105 | List distances = new ArrayList <>(); 106 | int[][] product = new int[getNumVertices()][getNumVertices()]; 107 | 108 | for(int j=0; j0){ 114 | for(int m=0; m geometryPoints; 20 | 21 | private String roadName; 22 | private String roadType; 23 | 24 | // Length in km 25 | private double length; 26 | 27 | public RoadSegment(GeographicPoint pt1, GeographicPoint pt2, 28 | List geometry, String roadName, 29 | String roadType, double length) 30 | { 31 | point1 = pt1; 32 | point2 = pt2; 33 | geometryPoints = new ArrayList(geometry); 34 | this.roadName = roadName; 35 | this.roadType = roadType; 36 | this.length = length; 37 | } 38 | 39 | 40 | /** Return all of the points from start to end in that order 41 | * on this segment. 42 | * @param start 43 | * @param end 44 | * @return 45 | */ 46 | public List getPoints(GeographicPoint start, 47 | GeographicPoint end) 48 | { 49 | List allPoints = new ArrayList(); 50 | if (point1.equals(start) && point2.equals(end)) { 51 | allPoints.add(start); 52 | allPoints.addAll(geometryPoints); 53 | allPoints.add(end); 54 | } 55 | else if (point2.equals(start) && point1.equals(end)) { 56 | allPoints.add(end); 57 | allPoints.addAll(geometryPoints); 58 | allPoints.add(start); 59 | Collections.reverse(allPoints); 60 | } 61 | else { 62 | throw new IllegalArgumentException("Start and end points do not " 63 | + "match end points of segment"); 64 | } 65 | 66 | return allPoints; 67 | } 68 | 69 | /** Two road segments are equal if they have the same start and end points 70 | * and they have the same road name. 71 | */ 72 | public boolean equals(Object o) 73 | { 74 | if (!(o instanceof RoadSegment)) { 75 | return false; 76 | } 77 | 78 | RoadSegment other = (RoadSegment)o; 79 | boolean ptsEqual = false; 80 | if (other.point1.equals(this.point1) && other.point2.equals(this.point2)) { 81 | ptsEqual = true; 82 | } 83 | if (other.point2.equals(this.point1) && other.point1.equals(this.point2)) 84 | { 85 | ptsEqual = true; 86 | } 87 | return this.roadName.equals(other.roadName) && ptsEqual && this.length == other.length; 88 | } 89 | 90 | // get hashCode 91 | public int hashCode() 92 | { 93 | return point1.hashCode() + point2.hashCode(); 94 | } 95 | 96 | // return road segment as String 97 | public String toString() 98 | { 99 | String toReturn = this.roadName + ", " +this.roadType; 100 | toReturn += " [" + point1; 101 | for (GeographicPoint p : this.geometryPoints) { 102 | toReturn += "; " + p; 103 | } 104 | toReturn += "; " + point2 + "]"; 105 | 106 | return toReturn; 107 | } 108 | 109 | // get the length of the road segment 110 | public double getLength() { return this.length; } 111 | 112 | 113 | // given one end, return the other. 114 | public geography.GeographicPoint getOtherPoint(geography.GeographicPoint point) { 115 | if(point.equals(point1)) { 116 | return point2; 117 | } 118 | if(point.equals(point2)) { 119 | return point1; 120 | } 121 | 122 | System.out.println("ERROR!! : in RoadSegment::getOtherPoint Neither point matched"); 123 | return null; 124 | } 125 | 126 | 127 | 128 | } 129 | -------------------------------------------------------------------------------- /src/gmapsfx/ArrayTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx; 18 | 19 | import gmapsfx.javascript.JavaFxWebEngine; 20 | import gmapsfx.javascript.JavascriptArray; 21 | import gmapsfx.javascript.JavascriptObject; 22 | import gmapsfx.javascript.JavascriptRuntime; 23 | import javafx.application.Application; 24 | import javafx.application.Platform; 25 | import javafx.beans.value.ChangeListener; 26 | import javafx.beans.value.ObservableValue; 27 | import javafx.concurrent.Worker; 28 | import javafx.scene.Scene; 29 | import javafx.scene.layout.BorderPane; 30 | import javafx.scene.web.WebView; 31 | import javafx.stage.Stage; 32 | import netscape.javascript.JSObject; 33 | 34 | /** 35 | * 36 | * @author Geoff Capper 37 | */ 38 | public class ArrayTester extends Application { 39 | 40 | protected WebView webview; 41 | protected JavaFxWebEngine webengine; 42 | 43 | @Override 44 | public void start(final Stage stage) throws Exception { 45 | 46 | webview = new WebView(); 47 | webengine = new JavaFxWebEngine(webview.getEngine()); 48 | JavascriptRuntime.setDefaultWebEngine( webengine ); 49 | 50 | BorderPane bp = new BorderPane(); 51 | bp.setCenter(webview); 52 | 53 | webengine.getLoadWorker().stateProperty().addListener( 54 | new ChangeListener() { 55 | public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { 56 | if (newState == Worker.State.SUCCEEDED) { 57 | runTests(); 58 | //Platform.exit(); 59 | } 60 | } 61 | }); 62 | webengine.load(getClass().getResource("/html/arrays.html").toExternalForm()); 63 | 64 | Scene scene = new Scene(bp, 600, 600); 65 | 66 | stage.setScene(scene); 67 | stage.show(); 68 | 69 | } 70 | 71 | private void runTests() { 72 | 73 | JSObject jsWin = (JSObject) webengine.executeScript("window"); 74 | jsWin.call("displayTest", new Object[]{null}); 75 | 76 | JavascriptArray ary = new JavascriptArray(); 77 | 78 | int len = 0; 79 | for (int i = 0; i < 6; i++) { 80 | len = ary.push("String " + i); 81 | System.out.println("testArrays push " + i + " gives len: " + len); 82 | } 83 | 84 | System.out.println("testArrays toString: " + ary.toString()); 85 | 86 | ary.reverse(); 87 | 88 | System.out.println("testArrays reverse toString: " + ary.toString()); 89 | 90 | ary.reverse(); 91 | 92 | Object obj = ary.pop(); 93 | 94 | System.out.println("testArrays popped: " + obj); 95 | System.out.println("testArrays popped toString: " + ary.toString()); 96 | 97 | TestJSO jso = new TestJSO(); 98 | jso.setTestName("Test 1"); 99 | 100 | ary.unshift(jso); 101 | 102 | System.out.println("testArrays unshift JsO toString: " + ary.toString()); 103 | 104 | Object jso1 = ary.shift(); 105 | 106 | System.out.println("testArrays shift JsO: " + jso1); 107 | System.out.println("testArrays shift JsO reference equality: " + (jso == jso1)); 108 | System.out.println("testArrays shift JsO toString: " + ary.toString()); 109 | 110 | ary.push(jso); 111 | System.out.println("testArrays push JsO toString: " + ary.toString()); 112 | 113 | jsWin.call("displayArray", ary); 114 | 115 | jso.setTestName("Altered Test 1"); 116 | 117 | jsWin.call("displayArray", ary); 118 | 119 | System.out.println("testArrays alter JsO toString: " + ary.toString()); 120 | 121 | Object jso2 = ary.get(ary.length() - 1); 122 | System.out.println("testArrays get JsO2: " + jso2); 123 | 124 | jsWin.call("iterateArray", ary); 125 | 126 | jsWin.call("displayTestEnd", new Object[]{null}); 127 | 128 | } 129 | 130 | 131 | public static void main(String[] args) { 132 | System.setProperty("java.net.useSystemProxies", "true"); 133 | launch(args); 134 | } 135 | 136 | 137 | class TestJSO extends JavascriptObject { 138 | 139 | public TestJSO() { 140 | super("Object"); 141 | } 142 | 143 | public void setTestName(String testName) { 144 | setProperty("testName", testName); 145 | } 146 | 147 | public String getTestName() { 148 | return getProperty("testName", String.class); 149 | } 150 | 151 | @Override 152 | public String toString() { 153 | return getTestName(); 154 | } 155 | 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /src/gmapsfx/MapComponentInitializedListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx; 18 | 19 | /** 20 | * 21 | * @author Rob Terpilowski 22 | */ 23 | public interface MapComponentInitializedListener { 24 | 25 | public void mapInitialized(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/gmapsfx/MapNotInitializedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx; 18 | 19 | /** 20 | * 21 | * @author Rob Terpilowski 22 | */ 23 | public class MapNotInitializedException extends RuntimeException { 24 | 25 | public MapNotInitializedException() { 26 | super( "Map has not yet been initialized"); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/gmapsfx/MapReadyListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 GMapsFX. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx; 18 | 19 | /** A MapReadyListener is called when the MapOptions have been loaded and the 20 | * Javascript map object is set up ready to be accessed. While the MapType is 21 | * null many methods will cause errors, so this listener is notified when 22 | * projection_changed returns a non-null value, as this is expected to happen 23 | * after the MapType is set. 24 | * 25 | * @author Geoff Capper 26 | */ 27 | public interface MapReadyListener { 28 | 29 | public void mapReady(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/IJavascriptRuntime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package gmapsfx.javascript; 17 | 18 | import netscape.javascript.JSObject; 19 | 20 | /** 21 | * An interface for interacting with a JavaScript environment which includes 22 | * methods for building strings that represent functions and constructors as 23 | * well as providing a means to execute commands. 24 | * 25 | * @author Rob Terpilowski 26 | */ 27 | public interface IJavascriptRuntime { 28 | 29 | /** 30 | * Execute the specified command returning a value (if any) 31 | * 32 | * @param command The JavaScript command to execute 33 | * @return The underlying JavaScript object that was returned by the script. 34 | */ 35 | JSObject execute(String command); 36 | 37 | /** 38 | * Gets a constructor as a string which then can be passed to the execute(). 39 | * 40 | * @param javascriptObjectType The type of JavaScript object to create 41 | * @param args The args of the constructor 42 | * @return A string which can be passed to the JavaScript environment to 43 | * create a new object. 44 | */ 45 | String getConstructor(String javascriptObjectType, Object... args); 46 | 47 | /** 48 | * Gets an array parameter constructor as a String, which then can be 49 | * passed to the execute() method. Note, this is where the parameter to the 50 | * constructor is an array, rather than the varargs which are broken down 51 | * into separate parameters. 52 | * 53 | * @param javascriptObjectType type The type of JavaScript object array to create 54 | * @param ary The array elements 55 | * @return A string which can be passed to the JavaScript environment to 56 | * create a new array. 57 | */ 58 | String getArrayConstructor(String javascriptObjectType, Object[] ary); 59 | 60 | /** 61 | * Gets a function as a String, which then can be passed to the 62 | * execute() method. 63 | * 64 | * @param variable The variable to invoke the function on. 65 | * @param function The function to invoke 66 | * @param args Arguments the function requires 67 | * @return A string which can be passed to the JavaScript environment to 68 | * invoke the function 69 | */ 70 | String getFunction(String variable, String function, Object... args); 71 | 72 | 73 | /** 74 | * Gets a function as a String, which then can be passed to the 75 | * execute() method. 76 | * 77 | * @param function The function to invoke 78 | * @param args Arguments the function requires 79 | * @return A string which can be passed to the JavaScript environment to 80 | * invoke the function 81 | */ 82 | String getFunction(String function, Object... args); 83 | 84 | 85 | /** 86 | * Gets an array function as a String, which then can be passed to the 87 | * execute() method. 88 | * 89 | * @param function The function to invoke 90 | * @param ary The array of arguments to pass to the function. 91 | * @return A string which can be passed to the JavaScript environment to 92 | * invoke the function 93 | */ 94 | String getArrayFunction(String function, Object[] ary); 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/IWebEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gmapsfx.javascript; 7 | 8 | import javafx.concurrent.Worker; 9 | 10 | /** 11 | * Provides an abstraction to the web engine, so that a mock engine can be utilized in unit tests, or a different web engine 12 | * could be utilized in future versions of this framework. 13 | * 14 | * @author Rob Terpilowski 15 | */ 16 | public interface IWebEngine { 17 | 18 | /** 19 | * Executes the specified JavaScript Command 20 | * 21 | * @param command The command to execute 22 | * @return The object returned by the script (if any). 23 | */ 24 | public Object executeScript(String command); 25 | 26 | /** 27 | * Gets a worked which will be notified when a web page has finished 28 | * loading. 29 | * 30 | * @return The worker 31 | */ 32 | public Worker getLoadWorker(); 33 | 34 | /** 35 | * Loads the specified URL 36 | * 37 | * @param url The URL to load in the engine. 38 | */ 39 | public void load(String url); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/JavaFxWebEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.javascript; 8 | 9 | import javafx.concurrent.Worker; 10 | import javafx.scene.web.WebEngine; 11 | 12 | /** 13 | * This class provides an implementation of the IWebEngine interface utilizing 14 | * a javafx.scene.web.WebEngine as the underlying engine. 15 | * 16 | * @author Rob Terpilowski 17 | */ 18 | public class JavaFxWebEngine implements IWebEngine { 19 | 20 | 21 | protected WebEngine webEngine; 22 | 23 | /** 24 | * Builds a new engine utilizing the specified JavaFX WebEngine 25 | * @param engine The JavaFX WebEngine to use. 26 | */ 27 | public JavaFxWebEngine( WebEngine engine ) { 28 | this.webEngine = engine; 29 | } 30 | 31 | 32 | /** 33 | * Executes the specified JavaScript Command 34 | * @param command The command to execute 35 | * @return The object returned by the script (if any). 36 | */ 37 | @Override 38 | public Object executeScript(String command) { 39 | return webEngine.executeScript(command); 40 | } 41 | 42 | /** 43 | * Gets a worked which will be notified when a web page has finished loading. 44 | * @return The worker 45 | */ 46 | @Override 47 | public Worker getLoadWorker() { 48 | return webEngine.getLoadWorker(); 49 | } 50 | 51 | /** 52 | * Loads the specified URL 53 | * @param url The URL to load in the engine. 54 | */ 55 | @Override 56 | public void load(String url) { 57 | webEngine.load(url); 58 | } 59 | 60 | 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/JavascriptArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 GMapsFX. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | import netscape.javascript.JSObject; 22 | 23 | /** JavascriptObject implementation of an array. 24 | *

25 | * Return values are supplied as their raw return value from Javascript, unless 26 | * that value has previously been passed in to the array as a JavascriptObject. 27 | * The caller is then responsible for wrapping any new JSObjects in the 28 | * appropriate JavascriptObject, as they should know what is needed. 29 | *

30 | * 31 | * 32 | * @author Geoff Capper 33 | */ 34 | public class JavascriptArray extends JavascriptObject { 35 | 36 | private final Map content = new HashMap<>(); 37 | 38 | public JavascriptArray() { 39 | runtime.execute("var " + variableName + " = []"); 40 | jsObject = runtime.execute(variableName); 41 | } 42 | 43 | public Object get(int idx) { 44 | Object obj = getJSObject().getSlot(idx); 45 | if (obj instanceof JSObject && content.containsKey((JSObject) obj)) { 46 | return (JavascriptObject) content.get((JSObject) obj); 47 | } 48 | return obj; 49 | } 50 | 51 | //concat() Joins two or more arrays, and returns a copy of the joined arrays 52 | //indexOf() Search the array for an element and returns its position 53 | public int indexOf(Object obj) { 54 | if (obj instanceof JavascriptObject) { 55 | return checkInteger(invokeJavascript("indexOf", ((JavascriptObject) obj).getJSObject()), -1); 56 | } 57 | return checkInteger(invokeJavascript("indexOf", obj), -1); 58 | } 59 | 60 | //join() Joins all elements of an array into a string 61 | //lastIndexOf() Search the array for an element, starting at the end, and returns its position 62 | public int lastIndexOf(Object obj) { 63 | if (obj instanceof JavascriptObject) { 64 | return checkInteger(invokeJavascript("lastIndexOf", ((JavascriptObject) obj).getJSObject()), -1); 65 | } 66 | return checkInteger(invokeJavascript("lastIndexOf", obj), -1); 67 | } 68 | 69 | //pop() Removes the last element of an array, and returns that element 70 | public Object pop() { 71 | //Object obj = jsObject.getSlot(jsLen - 1); 72 | Object obj = invokeJavascript("pop"); 73 | if (obj instanceof JSObject && content.containsKey((JSObject) obj)) { 74 | return (JavascriptObject) content.get((JSObject) obj); 75 | } 76 | return obj; 77 | } 78 | 79 | //push() Adds new elements to the end of an array, and returns the new length 80 | public int push(Object obj) { 81 | if (obj instanceof JavascriptObject) { 82 | //jsObject.setSlot(length(), ((JavascriptObject) obj).getJSObject()); 83 | content.put(((JavascriptObject) obj).getJSObject(), (JavascriptObject) obj); 84 | } 85 | return checkInteger(invokeJavascript("push", obj), 0); 86 | } 87 | 88 | //reverse() Reverses the order of the elements in an array 89 | public void reverse() { 90 | invokeJavascript("reverse"); 91 | } 92 | 93 | //shift() Removes the first element of an array, and returns that element 94 | public Object shift() { 95 | Object obj = invokeJavascript("shift"); 96 | if (obj instanceof JSObject && content.containsKey((JSObject) obj)) { 97 | return (JavascriptObject) content.get((JSObject) obj); 98 | } 99 | return obj; 100 | } 101 | 102 | //slice() Selects a part of an array, and returns the new array 103 | 104 | //sort() Sorts the elements of an array 105 | public void sort(String func) { 106 | if (func == null || func.isEmpty()) { 107 | Object ary = invokeJavascript("sort"); 108 | } else { 109 | Object ary = invokeJavascript("sort", func); 110 | } 111 | } 112 | 113 | //splice() Adds/Removes elements from an array 114 | //toString() Converts an array to a string, and returns the result 115 | @Override 116 | public String toString() { 117 | return invokeJavascriptReturnValue("toString", String.class); 118 | } 119 | 120 | //unshift() Adds new elements to the beginning of an array, and returns the new length 121 | public int unshift(Object obj) { 122 | if (obj instanceof JavascriptObject) { 123 | //jsObject.setSlot(length(), ((JavascriptObject) obj).getJSObject()); 124 | content.put(((JavascriptObject) obj).getJSObject(), (JavascriptObject) obj); 125 | } 126 | return checkInteger(invokeJavascript("unshift", obj), 0); 127 | } 128 | 129 | //valueOf() 130 | 131 | /** Get the length of the array. This returns the value from the underlying 132 | * Javascrpt object. 133 | * 134 | * @return 135 | */ 136 | public int length() { 137 | return checkInteger(getProperty("length"), 0); 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/JavascriptEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package gmapsfx.javascript; 17 | 18 | import netscape.javascript.JSObject; 19 | 20 | /** 21 | * 22 | * @author Rob Terpilowski 23 | */ 24 | public class JavascriptEnum { 25 | 26 | protected IJavascriptRuntime runtime; 27 | protected String type; 28 | protected String name; 29 | protected Object value; 30 | 31 | 32 | protected JavascriptEnum(String type, String name) { 33 | this.type = type; 34 | this.name = name; 35 | runtime = JavascriptRuntime.getInstance(); 36 | 37 | } 38 | 39 | public Object getEnumValue() { 40 | if (value == null) { 41 | JSObject jsObject = runtime.execute(type); 42 | value = jsObject.getMember(name); 43 | } 44 | return value; 45 | } 46 | 47 | public String getType() { 48 | return type; 49 | } 50 | 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/JavascriptFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package gmapsfx.javascript; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 22 | * @author robt 23 | */ 24 | public class JavascriptFunction extends JavascriptObject { 25 | 26 | /** 27 | * Attempt to create a function as an object 28 | * 29 | * var myCallback = function( argX ) { someVariable.someMethod( argX ); 30 | * someOtherVariable.someOtherMethod(); } 31 | */ 32 | protected String functionName; 33 | protected List args; 34 | protected List functionLines; 35 | 36 | public JavascriptFunction(String functionName, List args, List functionLines) { 37 | this.functionName = functionName; 38 | this.args = args; 39 | this.functionLines = functionLines; 40 | } 41 | 42 | public String getFunctionAsString() { 43 | StringBuilder sb = new StringBuilder(); 44 | sb.append(functionName).append("("); 45 | if (args.isEmpty()) { 46 | sb.append(")"); 47 | } else { 48 | for (String arg : args) { 49 | sb.append(arg).append(","); 50 | } 51 | sb.deleteCharAt(sb.length() - 1); 52 | sb.append(")"); 53 | } 54 | sb.append("{\n"); 55 | for( JavascriptFunctionLine line : functionLines ) { 56 | sb.append( line.getFunctionLine() ); 57 | } 58 | sb.append("}"); 59 | 60 | return sb.toString(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/JavascriptFunctionLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript; 18 | 19 | import java.util.List; 20 | import netscape.javascript.JSObject; 21 | 22 | /** 23 | * 24 | * @author robt 25 | */ 26 | public class JavascriptFunctionLine { 27 | 28 | protected JSObject jsObject; 29 | protected JavascriptObject object; 30 | protected String method; 31 | protected List args; 32 | 33 | public JavascriptFunctionLine(JavascriptObject object, String method, List args) { 34 | this.object = object; 35 | this.method = method; 36 | this.args = args; 37 | } 38 | 39 | 40 | public String getFunctionLine() { 41 | StringBuilder sb = new StringBuilder(); 42 | sb.append( object.getVariableName() ).append(".").append(method); 43 | sb.append("("); 44 | for( Object arg : args ) { 45 | if( arg instanceof JavascriptObject) { 46 | sb.append( ((JavascriptObject) arg).getVariableName() ); 47 | } else { 48 | sb.append( arg.toString() ); 49 | } 50 | sb.append(","); 51 | } 52 | sb.deleteCharAt( sb.length()-1); 53 | sb.append(");\n"); 54 | 55 | return sb.toString(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/event/EventHandlers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.event; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | import java.util.UUID; 22 | import netscape.javascript.JSObject; 23 | 24 | /** This object forms the bridge between Javascript events and the Java events. 25 | *

26 | * An instance of this class is assigned to the document model so that 27 | * Javascript can access it to make callbacks when events occur. 28 | *

29 | * An application calls on one of the two addXXEventHandler methods in the 30 | * {@link gmapsfx.javascript.object.GoogleMap} class to register an 31 | * instance of the {@link GFXEventHandler} interface against a certain event 32 | * type in the Google Maps event model. See addUIEventHandler and addStateEventHandler. 33 | *

34 | * This class uses a key based on a UUID to map the Javascript event handlers 35 | * registered against the Google Maps model back to our Java event handlers 36 | * stored here. The addXXEventHandler methods in GoogleMap create functions 37 | * that call back into this class using the supplied key. 38 | *

39 | * Currently an instance of this class is registered as: 40 | * document.jsHandlers 41 | *

42 | * The event listeners are established using the following Javascript calls: 43 | *

44 | * {@link gmapsfx.javascript.object.GoogleMap#addUIEventHandler} 45 | *


 46 |  * google.maps.event.addListener(map, 'event_type', function(event) {
 47 |  *      document.jsHandlers.handleUIEvent('key', event.latLng);
 48 |  * });
 49 |  * 
50 | *

51 | * {@link gmapsfx.javascript.object.GoogleMap#addStateEventHandler} 52 | *


 53 |  *  google.maps.event.addListener(map, 'event_type', function() {
 54 |  *      document.jsHandlers.handleStateEvent('key');
 55 |  *  });
 56 |  * 
57 | * 58 | * @author Geoff Capper 59 | * 60 | */ 61 | public class EventHandlers { 62 | 63 | private final Map handlers = new HashMap<>(); 64 | 65 | public EventHandlers() { 66 | } 67 | 68 | /** Registers a handler and returns the callback key to be passed to 69 | * Javascript. 70 | * 71 | * @param handler Handler to be registered. 72 | * @return A String random UUID that can be used as the callback key. 73 | */ 74 | public String registerHandler(GFXEventHandler handler) { 75 | String uuid = UUID.randomUUID().toString(); 76 | handlers.put(uuid, handler); 77 | return uuid; 78 | } 79 | 80 | /** This method is called from Javascript, passing in the previously 81 | * created callback key, and the event object. The current implementation 82 | * is receiving the LatLng object that the Javascript MouseEvent contains. 83 | *

84 | * It may be more useful to return the MouseEvent and let clients go from 85 | * there, but there is only the stop() method on the MouseEvent? 86 | * 87 | * @param callbackKey Key generated by the call to registerHandler. 88 | * @param result Currently the LatLng object from the Google Maps event. 89 | */ 90 | public void handleUIEvent(String callbackKey, JSObject result) { 91 | if (handlers.containsKey(callbackKey) && handlers.get(callbackKey) instanceof UIEventHandler) { 92 | ((UIEventHandler) handlers.get(callbackKey)).handle(result); 93 | } else { 94 | System.err.println("Error in handle: " + callbackKey + " for result: " + result); 95 | } 96 | } 97 | 98 | /** This method is called from Javascript, passing in the previously 99 | * created callback key. It uses that to find the correct handler and 100 | * then passes on the call. State events in the Google Maps API don't pass 101 | * any parameters. 102 | * 103 | * @param callbackKey Key generated by the call to registerHandler. 104 | */ 105 | public void handleStateEvent(String callbackKey) { 106 | if (handlers.containsKey(callbackKey) && handlers.get(callbackKey) instanceof StateEventHandler) { 107 | ((StateEventHandler) handlers.get(callbackKey)).handle(); 108 | } else { 109 | System.err.println("Error in handle: " + callbackKey + " for state handler "); 110 | } 111 | } 112 | 113 | } -------------------------------------------------------------------------------- /src/gmapsfx/javascript/event/GFXEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.event; 18 | 19 | /** A tagging interface to allow us to store all event handlers in the one 20 | * {@link EventHandlers} object. 21 | * 22 | * @author Geoff Capper 23 | */ 24 | public interface GFXEventHandler { 25 | } 26 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/event/MapStateEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.event; 18 | 19 | /** An enum of Google Maps state events for the Map object. 20 | *

21 | * See Google Maps Javascript API V3 Reference 22 | * 23 | * @author Geoff Capper 24 | */ 25 | public enum MapStateEventType { 26 | bounds_changed, center_changed, drag, dragend, dragstart, 27 | heading_changed, idle, maptypeid_changed, projection_changed, 28 | resize, tilesloaded, tilt_changed, zoom_changed; 29 | } 30 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/event/StateEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.event; 18 | 19 | /** Handles Google Maps state events, which are called without any parameters. 20 | * 21 | * @author Geoff Capper 22 | */ 23 | public interface StateEventHandler extends GFXEventHandler { 24 | public void handle(); 25 | } 26 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/event/UIEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.event; 18 | 19 | import netscape.javascript.JSObject; 20 | 21 | /** Handles Google Maps UI events. 22 | * 23 | * @author Geoff Capper 24 | */ 25 | public interface UIEventHandler extends GFXEventHandler { 26 | /** 27 | * @param obj This object may be either a MouseEvent or one of it's subclasses. 28 | */ 29 | public void handle(JSObject obj); 30 | } 31 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/event/UIEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.event; 18 | 19 | /** Enum containing the strings for the event types passed to the Google Maps 20 | * APIs for UI events. Whilst drawn from those for the Map object, they should 21 | * be the same for most other objects. 22 | *

23 | * See Google Maps Javascript API V3 Reference 24 | * 25 | * @author Geoff Capper 26 | */ 27 | public enum UIEventType { 28 | 29 | click, dblclick, mousemove, mouseup, mousedown, mouseover, mouseout, rightclick; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/Animation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package gmapsfx.javascript.object; 17 | 18 | /** 19 | * 20 | * @author Rob Terpilowski 21 | */ 22 | public enum Animation { 23 | 24 | NULL("null"), 25 | BOUNCE("google.maps.Animation.BOUNCE"), 26 | DROP("google.maps.Animation.DROP"); 27 | 28 | protected String typeString; 29 | 30 | Animation(String typeString) { 31 | this.typeString = typeString; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return typeString; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/GMapObjectType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | /** 20 | * 21 | * @author Rob Terpilowski 22 | */ 23 | public interface GMapObjectType { 24 | 25 | public static final String OBJECT = "Object"; 26 | public static final String MAP = "google.maps.Map"; 27 | public static final String INFO_WINDOW = "google.maps.InfoWindow"; 28 | public static final String LAT_LNG = "google.maps.LatLng"; 29 | public static final String MARKER = "google.maps.Marker"; 30 | public static final String SIZE = "google.maps.Size"; 31 | public static final String POLYLINE = "google.maps.Polyline"; 32 | public static final String POLYGON = "google.maps.Polygon"; 33 | public static final String RECTANGLE = "google.maps.Rectangle"; 34 | public static final String CIRCLE = "google.maps.Circle"; 35 | public static final String MVC_ARRAY = "google.maps.MVCArray"; 36 | public static final String LAT_LNG_BOUNDS = "google.maps.LatLngBounds"; 37 | public static final String ELEVATION_SERVICE = "google.maps.ElevationService"; 38 | public static final String ELEVATION_RESULT = "google.maps.ElevationResult"; 39 | public static final String MAX_ZOOM_SERVICE = "google.maps.MaxZoomService"; 40 | public static final String MAX_ZOOM_RESULT = "google.maps.MaxZoomResult"; 41 | public static final String PROJECTION = "google.maps.Projection"; 42 | public static final String POINT = "google.maps.Point"; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/GMapPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 GMapsFX. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | import netscape.javascript.JSObject; 21 | 22 | /** 23 | * 24 | * @author Geoff Capper 25 | */ 26 | public class GMapPoint extends JavascriptObject { 27 | 28 | public GMapPoint(JSObject obj) { 29 | super(GMapObjectType.POINT, obj); 30 | } 31 | 32 | public double getX() { 33 | return getProperty("x", Double.class ); 34 | } 35 | 36 | public double getY() { 37 | return getProperty("y", Double.class ); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "GMapPoint[" + getX() + ", " + getY() + "]"; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/InfoWindow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** 22 | * An overlay that looks like a bubble and is often connected to a marker. 23 | * This class corresponds to google.maps.InfoWindow in the Google Maps JavaScript API 24 | * 25 | * 26 | * @author Rob Terpilowski 27 | */ 28 | public class InfoWindow extends JavascriptObject { 29 | 30 | public static final String INFO_WINDOW_TYPE = "google.maps.InfoWindow"; 31 | 32 | public InfoWindow() { 33 | super(INFO_WINDOW_TYPE); 34 | } 35 | 36 | 37 | public InfoWindow( InfoWindowOptions options ) { 38 | super(GMapObjectType.INFO_WINDOW, options); 39 | } 40 | 41 | 42 | public void close() { 43 | invokeJavascript("close"); 44 | } 45 | 46 | public String getContent() { 47 | return invokeJavascriptReturnValue("getContent", String.class ); 48 | } 49 | 50 | public LatLong getPosition() { 51 | return invokeJavascriptReturnValue("getPosition", LatLong.class ); 52 | } 53 | 54 | public int getZIndex() { 55 | return invokeJavascriptReturnValue("getZIndex", Integer.class ); 56 | } 57 | 58 | public void open( GoogleMap map ) { 59 | invokeJavascript("open", map); 60 | } 61 | 62 | public void open( GoogleMap map, Marker marker ){ 63 | invokeJavascript( "open", map, marker ); 64 | } 65 | 66 | public void setContent( String content ) { 67 | invokeJavascript("setContent", content); 68 | } 69 | 70 | public void setOptions( InfoWindowOptions options ) { 71 | invokeJavascript("setOptions", options); 72 | } 73 | 74 | public void setPosition( LatLong position ){ 75 | invokeJavascript( "setPosition", position ); 76 | } 77 | 78 | public void setZIndex( int index ) { 79 | invokeJavascript( "setZIndex", index ); 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/InfoWindowOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** 22 | * Options for setting an InfoWindow on a Map. This class corresponds to google.maps.InfoWindowOptions" in 23 | * the Google Maps JavaScript API. 24 | * 25 | * @author Rob Terpilowski 26 | */ 27 | public class InfoWindowOptions extends JavascriptObject { 28 | 29 | /** 30 | * Default constructor 31 | */ 32 | public InfoWindowOptions() { 33 | super(GMapObjectType.OBJECT); 34 | } 35 | 36 | /** 37 | *Content to display in the InfoWindow. This can be an HTML element, a plain-text string, or a string containing HTML. 38 | * The InfoWindow will be sized according to the content. 39 | * @param content 40 | * @return this instance of the InfoWindowOptions 41 | */ 42 | public InfoWindowOptions content( String content ) { 43 | setProperty("content", content); 44 | return this; 45 | } 46 | 47 | /** 48 | * Disable auto-pan on open. By default, the info window will pan the map so that it is fully visible when it opens. 49 | * @param disabled true if it should be disabled 50 | * @return this instance of the InfoWindowOptions 51 | */ 52 | public InfoWindowOptions disableAutoPan( boolean disabled ) { 53 | setProperty("disableAutoPan", disabled); 54 | return this; 55 | } 56 | 57 | /** 58 | * Maximum width of the infowindow, regardless of content's width. This value is only considered if it is set before a call to open. 59 | * To change the maximum width when changing content, call close, setOptions, and then open. 60 | * @param width The max width 61 | * @return this instance of the InfoWindowOptions 62 | */ 63 | public InfoWindowOptions maxWidth( int width ) { 64 | setProperty( "maxWidth", width ); 65 | return this; 66 | } 67 | 68 | 69 | 70 | /** 71 | * The offset, in pixels, of the tip of the info window from the point on the map at whose geographical coordinates the info window is anchored. 72 | * If an InfoWindow is opened with an anchor, the pixelOffset will be calculated from the anchor's anchorPoint property. 73 | * @param size The offset in pixels. 74 | * @return this instance of the InfoWindowOptions 75 | */ 76 | public InfoWindowOptions pixelOffset( Size size ) { 77 | setProperty( "pixelOffset", size ); 78 | return this; 79 | } 80 | 81 | 82 | /** 83 | * The LatLng at which to display this InfoWindow. 84 | * If the InfoWindow is opened with an anchor, the anchor's position will be used instead. 85 | * @param latlong The position of the window 86 | * @return this instance of the InfoWindowOptions 87 | */ 88 | public InfoWindowOptions position( LatLong latlong ) { 89 | setProperty( "position", latlong ); 90 | return this; 91 | } 92 | 93 | /** 94 | * All InfoWindows are displayed on the map in order of their zIndex, with higher values displaying in front of InfoWindows with lower values. 95 | * By default, InfoWindows are displayed according to their latitude, with InfoWindows of lower latitudes appearing in front of InfoWindows at higher latitudes. 96 | * InfoWindows are always displayed in front of markers. 97 | * @param index The index to set this window to 98 | * @return this instance of the InfoWindowOptions 99 | */ 100 | public InfoWindowOptions zIndex( int index ) { 101 | setProperty( "zIndex", index ); 102 | return this; 103 | } 104 | 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/LatLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * This file includes Java implementations of some of the v3_epolys.js 17 | * extensions to LatLng for Javascript by Mike Williams and Larry Ross. 18 | * See included file src/main/resource/html/v3_epoly.js for their original 19 | * licence. 20 | */ 21 | package gmapsfx.javascript.object; 22 | 23 | import gmapsfx.javascript.JavascriptObject; 24 | import netscape.javascript.JSObject; 25 | 26 | /** 27 | * 28 | * @author Rob Terpilowski 29 | */ 30 | public class LatLong extends JavascriptObject { 31 | 32 | public static final double EarthRadiusMeters = 6378137.0; // meters 33 | 34 | 35 | public LatLong(double latitude, double longitude) { 36 | super(GMapObjectType.LAT_LNG, latitude, longitude); 37 | } 38 | 39 | public LatLong(JSObject jsObject) { 40 | super(GMapObjectType.LAT_LNG, jsObject); 41 | } 42 | 43 | public double getLatitude() { 44 | return invokeJavascriptReturnValue("lat", Number.class ).doubleValue(); 45 | } 46 | 47 | public double getLongitude() { 48 | return invokeJavascriptReturnValue("lng", Number.class ).doubleValue(); 49 | } 50 | 51 | /** 52 | * From v3_epoly.js, calculates the distance between this LatLong point and 53 | * another. 54 | * 55 | * @param end The end point to calculate the distance to. 56 | * @return The distance, in metres, to the end point. 57 | */ 58 | public double distanceFrom(LatLong end) { 59 | 60 | double dLat = (end.getLatitude() - getLatitude()) * Math.PI / 180; 61 | double dLon = (end.getLongitude() - getLongitude()) * Math.PI / 180; 62 | 63 | double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) 64 | + Math.cos(getLatitude() * Math.PI / 180) 65 | * Math.cos(end.getLatitude() * Math.PI / 180) 66 | * Math.sin(dLon / 2) * Math.sin(dLon / 2); 67 | 68 | double c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 69 | double d = EarthRadiusMeters * c; 70 | return d; 71 | } 72 | 73 | /** 74 | * Convenience method to convert the latitude of this LatLong to radians. 75 | * 76 | * @return The latitude value of this LatLong, as radians. 77 | */ 78 | public double latToRadians() { 79 | return Math.toRadians(getLatitude()); 80 | } 81 | 82 | /** 83 | * Convenience method to convert the longitude of this LatLong to radians. 84 | * 85 | * @return The longitude of this LatLong, as radians. 86 | */ 87 | public double longToRadians() { 88 | return Math.toRadians(getLongitude()); 89 | } 90 | 91 | /** 92 | * Calculates the LatLong position of the end point of a line the specified 93 | * distance from this LatLong, along the provided bearing, where North is 0, 94 | * East is 90 etc. 95 | * 96 | * @param bearing The bearing, in degrees, with North as 0, East as 90 etc. 97 | * @param distance The distance in metres. 98 | * @return A new LatLong indicating the end point. 99 | */ 100 | public LatLong getDestinationPoint(double bearing, double distance) { 101 | 102 | double brng = Math.toRadians(bearing); 103 | 104 | double lat1 = latToRadians(); 105 | double lon1 = longToRadians(); 106 | 107 | double lat2 = Math.asin(Math.sin(lat1) 108 | * Math.cos(distance / EarthRadiusMeters) 109 | + Math.cos(lat1) * Math.sin(distance / EarthRadiusMeters) 110 | * Math.cos(brng)); 111 | 112 | double lon2 = lon1 + Math.atan2(Math.sin(brng) 113 | * Math.sin(distance / EarthRadiusMeters) * Math.cos(lat1), 114 | Math.cos(distance / EarthRadiusMeters) 115 | - Math.sin(lat1) * Math.sin(lat2)); 116 | 117 | return new LatLong(Math.toDegrees(lat2), Math.toDegrees(lon2)); 118 | 119 | } 120 | 121 | /** 122 | * Calculates the bearing, in degrees, of the end LatLong point from this 123 | * LatLong point. 124 | * 125 | * @param end The point that the bearing is calculated for. 126 | * @return The bearing, in degrees, of the supplied point from this point. 127 | */ 128 | public double getBearing(LatLong end) { 129 | if (this.equals(end)) { 130 | return 0; 131 | } 132 | 133 | double lat1 = latToRadians(); 134 | double lon1 = longToRadians(); 135 | double lat2 = end.latToRadians(); 136 | double lon2 = end.longToRadians(); 137 | 138 | double angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), 139 | Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) 140 | * Math.cos(lat2) * Math.cos(lon1 - lon2)); 141 | 142 | if (angle < 0.0) { 143 | angle += Math.PI * 2.0; 144 | } 145 | if (angle > Math.PI) { 146 | angle -= Math.PI * 2.0; 147 | } 148 | 149 | return Math.toDegrees(angle); 150 | } 151 | 152 | 153 | 154 | 155 | @Override 156 | public String toString() { 157 | return "lat: " + String.format("%.8G", getLatitude()) + " lng: " + String.format("%.8G", getLongitude()); 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/LatLongBounds.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 GMapsFX 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | import netscape.javascript.JSObject; 21 | 22 | /** 23 | * 24 | * @author Geoff Capper 25 | */ 26 | public class LatLongBounds extends JavascriptObject { 27 | 28 | public LatLongBounds() { 29 | super(GMapObjectType.LAT_LNG_BOUNDS); 30 | } 31 | 32 | public LatLongBounds(LatLong sw, LatLong ne) { 33 | super(GMapObjectType.LAT_LNG_BOUNDS, sw, ne); 34 | } 35 | 36 | public LatLongBounds(JSObject obj) { 37 | super(GMapObjectType.LAT_LNG_BOUNDS, obj); 38 | } 39 | 40 | public LatLongBounds extend(LatLong point) { 41 | Object obj = invokeJavascript("extend", point); 42 | return new LatLongBounds((JSObject)obj); 43 | } 44 | 45 | public LatLong getNorthEast() { 46 | Object obj = invokeJavascript("getNorthEast"); 47 | return new LatLong((JSObject) obj); 48 | } 49 | 50 | public LatLong getSouthWest() { 51 | Object obj = invokeJavascript("getSouthWest"); 52 | return new LatLong((JSObject) obj); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "LatLongBounds[NE:" + getNorthEast() + ", SW:" + getSouthWest() + "]"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/MVCArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package gmapsfx.javascript.object; 17 | 18 | import gmapsfx.javascript.JavascriptObject; 19 | import netscape.javascript.JSObject; 20 | 21 | /** 22 | * This javascript object current takes JavascriptObjects as parameters, but 23 | * returns JSObjects, as it doesn't know what has been placed within it. 24 | * 25 | * @author Geoff Capper 26 | */ 27 | public class MVCArray extends JavascriptObject { 28 | 29 | public MVCArray() { 30 | this(new Object[]{}); 31 | } 32 | 33 | public MVCArray(Object[] ary) { 34 | super(GMapObjectType.MVC_ARRAY, ary, true); 35 | } 36 | 37 | public MVCArray(JSObject obj) { 38 | super(GMapObjectType.MVC_ARRAY, obj); 39 | } 40 | 41 | /** 42 | * Removes all elements from the array. 43 | * 44 | */ 45 | public void clear() { 46 | invokeJavascript("clear"); 47 | } 48 | 49 | /** 50 | * Iterates over the elements within the array, calling the supplied 51 | * function for each member. The parameters to the callback function are: 52 | * func(element, index) 53 | * 54 | * @param func 55 | */ 56 | public void forEach(String func) { 57 | invokeJavascript("forEach", func); 58 | } 59 | 60 | /** 61 | * Returns a JSObject representing the underlying array. Not entirely sure 62 | * how useful this would be for people. 63 | * 64 | * @return 65 | */ 66 | public JSObject getArray() { 67 | return (JSObject) invokeJavascript("getArray"); 68 | } 69 | 70 | /** 71 | * Returns the item at the specified index in the array. 72 | * 73 | * @param idx The index of the item to be returned. 74 | * @return The object at the specified index. 75 | */ 76 | public JSObject getAt(int idx) { 77 | return (JSObject) invokeJavascript("getAt", idx); 78 | } 79 | 80 | /** 81 | * Gets the length of the array. 82 | * 83 | * @return 84 | */ 85 | public int getLength() { 86 | return (int) invokeJavascript("getLength"); 87 | } 88 | 89 | /** 90 | * Inserts the supplied element at the specified index in the array. 91 | * 92 | * @param idx The index at which to insert the item. 93 | * @param elem The item to be inserted. 94 | */ 95 | public void insertAt(int idx, JavascriptObject elem) { 96 | invokeJavascript("insertAt", idx, elem); 97 | } 98 | 99 | /** 100 | * Removes and returns the last element of the array 101 | * 102 | * @return 103 | */ 104 | public JSObject pop() { 105 | return (JSObject) invokeJavascript("pop"); 106 | } 107 | 108 | /** 109 | * Adds the supplied element onto the end of the array, then returns the 110 | * length of the array. 111 | * 112 | * @param obj The Javascript object to be added to the array. 113 | * @return The length of the array after the addition. 114 | */ 115 | public int push(JavascriptObject obj) { 116 | return (int) invokeJavascript("push", obj); 117 | } 118 | 119 | /** 120 | * Removes and discards the item at the specified index. 121 | * 122 | * @param idx The index of the object to be removed. 123 | */ 124 | public void removeAt(int idx) { 125 | invokeJavascript("removeAt", idx); 126 | } 127 | 128 | /** 129 | * Sets the supplied object at the supplied index. 130 | * 131 | * @param idx The index at which the item should be set. 132 | * @param obj The object to be set at the supplied index. 133 | */ 134 | public void setAt(int idx, JavascriptObject obj) { 135 | invokeJavascript("setAt", idx, obj); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/MapOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** 22 | * 23 | * @author robt 24 | */ 25 | public class MapOptions extends JavascriptObject { 26 | 27 | protected LatLong center; 28 | protected MapTypeIdEnum mapType; 29 | protected boolean mapMarker; 30 | protected boolean overviewMapControl; 31 | protected boolean panControl; 32 | protected boolean rotateControl; 33 | protected boolean scaleControl; 34 | protected boolean streetViewControl; 35 | protected int zoom; 36 | protected boolean zoomControl; 37 | protected boolean mapTypeControl; 38 | 39 | 40 | public MapOptions() { 41 | super(GMapObjectType.OBJECT); 42 | } 43 | 44 | 45 | public MapOptions center( LatLong center ) { 46 | setProperty("center", center); 47 | this.center = center; 48 | return this; 49 | } 50 | 51 | public MapOptions mapMarker( boolean mapMarker ) { 52 | setProperty("mapMarker", mapMarker ); 53 | this.mapMarker = mapMarker; 54 | return this; 55 | } 56 | 57 | public MapOptions mapType( MapTypeIdEnum mapType ) { 58 | setProperty( "mapTypeId", mapType ); 59 | this.mapType = mapType; 60 | return this; 61 | } 62 | 63 | public MapOptions overviewMapControl( boolean overviewMapControl ) { 64 | setProperty("overviewMapControl", overviewMapControl ); 65 | this.overviewMapControl = overviewMapControl; 66 | return this; 67 | } 68 | 69 | public MapOptions panControl( boolean panControl ) { 70 | setProperty( "panControl", panControl); 71 | this.panControl = panControl; 72 | return this; 73 | } 74 | 75 | public MapOptions rotateControl( boolean rotateControl ) { 76 | setProperty( "rotateControl", rotateControl ); 77 | this.rotateControl = rotateControl; 78 | return this; 79 | } 80 | 81 | public MapOptions scaleControl( boolean scaleControl ) { 82 | setProperty( "scaleControl", scaleControl ); 83 | this.scaleControl = scaleControl; 84 | return this; 85 | } 86 | 87 | public MapOptions streetViewControl( boolean streetViewControl ) { 88 | setProperty( "streetViewControl", streetViewControl ); 89 | this.streetViewControl = streetViewControl; 90 | return this; 91 | } 92 | 93 | public MapOptions zoom( int zoom ) { 94 | setProperty( "zoom", zoom ); 95 | this.zoom = zoom; 96 | return this; 97 | } 98 | 99 | public MapOptions zoomControl( boolean zoomControl ) { 100 | setProperty( "zoomControl", zoomControl ); 101 | this.zoomControl = zoomControl; 102 | return this; 103 | } 104 | 105 | public MapOptions mapTypeControl( boolean mapTypeControl ) { 106 | setProperty( "mapTypeControl", mapTypeControl); 107 | this.mapTypeControl = mapTypeControl; 108 | return this; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/MapShape.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | import gmapsfx.shapes.MapShapeOptions; 21 | import netscape.javascript.JSObject; 22 | 23 | /** 24 | * 25 | * @author Geoff Capper 26 | */ 27 | public abstract class MapShape extends JavascriptObject { 28 | 29 | public MapShape(String type) { 30 | super(type); 31 | } 32 | 33 | public MapShape(String type, MapShapeOptions opts) { 34 | super(type, opts); 35 | } 36 | 37 | /** 38 | * This method is called from the GoogleMap.addPolygon() method, 39 | * it should not be invoked directly. 40 | * 41 | * @param map The map to add this Polygon to. 42 | */ 43 | protected void setMap(GoogleMap map) { 44 | invokeJavascript("setMap", map); 45 | } 46 | 47 | // LatLngBounds Gets the LatLngBounds of this Circle. 48 | public LatLongBounds getBounds() { 49 | return new LatLongBounds((JSObject) invokeJavascript("getBounds")); 50 | } 51 | 52 | // Returns whether this circle can be dragged by the user. 53 | public boolean getDraggable() { 54 | return checkBoolean(invokeJavascript("getDraggable"), Boolean.FALSE); 55 | } 56 | 57 | // Returns whether this circle can be edited by the user. 58 | public boolean getEditable() { 59 | return checkBoolean(invokeJavascript("getEditable"), Boolean.FALSE); 60 | } 61 | 62 | //Returns whether this circle is visible on the map. 63 | public boolean getVisible() { 64 | return checkBoolean(invokeJavascript("getVisible"), Boolean.FALSE); 65 | } 66 | 67 | //If set to true, the user can drag this circle over the map. 68 | public void setDraggable(boolean draggable) { 69 | invokeJavascript("setDraggable", draggable); 70 | } 71 | 72 | //If set to true, the user can edit this circle by dragging the control points shown at the center and around the circumference of the circle. 73 | public void setEditable(boolean editable) { 74 | invokeJavascript("setEditable", editable); 75 | } 76 | 77 | //Hides this circle if set to false. 78 | public void setVisible(boolean visible) { 79 | invokeJavascript("setVisible", visible); 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/MapTypeIdEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package gmapsfx.javascript.object; 17 | 18 | import gmapsfx.javascript.JavascriptEnum; 19 | 20 | /** 21 | * 22 | * @author Rob Terpilowski 23 | */ 24 | public class MapTypeIdEnum extends JavascriptEnum { 25 | 26 | public static final String MAP_ENUM = "google.maps.MapTypeId"; 27 | 28 | public static final MapTypeIdEnum TERRAIN = new MapTypeIdEnum("TERRAIN"); 29 | public static final MapTypeIdEnum ROADMAP = new MapTypeIdEnum("ROADMAP"); 30 | public static final MapTypeIdEnum SATELLITE = new MapTypeIdEnum("SATELLITE"); 31 | public static final MapTypeIdEnum HYBRID = new MapTypeIdEnum("HYBRID"); 32 | 33 | public static final MapTypeIdEnum[] ALL = { TERRAIN, ROADMAP, SATELLITE, HYBRID }; 34 | 35 | protected MapTypeIdEnum(String value) { 36 | super(MAP_ENUM, value); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return getName(); 42 | } 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/Marker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** 22 | * Marker which can be placed on a GoogleMap. 23 | * 24 | * @author Rob Terpilowski 25 | */ 26 | public class Marker extends JavascriptObject { 27 | 28 | 29 | protected String title; 30 | protected MarkerOptions markerOptions; 31 | 32 | 33 | /** 34 | * Contructs a new map Marker with the specified options 35 | * @param markerOptions The options to use when constructing this marker. 36 | */ 37 | public Marker(MarkerOptions markerOptions) { 38 | super(GMapObjectType.MARKER, markerOptions); 39 | this.markerOptions = markerOptions; 40 | } 41 | 42 | 43 | /** 44 | * Sets the title of this Marker 45 | * @param title The Marker's new title 46 | */ 47 | public void setTitle( String title ) { 48 | invokeJavascript("setTitle", title); 49 | this.title = title; 50 | } 51 | 52 | 53 | 54 | 55 | // TODO -- take this out ? 56 | /** 57 | * Sets the icon of this Marker 58 | * @param icon The Marker's new icon 59 | */ 60 | public void setIcon( String icon ) { 61 | invokeJavascript("setIcon", icon); 62 | getMarkerOptions().icon = icon; 63 | } 64 | /** 65 | * This method is called from the GoogleMap.addMarker() method, it should not be invoked directly. 66 | * 67 | * @param map The map to add this Marker to. 68 | */ 69 | protected void setMap( GoogleMap map ) { 70 | invokeJavascript("setMap", map); 71 | } 72 | 73 | 74 | /** 75 | * Sets how the marker should be animated. To clear the animation use Animation.NULL 76 | * @param animation The animation to use for this marker. 77 | */ 78 | public void setAnimation( Animation animation ) { 79 | invokeJavascript("setAnimation", animation); 80 | } 81 | 82 | public void setZIndex(double index) { 83 | invokeJavascript("setZIndex", index); 84 | } 85 | 86 | public void setPosition( LatLong latLong ) { 87 | invokeJavascript( "setPosition", latLong ); 88 | } 89 | 90 | public void setOptions(MarkerOptions markerOptions2) { 91 | invokeJavascript("setOptions", markerOptions2); 92 | } 93 | 94 | public void setVisible(boolean visible) { 95 | invokeJavascript("setVisible", visible); 96 | } 97 | 98 | public boolean getVisible() { 99 | return invokeJavascriptReturnValue("getVisible", Boolean.class ); 100 | } 101 | 102 | public MarkerOptions getMarkerOptions() { 103 | return this.markerOptions; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/MarkerOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** 22 | * 23 | * @author Rob Terpilowski 24 | */ 25 | public class MarkerOptions extends JavascriptObject { 26 | 27 | protected LatLong position; 28 | protected String title; 29 | protected boolean visible = true; 30 | protected String icon; 31 | protected Animation animation; 32 | 33 | 34 | 35 | public MarkerOptions() { 36 | super(GMapObjectType.OBJECT); 37 | } 38 | 39 | public MarkerOptions title( String title ) { 40 | setProperty("title", title); 41 | this.title = title; 42 | return this; 43 | } 44 | 45 | public MarkerOptions visible( Boolean visible ) { 46 | setProperty( "visible", visible ); 47 | this.visible = visible; 48 | return this; 49 | } 50 | 51 | 52 | public MarkerOptions position( LatLong latLong ) { 53 | setProperty("position", latLong); 54 | position = latLong; 55 | return this; 56 | } 57 | 58 | 59 | public MarkerOptions icon( String iconPath ) { 60 | setProperty("icon", iconPath); 61 | return this; 62 | } 63 | 64 | public MarkerOptions animation( Animation animation ) { 65 | setProperty("animation", animation); 66 | return this; 67 | } 68 | 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/MarkerShape.java: -------------------------------------------------------------------------------- 1 | package gmapsfx.javascript.object; 2 | 3 | import gmapsfx.javascript.JavascriptArray; 4 | import gmapsfx.javascript.JavascriptObject; 5 | 6 | public class MarkerShape extends JavascriptObject { 7 | private JavascriptArray coords; 8 | private String type; 9 | 10 | public MarkerShape() { 11 | super(GMapObjectType.OBJECT); 12 | } 13 | 14 | public MarkerShape coords(JavascriptArray coords) { 15 | setProperty("coords", coords); 16 | this.coords = coords; 17 | return this; 18 | } 19 | 20 | public MarkerShape type(String type) { 21 | setProperty("type", type); 22 | this.type = type; 23 | return this; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/Polyline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** Wraps a google.maps.Polyline object. 22 | * 23 | * @author Geoff Capper 24 | */ 25 | public class Polyline extends JavascriptObject { 26 | 27 | public Polyline() { 28 | super(GMapObjectType.POLYLINE); 29 | } 30 | 31 | public Polyline(PolylineOptions opts) { 32 | super(GMapObjectType.POLYLINE, opts); 33 | } 34 | 35 | /** 36 | * This method is called from the GoogleMap.addPolyline() method, 37 | * it should not be invoked directly. 38 | * 39 | * @param map The map to add this Polyline to. 40 | */ 41 | protected void setMap(GoogleMap map) { 42 | invokeJavascript("setMap", map); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/PolylineOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** 22 | * 23 | * @author Geoff Capper 24 | */ 25 | public class PolylineOptions extends JavascriptObject { 26 | 27 | private boolean clickable;// Indicates whether this Polyline handles mouse events. Defaults to true. 28 | private boolean draggable;// If set to true, the user can drag this shape over the map. The geodesic property defines the mode of dragging. Defaults to false. 29 | private boolean editable;// If set to true, the user can edit this shape by dragging the control points shown at the vertices and on each segment. Defaults to false. 30 | private boolean geodesic;// When true, edges of the polygon are interpreted as geodesic and will follow the curvature of the Earth. When false, edges of the polygon are rendered as straight lines in screen space. Note that the shape of a geodesic polygon may appear to change when dragged, as the dimensions are maintained relative to the surface of the earth. Defaults to false. 31 | //private icons Array. The icons to be rendered along the polyline. 32 | //map Map Map on which to display Polyline. 33 | private MVCArray path;// MVCArray.|Array. The ordered sequence of coordinates of the Polyline. This path may be specified using either a simple array of LatLngs, or an MVCArray of LatLngs. Note that if you pass a simple array, it will be converted to an MVCArray Inserting or removing LatLngs in the MVCArray will automatically update the polyline on the map. 34 | private String strokeColor;// The stroke color. All CSS3 colors are supported except for extended named colors. 35 | private double strokeOpacity; // The stroke opacity between 0.0 and 1.0. 36 | private double strokeWeight;// The stroke width in pixels. 37 | private boolean visible; // Whether this polyline is visible on the map. Defaults to true. 38 | private int zIndex;// The zIndex compared to other polys. 39 | 40 | 41 | public PolylineOptions() { 42 | super(GMapObjectType.OBJECT); 43 | } 44 | 45 | public PolylineOptions clickable(boolean clickable) { 46 | setProperty("clickable", clickable); 47 | this.clickable = clickable; 48 | return this; 49 | } 50 | 51 | public PolylineOptions draggable(boolean draggable) { 52 | setProperty("draggable", draggable); 53 | this.draggable = draggable; 54 | return this; 55 | } 56 | 57 | public PolylineOptions editable(boolean editable) { 58 | setProperty("editable", editable); 59 | this.editable = editable; 60 | return this; 61 | } 62 | 63 | public PolylineOptions geodesic(boolean geodesic) { 64 | setProperty("geodesic", geodesic); 65 | this.geodesic = geodesic; 66 | return this; 67 | } 68 | // private double[] path;// MVCArray.|Array. The ordered sequence of coordinates of the Polyline. This path may be specified using either a simple array of LatLngs, or an MVCArray of LatLngs. Note that if you pass a simple array, it will be converted to an MVCArray Inserting or removing LatLngs in the MVCArray will automatically update the polyline on the map. 69 | public PolylineOptions path(MVCArray path) { 70 | setProperty("path", path); 71 | this.path = path; 72 | return this; 73 | } 74 | 75 | public PolylineOptions strokeColor(String strokeColor) { 76 | setProperty("strokeColor", strokeColor); 77 | this.strokeColor = strokeColor; 78 | return this; 79 | } 80 | 81 | public PolylineOptions strokeOpacity(double strokeOpacity) { 82 | setProperty("strokeOpacity", strokeOpacity); 83 | this.strokeOpacity = strokeOpacity; 84 | return this; 85 | } 86 | 87 | public PolylineOptions strokeWeight(double strokeWeight) { 88 | setProperty("strokeWeight", strokeWeight); 89 | this.strokeWeight = strokeWeight; 90 | return this; 91 | } 92 | 93 | public PolylineOptions visible(boolean visible) { 94 | setProperty("draggable", visible); 95 | this.visible = visible; 96 | return this; 97 | } 98 | 99 | public PolylineOptions zIndex(int zIndex) { 100 | setProperty("zIndex", zIndex); 101 | this.zIndex = zIndex; 102 | return this; 103 | } 104 | 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/Projection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 GMapsFX. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | import netscape.javascript.JSObject; 21 | 22 | /** 23 | * 24 | * @author Geoff Capper 25 | */ 26 | public class Projection extends JavascriptObject { 27 | 28 | public Projection(JSObject obj) { 29 | super(GMapObjectType.PROJECTION, obj); 30 | } 31 | 32 | public GMapPoint fromLatLngToPoint(LatLong loc) { 33 | // System.out.println("Projection.fromLatLngToPoint: " + loc); 34 | Object res = invokeJavascript("fromLatLngToPoint", loc); 35 | // System.out.println("Projection.fromLatLngToPoint.res: " + res); 36 | if (res != null && res instanceof JSObject) { 37 | return new GMapPoint((JSObject) res); 38 | } 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/gmapsfx/javascript/object/Size.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.javascript.object; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** 22 | * Size object corresponding to google.maps.Size 23 | * 24 | * Two-dimensonal size, where width is the distance on the x-axis, and height is the distance on the y-axis. 25 | * 26 | * @author Rob Terpilowski 27 | */ 28 | public class Size extends JavascriptObject { 29 | 30 | protected int width; 31 | protected int height; 32 | protected String widthUnit; 33 | protected String heightUnit; 34 | 35 | 36 | 37 | /** 38 | * 39 | * @param width distance on x-axis 40 | * @param height distance on y-axis 41 | */ 42 | public Size(int width, int height) { 43 | super(GMapObjectType.SIZE, width, height); 44 | } 45 | 46 | /** 47 | * 48 | * @param width distance on x-axis 49 | * @param height distance on y-axis 50 | * @param widthUnit 51 | * @param heightUnit 52 | */ 53 | public Size( int width, int height, String widthUnit, String heightUnit ) { 54 | super( GMapObjectType.SIZE, width, height, widthUnit, heightUnit ); 55 | } 56 | 57 | public int getWidth() { 58 | return getProperty("width", Integer.class); 59 | } 60 | 61 | public int getHeight() { 62 | return getProperty("height", Integer.class); 63 | } 64 | 65 | public String getWidthUnit() { 66 | return widthUnit; 67 | } 68 | 69 | public String getHeightUnit() { 70 | return heightUnit; 71 | } 72 | 73 | public boolean equals( Size other ) { 74 | return invokeJavascriptReturnValue("equals", Boolean.class, other); 75 | } 76 | 77 | 78 | @Override 79 | public String toString() { 80 | return invokeJavascriptReturnValue("toString", String.class, (Object)null); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/gmapsfx/service/elevation/ElevationResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.service.elevation; 8 | 9 | import gmapsfx.javascript.JavascriptObject; 10 | import gmapsfx.javascript.object.GMapObjectType; 11 | import gmapsfx.javascript.object.LatLong; 12 | import netscape.javascript.JSObject; 13 | 14 | /** Encapsulates the response from the ElevationService for one particular 15 | * location. 16 | * 17 | * @author Geoff Capper 18 | */ 19 | public class ElevationResult extends JavascriptObject { 20 | 21 | private LatLong location; 22 | 23 | public ElevationResult(JSObject jsObject) { 24 | super(GMapObjectType.ELEVATION_RESULT, jsObject); 25 | } 26 | 27 | /** The elevation returned from the ElevationService. 28 | * 29 | * @return The elevation in metres. 30 | */ 31 | public double getElevation() { 32 | return (double) getJSObject().getMember("elevation"); 33 | } 34 | 35 | /** The location for this elevation. 36 | * 37 | * @return 38 | */ 39 | public LatLong getLocation() { 40 | if (location == null) { 41 | location = new LatLong((JSObject) (getJSObject().getMember("location"))); 42 | } 43 | return location; 44 | } 45 | 46 | /** The resolution for the elevation, which is the distance in metres 47 | * between the points that were used to interpolate the elevation. 48 | * 49 | * @return 50 | */ 51 | public double getResolution() { 52 | return (double) getJSObject().getMember("resolution"); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/gmapsfx/service/elevation/ElevationService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.service.elevation; 8 | 9 | import gmapsfx.javascript.JavascriptObject; 10 | import gmapsfx.javascript.object.GMapObjectType; 11 | import netscape.javascript.JSObject; 12 | 13 | /** Makes a request to the Google Maps Elevation Service. 14 | *

15 | * Instances of this class are not safe for re-use at this stage. A new 16 | * one should be created for each request. 17 | * 18 | * @author Geoff Capper 19 | */ 20 | public class ElevationService extends JavascriptObject { 21 | 22 | private ElevationServiceCallback callback; 23 | 24 | public ElevationService() { 25 | super(GMapObjectType.ELEVATION_SERVICE); 26 | } 27 | 28 | /** Create a request for elevations for multiple locations. 29 | * 30 | * @param req 31 | * @param callback 32 | */ 33 | public void getElevationForLocations(LocationElevationRequest req, ElevationServiceCallback callback) { 34 | 35 | this.callback = callback; 36 | 37 | JSObject doc = (JSObject) getJSObject().eval("document"); 38 | doc.setMember(getVariableName(), this); 39 | 40 | StringBuilder r = new StringBuilder(getVariableName()) 41 | .append(".") 42 | .append("getElevationForLocations(") 43 | .append(req.getVariableName()) 44 | .append(", ") 45 | .append("function(results, status) {alert('rec:'+status);\ndocument.") 46 | .append(getVariableName()) 47 | .append(".processResponse(results, status);});"); 48 | 49 | // System.out.println("ElevationService direct call: " + r.toString()); 50 | 51 | getJSObject().eval(r.toString()); 52 | 53 | } 54 | 55 | /** Create a request for elevations for samples along a path. 56 | * 57 | * @param req 58 | * @param callback 59 | */ 60 | public void getElevationAlongPath(PathElevationRequest req, ElevationServiceCallback callback) { 61 | 62 | this.callback = callback; 63 | 64 | JSObject doc = (JSObject) getJSObject().eval("document"); 65 | doc.setMember(getVariableName(), this); 66 | 67 | StringBuilder r = new StringBuilder(getVariableName()) 68 | .append(".") 69 | .append("getElevationAlongPath(") 70 | .append(req.getVariableName()) 71 | .append(", ") 72 | .append("function(results, status) {document.") 73 | .append(getVariableName()) 74 | .append(".processResponse(results, status);});"); 75 | 76 | getJSObject().eval(r.toString()); 77 | 78 | } 79 | 80 | /** Processess the Javascript response and generates the required objects 81 | * that are then passed back to the original callback. 82 | * 83 | * @param results 84 | * @param status 85 | */ 86 | public void processResponse(Object results, Object status) { 87 | ElevationStatus pStatus = ElevationStatus.UNKNOWN_ERROR; 88 | 89 | if (status instanceof String && results instanceof JSObject) { 90 | pStatus = ElevationStatus.valueOf((String) status); 91 | if (ElevationStatus.OK.equals(pStatus)) { 92 | JSObject jsres = (JSObject) results; 93 | Object len = jsres.getMember("length"); 94 | if (len instanceof Number) { 95 | int n = ((Number)len).intValue(); 96 | // System.out.println("n: " + n); 97 | ElevationResult[] ers = new ElevationResult[n]; 98 | for (int i = 0; i < n; i++) { 99 | Object obj = jsres.getSlot(i); 100 | if (obj instanceof JSObject) { 101 | ers[i] = new ElevationResult((JSObject) obj); 102 | } 103 | } 104 | callback.elevationsReceived(ers, pStatus); 105 | return; 106 | } 107 | } 108 | } 109 | callback.elevationsReceived(new ElevationResult[]{}, pStatus); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/gmapsfx/service/elevation/ElevationServiceCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.service.elevation; 8 | 9 | /** Parties interested in receiving the results from a call to the 10 | * {@link ElevationService} must implement this interface. The results may be 11 | * an empty array if the status is anything other than ElevationStatus.OK 12 | * 13 | * @author Geoff Capper 14 | */ 15 | public interface ElevationServiceCallback { 16 | 17 | public void elevationsReceived(ElevationResult[] results, ElevationStatus status); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/gmapsfx/service/elevation/ElevationStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.service.elevation; 8 | 9 | /** Status responses from the ElevationService. 10 | * 11 | * @author Geoff Capper 12 | */ 13 | public enum ElevationStatus { 14 | 15 | INVALID_REQUEST, OK, OVER_QUERY_LIMIT, REQUEST_DENIED, UNKNOWN_ERROR; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/gmapsfx/service/elevation/LocationElevationRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.service.elevation; 8 | 9 | import gmapsfx.javascript.JavascriptObject; 10 | import gmapsfx.javascript.object.GMapObjectType; 11 | import gmapsfx.javascript.object.LatLong; 12 | 13 | /** Creates a request that can be passed in to the {@link ElevationService} to 14 | * get the elevations for a number of locations. 15 | * 16 | * @author Geoff Capper 17 | */ 18 | public class LocationElevationRequest extends JavascriptObject { 19 | 20 | public LocationElevationRequest() { 21 | super(GMapObjectType.OBJECT); 22 | } 23 | 24 | public LocationElevationRequest(LatLong[] locations) { 25 | super(GMapObjectType.OBJECT); 26 | getJSObject().setMember("locations", getJSObject().eval("[]")); 27 | for (int i = 0; i < locations.length; i++) { 28 | getJSObject().eval(getVariableName()+".locations.push("+locations[i].getVariableName()+")"); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/gmapsfx/service/elevation/PathElevationRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.service.elevation; 8 | 9 | import gmapsfx.javascript.JavascriptObject; 10 | import gmapsfx.javascript.object.GMapObjectType; 11 | import gmapsfx.javascript.object.LatLong; 12 | 13 | /** 14 | * 15 | * @author Geoff Capper 16 | */ 17 | public class PathElevationRequest extends JavascriptObject { 18 | 19 | public PathElevationRequest() { 20 | super(GMapObjectType.OBJECT); 21 | } 22 | 23 | public PathElevationRequest(LatLong[] path, int samples) { 24 | super(GMapObjectType.OBJECT); 25 | getJSObject().setMember("path", getJSObject().eval("[]")); 26 | for (int i = 0; i < path.length; i++) { 27 | getJSObject().eval(getVariableName()+".path.push("+path[i].getVariableName()+")"); 28 | } 29 | getJSObject().setMember("samples", samples); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/gmapsfx/service/geocoding/GeocodingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Lynden, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.service.geocoding; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | 21 | /** 22 | * 23 | * @author Rob Terpilowski 24 | */ 25 | public class GeocodingService extends JavascriptObject { 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/ArcBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gmapsfx.shapes; 7 | 8 | import gmapsfx.javascript.object.LatLong; 9 | import gmapsfx.javascript.object.MVCArray; 10 | import javafx.scene.shape.ArcType; 11 | 12 | /** 13 | * Builds a Polygon or Polyline in the shape of an Arc. Based on the logic in 14 | * v3_polygon_exanple_arc.html from http://econym.org.uk/gmap/ which is based in 15 | * turn on the Latitude/longitude spherical geodesy formulae and scripts at 16 | * http://www.movable-type.co.uk/scripts/latlong.html (c) Chris Veness 2002-2010 17 | * 18 | * @author Geoff Capper 19 | */ 20 | public class ArcBuilder { 21 | 22 | private static final int DEFAULT_ARC_POINTS = 32; 23 | 24 | /** 25 | * Builds the path for a closed arc, returning a PolygonOptions that can be 26 | * further customised before use. 27 | * 28 | * @param center 29 | * @param start 30 | * @param end 31 | * @param arcType Pass in either ArcType.CHORD or ArcType.ROUND 32 | * @return PolygonOptions with the paths element populated. 33 | */ 34 | public static final PolygonOptions buildClosedArc(LatLong center, LatLong start, LatLong end, ArcType arcType) { 35 | MVCArray res = buildArcPoints(center, start, end); 36 | if (ArcType.ROUND.equals(arcType)) { 37 | res.push(center); 38 | } 39 | return new PolygonOptions().paths(res); 40 | } 41 | 42 | /** 43 | * Builds the path for an open arc based on a PolylineOptions. 44 | * 45 | * @param center 46 | * @param start 47 | * @param end 48 | * @return PolylineOptions with the paths element populated. 49 | */ 50 | public static final PolylineOptions buildOpenArc(LatLong center, LatLong start, LatLong end) { 51 | MVCArray res = buildArcPoints(center, start, end); 52 | return new PolylineOptions().path(res); 53 | } 54 | 55 | public static final MVCArray buildArcPoints(LatLong center, LatLong start, LatLong end) { 56 | return buildArcPoints(center, center.getBearing(start), center.getBearing(end), center.distanceFrom(start)); 57 | } 58 | 59 | /** 60 | * Generates the points for an arc based on two bearings from a centre point 61 | * and a radius. 62 | * 63 | * @param center The LatLong point of the center. 64 | * @param startBearing North is 0 degrees, East is 90 degrees, etc. 65 | * @param endBearing North is 0 degrees, East is 90 degrees, etc. 66 | * @param radius In metres 67 | * @return An array of LatLong points in an MVC array representing the arc. 68 | * Using this method directly you will need to push the centre point onto 69 | * the array in order to close it, if desired. 70 | */ 71 | public static final MVCArray buildArcPoints(LatLong center, double startBearing, double endBearing, double radius) { 72 | int points = DEFAULT_ARC_POINTS; 73 | 74 | MVCArray res = new MVCArray(); 75 | 76 | if (startBearing > endBearing) { 77 | endBearing += 360.0; 78 | } 79 | double deltaBearing = endBearing - startBearing; 80 | deltaBearing = deltaBearing / points; 81 | for (int i = 0; (i < points + 1); i++) { 82 | res.push(center.getDestinationPoint(startBearing + i * deltaBearing, radius)); 83 | } 84 | 85 | return res; 86 | 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/Circle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.object.GMapObjectType; 20 | import gmapsfx.javascript.object.LatLong; 21 | import gmapsfx.javascript.object.MapShape; 22 | import netscape.javascript.JSObject; 23 | 24 | /** 25 | * 26 | * @author Geoff Capper 27 | */ 28 | public class Circle extends MapShape { 29 | 30 | public Circle() { 31 | super(GMapObjectType.CIRCLE); 32 | } 33 | 34 | public Circle(CircleOptions opts) { 35 | super(GMapObjectType.CIRCLE, opts); 36 | } 37 | 38 | //getCenter 39 | public LatLong getCenter() { 40 | return new LatLong((JSObject) invokeJavascript("getCenter")); 41 | } 42 | 43 | //getRadius 44 | public double getRadius() { 45 | return (double) invokeJavascript("getRadius"); 46 | } 47 | 48 | //setCenter 49 | public void setCenter(LatLong center) { 50 | invokeJavascript("setCenter", center); 51 | } 52 | 53 | //setRadius 54 | public void setRadius(double radius) { 55 | invokeJavascript("setRadius", radius); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/CircleOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.object.LatLong; 20 | 21 | /** 22 | * 23 | * @author Geoff Capper 24 | */ 25 | public class CircleOptions extends FillableMapShapeOptions { 26 | 27 | private LatLong center; 28 | private double radius;// in metres 29 | 30 | 31 | public CircleOptions center(LatLong center) { 32 | setProperty("center", center); 33 | this.center = center; 34 | return this; 35 | } 36 | 37 | public CircleOptions radius(double radius) { 38 | setProperty("radius", radius); 39 | this.radius = radius; 40 | return this; 41 | } 42 | 43 | @Override 44 | protected CircleOptions getMe() { 45 | return this; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/FillableMapShapeOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | /** Options for a MapShape that is fillable. 20 | * 21 | * @author Geoff Capper 22 | * @param 23 | */ 24 | public abstract class FillableMapShapeOptions extends MapShapeOptions { 25 | 26 | private String fillColor; 27 | private double fillOpacity; 28 | private StrokePosition strokePosition; 29 | 30 | public FillableMapShapeOptions() { 31 | } 32 | 33 | public T fillColor(String fillColor) { 34 | setProperty("fillColor", fillColor); 35 | this.fillColor = fillColor; 36 | return getMe(); 37 | } 38 | 39 | public T fillOpacity(double fillOpacity) { 40 | setProperty("fillOpacity", fillOpacity); 41 | this.fillOpacity = fillOpacity; 42 | return getMe(); 43 | } 44 | 45 | public T strokePosition(StrokePosition strokePosition) { 46 | setProperty("strokePosition", strokePosition.name()); 47 | this.strokePosition = strokePosition; 48 | return getMe(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/MapShapeOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.JavascriptObject; 20 | import gmapsfx.javascript.object.GMapObjectType; 21 | 22 | /** Abstract base class for our shape options, as they all have a lot of 23 | * common properties. 24 | * 25 | * @author Geoff Capper 26 | * @param 27 | */ 28 | public abstract class MapShapeOptions extends JavascriptObject { 29 | 30 | private boolean clickable; 31 | private boolean draggable; 32 | private boolean editable; 33 | private boolean geodesic; 34 | private String strokeColor; 35 | private double strokeOpacity; 36 | private double strokeWeight; 37 | private boolean visible; 38 | private int zIndex; 39 | 40 | // private T me; 41 | 42 | public MapShapeOptions() { 43 | super(GMapObjectType.OBJECT); 44 | } 45 | 46 | protected abstract T getMe(); 47 | 48 | public T clickable(boolean clickable) { 49 | setProperty("clickable", clickable); 50 | this.clickable = clickable; 51 | return getMe(); 52 | } 53 | 54 | public T draggable(boolean draggable) { 55 | setProperty("draggable", draggable); 56 | this.draggable = draggable; 57 | return getMe(); 58 | } 59 | 60 | public T editable(boolean editable) { 61 | setProperty("editable", editable); 62 | this.editable = editable; 63 | return getMe(); 64 | } 65 | 66 | public T geodesic(boolean geodesic) { 67 | setProperty("geodesic", geodesic); 68 | this.geodesic = geodesic; 69 | return getMe(); 70 | } 71 | 72 | public T strokeColor(String strokeColor) { 73 | setProperty("strokeColor", strokeColor); 74 | this.strokeColor = strokeColor; 75 | return getMe(); 76 | } 77 | 78 | public T strokeOpacity(double strokeOpacity) { 79 | setProperty("strokeOpacity", strokeOpacity); 80 | this.strokeOpacity = strokeOpacity; 81 | return getMe(); 82 | } 83 | 84 | public T strokeWeight(double strokeWeight) { 85 | setProperty("strokeWeight", strokeWeight); 86 | this.strokeWeight = strokeWeight; 87 | return getMe(); 88 | } 89 | 90 | public T visible(boolean visible) { 91 | setProperty("draggable", visible); 92 | this.visible = visible; 93 | return getMe(); 94 | } 95 | 96 | public T zIndex(int zIndex) { 97 | setProperty("zIndex", zIndex); 98 | this.zIndex = zIndex; 99 | return getMe(); 100 | } 101 | 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/Polygon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.object.GMapObjectType; 20 | import gmapsfx.javascript.object.MVCArray; 21 | import gmapsfx.javascript.object.MapShape; 22 | import netscape.javascript.JSObject; 23 | 24 | /** 25 | * 26 | * @author Geoff Capper 27 | */ 28 | public class Polygon extends MapShape { 29 | 30 | public Polygon() { 31 | super(GMapObjectType.POLYGON); 32 | } 33 | 34 | public Polygon(PolygonOptions opts) { 35 | super(GMapObjectType.POLYGON, opts); 36 | } 37 | 38 | public MVCArray getPath() { 39 | return new MVCArray((JSObject) invokeJavascript("getPath")); 40 | } 41 | 42 | public MVCArray getPaths() { 43 | return new MVCArray((JSObject) invokeJavascript("getPaths")); 44 | } 45 | 46 | public void setPath(MVCArray path) { 47 | invokeJavascript("setPath", path); 48 | } 49 | 50 | public void setPaths(MVCArray paths) { 51 | invokeJavascript("setPaths", paths); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/PolygonOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.object.MVCArray; 20 | 21 | /** 22 | * 23 | * @author Geoff Capper 24 | */ 25 | public class PolygonOptions extends FillableMapShapeOptions { 26 | 27 | private MVCArray paths; 28 | 29 | public PolygonOptions() { 30 | } 31 | 32 | public PolygonOptions paths(MVCArray paths) { 33 | setProperty("path", paths); 34 | this.paths = paths; 35 | return this; 36 | } 37 | 38 | @Override 39 | protected PolygonOptions getMe() { 40 | return this; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/Polyline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.object.GMapObjectType; 20 | import gmapsfx.javascript.object.MVCArray; 21 | import gmapsfx.javascript.object.MapShape; 22 | import netscape.javascript.JSObject; 23 | 24 | /** Wraps a google.maps.Polyline object. 25 | * 26 | * @author Geoff Capper 27 | */ 28 | public class Polyline extends MapShape { 29 | 30 | public Polyline() { 31 | super(GMapObjectType.POLYLINE); 32 | } 33 | 34 | public Polyline(PolylineOptions opts) { 35 | super(GMapObjectType.POLYLINE, opts); 36 | } 37 | 38 | public MVCArray getPath() { 39 | return new MVCArray((JSObject) invokeJavascript("getPath")); 40 | } 41 | 42 | public void setPath(MVCArray path) { 43 | invokeJavascript("setPath", path); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/PolylineOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.object.MVCArray; 20 | 21 | /** 22 | * 23 | * @author Geoff Capper 24 | */ 25 | public class PolylineOptions extends MapShapeOptions { 26 | 27 | // icons Array. The icons to be rendered along the polyline. 28 | 29 | private MVCArray path; 30 | 31 | public PolylineOptions() { 32 | } 33 | 34 | public PolylineOptions path(MVCArray path) { 35 | setProperty("path", path); 36 | this.path = path; 37 | return this; 38 | } 39 | 40 | @Override 41 | protected PolylineOptions getMe() { 42 | return this; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/Rectangle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.object.GMapObjectType; 20 | import gmapsfx.javascript.object.LatLongBounds; 21 | import gmapsfx.javascript.object.MapShape; 22 | 23 | /** 24 | * 25 | * @author Geoff Capper 26 | */ 27 | public class Rectangle extends MapShape { 28 | 29 | public Rectangle() { 30 | super(GMapObjectType.RECTANGLE); 31 | } 32 | 33 | public Rectangle(RectangleOptions opts) { 34 | super(GMapObjectType.RECTANGLE, opts); 35 | } 36 | 37 | //setBounds 38 | public void setBounds(LatLongBounds bounds) { 39 | invokeJavascript("setBounds", bounds); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/RectangleOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | import gmapsfx.javascript.object.LatLongBounds; 20 | 21 | /** 22 | * 23 | * @author Geoff Capper 24 | */ 25 | public class RectangleOptions extends FillableMapShapeOptions { 26 | 27 | private LatLongBounds bounds; 28 | 29 | public RectangleOptions bounds(LatLongBounds bounds) { 30 | setProperty("bounds", bounds); 31 | this.bounds = bounds; 32 | return this; 33 | } 34 | 35 | @Override 36 | protected RectangleOptions getMe() { 37 | return this; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/gmapsfx/shapes/StrokePosition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Geoff Capper. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package gmapsfx.shapes; 18 | 19 | /** From google.maps.StrokePosition 20 | * 21 | * @author Geoff Capper 22 | */ 23 | public enum StrokePosition { 24 | CENTER, INSIDE, OUTSIDE; 25 | } 26 | -------------------------------------------------------------------------------- /src/gmapsfx/zoom/MaxZoomResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.zoom; 8 | 9 | import gmapsfx.javascript.JavascriptObject; 10 | import gmapsfx.javascript.object.GMapObjectType; 11 | import netscape.javascript.JSObject; 12 | 13 | /** 14 | * 15 | * @author Geoff Capper 16 | */ 17 | public class MaxZoomResult extends JavascriptObject { 18 | 19 | private MaxZoomStatus status; 20 | 21 | public MaxZoomResult() { 22 | super(GMapObjectType.MAX_ZOOM_RESULT); 23 | } 24 | 25 | public MaxZoomResult(JSObject obj) { 26 | super(GMapObjectType.MAX_ZOOM_RESULT, obj); 27 | } 28 | 29 | public MaxZoomResult(MaxZoomStatus status) { 30 | super(GMapObjectType.MAX_ZOOM_RESULT); 31 | this.status = status; 32 | } 33 | 34 | public MaxZoomStatus getStatus() { 35 | if (status == null) { 36 | status = MaxZoomStatus.valueOf((String) getJSObject().getMember("status")); 37 | } 38 | return status; 39 | } 40 | 41 | public int getMaxZoom() { 42 | return (int) getJSObject().getMember("zoom"); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/gmapsfx/zoom/MaxZoomService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.zoom; 8 | 9 | import gmapsfx.javascript.JavascriptObject; 10 | import gmapsfx.javascript.object.GMapObjectType; 11 | import gmapsfx.javascript.object.LatLong; 12 | import netscape.javascript.JSObject; 13 | 14 | /** 15 | * 16 | * @author Geoff Capper 17 | */ 18 | public class MaxZoomService extends JavascriptObject { 19 | 20 | private MaxZoomServiceCallback callback; 21 | 22 | public MaxZoomService() { 23 | super(GMapObjectType.MAX_ZOOM_SERVICE); 24 | } 25 | 26 | public void getMaxZoomAtLatLng(LatLong loc, MaxZoomServiceCallback callback) { 27 | 28 | this.callback = callback; 29 | 30 | JSObject doc = (JSObject) getJSObject().eval("document"); 31 | doc.setMember(getVariableName(), this); 32 | 33 | StringBuilder r = new StringBuilder(getVariableName()) 34 | .append(".") 35 | .append("getMaxZoomAtLatLng(") 36 | .append(loc.getVariableName()) 37 | .append(", ") 38 | .append("function(result) {document.") 39 | .append(getVariableName()) 40 | .append(".processResponse(result);});"); 41 | 42 | // System.out.println("MaxZoomService direct call: " + r.toString()); 43 | 44 | getJSObject().eval(r.toString()); 45 | 46 | } 47 | 48 | /** Processess the Javascript response and generates the required objects 49 | * that are then passed back to the original callback. 50 | * 51 | * @param result 52 | */ 53 | public void processResponse(Object result) { 54 | if (result instanceof JSObject) { 55 | MaxZoomResult mzr = new MaxZoomResult((JSObject) result); 56 | callback.maxZoomReceived(mzr); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/gmapsfx/zoom/MaxZoomServiceCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.zoom; 8 | 9 | /** 10 | * 11 | * @author Geoff Capper 12 | */ 13 | public interface MaxZoomServiceCallback { 14 | 15 | public void maxZoomReceived(MaxZoomResult result); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/gmapsfx/zoom/MaxZoomStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package gmapsfx.zoom; 8 | 9 | /** 10 | * 11 | * @author Geoff Capper 12 | */ 13 | public enum MaxZoomStatus { 14 | ERROR, OK; 15 | } 16 | -------------------------------------------------------------------------------- /src/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Simple Map! 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | 15 | 16 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/html/main.js: -------------------------------------------------------------------------------- 1 | mapInit() { 2 | alert("It's in!!"); 3 | } -------------------------------------------------------------------------------- /src/html/routing.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | height: 100%; 3 | margin: 0; 4 | padding: 0; 5 | } 6 | 7 | .root{ 8 | -fx-font-size: 16px ; 9 | -fx-font-family: Helvetica, Trebuchet , Verdana, Sans-Serif, Times New Roman; 10 | } 11 | 12 | #map { 13 | height: 100%; 14 | } 15 | 16 | #directions-panel { 17 | font-family: 'Roboto','sans-serif'; 18 | line-height: 30px; 19 | padding-left: 10px; 20 | } 21 | 22 | #directions-panel select, #directions-panel input { 23 | font-size: 15px; 24 | } 25 | 26 | #directions-panel select { 27 | width: 100%; 28 | } 29 | 30 | #directions-panel i { 31 | font-size: 12px; 32 | } 33 | 34 | #directions-panel { 35 | height: 100%; 36 | float: right; 37 | width: 390px; 38 | overflow: auto; 39 | } 40 | -------------------------------------------------------------------------------- /src/html/visual.js: -------------------------------------------------------------------------------- 1 | var delay = 300; 2 | var map, markers; 3 | var markerURL = "http://maps.google.com/mapfiles/kml/paddle/red-diamond-lv.png"; 4 | var destURL = "http://maps.google.com/mapfiles/kml/pal2/icon5.png"; 5 | 6 | function visualizeSearch(mapParam, markersParam) { 7 | markers = markersParam; 8 | map = mapParam; 9 | drop(); 10 | } 11 | 12 | function displayMarker(marker, timeout, URL) { 13 | window.setTimeout(function() { 14 | marker.setIcon(URL); 15 | marker.setMap(map); 16 | }, timeout); 17 | } 18 | 19 | function drop() { 20 | var i; 21 | for(i = 1; i < markers.length - 1; ++i) { 22 | displayMarker(markers[i], i*delay, markerURL); 23 | } 24 | displayMarker(markers[markers.length - 1], i*delay, destURL); 25 | i++; 26 | displayAlert(markers.length, i*delay); 27 | } 28 | 29 | function displayAlert(length, delay) { 30 | ////window.setTimeout(function() { 31 | alert(length + " nodes visited in search."); 32 | //}, delay); 33 | } -------------------------------------------------------------------------------- /src/mapmaker/DataFetcher.java: -------------------------------------------------------------------------------- 1 | package mapmaker; 2 | 3 | import java.io.DataOutputStream; 4 | import java.io.InputStream; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import javax.json.*; 8 | 9 | public class DataFetcher { 10 | private final String[] HIGHWAYS = {"motorway", "trunk", "primary", "secondary", "tertiary", "unclassified", "residential", "motorway_link", "trunk_link", "primary_link", "secondary_link", "tertiary_link", "living_street"}; 11 | 12 | private String query; 13 | public DataFetcher(float[] bounds) { 14 | this.query = this.constructQuery(bounds); 15 | } 16 | 17 | public JsonObject getData() { 18 | HttpURLConnection conn = null; 19 | try { 20 | URL url = new URL("http://overpass-api.de/api/interpreter"); 21 | conn = (HttpURLConnection)url.openConnection(); 22 | conn.setDoOutput(true); 23 | conn.setRequestMethod("POST"); 24 | conn.setRequestProperty("Accept-Charset", "utf-8;q=0.7,*;q=0.7"); 25 | 26 | DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); 27 | wr.writeBytes(this.query); 28 | wr.close(); 29 | 30 | InputStream is = conn.getInputStream(); 31 | JsonReader rdr = Json.createReader(is); 32 | 33 | return rdr.readObject(); 34 | } catch (Exception e) { 35 | System.out.println(e); 36 | return null; 37 | } 38 | } 39 | 40 | public String constructQuery(float[] boundsArray) { 41 | String q = "[out:json];("; 42 | String bounds = "("; 43 | for (int i = 0; i < 4; i++) { 44 | bounds += boundsArray[i]; 45 | if (i < 3) { 46 | bounds += ","; 47 | } else { 48 | bounds += ")"; 49 | } 50 | } 51 | 52 | 53 | for (String s : HIGHWAYS) { 54 | q += "way[\"highway\"=\"" + s + "\"]" + bounds + ";"; 55 | } 56 | 57 | q += "); (._;>;); out;"; 58 | 59 | return q; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/mapmaker/MapMaker.java: -------------------------------------------------------------------------------- 1 | package mapmaker; 2 | 3 | import java.io.PrintWriter; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import javax.json.*; 7 | 8 | public class MapMaker { 9 | float[] bounds; 10 | HashMap nodes = new HashMap(); 11 | 12 | public MapMaker(float[] bounds) { 13 | this.bounds = bounds; 14 | } 15 | 16 | public boolean parseData(String filename) { 17 | DataFetcher fetcher = new DataFetcher(bounds); 18 | JsonObject data = fetcher.getData(); 19 | 20 | JsonArray elements = data.getJsonArray("elements"); 21 | 22 | for (JsonObject elem : elements.getValuesAs(JsonObject.class)) { 23 | if (elem.getString("type").equals("node")) { 24 | nodes.put(elem.getInt("id"), new Location(elem.getJsonNumber("lat").doubleValue(), elem.getJsonNumber("lon").doubleValue())); 25 | } 26 | } 27 | 28 | PrintWriter outfile; 29 | try { 30 | outfile = new PrintWriter(filename); 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | return false; 34 | } 35 | 36 | for (JsonObject elem : elements.getValuesAs(JsonObject.class)) { 37 | if (elem.getString("type").equals("way")) { 38 | String street = elem.getJsonObject("tags").getString("name", ""); 39 | String type = elem.getJsonObject("tags").getString("highway", ""); 40 | String oneway = elem.getJsonObject("tags").getString("oneway", "no"); 41 | List nodelist = elem.getJsonArray("nodes").getValuesAs(JsonNumber.class); 42 | for (int i = 0; i < nodelist.size() - 1; i++) { 43 | Location start = nodes.get(nodelist.get(i).intValue()); 44 | Location end = nodes.get(nodelist.get(i + 1).intValue()); 45 | if (start.outsideBounds(bounds) || end.outsideBounds(bounds)) { 46 | continue; 47 | } 48 | 49 | outfile.println("" + start + end + "\"" + street + "\" " + type); 50 | if (oneway.equals("no")) { 51 | outfile.println("" + end + start + "\"" + street + "\" " + type); 52 | } 53 | } 54 | } 55 | } 56 | outfile.close(); 57 | return true; 58 | } 59 | 60 | public static void main(String[] args) { 61 | if (args.length != 4) { 62 | System.out.println("Incorrect number of arguments."); 63 | System.out.println(args.length); 64 | return; 65 | } 66 | 67 | float[] bound_arr = new float[4]; 68 | try { 69 | for (int i = 0; i < args.length; i++) { 70 | bound_arr[i] = Float.parseFloat(args[i]); 71 | } 72 | } catch (Exception e) { 73 | e.printStackTrace(); 74 | return; 75 | } 76 | 77 | MapMaker map = new MapMaker(bound_arr); 78 | map.parseData("ucsd.map"); 79 | } 80 | } 81 | 82 | class Location { 83 | private double lat; 84 | private double lon; 85 | 86 | public Location(double lat, double lon) { 87 | this.lat = lat; 88 | this.lon = lon; 89 | } 90 | 91 | public String toString() { 92 | return "" + lat + " " + lon + " "; 93 | } 94 | 95 | /** 96 | * @param bounds [south, west, north, east] 97 | */ 98 | public boolean outsideBounds(float[] bounds) { 99 | return (lat < bounds[0] || lat > bounds[2] || lon < bounds[1] || lon > bounds[3]); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/roadgraph/AStarGrader.java: -------------------------------------------------------------------------------- 1 | package roadgraph; 2 | 3 | import geography.GeographicPoint; 4 | import util.GraphLoader; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author UCSD MOOC Development Team 10 | * Grader for Module 4, Part 2. 11 | */ 12 | public class AStarGrader implements Runnable { 13 | public String feedback; 14 | 15 | public int correct; 16 | 17 | private static final int TESTS = 4; 18 | 19 | /** Format readable feedback */ 20 | public static String printOutput(double score, String feedback) { 21 | return "Score: " + score + "\nFeedback: " + feedback; 22 | } 23 | 24 | /** Format test number and description */ 25 | public static String appendFeedback(int num, String test) { 26 | return "\n** Test #" + num + ": " + test + "..."; 27 | } 28 | 29 | public static void main(String[] args) { 30 | AStarGrader grader = new AStarGrader(); 31 | 32 | // Infinite loop detection 33 | Thread thread = new Thread(grader); 34 | thread.start(); 35 | long endTime = System.currentTimeMillis() + 10000; 36 | boolean infinite = false; 37 | while(thread.isAlive()) { 38 | // Stop after 10 seconds 39 | if (System.currentTimeMillis() > endTime) { 40 | thread.stop(); 41 | infinite = true; 42 | break; 43 | } 44 | } 45 | if (infinite) { 46 | System.out.println(printOutput((double)grader.correct / TESTS, grader.feedback + "\nYour program entered an infinite loop.")); 47 | } 48 | } 49 | 50 | /** Run a test case on an adjacency list and adjacency matrix. 51 | * @param i The graph number 52 | * @param file The file to read from 53 | * @param desc A description of the graph 54 | * @param start The point to start from 55 | * @param end The point to end at 56 | */ 57 | public void runTest(int i, String file, String desc, GeographicPoint start, GeographicPoint end) { 58 | MapGraph graph = new MapGraph(); 59 | 60 | feedback += "\n\n" + desc; 61 | 62 | GraphLoader.loadRoadMap("data/graders/mod3/" + file, graph); 63 | CorrectAnswer corr = new CorrectAnswer("data/graders/mod3/" + file + ".answer", false); 64 | 65 | judge(i, graph, corr, start, end); 66 | } 67 | 68 | /** Compare the user's result with the right answer. 69 | * @param i The graph number 70 | * @param result The user's graph 71 | * @param corr The correct answer 72 | * @param start The point to start from 73 | * @param end The point to end at 74 | */ 75 | public void judge(int i, MapGraph result, CorrectAnswer corr, GeographicPoint start, GeographicPoint end) { 76 | // Correct if paths are same length and have the same elements 77 | feedback += appendFeedback(i, "Running A* from (" + start.getX() + ", " + start.getY() + ") to (" + end.getX() + ", " + end.getY() + ")"); 78 | List path = result.aStarSearch(start, end); 79 | if (path == null) { 80 | if (corr.path == null) { 81 | feedback += "PASSED."; 82 | correct++; 83 | } else { 84 | feedback += "FAILED. Your implementation returned null; expected \n" + printPath(corr.path) + "."; 85 | } 86 | } else if (path.size() != corr.path.size() || !corr.path.containsAll(path)) { 87 | feedback += "FAILED. Expected: \n" + printPath(corr.path) + "Got: \n" + printPath(path); 88 | if (path.size() != corr.path.size()) { 89 | feedback += "Your result has size " + path.size() + "; expected " + corr.path.size() + "."; 90 | } else { 91 | feedback += "Correct size, but incorrect path."; 92 | } 93 | } else { 94 | feedback += "PASSED."; 95 | correct++; 96 | } 97 | } 98 | 99 | /** Print a search path in readable form */ 100 | public String printPath(List path) { 101 | String ret = ""; 102 | for (GeographicPoint point : path) { 103 | ret += point + "\n"; 104 | } 105 | return ret; 106 | } 107 | 108 | /** Run the grader */ 109 | public void run() { 110 | feedback = ""; 111 | 112 | correct = 0; 113 | 114 | try { 115 | runTest(1, "map1.txt", "MAP: Straight line (-3 <- -2 <- -1 <- 0 -> 1 -> 2-> 3 ->...)", new GeographicPoint(0, 0), new GeographicPoint(6, 6)); 116 | 117 | runTest(2, "map2.txt", "MAP: Example map from the writeup", new GeographicPoint(7, 3), new GeographicPoint(4, -1)); 118 | 119 | runTest(3, "map3.txt", "MAP: Right triangle (with a little detour)", new GeographicPoint(0, 0), new GeographicPoint(0, 4)); 120 | 121 | runTest(4, "ucsd.map", "UCSD MAP: Intersections around UCSD", new GeographicPoint(32.8709815, -117.2434254), new GeographicPoint(32.8742087, -117.2381344)); 122 | 123 | if (correct == TESTS) 124 | feedback = "All tests passed. Great job!" + feedback; 125 | else 126 | feedback = "Some tests failed. Check your code for errors, then try again:" + feedback; 127 | 128 | } catch (Exception e) { 129 | feedback += "\nError during runtime: " + e; 130 | e.printStackTrace(); 131 | } 132 | 133 | System.out.println(printOutput((double)correct / TESTS, feedback)); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/roadgraph/CorrectAnswer.java: -------------------------------------------------------------------------------- 1 | package roadgraph; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Locale; 7 | import java.util.Scanner; 8 | import geography.*; 9 | 10 | public class CorrectAnswer { 11 | public int vertices; 12 | public int edges; 13 | public List path; 14 | public CorrectAnswer(String file, boolean hasEdges) { 15 | try { 16 | Scanner s = new Scanner(new File(file)); 17 | s.useLocale(Locale.ENGLISH); 18 | if (hasEdges) { 19 | vertices = s.nextInt(); 20 | edges = s.nextInt(); 21 | } 22 | path = null; 23 | if (s.hasNextDouble()) { 24 | path = new ArrayList(); 25 | } 26 | while (s.hasNextDouble()) { 27 | double x = s.nextDouble(); 28 | double y = s.nextDouble(); 29 | path.add(new GeographicPoint(x, y)); 30 | } 31 | } catch (Exception e) { 32 | System.err.println("Error reading correct answer!"); 33 | e.printStackTrace(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/roadgraph/DijkstraGrader.java: -------------------------------------------------------------------------------- 1 | package roadgraph; 2 | 3 | import geography.GeographicPoint; 4 | import util.GraphLoader; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author UCSD MOOC Development Team 10 | * Grader for Module 4, Part 1. 11 | */ 12 | public class DijkstraGrader implements Runnable { 13 | public String feedback; 14 | 15 | public int correct; 16 | 17 | private static final int TESTS = 4; 18 | 19 | /** Format readable feedback */ 20 | public static String printOutput(double score, String feedback) { 21 | return "Score: " + score + "\nFeedback: " + feedback; 22 | } 23 | 24 | /** Format test number and description */ 25 | public static String appendFeedback(int num, String test) { 26 | return "\n** Test #" + num + ": " + test + "..."; 27 | } 28 | 29 | public static void main(String[] args) { 30 | DijkstraGrader grader = new DijkstraGrader(); 31 | 32 | // Infinite loop detection 33 | Thread thread = new Thread(grader); 34 | thread.start(); 35 | long endTime = System.currentTimeMillis() + 10000; 36 | boolean infinite = false; 37 | while(thread.isAlive()) { 38 | // Stop thread after 10 seconds 39 | if (System.currentTimeMillis() > endTime) { 40 | thread.stop(); 41 | infinite = true; 42 | break; 43 | } 44 | } 45 | if (infinite) { 46 | System.out.println(printOutput((double)grader.correct / TESTS, grader.feedback + "\nYour program entered an infinite loop.")); 47 | } 48 | } 49 | 50 | /** Run a test case on an adjacency list and adjacency matrix. 51 | * @param i The graph number 52 | * @param file The file to read from 53 | * @param desc A description of the graph 54 | * @param start The point to start from 55 | * @param end The point to end at 56 | */ 57 | public void runTest(int i, String file, String desc, GeographicPoint start, GeographicPoint end) { 58 | MapGraph graph = new MapGraph(); 59 | 60 | feedback += "\n\n" + desc; 61 | 62 | GraphLoader.loadRoadMap("data/graders/mod3/" + file, graph); 63 | CorrectAnswer corr = new CorrectAnswer("data/graders/mod3/" + file + ".answer", false); 64 | 65 | judge(i, graph, corr, start, end); 66 | } 67 | 68 | /** Compare the user's result with the right answer. 69 | * @param i The graph number 70 | * @param result The user's graph 71 | * @param corr The correct answer 72 | * @param start The point to start from 73 | * @param end The point to end at 74 | */ 75 | public void judge(int i, MapGraph result, CorrectAnswer corr, GeographicPoint start, GeographicPoint end) { 76 | // Correct if paths are same length and have the same elements 77 | feedback += appendFeedback(i, "Running Dijkstra's algorithm from (" + start.getX() + ", " + start.getY() + ") to (" + end.getX() + ", " + end.getY() + ")"); 78 | List path = result.dijkstra(start, end); 79 | if (path == null) { 80 | if (corr.path == null) { 81 | feedback += "PASSED."; 82 | correct++; 83 | } else { 84 | feedback += "FAILED. Your implementation returned null; expected \n" + printPath(corr.path) + "."; 85 | } 86 | } else if (path.size() != corr.path.size() || !corr.path.containsAll(path)) { 87 | feedback += "FAILED. Expected: \n" + printPath(corr.path) + "Got: \n" + printPath(path); 88 | if (path.size() != corr.path.size()) { 89 | feedback += "Your result has size " + path.size() + "; expected " + corr.path.size() + "."; 90 | } else { 91 | feedback += "Correct size, but incorrect path."; 92 | } 93 | } else { 94 | feedback += "PASSED."; 95 | correct++; 96 | } 97 | } 98 | 99 | /** Print a search path in readable form */ 100 | public String printPath(List path) { 101 | String ret = ""; 102 | for (GeographicPoint point : path) { 103 | ret += point + "\n"; 104 | } 105 | return ret; 106 | } 107 | 108 | /** Run the grader */ 109 | public void run() { 110 | feedback = ""; 111 | 112 | correct = 0; 113 | 114 | try { 115 | runTest(1, "map1.txt", "MAP: Straight line (-3 <- -2 <- -1 <- 0 -> 1 -> 2-> 3 ->...)", new GeographicPoint(0, 0), new GeographicPoint(6, 6)); 116 | 117 | runTest(2, "map2.txt", "MAP: Example map from the writeup", new GeographicPoint(7, 3), new GeographicPoint(4, -1)); 118 | 119 | runTest(3, "map3.txt", "MAP: Right triangle (with a little detour)", new GeographicPoint(0, 0), new GeographicPoint(0, 4)); 120 | 121 | runTest(4, "ucsd.map", "UCSD MAP: Intersections around UCSD", new GeographicPoint(32.8709815, -117.2434254), new GeographicPoint(32.8742087, -117.2381344)); 122 | 123 | if (correct == TESTS) 124 | feedback = "All tests passed. Great job!" + feedback; 125 | else 126 | feedback = "Some tests failed. Check your code for errors, then try again:" + feedback; 127 | 128 | } catch (Exception e) { 129 | feedback += "\nError during runtime: " + e; 130 | e.printStackTrace(); 131 | } 132 | 133 | System.out.println(printOutput((double)correct / TESTS, feedback)); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/roadgraph/MapGraphNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author: salimt 3 | */ 4 | 5 | package roadgraph; 6 | 7 | import geography.GeographicPoint; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class MapGraphNode implements Comparable { 13 | private List neighbors; 14 | private String roadName; 15 | private String roadType; 16 | private double length; 17 | private GeographicPoint value; 18 | private double actualDist; 19 | 20 | public MapGraphNode(GeographicPoint loc, String roadName, String roadType, double length) { 21 | neighbors = new ArrayList <>(); 22 | this.roadName = roadName; 23 | this.length = length; 24 | this.roadType = roadType; 25 | this.value = loc; 26 | } 27 | 28 | public MapGraphNode(GeographicPoint loc) { 29 | this.value = loc; 30 | } 31 | 32 | public void addEdge(GeographicPoint endPoint, String roadName, String roadType, double length){ 33 | this.addNeighbor(new MapGraphNode(endPoint, roadName, roadType, length)); 34 | } 35 | 36 | public String getRoadName() { return roadName; } 37 | 38 | public void setRoadName(String roadName) { this.roadName = roadName; } 39 | 40 | public String getRoadType() { return roadType; } 41 | 42 | public void setRoadType(String roadType) { this.roadType = roadType; } 43 | 44 | public void setActualDist (double actualDist) { this.actualDist = actualDist; } 45 | 46 | public void addNeighbor(MapGraphNode n) { neighbors.add(n); } 47 | 48 | public List getNeighbor() { return neighbors; } 49 | 50 | public double getActualDist() { return actualDist; } 51 | 52 | public double getLength() { return length; } 53 | 54 | public void setLength(double length) { this.length = length; } 55 | 56 | public GeographicPoint getValue() { return value; } 57 | 58 | public void setValue(GeographicPoint value) { this.value = value; } 59 | 60 | @Override 61 | public int compareTo(MapGraphNode o) { 62 | return Double.compare(length, o.getLength()); 63 | } 64 | 65 | public String toString() { return this.getValue().toString(); } 66 | } 67 | -------------------------------------------------------------------------------- /src/week3example/MazeLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package week3example; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.FileReader; 8 | import java.io.IOException; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | 12 | 13 | /** 14 | * @author Christine 15 | * 16 | */ 17 | public class MazeLoader { 18 | 19 | public static void loadMaze(String filename, Maze maze) 20 | { 21 | BufferedReader reader = null; 22 | try { 23 | String nextLine; 24 | int width = 0; 25 | int height = 0; 26 | reader = new BufferedReader(new FileReader(filename)); 27 | if ((nextLine = reader.readLine()) != null) { 28 | String[] dims = nextLine.split(" "); 29 | width = Integer.parseInt(dims[0]); 30 | height = Integer.parseInt(dims[1]); 31 | maze.initialize(width, height); 32 | } 33 | int currRow = 0; 34 | int currCol = 0; 35 | while ((nextLine = reader.readLine()) != null) { 36 | currCol = 0; 37 | for (char c : nextLine.toCharArray()) { 38 | if (c != '*') { 39 | maze.addNode(currRow, currCol); 40 | } 41 | currCol++; 42 | } 43 | while (currCol < width) { 44 | maze.addNode(currRow, currCol); 45 | currCol++; 46 | } 47 | currRow++; 48 | 49 | } 50 | while (currRow < height) { 51 | for (int c = 0; c neighbors; 18 | // Since our maze is always a grid, nodes keep track of their row and column 19 | private int row; 20 | private int column; 21 | private char displayChar; 22 | 23 | public static final char EMPTY = '-'; 24 | public static final char PATH = 'o'; 25 | public static final char START = 'S'; 26 | public static final char GOAL = 'G'; 27 | 28 | /** 29 | * @return the displayChar 30 | */ 31 | public char getDisplayChar() { 32 | return displayChar; 33 | } 34 | 35 | /** 36 | * @param displayChar the displayChar to set 37 | */ 38 | public void setDisplayChar(char displayChar) { 39 | this.displayChar = displayChar; 40 | } 41 | 42 | public MazeNode(int row, int col) 43 | { 44 | this.row = row; 45 | this.column = col; 46 | neighbors = new LinkedList(); 47 | displayChar = EMPTY; 48 | } 49 | 50 | public void addNeighbor(MazeNode neighbor) 51 | { 52 | neighbors.add(neighbor); 53 | } 54 | 55 | /** 56 | * @return the neighbors 57 | */ 58 | public List getNeighbors() { 59 | return neighbors; 60 | } 61 | 62 | /** 63 | * @return the row 64 | */ 65 | public int getRow() { 66 | return row; 67 | } 68 | 69 | /** 70 | * @return the column 71 | */ 72 | public int getColumn() { 73 | return column; 74 | } 75 | 76 | 77 | } 78 | --------------------------------------------------------------------------------