Created
November 5, 2011 20:24
-
-
Save uwePhillPhelps/1341973 to your computer and use it in GitHub Desktop.
Satsymph Hermes - interrogating google map API markers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createPerimeterFromMarkers() | |
{ | |
/* | |
1. interrogate the named elements in our named frame | |
(containing a google map API with four user-droppable markers) | |
2. create an AppFurnace Geo Line object using the four co-ordinates | |
indicated by the user in the google map API frame | |
*/ | |
// references to the screen and frame | |
var scr = Screens.getScreen( 'index' ); | |
var frame = scr.getIFrameElement( 'myIFrame' ); | |
var actualFrame = document.getElementById('calMyIFrameSubframe'); | |
// reference to the document in the named frame | |
var aFDoc = (actualFrame.contentWindow || actualFrame.contentDocument); | |
if (aFDoc.document){ aFDoc = aFDoc.document; } | |
/* | |
interrogate the named DIV elements | |
if any of the elements are blank - pop up an alert and abort! | |
*/ | |
for (var i=1; i<=4; i++) | |
{ | |
var markerLat = aFDoc.getElementById('m' + i + 'lat').innerHTML; | |
var markerLng = aFDoc.getElementById('m' + i + 'lng').innerHTML; | |
// abort if the marker is not set | |
if ( markerLat == '' || markerLat === null || markerLat === undefined | |
|| markerLng == '' || markerLng === null || markerLng === undefined) | |
{ | |
var errorMessage = 'You must set all 4 markers. (marker ' + i + ' is not set)'; | |
Debug.log(errorMessage); | |
alert('error', errorMessage); | |
return; | |
} | |
else | |
{ | |
markerLat = parseFloat( markerLat ); | |
markerLng = parseFloat( markerLng ); | |
var currentCoord = new Coord( markerLng, markerLat, cal.Coord.Datum.WGS84 ); | |
var userPerimeterLine = null; | |
if ( i == 1 ) | |
{ | |
Debug.log('first point'); | |
// workaround bug that line constructor requires two points | |
// solution: add two identical points! | |
userPerimeterLine = | |
new Line("userPerimeterLine", [currentCoord, currentCoord]); | |
GeoFeatures.addFeature(userPerimeterLine); | |
// modify the object added to geo features to be visible | |
// question: not sure if this could be done to the var userPerimeterLine | |
GeoFeatures.getFeatureByName( "userPerimeterLine" ).setShapeVisible( true ); | |
} | |
else | |
{ | |
userPerimeterLine = GeoFeatures.getFeatureByName("userPerimeterLine"); | |
userPerimeterLine.addNode( currentCoord ); | |
} | |
}// else marker lat/lng is valid | |
}// for each marker | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment