Created
July 26, 2011 20:20
-
-
Save wboykinm/1107911 to your computer and use it in GitHub Desktop.
Interface for farm mapping
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
// Created by MSSB consulting | |
// JavaScript Document | |
function obj_mapObject(){ | |
this.latLng = new Array(); | |
} | |
function obj_xmlEntity(){ | |
this.tagOne=null; | |
this.tagTwo=null; | |
this.tagThree=null; | |
this.tagFour=null; | |
this.xmlEntityLoad=xmlEntityLoad; | |
} | |
function xmlEntityLoad(){ | |
this.tagOne=xmlDoc.getElementsByTagName("one"); | |
this.tagTwo=xmlDoc.getElementsByTagName("two"); | |
this.tagThree=xmlDoc.getElementsByTagName("three"); | |
this.tagFour=xmlDoc.getElementsByTagName("four"); | |
} | |
function obj_overlayObject(){ | |
this.overlayFeature=new Array(); | |
this.overlayObjectLoad=overlayObjectLoad; | |
//this.overlayObjectsUpdate=overlayObjectsUpdate; | |
} | |
function overlayObjectLoad(){ | |
try{ | |
var xml_primaryEntity=xmlEntity.tagThree; | |
var overlayObjectEntityList = xml_primaryEntity[0].getElementsByTagName("primaryEntity"); | |
for(var core_loop=0; core_loop < overlayObjectEntityList.length; core_loop++){ | |
var int_overlayObjectEntityID=parseInt(overlayObjectEntityList[core_loop].getAttribute("int_primaryEntityID")); | |
this.overlayFeature[int_overlayObjectEntityID]=new obj_overlayEntity(); | |
this.overlayFeature[int_overlayObjectEntityID].overlayEntityUpdate(overlayObjectEntityList[core_loop]); | |
} | |
}catch(err){ | |
this.loaded='F'; | |
} | |
} | |
function obj_overlayEntity(){ | |
this.overlayGroup=null; | |
this.overlayClassID=null; | |
this.overlayClass=null; | |
this.overlayType=null; | |
this.overlayColor=null; | |
this.overlayEntityUpdate=overlayEntityUpdate; | |
} | |
function overlayEntityUpdate(overlayObjectEntityList) { | |
this.overlayGroup=overlayObjectEntityList.getAttribute("str_objectGroup"); | |
this.overlayClass=overlayObjectEntityList.childNodes[0].nodeValue; | |
this.overlayType=overlayObjectEntityList.getAttribute("str_objectType"); | |
this.overlayColor=overlayObjectEntityList.getAttribute("str_objectColor"); | |
} | |
function obj_farmEntity(){ | |
this.entityID=null; | |
this.farmName=null; | |
this.addressOne=null; | |
this.addressTwo=null; | |
this.postCode=null; | |
this.areaLevelOneID=null; | |
this.areaLevelOneName=null; | |
this.map=null; | |
this.geocoder=null; | |
this.loaded=null; | |
this.mapEntity=new obj_mapEntity(); | |
this.featureEntity=new Array(); | |
this.plantingEntity=new Array(); | |
this.farmEntityLoad=farmEntityLoad; | |
this.farmEntityOutput=farmEntityOutput; | |
this.farmEntitySelect=farmEntitySelect; | |
this.featureEntityLoad=featureEntityLoad; | |
this.featureEntityOutput=featureEntityOutput; | |
} | |
function farmEntityLoad(){ | |
try{ | |
var xml_primaryEntity=xmlEntity.tagFour; | |
var farmEntityList = xml_primaryEntity[0].getElementsByTagName("farmEntity"); | |
this.entityID=parseInt(farmEntityList[0].getAttribute("int_primaryEntityID")); | |
this.farmName=farmEntityList[0].getAttribute("str_farmName"); | |
this.addressOne=farmEntityList[0].getAttribute("str_addressOne"); | |
this.addressTwo=farmEntityList[0].getAttribute("str_addressTwo"); | |
this.postCode=farmEntityList[0].getAttribute("str_postCode"); | |
this.areaLevelOneID=farmEntityList[0].getAttribute("int_areaLevelOneID"); | |
userEntity.userSelectAction="edit"; | |
this.loaded='T'; | |
window.document.getElementById("panel_page_two").style.left="800px"; | |
} catch(err){ | |
this.entityID=0; | |
userEntity.userSelectAction="add"; | |
this.loaded='F'; | |
} | |
bodyEntity.bodyEntityLists(window.document.getElementById('dropDownListTwo'), xmlEntity.tagThree); | |
this.mapEntity.mapEntityLoad(); | |
this.featureEntityLoad(); | |
this.featureEntityOutput(); | |
} | |
function farmEntityOutput(){ | |
if(this.loaded=="T"){ | |
this.mapEntity.mapEntityOutput(); | |
if(this.mapEntity.loaded=="T"){ | |
window.document.getElementById("dropDownListTwo").value=10; | |
if(this.featureEntity.length>0){ | |
bodyEntity.bodyEntityHelp(bodyEntity.overlayClass['add a feature'].helpLevelTwo); | |
}else{ | |
userEntity.userSelectGroup="feature"; | |
bodyEntity.bodyEntityHelp(bodyEntity.overlayClass['add a feature'].helpLevelOne); | |
} | |
}else{ | |
userEntity.userSelectGroup="map"; | |
window.document.getElementById("dropDownListTwo").value=7; | |
bodyEntity.bodyEntityHelp(bodyEntity.overlayClass['map'].helpLevelOne); | |
} | |
} else { | |
userEntity.userSelectGroup="farm"; | |
window.document.getElementById("dropDownListTwo").value=1; | |
bodyEntity.bodyEntityHelp(bodyEntity.overlayClass['farm'].helpLevelOne); | |
} | |
objectSelect(); | |
} | |
function farmEntitySelect(){ | |
window.document.getElementById("str_farmName").value=this.farmName; | |
window.document.getElementById("str_addressOne").value=this.addressOne; | |
window.document.getElementById("str_addressTwo").value=this.addressTwo; | |
window.document.getElementById("str_postCode").value=this.postCode; | |
window.document.getElementById("dropDownListOne").value=this.areaLevelOneID; | |
} | |
function obj_mapEntity(){ | |
this.entityID=null; | |
this.map=new GMap2(window.document.getElementById("panel_page_one")); | |
this.map.addControl(new GSmallMapControl()); | |
this.map.addControl(new GMapTypeControl()); | |
this.map.setMapType(G_SATELLITE_MAP); | |
GEvent.addListener(this.map, 'click', mapObjectUpdate); | |
GEvent.addListener(this.map, 'zoomend', mapObjectZoom); | |
this.geocoder=new GClientGeocoder(); | |
this.latLng=null; | |
this.zoom=null; | |
this.loaded='F'; | |
this.mapEntityLoad=mapEntityLoad; | |
this.mapEntityOutput=mapEntityOutput; | |
} | |
function mapEntityLoad(){ | |
try{ | |
var xml_primaryEntity=xmlEntity.tagFour; | |
var farmEntityList = xml_primaryEntity[0].getElementsByTagName("farmEntity"); | |
var farmMapEntityList = farmEntityList[0].getElementsByTagName("farmMapEntity"); | |
var mapEntityList = farmMapEntityList[0].getElementsByTagName("mapEntity"); | |
this.entityID=parseFloat(mapEntityList[0].getAttribute("int_mapEntityID")); | |
var float_latitude = parseFloat(mapEntityList[0].getAttribute("float_latitude")); | |
var float_longitude = parseFloat(mapEntityList[0].getAttribute("float_longitude")); | |
var latlng = new GLatLng(float_latitude, float_longitude); | |
this.latLng=latlng; | |
this.zoom=parseInt(mapEntityList[0].getAttribute("int_zoom")); | |
this.loaded="T"; | |
} catch(err){ | |
this.map.setMapType(G_NORMAL_MAP); | |
var xml_primaryEntity=xmlEntity.tagOne; | |
var mapEntityList = xml_primaryEntity[0].getElementsByTagName("mapEntity"); | |
this.entityID=0; | |
var float_latitude = parseFloat(mapEntityList[0].getAttribute("float_latitude")); | |
var float_longitude = parseFloat(mapEntityList[0].getAttribute("float_longitude")); | |
var latlng = new GLatLng(float_latitude, float_longitude); | |
this.latLng=latlng; | |
this.zoom=parseInt(mapEntityList[0].getAttribute("int_zoom")); | |
this.loaded='F'; | |
} | |
} | |
function mapEntityOutput(){ | |
this.map.setCenter(this.latLng, this.zoom); | |
} | |
function featureEntityLoad(){ | |
try{ | |
var xml_primaryEntity=xmlEntity.tagFour; | |
var farmEntityList = xml_primaryEntity[0].getElementsByTagName("farmEntity"); | |
var farmFeatureEntityList=farmEntityList[0].getElementsByTagName("farmFeatureEntity"); | |
for(var outer_loop = 0; outer_loop < farmFeatureEntityList.length; outer_loop++) { | |
var featureEntityList=farmFeatureEntityList[outer_loop].getElementsByTagName("featureEntity"); | |
for(var inner_loop=0; inner_loop < featureEntityList.length; inner_loop++){ | |
var int_featureEntityID=parseInt(featureEntityList[inner_loop].getAttribute("int_featureEntityID")); | |
this.featureEntity[int_featureEntityID]=new obj_featureEntity(); | |
this.featureEntity[int_featureEntityID].featureEntityUpdate(int_featureEntityID, featureEntityList[inner_loop]); | |
} | |
} | |
}catch(err){ | |
} | |
} | |
function obj_featureEntity(){ | |
this.farmFeatureGroup=null; | |
this.farmFeatureClass=null; | |
this.farmFeatureTextOne=null; | |
this.farmFeatureTextTwo=null; | |
this.objectOverlay=new obj_overlay(); | |
this.loaded='F'; | |
this.featureEntityUpdate=featureEntityUpdate; | |
this.featureEntitySelect=featureEntitySelect; | |
this.featureEntityOutput=featureEntityOutput; | |
} | |
function featureEntityUpdate(int_objectEntityID, featureEntityList){ | |
this.farmMapFeatureID=featureEntityList.getAttribute("int_farmMapFeatureID"); | |
this.farmFeatureTextOne=featureEntityList.getAttribute("str_farmFeatureTextOne"); | |
this.farmFeatureTextTwo=featureEntityList.getAttribute("str_farmFeatureTextTwo"); | |
this.objectOverlay.type=overlayObject.overlayFeature[this.farmMapFeatureID].overlayType; | |
featureCoordinateList=featureEntityList.getElementsByTagName("featureCoordinates"); | |
for(var core_loop = 0; core_loop < featureCoordinateList.length; core_loop++) { | |
var float_latitude = parseFloat(featureCoordinateList[core_loop].getAttribute("float_latitude")); | |
var float_longitude = parseFloat(featureCoordinateList[core_loop].getAttribute("float_longitude")); | |
var latlng = new GLatLng(float_latitude, float_longitude); | |
this.objectOverlay.latLngs.push(latlng); | |
} | |
switch (overlayObject.overlayFeature[this.farmMapFeatureID].overlayType){ | |
case "polygon": | |
this.objectOverlay.overlay = new GPolygon(this.objectOverlay.latLngs, overlayObject.overlayFeature[this.farmMapFeatureID].overlayColor, 2.0, 0.9,overlayObject.overlayFeature[this.farmMapFeatureID].overlayColor, 0.9); | |
break; | |
case "polyarea": | |
this.objectOverlay.overlay = new GPolyline(this.objectOverlay.latLngs, overlayObject.overlayFeature[this.farmMapFeatureID].overlayColor, 4, 0.8); | |
break; | |
case "polyline": | |
this.objectOverlay.overlay = new GPolyline(this.objectOverlay.latLngs, overlayObject.overlayFeature[this.farmMapFeatureID].overlayColor, 4, 0.8); | |
break; | |
} | |
this.objectOverlay.overlay.objectGroup=overlayObject.overlayFeature[this.farmMapFeatureID].overlayGroup; | |
this.objectOverlay.objectClassID=this.farmMapFeatureID; | |
this.objectOverlay.overlay.objectClass=overlayObject.overlayFeature[this.farmMapFeatureID].overlayClass; | |
this.objectOverlay.overlay.type=overlayObject.overlayFeature[this.farmMapFeatureID].overlayType; | |
this.objectOverlay.overlay.entityID=int_objectEntityID; | |
GEvent.addListener(this.objectOverlay.overlay, 'mouseover', mapObjectCursor); | |
this.objectOverlay.area=featureEntityList.getAttribute("float_farmFeatureArea"); | |
this.objectOverlay.xLength=featureEntityList.getAttribute("int_farmFeatureXLength"); | |
this.objectOverlay.yLength=featureEntityList.getAttribute("int_farmFeatureYLength"); | |
} | |
function featureEntityOutput(){ | |
for (array_index in this.featureEntity){ | |
if(this.featureEntity[array_index].objectOverlay.overlay) { | |
this.featureEntity[array_index].overlay=null; | |
} | |
this.mapEntity.map.addOverlay(this.featureEntity[array_index].objectOverlay.overlay); | |
} | |
} | |
function featureEntitySelect(){ | |
userEntity.userSelectObject.area=this.objectOverlay.area; | |
userEntity.userSelectObject.xLength=this.objectOverlay.xLength; | |
userEntity.userSelectObject.yLength=this.objectOverlay.yLength; | |
if(window.document.getElementById("str_featureTextOne")){ | |
window.document.getElementById("str_featureTextOne").value=this.farmFeatureTextOne; | |
window.document.getElementById("str_featureTextTwo").value=this.farmFeatureTextTwo; | |
} | |
window.document.getElementById("dropDownListTwo").value=this.objectOverlay.objectClassID; | |
bodyEntity.bodyEntityHelp(bodyEntity.overlayClass[userEntity.userSelectObject.objectClass].helpLevelTwo); | |
window.document.getElementById("objectInfo").objectInfoOutput(); | |
} | |
function obj_overlay(){ | |
this.type=null; | |
this.latLngs=new Array(); | |
this.overlay=null; | |
this.area=null; | |
this.xLength=null; | |
this.yLength=null; | |
} | |
function mapObjectUpdate(overlay, latlng){ | |
if(overlay && overlay.entityID && userEntity.userSelectAction=="add"){ | |
if(userEntity.userSelectObject.markers.length>1){ | |
alert("you cannot lay a marker on top of another feature"); | |
return; | |
} else { | |
var userMessage = "You are currently adding a " + userEntity.userSelectObject.objectClass + " do you want to switch to editing this feature"; | |
var userConfirm = confirm(userMessage); | |
if(userConfirm) { | |
mapObjectClear(); | |
userEntity.userSelectAction="edit"; | |
userEntity.userSelectGroup=overlay.objectGroup; | |
userEntity.userSelectObject.entityID=overlay.entityID; | |
userEntity.userSelectObject.overlay=overlay; | |
window.document.getElementById("dropDownListTwo").value=overlay.objectClassID; | |
userEntity.userSelectObject.objectClass=overlay.objectClass; | |
//objectSelect(); | |
bodyEntity.bodyEntityOutput(); | |
buttonEntity.buttonEntitySelect(); | |
window.document.getElementById("data_delete").style.visibility="visible"; | |
window.document.getElementById("panel_page_two").style.height="230px"; | |
farmEntity.featureEntity[userEntity.userSelectObject.entityID].featureEntitySelect(); | |
return; | |
} | |
} | |
} | |
if(overlay && overlay.entityID && userEntity.userSelectAction=="edit"){ | |
userEntity.userSelectAction="edit"; | |
userEntity.userSelectGroup=overlay.objectGroup; | |
userEntity.userSelectObject.entityID=overlay.entityID; | |
userEntity.userSelectObject.type=overlay.type; | |
userEntity.userSelectObject.objectClass=overlay.objectClass; | |
userEntity.userSelectObject.overlay=overlay; | |
userEntity.userSelectObject.latLngs=overlay.latLngs; | |
bodyEntity.bodyEntityHelp(bodyEntity.overlayClass[userEntity.userSelectObject.objectClass].helpLevelTwo); | |
bodyEntity.bodyEntityOutput(); | |
buttonEntity.buttonEntitySelect(); | |
window.document.getElementById("panel_page_two_one").style.height="70px"; | |
farmEntity.featureEntity[userEntity.userSelectObject.entityID].featureEntitySelect(); | |
return; | |
} | |
if(userEntity.userSelectAction=="edit"){ | |
window.document.getElementById("dropDownListTwo").value=10; | |
objectSelect(); | |
} | |
if( userEntity.userSelectAction=="add") { | |
if(userEntity.userSelectObject.objectClass != "farm"){ | |
var marker = new GMarker(latlng, {draggable:true}); | |
GEvent.addListener(marker, 'dragend', markerObjectMove); | |
farmEntity.mapEntity.map.addOverlay(marker); | |
userEntity.userSelectObject.markers.push(marker); | |
userEntity.userSelectObject.latLngs.push(latlng); | |
marker.entityID=userEntity.userSelectObject.latLngs.length-1; | |
switch (userEntity.userSelectObject.type){ | |
case "polygon": | |
userEntity.userSelectObject.latLngs.push(userEntity.userSelectObject.latLngs[0]); | |
if (userEntity.userSelectObject.latLngs.length > 2) { | |
mapObjectOutput(); | |
} | |
userEntity.userSelectObject.latLngs.pop(); | |
break; | |
case "polyarea": | |
userEntity.userSelectObject.latLngs.push(userEntity.userSelectObject.latLngs[0]); | |
if (userEntity.userSelectObject.latLngs.length > 2) { | |
mapObjectOutput(); | |
} | |
userEntity.userSelectObject.latLngs.pop(); | |
break; | |
case "polyline": | |
mapObjectOutput(); | |
break; | |
} | |
} else { | |
} | |
} | |
} | |
function markerObjectMove(){ | |
userEntity.userSelectObject.latLngs[this.entityID]=this.getPoint(); | |
if(userEntity.userSelectObject.latLngs.length>2){ | |
mapObjectOutput(); | |
} | |
} | |
function mapObjectOutput(){ | |
if(userEntity.userSelectObject.overlay){ | |
farmEntity.mapEntity.map.removeOverlay(userEntity.userSelectObject.overlay); | |
} | |
switch (userEntity.userSelectObject.type){ | |
case "polygon": | |
userEntity.userSelectObject.overlay = new GPolygon(userEntity.userSelectObject.latLngs, userEntity.userSelectObject.color, 2.0, 0.5, userEntity.userSelectObject.color, 1); | |
userEntity.userSelectObject.area=userEntity.userSelectObject.overlay.getArea()*userEntity.areaConversion; | |
userEntity.userSelectObject.area=userEntity.userSelectObject.area.toFixed(2); | |
var bounds = userEntity.userSelectObject.overlay.getBounds(); | |
var obj_southWest = bounds.getSouthWest(); | |
var obj_northEast = bounds.getNorthEast(); | |
var obj_latBottom = obj_southWest.lat(); | |
var obj_longRight = obj_northEast.lng(); | |
var obj_latlngRight = new GLatLng(obj_latBottom,obj_longRight); | |
userEntity.userSelectObject.yLength = Math.round(obj_latlngRight.distanceFrom(obj_northEast)*userEntity.lengthConversion); | |
userEntity.userSelectObject.xLength = Math.round(obj_latlngRight.distanceFrom(obj_southWest)*userEntity.lengthConversion); | |
//window.document.getElementById("objectInfo").innerHTML="w="+userEntity.userSelectObject.xLength+userEntity.lengthUnits+", h="+userEntity.userSelectObject.yLength+userEntity.lengthUnits+", a="+userEntity.userSelectObject.area+userEntity.areaUnits; | |
break; | |
case "polyarea": | |
userEntity.userSelectObject.overlay = new GPolygon(userEntity.userSelectObject.latLngs, userEntity.userSelectObject.color, 2.0, 0.5, userEntity.userSelectObject.color, 1); | |
userEntity.userSelectObject.area=userEntity.userSelectObject.overlay.getArea()*userEntity.areaConversion; | |
userEntity.userSelectObject.area=userEntity.userSelectObject.area.toFixed(2); | |
userEntity.userSelectObject.overlay = new GPolyline(userEntity.userSelectObject.latLngs, userEntity.userSelectObject.color, userEntity.userSelectObject.weight); | |
userEntity.userSelectObject.xLength=Math.round(userEntity.userSelectObject.overlay.getLength()*userEntity.lengthConversion); | |
break; | |
case "polyline": | |
userEntity.userSelectObject.overlay = new GPolyline(userEntity.userSelectObject.latLngs, userEntity.userSelectObject.color, userEntity.userSelectObject.weight); | |
userEntity.userSelectObject.xLength=Math.round(userEntity.userSelectObject.overlay.getLength()*userEntity.lengthConversion); | |
break; | |
} | |
GEvent.addListener(userEntity.userSelectObject.overlay, 'mouseover', mapObjectCursor); | |
farmEntity.mapEntity.map.addOverlay(userEntity.userSelectObject.overlay); | |
window.document.getElementById("objectInfo").objectInfoOutput(); | |
} | |
function mapObjectDelete(){ | |
if(userEntity.userSelectObject.latLngs.length>0){ | |
buttonEntity.buttonEntityUpdate("delete"); | |
userEntity.userSelectObject.latLngs.pop(); | |
farmEntity.mapEntity.map.removeOverlay(userEntity.userSelectObject.markers.pop()); | |
if(userEntity.userSelectObject.latLngs.length > 0){ | |
mapObjectOutput(); | |
} | |
buttonEntity.buttonEntityUpdate("delete"); | |
} | |
} | |
function mapObjectClear(){ | |
if(userEntity.userSelectObject.markers.length>0){ | |
for (var array_index in userEntity.userSelectObject.markers){ | |
farmEntity.mapEntity.map.removeOverlay(userEntity.userSelectObject.markers[array_index]); | |
} | |
userEntity.userSelectObject.markers.length=0; | |
} | |
if(userEntity.userSelectObject.overlay){ | |
farmEntity.mapEntity.map.removeOverlay(userEntity.userSelectObject.overlay); | |
userEntity.userSelectObject.overlay=null; | |
//userEntity.userSelectObject.latLngs.length=0; | |
//userEntity.userSelectObject.markers.length=0; | |
} | |
} | |
function mapObjectCursor(){ | |
window.document.getElementById("panel_page_one").style.cursor="default"; | |
} | |
function mapObjectPolyline(){ | |
userEntity.userSelectObject.weight=window.document.getElementById("str_featureTextTwo").value; | |
} | |
function mapObjectZoom(oldLevel, newLevel){ | |
if(newLevel>14){ | |
if(farmEntity.mapEntity.map.getCurrentMapType().getName()=="Map"){ | |
farmEntity.mapEntity.map.setMapType(G_SATELLITE_MAP); | |
} | |
}else{ | |
if(farmEntity.mapEntity.map.getCurrentMapType().getName()!="Map"){ | |
farmEntity.mapEntity.map.setMapType(G_NORMAL_MAP); | |
//farmEntity.mapEntity.map.addControl(new GSmallMapControl()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment