Skip to content

Commit

Permalink
+ GoogleMapView const. throws a FileNotFoundException if rsc is missing
Browse files Browse the repository at this point in the history
+ mapResized(): fixed NullPointerException if resized before the map was
                loaded (Issue dlsc-software-consulting-gmbh#41)
  • Loading branch information
masinger committed Oct 3, 2015
1 parent 40218df commit 24341ee
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions GMapsFX/src/main/java/com/lynden/gmapsfx/GoogleMapView.java
Expand Up @@ -21,6 +21,9 @@
import com.lynden.gmapsfx.javascript.object.GoogleMap;
import com.lynden.gmapsfx.javascript.object.LatLong;
import com.lynden.gmapsfx.javascript.object.MapOptions;

import java.io.FileNotFoundException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CyclicBarrier;
Expand All @@ -46,11 +49,11 @@ public class GoogleMapView extends AnchorPane {
protected final List<MapReadyListener> mapReadyListeners = new ArrayList<>();
protected GoogleMap map;

public GoogleMapView() {
public GoogleMapView() throws FileNotFoundException {
this(false);
}

public GoogleMapView(boolean debug) {
public GoogleMapView(boolean debug) throws FileNotFoundException {
this(null, debug);
}

Expand Down Expand Up @@ -98,8 +101,9 @@ public GoogleMapView(boolean debug) {
* }
*
* @param mapResourcePath
* @throws FileNotFoundException if the map resource can not be found.
*/
public GoogleMapView(String mapResourcePath) {
public GoogleMapView(String mapResourcePath) throws FileNotFoundException {
this(mapResourcePath, false);
}

Expand All @@ -109,8 +113,9 @@ public GoogleMapView(String mapResourcePath) {
*
* @param mapResourcePath
* @param debug true if the FireBug pane should be displayed in the WebView.
* @throws FileNotFoundException if the map resource can not be found.
*/
public GoogleMapView(String mapResourcePath, boolean debug) {
public GoogleMapView(String mapResourcePath, boolean debug) throws FileNotFoundException {
String htmlFile;
if (mapResourcePath == null) {
if (debug) {
Expand Down Expand Up @@ -147,12 +152,16 @@ public void changed(ObservableValue ov, Worker.State oldState, Worker.State newS
}
}
});
webengine.load(getClass().getResource(htmlFile).toExternalForm());
URL rsc = getClass().getResource(htmlFile);
if(rsc == null){
throw new FileNotFoundException(String.format("The map resource was not found at the given path ('%s').", htmlFile));
}
webengine.load(rsc.toExternalForm());

}

private void mapResized() {
if (initialized) {
if (initialized && map != null) {
//map.triggerResized();
// System.out.println("GoogleMapView.mapResized: triggering resize event");
webengine.executeScript("google.maps.event.trigger(" + map.getVariableName() + ", 'resize')");
Expand Down

0 comments on commit 24341ee

Please sign in to comment.