Commit 5eec8ca3 authored by ecrombag's avatar ecrombag

Added an example which uses Google Maps to point out incident locations.

Added support for Static Maps (pre-rendered images). This is still based on google maps API V2 though, so it needs an API-key, which is set in GeoDomain.dcl

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@676 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent 922c1885
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<!-- import the Google Maps API V3 --> <!-- import the Google Maps API V3 -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<!-- import the Google Maps API V2 for Static Maps -->
<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;key=ABQIAAAAaZ6XgbNqm4h_DL45IQMnSRSrEXT3fNkwKSNTH8TDIqmpG-dFexSqJbR7bjG_6PAGWu4c1EGXviNLNQ"></script>
<!-- import the Extended Javascript Framework --> <!-- import the Extended Javascript Framework -->
<script type="text/javascript" src="ext3/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext3/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext3/ext-all-debug.js"></script> <script type="text/javascript" src="ext3/ext-all-debug.js"></script>
......
...@@ -14,6 +14,7 @@ itasks.GMapPanel = Ext.extend( Ext.Panel, { ...@@ -14,6 +14,7 @@ itasks.GMapPanel = Ext.extend( Ext.Panel, {
, height: 400 , height: 400
, width: 500 , width: 500
, scope: this , scope: this
, displayedMarkers : new Array()
}); });
itasks.GMapPanel.superclass.initComponent.apply(this,arguments); itasks.GMapPanel.superclass.initComponent.apply(this,arguments);
...@@ -26,6 +27,8 @@ itasks.GMapPanel = Ext.extend( Ext.Panel, { ...@@ -26,6 +27,8 @@ itasks.GMapPanel = Ext.extend( Ext.Panel, {
//this.gmap.setCenter(new google.maps.LatLng(data.center[0],data.center[1])); //this.gmap.setCenter(new google.maps.LatLng(data.center[0],data.center[1]));
//this.gmap.setZoom(data.zoom); //this.gmap.setZoom(data.zoom);
//this.gmap.setMapTypeId(this.getMapType(data.mapType)); //this.gmap.setMapTypeId(this.getMapType(data.mapType));
this.markers = data.markers;
this.addMarkers();
}, },
getMapType : function (mapType){ getMapType : function (mapType){
...@@ -45,7 +48,7 @@ itasks.GMapPanel = Ext.extend( Ext.Panel, { ...@@ -45,7 +48,7 @@ itasks.GMapPanel = Ext.extend( Ext.Panel, {
this.gmap = new google.maps.Map(this.body.dom, options); this.gmap = new google.maps.Map(this.body.dom, options);
//this.addMarkers(gmap) this.addMarkers()
var parent = this; var parent = this;
...@@ -92,14 +95,22 @@ itasks.GMapPanel = Ext.extend( Ext.Panel, { ...@@ -92,14 +95,22 @@ itasks.GMapPanel = Ext.extend( Ext.Panel, {
}, },
addMarkers : function (gmap){ addMarkers : function (){
var i=0; var i=0;
for(i=0; i<this.displayedMarkers.length; i++){
this.displayedMarkers[i].setMap(null);
}
this.displayedMarkers = new Array();
for(i=0; i<this.markers.length; i++){ for(i=0; i<this.markers.length; i++){
var markerObj = new google.maps.Marker({ var markerObj = new google.maps.Marker({
map : gmap, map : this.gmap,
position : new google.maps.LatLng(this.markers[i].position[0],this.markers[i].position[1]) position : new google.maps.LatLng(this.markers[i].position[0],this.markers[i].position[1])
}); });
this.displayedMarkers[i] = markerObj;
} }
} }
}); });
......
definition module AmbulanceDispatchMap
import iTasks
ambulanceDispatchMapExamples :: [Workflow]
\ No newline at end of file
implementation module AmbulanceDispatchMap
import iTasks
import CommonDomain
import GeoDomain
derive gPrint Incident, IncidentType
derive gParse Incident, IncidentType
derive gVisualize Incident, IncidentType
derive gUpdate Incident, IncidentType
ambulanceDispatchMapExamples :: [Workflow]
ambulanceDispatchMapExamples = flows
where
flows = [ workflow "Examples/Crisis response/Report incident (Map)" reportIncident ]
:: Incident =
{ location :: Coordinate
, type :: IncidentType
, time :: Time
, nrInjured :: Int
, description :: String
}
:: IncidentType = Accident | Fire | Fight | Other String
reportIncident :: Task Void
reportIncident
= markLocations >>=
\map -> specifiyIncidents map
>>| return Void
markLocations :: Task Map
markLocations =
enterInformation "Mark all locations where incidents have occurred"
specifiyIncidents :: Map -> Task [Incident]
specifiyIncidents map = sequence "Specify individual incident details" [ (specifyIncident m) \\ m <- map.Map.markers ]
specifyIncident :: MapMarker -> Task Incident
specifyIncident marker
# smap = convertToStaticMap {Map | mkMap & center = marker.position, width = 200, height = 200, zoom = 15, markers = [marker]}
# incident = { Incident
| location = marker.position
, type = Accident
, time = {Time | hour = 0, min = 0, sec = 0}
, nrInjured = 0
, description = ""
}
= showStickyMessage smap ||- updateInformation "Specify incident details" incident
\ No newline at end of file
definition module GeoDomain definition module GeoDomain
import Html, InteractionTasks import Html, InteractionTasks, CommonDomain
derive gPrint Map, MapMarker, MapInfoWindow, GoogleMapType derive gPrint Map, MapMarker, MapInfoWindow, GoogleMapType
derive gParse Map, MapMarker, MapInfoWindow, GoogleMapType derive gParse Map, MapMarker, MapInfoWindow, GoogleMapType
derive gVisualize Map, MapMarker, MapInfoWindow, GoogleMapType derive gVisualize Map, MapMarker, MapInfoWindow, GoogleMapType
derive gUpdate Map, MapMarker, MapInfoWindow, GoogleMapType derive gUpdate Map, MapMarker, MapInfoWindow, GoogleMapType
GOOGLE_API_KEY :== "ABQIAAAAaZ6XgbNqm4h_DL45IQMnSRSrEXT3fNkwKSNTH8TDIqmpG-dFexSqJbR7bjG_6PAGWu4c1EGXviNLNQ"
:: StaticMap = StaticMap Int Int String
:: Map = :: Map =
{ center :: Coordinate // Coordinate of the center point (Required by maps) { center :: Coordinate // Coordinate of the center point (Required by maps)
, width :: Int // Width & , width :: Int // Width &
, height :: Int // Height of the map , height :: Int // Height of the map
, mapTypeControl :: Bool // Show the control for switching between map types , mapTypeControl :: Bool // Show the control for switching between map types
, navigationControl :: Bool // Show the control for panning , navigationControl :: Bool // Show the control for panning
, scaleControl :: Bool // Show the control for zooming , scaleControl :: Bool // Show the control for zooming
, zoom :: Int // The zoom level (Required by maps) , zoom :: Int // The zoom level (Required by maps)
, mapType :: GoogleMapType // The map type , mapType :: GoogleMapType // The map type
, markers :: [MapMarker] // Markers placed on the map , markers :: [MapMarker] // Markers placed on the map
} }
:: Coordinate :== (Real, Real) // (Lattitude, Longitude) :: Coordinate :== (Real, Real) // (Lattitude, Longitude)
...@@ -33,4 +37,23 @@ derive gUpdate Map, MapMarker, MapInfoWindow, GoogleMapType ...@@ -33,4 +37,23 @@ derive gUpdate Map, MapMarker, MapInfoWindow, GoogleMapType
:: GoogleMapType = ROADMAP | SATELLITE | HYBRID | TERRAIN :: GoogleMapType = ROADMAP | SATELLITE | HYBRID | TERRAIN
:: MVCUpdate =
{ center :: Coordinate
, zoom :: Int
, type :: GoogleMapType
}
:: ClickUpdate =
{ event :: ClickEvent
, source :: ClickSource
, point :: Coordinate
}
:: ClickEvent = LEFTCLICK | RIGHTCLICK | DBLCLICK
:: ClickSource = MAP | MARKER Coordinate
convertToStaticMap :: Map -> StaticMap
mkMap :: Map
instance toString GoogleMapType instance toString GoogleMapType
instance html StaticMap
implementation module GeoDomain implementation module GeoDomain
import Html, InteractionTasks, StdEnv, JSON import Html, InteractionTasks, StdEnv, JSON, CommonDomain
derive JSONEncode JSONMap, MapMarker, GoogleMapType, MapInfoWindow derive JSONEncode JSONMap, MapMarker, GoogleMapType, MapInfoWindow
derive JSONDecode MVCUpdate, ClickUpdate, GoogleMapType, ClickSource, ClickEvent derive JSONDecode MVCUpdate, ClickUpdate, GoogleMapType, ClickSource, ClickEvent
...@@ -26,21 +26,6 @@ derive gUpdate MapMarker, MapInfoWindow, GoogleMapType ...@@ -26,21 +26,6 @@ derive gUpdate MapMarker, MapInfoWindow, GoogleMapType
, isEditor :: Bool , isEditor :: Bool
} }
:: MVCUpdate =
{ center :: Coordinate
, zoom :: Int
, type :: GoogleMapType
}
:: ClickUpdate =
{ event :: ClickEvent
, source :: ClickSource
, point :: Coordinate
}
:: ClickEvent = LEFTCLICK | RIGHTCLICK | DBLCLICK
:: ClickSource = MAP | MARKER Coordinate
instance toString GoogleMapType instance toString GoogleMapType
where where
toString ROADMAP = "ROADMAP" toString ROADMAP = "ROADMAP"
...@@ -48,6 +33,10 @@ where ...@@ -48,6 +33,10 @@ where
toString HYBRID = "HYBRID" toString HYBRID = "HYBRID"
toString TERRAIN = "TERRAIN" toString TERRAIN = "TERRAIN"
instance html StaticMap
where
html (StaticMap width height url) = [DivTag [WidthAttr (toString width), HeightAttr (toString height)] [ImgTag [SrcAttr url, WidthAttr (toString width), HeightAttr (toString height)]]]
gVisualize {|Map|} old new vst=:{vizType,label,idPrefix,currentPath, valid, optional} gVisualize {|Map|} old new vst=:{vizType,label,idPrefix,currentPath, valid, optional}
= case vizType of = case vizType of
VEditorDefinition = ([TUIFragment (mapsPanel old True)], {VSt | vst & currentPath = stepDataPath currentPath }) VEditorDefinition = ([TUIFragment (mapsPanel old True)], {VSt | vst & currentPath = stepDataPath currentPath })
...@@ -102,15 +91,55 @@ where ...@@ -102,15 +91,55 @@ where
# mbMVC = fromJSON update # mbMVC = fromJSON update
| isJust mbMVC | isJust mbMVC
# mvc = fromJust mbMVC # mvc = fromJust mbMVC
//= case orig.Map.mvcFun of
// Nothing
= {Map | orig & center = mvc.MVCUpdate.center, zoom = mvc.MVCUpdate.zoom, mapType = mvc.MVCUpdate.type} = {Map | orig & center = mvc.MVCUpdate.center, zoom = mvc.MVCUpdate.zoom, mapType = mvc.MVCUpdate.type}
// (Just fun) = fun mvc
# mbClick = fromJSON update # mbClick = fromJSON update
| isJust mbClick | isJust mbClick
# click = fromJust mbClick # click = fromJust mbClick
# marker = {MapMarker | position = click.ClickUpdate.point, infoWindow = {MapInfoWindow | content = "HI!", width=200}} //= case orig.Map.clickFun of
= {Map | orig & markers = [marker : orig.Map.markers]} // Nothing = orig
// (Just fun) = fun click
# marker = {MapMarker | position = click.ClickUpdate.point, infoWindow = {MapInfoWindow | content = "", width=0}}
= {Map | orig & markers = [marker:orig.Map.markers]}
| otherwise = orig | otherwise = orig
gUpdate {|Map|} s ust =: {USt | mode = UDMask, currentPath, mask} gUpdate {|Map|} s ust =: {USt | mode = UDMask, currentPath, mask}
= (s, {USt | ust & currentPath = stepDataPath currentPath, mask = [currentPath:mask]}) = (s, {USt | ust & currentPath = stepDataPath currentPath, mask = [currentPath:mask]})
gUpdate {|Map|} s ust = (s,ust) gUpdate {|Map|} s ust = (s,ust)
\ No newline at end of file
// -- Utility Functions --
mkMap :: Map
mkMap = { Map
| center = (0.0,0.0)
, width = 500
, height = 400
, mapTypeControl = True
, navigationControl = True
, scaleControl = True
, zoom = 10
, mapType = ROADMAP
, markers = []
}
convertToStaticMap :: Map -> StaticMap
convertToStaticMap map =:{Map | center = (lat,lng), width, height, zoom, mapType, markers}
# url = "http://maps.google.com/maps/api/staticmap?"
# cntr = "center="+++(toString lat)+++","+++(toString lng)
# zm = "zoom="+++(toString zoom)
# sz = "size="+++(toString width)+++"x"+++(toString height)
# tp = "maptype="+++(toString mapType)
# mrkrs = "markers="+++(convertMarkers markers)
= StaticMap width height (url+++cntr+++"&"+++zm+++"&"+++sz+++"&"+++tp+++"&"+++mrkrs+++"&sensor=false&key="+++GOOGLE_API_KEY)
where
convertMarkers :: [MapMarker] -> String
convertMarkers [] = "";
convertMarkers [x] = convertMarker x
convertMarkers [x:xs] = (convertMarker x)+++"|"+++(convertMarkers xs)
convertMarker :: MapMarker -> String
convertMarker mrkr =: {position = (lat,lng), infoWindow}
= toString lat+++","+++toString lng
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment