/// ----------------------------------------------------------------------------------
/// Copyright 2008 www.soulsolutions.com.au - sales@soulsolutions.com.au
/// All Rights Reserved.
/// 
///
/// Authors:   Bronwen Zande - bronwen@soulsolutions.com.au
///            John O'Brien - john@soulsolutions.com.au
/// ----------------------------------------------------------------------------------
Type.registerNamespace("SoulSolutions")
Type.registerNamespace("SoulSolutions.Mapping")
var screenBounds=new Object()
var resizetimer
var cResizeDelay=500
Sys.Application.add_load(function(){
$create(SoulSolutions.Mapping.Map,{
"Service":SoulSolutions.MVPMap.Web.services.MVPService,
"ClearInfoBoxStyles":false,
"Dashboard":true,
"DashboardSize":"normal",
"DisambiguationDialog":true,
"EnableShapeDisplayThreshold":true,
"FixedMap":false,
"Latitude":0,
"Longitude":0,
"MapMode":"1",
"MapStyle":"h",
"MiniMap":false,
"MiniMapSize":"small",
"MiniMapXoffset":0,
"MiniMapYoffset":400,
"MouseWheelZoomToCenter":true,
"NavigationControl3D":true,
"OnLoadMap":"",
"ScaleBarDistanceUnit":"k",
"ShapesAccuracy":"0",
"ShapesAccuracyRequestLimit":50,
"ShowMapModeSwitch":true,
"TileBuffer":0,
"Traffic":false,
"TrafficFlow":true,
"TrafficLegend":false,
"TrafficLegendText":"",
"TrafficLegendX":-1,
"TrafficLegendY":-1,
"Zoom":2,
"Size":Utility.getScreenBounds()},null,null,$get("myMap"))
setupPageResizing()
})
function setupPageResizing(){
if(window.attachEvent){
window.attachEvent("onresize",Page_Resize)
}else{
window.addEventListener("resize",Page_Resize,false)}
screenBounds.width=0
screenBounds.height=0
resizetimer=new Sys.Timer()
resizetimer.initialize()
resizetimer.set_interval(cResizeDelay)
resizetimer.add_tick(Resize_tick)
resizetimer.set_enabled(true)}
function Page_Resize(){
resizetimer.set_enabled(false)
resizetimer.set_enabled(true)}
function Resize_tick(){
resizetimer.set_enabled(false)
var CurrentscreenBounds=Utility.getScreenBounds()
if(CurrentscreenBounds.width !=screenBounds.width || CurrentscreenBounds.height !=screenBounds.height){
screenBounds.width=CurrentscreenBounds.width
screenBounds.height=CurrentscreenBounds.height
$find("myMap").set_Size(CurrentscreenBounds)}}
var GlobalCallQueue={
_callQueue : [],
_callInProgressNames : [],
_callInProgress : 0,
_maxConcurrentCall : 2,
call : function(servicePath,methodName,useGet,
params,onSuccess,onFailure,userContext,timeout){
var queuedCall=new QueuedCall(servicePath,methodName,useGet,
params,onSuccess,onFailure,userContext,timeout)
for(var x=0;x<GlobalCallQueue._callQueue.length;x++){
if(GlobalCallQueue._callQueue[x]._methodName==queuedCall._methodName){
Array.removeAt(GlobalCallQueue._callQueue,x)
break}}
Array.add(GlobalCallQueue._callQueue,queuedCall)
GlobalCallQueue.run()
},
run : function(){
if(GlobalCallQueue._callInProgress<GlobalCallQueue._maxConcurrentCall){
if(0==GlobalCallQueue._callQueue.length){
return}
GlobalCallQueue._callInProgress++
var runIndex=-1
for(var x=0;x<GlobalCallQueue._callQueue.length;x++){
var found=false
for(var y=0;y<GlobalCallQueue._callInProgressNames.length;y++){
if(GlobalCallQueue._callQueue[x]._methodName==GlobalCallQueue._callInProgressNames[y]){
found=true
break}}
if(!found){
runIndex=x
break}}
if(runIndex!=-1){
var queuedCall=GlobalCallQueue._callQueue[runIndex]
Array.removeAt(GlobalCallQueue._callQueue,runIndex)
Array.add(GlobalCallQueue._callInProgressNames,queuedCall._methodName)
queuedCall.execute()
}else{
GlobalCallQueue._callInProgress--}}
},
callComplete : function(methodName){
GlobalCallQueue._callInProgress--
for(var x=0;x<GlobalCallQueue._callInProgressNames.length;x++){
if(GlobalCallQueue._callInProgressNames[x]==methodName){
Array.removeAt(GlobalCallQueue._callInProgressNames,x)
break}}
GlobalCallQueue.run()}}
QueuedCall=function(servicePath,methodName,useGet,params,
onSuccess,onFailure,userContext,timeout){
this._servicePath=servicePath
this._methodName=methodName
this._useGet=useGet
this._params=params
this._onSuccess=onSuccess
this._onFailure=onFailure
this._userContext=userContext
this._timeout=timeout}
QueuedCall.prototype={
execute : function(){
Sys.Net.WebServiceProxy.original_invoke(
this._servicePath,this._methodName,this._useGet,this._params,
Function.createDelegate(this,this.onSuccess),
Function.createDelegate(this,this.onFailure),
this._userContext,this._timeout)
},
onSuccess : function(result,userContext,methodName){
this._onSuccess(result,userContext,methodName)
GlobalCallQueue.callComplete(methodName)
},
onFailure : function(result,userContext,methodName){
this._onFailure(result,userContext,methodName)
GlobalCallQueue.callComplete(methodName)}}
Sys.Net.WebServiceProxy.original_invoke=Sys.Net.WebServiceProxy.invoke
Sys.Net.WebServiceProxy.invoke=
function Sys$Net$WebServiceProxy$invoke(servicePath,methodName,
useGet,params,onSuccess,onFailure,userContext,timeout){
GlobalCallQueue.call(servicePath,methodName,useGet,params,
onSuccess,onFailure,userContext,timeout)}
var Utility={
OnFailed: function(error){
var stackTrace=error.get_stackTrace()
var message=error.get_message()
var statusCode=error.get_statusCode()
var exceptionType=error.get_exceptionType()
var timedout=error.get_timedOut()
var RsltElem=
"Stack Trace: "+stackTrace+"<br/>"+
"Service Error: "+message+"<br/>"+
"Status Code: "+statusCode+"<br/>"+
"Exception Type: "+exceptionType+"<br/>"+
"Timedout: "+timedout
alert(RsltElem)
},
GetBounds: function(_map){
var points=new Array()
if(_map.GetMapStyle()==VEMapStyle.Birdseye){
var be=_map.GetBirdseyeScene()
var rect=be.GetBoundingRectangle()
points.push(rect.TopLeftLatLong)
points.push(rect.BottomRightLatLong)
}else{
var view=_map.GetMapView()
points.push(view.TopLeftLatLong)
points.push(view.BottomRightLatLong)}
return Utility.createEncodings(points)
},
decodeLine: function(encoded){
var len=encoded.length
var index=0
var array=[]
var lat=0
var lng=0
try{
while(index<len){
var b
var shift=0
var result=0
do{
b=encoded.charCodeAt(index++)-63
result |=(b&0x1f)<<shift
shift+=5
}while(b>=0x20)
var dlat=((result&1)? ~(result>>1):(result>>1))
lat+=dlat
shift=0
result=0
do{
b=encoded.charCodeAt(index++)-63
result |=(b&0x1f)<<shift
shift+=5
}while(b>=0x20)
var dlng=((result&1)? ~(result>>1):(result>>1))
lng+=dlng
array.push(new VELatLong((lat*1e-5),(lng*1e-5)))}
}catch(ex){}
return array
},
decodeTypes: function(encoded){
var levels=[]
for(var pointIndex=0;pointIndex<encoded.length;++pointIndex){
var pointLevel=encoded.charCodeAt(pointIndex)-63
levels.push(pointLevel)}
return levels
},
createEncodings: function(points){
var i=0
var plat=0
var plng=0
var encoded_points=""
for(i=0;i<points.length;++i){
var point=points[i]
var lat=point.Latitude
var lng=point.Longitude
var late5=Math.floor(lat*1e5)
var lnge5=Math.floor(lng*1e5)
dlat=late5-plat
dlng=lnge5-plng
plat=late5
plng=lnge5
encoded_points+=this._encodeSignedNumber(dlat)+this._encodeSignedNumber(dlng)}
return encoded_points
},
_encodeSignedNumber: function(num){
var sgn_num=num<<1
if(num<0){
sgn_num=~(sgn_num)}
return(this._encodeNumber(sgn_num))
},
_encodeNumber: function(num){
var encodeString=""
while(num>=0x20){
encodeString+=(String.fromCharCode((0x20 |(num&0x1f))+63))
num>>=5}
encodeString+=(String.fromCharCode(num+63))
return encodeString
},
GetCirclePoints: function(impactPoint,radius){
var R=3959.872469777
var lat=(impactPoint.Latitude*Math.PI)/180
var lon=(impactPoint.Longitude*Math.PI)/180
var d=parseFloat(radius)/R
var locs1=new Array()
var locs2=new Array()
var locs=new Array()
var alreadyalerted=false
var absLongBoundary=180
var absLatBoundary=89.99995
for(var x=0;x<=360;x+=20){
var p2=new VELatLong(0,0)
brng=x*Math.PI/180
p2.Latitude=Math.asin(Math.sin(lat)*Math.cos(d)+Math.cos(lat)*Math.sin(d)*Math.cos(brng))
p2.Longitude=((lon+Math.atan2(Math.sin(brng)*Math.sin(d)*Math.cos(lat),Math.cos(d)-Math.sin(lat)*Math.sin(p2.Latitude)))*180)/Math.PI
p2.Latitude=(p2.Latitude*180)/Math.PI
var absLong=Math.abs(p2.Longitude)
var absLat=Math.abs(p2.Latitude)
if(absLong>absLongBoundary || absLat>absLatBoundary){
if(absLong>absLongBoundary){
if(p2.Longitude>0)
p2.Longitude=(p2.Longitude-absLongBoundary)-absLongBoundary
else
p2.Longitude=(p2.Longitude+absLongBoundary)+absLongBoundary}
if(absLat>absLatBoundary){
if(p2.Latitude>0)
p2.Latitude=(p2.Latitude-absLatBoundary)-absLatBoundary
else
p2.Latitude=(p2.Latitude+absLatBoundary)+absLatBoundary}
locs2.push(p2)}
else{
locs1.push(p2)}}
locs.push(locs1)
locs.push(locs2)
return locs
},
getScreenBounds: function(){
var Bounds=new Sys.UI.Bounds(0,0,0,0)
if(typeof window.innerWidth !='undefined'){
Bounds.width=window.innerWidth
Bounds.height=window.innerHeight}
else if(typeof document.documentElement !='undefined'
&&typeof document.documentElement.clientWidth !=
'undefined'&&document.documentElement.clientWidth !=0){
Bounds.width=document.documentElement.clientWidth
Bounds.height=document.documentElement.clientHeight}
else{
Bounds.width=document.getElementsByTagName('body')[0].clientWidth
Bounds.height=document.getElementsByTagName('body')[0].clientHeight}
if(Bounds.width<400)Bounds.width=400
if(Bounds.height<400)Bounds.height=400
return Bounds}}
SoulSolutions.Mapping.Map=function(element){
SoulSolutions.Mapping.Map.initializeBase(this,[element])
this._map=null
this._latitude
this._longitude
this._mapMode
this._mapStyle
this._navigationControl3D
this._dashboard
this._dashboardSize
this._miniMap
this._miniMapXoffset
this._miniMapYoffset
this._miniMapSize
this._trafficLegend
this._trafficLegendX
this._trafficLegendY
this._traffic
this._trafficFlow
this._enableShapeDisplayThreshold
this._mouseWheelZoomToCenter
this._scaleBarDistanceUnit
this._shapesAccuracy
this._shapesAccuracyRequestLimit
this._tileBuffer
this._trafficLegendText
this._zoom
this._disambiguationDialog
this._onLoadMap
this._clearInfoBoxStyles
this._fixedMap
this._showMapModeSwitch
this._size
this._service
this._layer=null
this._Mode=0
this._GetPinDataDelegate=null
this._onZoomDelegate=null}
SoulSolutions.Mapping.Map.prototype={
initialize : function(){
SoulSolutions.Mapping.Map.callBaseMethod(this,'initialize')
this._map=new VEMap(this.get_element().id)
if(this._dashboard)this._map.SetDashboardSize(this._dashboardSize)
this._map.onLoadMap=Function.createDelegate(this,this._onLoadVEMap)
this._map.LoadMap(new VELatLong(this._latitude,this._longitude),this._zoom,this._mapStyle,this._fixedMap,this._mapMode,this._showMapModeSwitch,this._tileBuffer)
},
_onLoadVEMap: function(){
this.set_Size(this._size)
this._map.SetScaleBarDistanceUnit(this._scaleBarDistanceUnit)
this._map.EnableShapeDisplayThreshold(this._enableShapeDisplayThreshold)
this._map.SetMouseWheelZoomToCenter(this._mouseWheelZoomToCenter)
this._map.SetShapesAccuracy(this._shapesAccuracy)
this._map.SetShapesAccuracyRequestLimit(this._shapesAccuracyRequestLimit)
this._map.ShowDisambiguationDialog(this._disambiguationDialog)
if(!this._dashboard){
this._map.HideDashboard()}
if(this._miniMap){
this._map.ShowMiniMap(this._miniMapXoffset,this._miniMapYoffset,this._miniMapSize)}
if(this._clearInfoBoxStyles){
this._map.ClearInfoBoxStyles()}
if(!this._navigationControl3D){
this._map.Hide3DNavigationControl()}
if(this._traffic){
this._map.LoadTraffic(this._trafficFlow)
if(this._trafficLegend){
this._map.ShowTrafficLegend(this._trafficLegendX,this._trafficLegendY)
if(this._trafficLegendText){
this._map.SetTrafficLegendText(this._trafficLegendText)}}}
this._GetPinDataDelegate=Function.createDelegate(this,this._GetPinData)
this._map.AttachEvent("onchangeview",this._GetPinDataDelegate)
this._onZoomDelegate=Function.createDelegate(this,this._onZoom)
this._map.AttachEvent("onstartzoom",this._onZoomDelegate)
this._layer=new VEShapeLayer()
this._map.AddShapeLayer(this._layer)
this._GetPinData()
},
_onZoom: function(){
this._layer.DeleteAllShapes()
},
_GetPinData: function(){
var zoom
if(this._map.GetMapStyle()==VEMapStyle.Birdseye){
zoom=19
}else{
zoom=this._map.GetZoomLevel()}
var bounds=Utility.GetBounds(this._map)
if(this._zoom !=zoom){
this._layer.DeleteAllShapes()
this._zoom=zoom}
this._service.GetClusteredMapData(bounds,zoom,Function.createDelegate(this,this._OnMapDataSucceeded),Utility.OnFailed)
},
_OnMapDataSucceeded: function(results){
this._layer.DeleteAllShapes()
var result=results.split(",")
var locs=Utility.decodeLine(result[0])
var zoom=this._map.GetZoomLevel()
var mapData=new Array()
for(var x=0;x<locs.length;x++){
var loc=locs[x]
var recordcount=result[x+1]
if(zoom<14){
var newShape=new VEShape(VEShapeType.Pushpin,loc)
var IconNormal
if(recordcount>40)IconNormal="pinMany"
else if(recordcount>20)IconNormal="pinFew"
else if(recordcount>1)IconNormal="pinCouple"
else IconNormal="pinSingle"
var Iconspec=new VECustomIconSpecification()
Iconspec.CustomHTML="<div class='"+IconNormal+"'></div>"
Iconspec.Image="/images/"+IconNormal+".png"
newShape.SetCustomIcon(Iconspec)
mapData.push(newShape)
}else{
var newShape=new VEShape(VEShapeType.Polygon,Utility.GetCirclePoints(loc,0.5)[0])
newShape.SetIconAnchor(loc)
newShape.HideIcon()
newShape.SetFillColor(new VEColor(0,37,227,0.2))
newShape.SetLineColor(new VEColor(0,37,227,0.9))
this._layer.AddShape(newShape)}}
if(mapData.length>0){
this._layer.AddShape(mapData)}
},
get_Service : function(){
return this._service
},
set_Service : function(value){
this._service=value
},
get_InfoBoxArgs : function(){
return this._infoBoxArgs
},
set_InfoBoxArgs : function(value){
this._infoBoxArgs=value
},
get_IsClustered : function(){
return this._isClustered
},
set_IsClustered : function(value){
this._isClustered=value
},
get_Latitude : function(){
return this._latitude
},
set_Latitude : function(value){
this._latitude=value
},
get_Longitude : function(){
return this._longitude
},
set_Longitude : function(value){
this._longitude=value
},
get_MapMode : function(){
return this._mapMode
},
set_MapMode : function(value){
this._mapMode=value
},
get_MapStyle : function(){
return this._mapStyle
},
set_MapStyle : function(value){
this._mapStyle=value
},
get_NavigationControl3D : function(){
return this._navigationControl3D
},
set_NavigationControl3D : function(value){
this._navigationControl3D=value
},
get_Dashboard : function(){
return this._dashboard
},
set_Dashboard : function(value){
this._dashboard=value
},
get_DashboardSize : function(){
return this._dashboardSize
},
set_DashboardSize : function(value){
this._dashboardSize=value
},
get_MiniMap : function(){
return this._miniMap
},
set_MiniMap : function(value){
this._miniMap=value
},
get_MiniMapXoffset : function(){
return this._miniMapXoffset
},
set_MiniMapXoffset : function(value){
this._miniMapXoffset=value
},
get_MiniMapYoffset : function(){
return this._miniMapYoffset
},
set_MiniMapYoffset : function(value){
this._miniMapYoffset=value
},
get_MiniMapSize : function(){
return this._miniMapSize
},
set_MiniMapSize : function(value){
this._miniMapSize=value
},
get_TrafficLegend : function(){
return this._trafficLegend
},
set_TrafficLegend : function(value){
this._trafficLegend=value
},
get_TrafficLegendX : function(){
return this._trafficLegendX
},
set_TrafficLegendX : function(value){
this._trafficLegendX=value
},
get_TrafficLegendY : function(){
return this._trafficLegendY
},
set_TrafficLegendY : function(value){
this._trafficLegendY=value
},
get_Traffic : function(){
return this._traffic
},
set_Traffic : function(value){
this._traffic=value
},
get_TrafficFlow : function(){
return this._trafficFlow
},
set_TrafficFlow : function(value){
this._trafficFlow=value
},
get_EnableShapeDisplayThreshold : function(){
return this._enableShapeDisplayThreshold
},
set_EnableShapeDisplayThreshold : function(value){
this._enableShapeDisplayThreshold=value
},
get_MouseWheelZoomToCenter : function(){
return this._mouseWheelZoomToCenter
},
set_MouseWheelZoomToCenter : function(value){
this._mouseWheelZoomToCenter=value
},
get_ScaleBarDistanceUnit : function(){
return this._scaleBarDistanceUnit
},
set_ScaleBarDistanceUnit : function(value){
this._scaleBarDistanceUnit=value
},
get_ShapesAccuracy : function(){
return this._shapesAccuracy
},
set_ShapesAccuracy : function(value){
this._shapesAccuracy=value
},
get_ShapesAccuracyRequestLimit : function(){
return this._shapesAccuracyRequestLimit
},
set_ShapesAccuracyRequestLimit : function(value){
this._shapesAccuracyRequestLimit=value
},
get_TileBuffer : function(){
return this._tileBuffer
},
set_TileBuffer : function(value){
this._tileBuffer=value
},
get_TrafficLegendText : function(){
return this._trafficLegendText
},
set_TrafficLegendText : function(value){
this._trafficLegendText=value
},
get_Zoom : function(){
return this._zoom
},
set_Zoom : function(value){
this._zoom=value
},
get_DisambiguationDialog : function(){
return this._disambiguationDialog
},
set_DisambiguationDialog : function(value){
this._disambiguationDialog=value
},
get_OnLoadMap : function(){
return this._onLoadMap
},
set_OnLoadMap : function(value){
this._onLoadMap=value
},
get_ClearInfoBoxStyles : function(){
return this._clearInfoBoxStyles
},
set_ClearInfoBoxStyles : function(value){
this._clearInfoBoxStyles=value
},
get_FixedMap : function(){
return this._fixedMap
},
set_FixedMap : function(value){
this._fixedMap=value
},
get_ShowMapModeSwitch : function(){
return this._showMapModeSwitch
},
set_ShowMapModeSwitch : function(value){
this._showMapModeSwitch=value
},
get_Size : function(){
return this._size
},
set_Size : function(value){
this._size=value
if(this._map){
this._map.Resize(this._size.width,this._size.height)}
},
dispose : function(){
if(this._map){
this._map.Dispose()
this._map=null}
this._GetPinDataDelegate=null
this._onZoomDelegate=null
SoulSolutions.Mapping.Map.callBaseMethod(this,'dispose')}}
SoulSolutions.Mapping.Map.registerClass('SoulSolutions.Mapping.Map',Sys.UI.Control)
if(typeof(Sys)!=="undefined")Sys.Application.notifyScriptLoaded()

