class RoutesMap constructor: (@target)-> @initMap() @area = [] @seenStopIds = [] @routes = {} initMap: -> @map = new ol.Map target: @target, layers: [ new ol.layer.Tile(source: new ol.source.OSM()) ] controls: [ new ol.control.ScaleLine(), new ol.control.Zoom(), new ol.control.ZoomSlider() ], interactions: ol.interaction.defaults(zoom: true) view: new ol.View() addRoutes: (routes)-> for route in routes @addRoute route addRoute: (route)-> geoColPts = [] geoColLns = [] @routes[route.id] = route if route.id stops = route.stops || route geoColEdges = [ new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(stops[0].longitude), parseFloat(stops[0].latitude)])) }), new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(stops[stops.length - 1].longitude), parseFloat(stops[stops.length - 1].latitude)])) }) ] prevStop = null stops.forEach (stop, i) => if stop.longitude && stop.latitude if prevStop geoColLns.push new ol.Feature geometry: new ol.geom.LineString([ ol.proj.fromLonLat([parseFloat(prevStop.longitude), parseFloat(prevStop.latitude)]), ol.proj.fromLonLat([parseFloat(stop.longitude), parseFloat(stop.latitude)]) ]) prevStop = stop geoColPts.push(new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(stop.longitude), parseFloat(stop.latitude)])) })) unless @seenStopIds.indexOf(stop.stoparea_id) > 0 @area.push [parseFloat(stop.longitude), parseFloat(stop.latitude)] @seenStopIds.push stop.stoparea_id vectorPtsLayer = new ol.layer.Vector({ source: new ol.source.Vector({ features: geoColPts }), style: @defaultStyles(), zIndex: 2 }) route.vectorPtsLayer = vectorPtsLayer if route.id vectorEdgesLayer = new ol.layer.Vector({ source: new ol.source.Vector({ features: geoColEdges }), style: @edgeStyles(), zIndex: 3 }) route.vectorEdgesLayer = vectorEdgesLayer if route.id vectorLnsLayer = new ol.layer.Vector({ source: new ol.source.Vector({ features: geoColLns }), style: [@lineStyle()], zIndex: 1 }) route.vectorLnsLayer = vectorLnsLayer if route.id @map.addLayer vectorPtsLayer @map.addLayer vectorEdgesLayer @map.addLayer vectorLnsLayer lineStyle: (highlighted=false)-> new ol.style.Style stroke: new ol.style.Stroke color: if highlighted then "#ed7f00" else '#007fbb' width: 3 edgeStyles: (highlighted=false)-> new ol.style.Style image: new ol.style.Circle radius: 5 stroke: new ol.style.Stroke color: if highlighted then "#ed7f00" else '#007fbb' width: 2 fill: new ol.style.Fill color: if highlighted then "#ed7f00" else '#007fbb' width: 2 defaultStyles: (highlighted=false)-> new ol.style.Style image: new ol.style.Circle radius: 4 stroke: new ol.style.Stroke color: if highlighted then "#ed7f00" else '#007fbb' width: 2 fill: new ol.style.Fill color: '#ffffff' width: 2 addRoutesLabels: -> labelsContainer = $("