I have an HTML file included in my project. I use it to initialize a WebView
that displays a custom Google Map. I'm brand new to OSX apps (I'm coming from iOS) so this is all kinda new to me...
There are certain parts of the HTML file that I would like to be "dynamic", especially in the javascript function.
Here is how I get the URL for the local file and load the WebView:
-(void)awakeFromNib
{
NSString *indexPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
[[mapView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:indexPath]]];
[[[mapView mainFrame] frameView] setAllowsScrolling:NO];
[mapView setNeedsDisplay:YES];
}
Here is the HTML file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</head>
<body style="width:100%;height:100%">
<div id="map_area" style="position: absolute; top: 0; right: 0; bottom: 0; left: 0"> </div>
<script type="text/javascript">
//map = new GMap2(document.getElementById("map_area"));
//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
var myLatLng = new google.maps.LatLng(0, -180);
var mapOptions = {
zoom: 1,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map_area'), mapOptions);
var flightPlanCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
</script>
</body>
</html>
How can I change the javascript on the fly? I would like to be able to add/remove coordinates and draw multiple polylines. When messing with HTML/XML in iOS, I had used something called HPPLE which parsed through HTML/XML files...
Any help in how to approach this would be appreciated... or if you are aware of a better way to call javascript functions feel free to let me know.