Beispiel #1
0
 calculateOpenlayersCenterOfGeometry: function(propertyModel) {
   var lineObject = propertyModel.getPoints().map(function(coordinate) {
     return convertPointCoordinate(coordinate)
   })
   var extent = Openlayers.extent.boundingExtent(lineObject)
   return Openlayers.extent.getCenter(extent)
 },
Beispiel #2
0
 calculateOpenlayersCenterOfGeometry: function(geometry) {
     var lineObject = geometry.getAllPoints().map(function(coordinate) {
         return convertPointCoordinate(coordinate);
     });
     var extent = Openlayers.extent.boundingExtent(lineObject);
     return Openlayers.extent.getCenter(extent);
 },
Beispiel #3
0
 calculateOpenlayersCenterOfGeometries: function(geometries) {
     var allPoints = _.flatten(geometries.map(function(geometry) {
         return geometry.getAllPoints();
     }), true).map(function(coordinate) {
         return convertPointCoordinate(coordinate);
     });
     var extent = Openlayers.extent.boundingExtent(allPoints);
     return Openlayers.extent.getCenter(extent);
 },
Beispiel #4
0
 calculateOpenlayersCenterOfGeometries: function(propertyModels) {
   var allPoints = _.flatten(
     propertyModels.map(function(propertyModel) {
       return propertyModel.getPoints()
     }),
     true
   ).map(function(coordinate) {
     return convertPointCoordinate(coordinate)
   })
   var extent = Openlayers.extent.boundingExtent(allPoints)
   return Openlayers.extent.getCenter(extent)
 },
Beispiel #5
0
 features.forEach(function(feature, index) {
   var center = ol.extent.getCenter(feature.getGeometry().getExtent());
   var distance = getDistance(center, coord);
   if (distance < current_distance) {
     current_distance = distance;
     current = index;
   }
 });
    this.get('source').forEachFeatureInExtent(extent, feature => {
      let coordinates = feature.getGeometry().getCoordinates();

      let lastCoord = coordinates[0];
      let nextCoord = null;
      let end = coordinates.length;

      let lastRel = ol.extent.containsCoordinate(extent, lastCoord);

      total_min = Math.min(total_min, lastCoord[3]);

      if (lastRel === true) {
        min = Math.min(lastCoord[3], min);
      }

      for (let i = 1; i < end; i += 1) {
        nextCoord = coordinates[i];

        let nextRel = ol.extent.containsCoordinate(extent, nextCoord);

        // current vector completely within extent. do nothing.
        // current vector completely outside extent. do nothing.

        // last vertice was inside extent, next one is outside.
        if (lastRel && !nextRel) {
          max = Math.max(nextCoord[3], max);
          lastRel = nextRel;
        } else if (!lastRel && nextRel) {
          // last vertice was outside extent, next one is inside
          min = Math.min(lastCoord[3], min);
        }

        lastCoord = nextCoord;
        lastRel = nextRel;
      }

      if (lastRel === true) {
        max = Math.max(lastCoord[3], max);
      }

      total_max = Math.max(total_max, lastCoord[3]);
    });
Beispiel #7
0
    zoomToExtent: function(coords) {
      var lineObject = coords.map(function(coordinate) {
        return convertPointCoordinate(coordinate)
      })

      var extent = Openlayers.extent.boundingExtent(lineObject)

      map.getView().fit(extent, {
        size: map.getSize(),
        duration: 500,
      })
    },
Beispiel #8
0
    zoomToExtent: function(coords, opts = {}) {
      const lineObject = coords.map(function(coordinate) {
        return convertPointCoordinate(coordinate)
      })

      const extent = Openlayers.extent.boundingExtent(lineObject)

      map.getView().fit(extent, {
        size: map.getSize(),
        duration: 500,
        ...opts,
      })
    },
Beispiel #9
0
    panToExtent: function(coords) {
      if (coords.constructor === Array && coords.length > 0) {
        const lineObject = coords.map(function(coordinate) {
          return convertPointCoordinate(coordinate)
        })

        const extent = Openlayers.extent.boundingExtent(lineObject)

        map.getView().fit(extent, {
          size: map.getSize(),
          maxZoom: map.getView().getZoom(),
          duration: 500,
        })
      }
    },
Beispiel #10
0
        zoomToExtent: function(coords) {
            var zoom = Openlayers.animation.zoom({
                duration: 250,
                resolution: map.getView().getResolution()
            });
            var pan1 = Openlayers.animation.pan({
                duration: 250,
                source: map.getView().getCenter()
            });

            var lineObject = coords.map(function(coordinate) {
                return convertPointCoordinate(coordinate);
            });

            var extent = Openlayers.extent.boundingExtent(lineObject)

            map.beforeRender(pan1, zoom);
            map.getView().fit(extent, map.getSize());
        },
Beispiel #11
0
 var key = this.attr('mapModel.mapObject').on('postrender', function() {
   self.attr('popupModel').centerPopup(ol.extent.getCenter(extent));
   self.attr('mapModel.mapObject').unByKey(key);
 });
Beispiel #12
0
      get: function() {
        //if no features, return null
        if (!this.attr('features').length) {
          //update Map layer
          this.updateSelectedFeature(null);
          return null;
        }

        //get this active feature by array index
        var feature = this.attr('features')[this.attr('activeFeatureIndex')];

        //update Map layer
        this.updateSelectedFeature(feature);

        //get the layer key name. Layer id is returned from wms by LayerName.fetureID
        var layer = feature.getId().split('.');
        var index = layer[1];
        layer = layer[0];

        //get the configured layer properties object key this.layerProperties.layerName
        var layerProperties = ['layerProperties', layer].join('.');
        var template, fieldProperties, prop,
          attributes = {};
        var title;

        //if its provided parse the alias and formatters
        if (this.attr(layerProperties)) {

          //set the layer alias
          title = this.attr([layerProperties, 'alias'].join('.'));

          //set the correct template for this feature this.layerproperties.layername.template
          template = this.attr([layerProperties, 'template'].join('.'));
        }

        //get the field properties like alias and formatters this.layerproperties.layername.properties
        fieldProperties = this.attr([layerProperties, 'properties'].join('.'));
        var featureProperties = feature.getProperties();
        if (layerProperties && fieldProperties) {
          //build a new attribute list
          for (prop in featureProperties) {
            if (featureProperties.hasOwnProperty(prop) &&
              //if we don't have field properties for this layer or we do
              //and the exclude property is false or undefined, show this field
              (!fieldProperties || !fieldProperties.attr([prop, 'exclude'].join('.')))) {
              attributes[prop] = {

                //alias defaults to the property name if not provided
                alias: fieldProperties.attr([prop, 'alias'].join('.')) || prop,

                //value gets formatted if there's a formatter function
                value: typeof fieldProperties.attr([prop, 'formatter'].join('.')) === 'function' ?
                  fieldProperties.attr([prop, 'formatter'].join('.'))(featureProperties[prop], featureProperties) : can.esc(featureProperties[prop]),

                //rawValue in case you need access to it
                rawValue: featureProperties[prop]
              };
            }
          }
        } else {
          //if we don't have a layerProperties for this layer, build a simpler
          //attribute list
          for (prop in featureProperties) {
            if (featureProperties.hasOwnProperty(prop) &&
              //if we don't have field properties for this layer or we do
              //and the exclude property is false or undefined, show this field
              (!fieldProperties || !fieldProperties.attr([prop, 'exclude'].join('.')))) {
              attributes[prop] = {
                alias: prop,
                value: featureProperties[prop],
                rawValue: featureProperties[prop]
              };
            }
          }
        }

        //show popup if used
        if (this.attr('popupModel')) {
          var self = this;
          //there seems to be a bug when loading geojson features
          var extent = feature
            .getGeometry()
            .getExtent();
          self.attr('popupModel').centerPopup(ol.extent.getCenter(extent));
        }
        return {
          feature: feature,
          featureTemplate: template || featureTemplate,
          defaultTemplate: featureTemplate,
          attributes: attributes,
          layer: layer,
          title: title || layer,
          index: index
        };
      }
Beispiel #13
0
module.exports = function OpenlayersMap(
  insertionElement,
  selectionInterface,
  notificationEl,
  componentElement,
  mapModel
) {
  let overlays = {}
  let shapes = []
  const map = createMap(insertionElement)
  listenToResize()
  setupTooltip(map)
  const drawingTools = setupDrawingTools(map)

  function setupTooltip(map) {
    map.on('pointermove', function(e) {
      const point = unconvertPointCoordinate(e.coordinate)
      if (!offMap(point)) {
        mapModel.updateMouseCoordinates({
          lat: point[1],
          lon: point[0],
        })
      } else {
        mapModel.clearMouseCoordinates()
      }
    })
  }

  function setupDrawingTools(map) {
    return {
      bbox: new DrawBBox.Controller({
        map,
        notificationEl,
      }),
      circle: new DrawCircle.Controller({
        map,
        notificationEl,
      }),
      polygon: new DrawPolygon.Controller({
        map,
        notificationEl,
      }),
      line: new DrawLine.Controller({
        map,
        notificationEl,
      }),
    }
  }

  function resizeMap() {
    map.updateSize()
  }

  function listenToResize() {
    wreqr.vent.on('resize', resizeMap)
  }

  function unlistenToResize() {
    wreqr.vent.off('resize', resizeMap)
  }

  const exposedMethods = _.extend({}, Map, {
    drawLine(model) {
      drawingTools.line.draw(model)
    },
    drawBbox(model) {
      drawingTools.bbox.draw(model)
    },
    drawCircle(model) {
      drawingTools.circle.draw(model)
    },
    drawPolygon(model) {
      drawingTools.polygon.draw(model)
    },
    destroyDrawingTools() {
      drawingTools.line.destroy()
      drawingTools.polygon.destroy()
      drawingTools.circle.destroy()
      drawingTools.bbox.destroy()
    },
    onLeftClick(callback) {
      $(map.getTargetElement()).on('click', function(e) {
        const boundingRect = map.getTargetElement().getBoundingClientRect()
        callback(e, {
          mapTarget: determineIdFromPosition(
            [e.clientX - boundingRect.left, e.clientY - boundingRect.top],
            map
          ),
        })
      })
    },
    onRightClick(callback) {
      $(map.getTargetElement()).on('contextmenu', function(e) {
        const boundingRect = map.getTargetElement().getBoundingClientRect()
        callback(e)
      })
    },
    onMouseMove(callback) {
      $(map.getTargetElement()).on('mousemove', function(e) {
        const boundingRect = map.getTargetElement().getBoundingClientRect()
        callback(e, {
          mapTarget: determineIdFromPosition(
            [e.clientX - boundingRect.left, e.clientY - boundingRect.top],
            map
          ),
        })
      })
    },
    onCameraMoveStart(callback) {
      map.on('movestart', callback)
    },
    onCameraMoveEnd(callback) {
      map.on('moveend', callback)
    },
    doPanZoom(coords) {
      const that = this
      that.zoomOut({ duration: 1000 }, () => {
        setTimeout(() => {
          that.zoomToExtent(coords, { duration: 2000 })
        }, 0)
      })
    },
    zoomOut(opts, next) {
      next()
    },
    zoomToSelected() {
      if (selectionInterface.getSelectedResults().length === 1) {
        this.panToResults(selectionInterface.getSelectedResults())
      }
    },
    panToResults(results) {
      const coordinates = _.flatten(
        results.map(function(result) {
          return result.getPoints()
        }),
        true
      )
      this.panToExtent(coordinates)
    },
    panToExtent(coords) {
      if (coords.constructor === Array && coords.length > 0) {
        const lineObject = coords.map(function(coordinate) {
          return convertPointCoordinate(coordinate)
        })

        const extent = Openlayers.extent.boundingExtent(lineObject)

        map.getView().fit(extent, {
          size: map.getSize(),
          maxZoom: map.getView().getZoom(),
          duration: 500,
        })
      }
    },
    zoomToExtent(coords, opts = {}) {
      const lineObject = coords.map(function(coordinate) {
        return convertPointCoordinate(coordinate)
      })

      const extent = Openlayers.extent.boundingExtent(lineObject)

      map.getView().fit(extent, {
        size: map.getSize(),
        duration: 500,
        ...opts,
      })
    },
    zoomToBoundingBox({ north, east, south, west }) {
      this.zoomToExtent([[west, south], [east, north]])
    },
    limit(value, min, max) {
      return Math.min(Math.max(value, min), max)
    },
    getBoundingBox() {
      const extent = map.getView().calculateExtent(map.getSize())
      let longitudeEast = wrapNum(extent[2], -180, 180)
      const longitudeWest = wrapNum(extent[0], -180, 180)
      //add 360 degrees to longitudeEast to accommodate bounding boxes that span across the anti-meridian
      if (longitudeEast < longitudeWest) {
        longitudeEast += 360
      }
      return {
        north: this.limit(extent[3], -90, 90),
        east: longitudeEast,
        south: this.limit(extent[1], -90, 90),
        west: longitudeWest,
      }
    },
    overlayImage(model) {
      const metacardId = model.get('properties').get('id')
      this.removeOverlay(metacardId)

      const coords = model.getPoints('location')
      const array = _.map(coords, function(coord) {
        return convertPointCoordinate(coord)
      })

      const polygon = new Openlayers.geom.Polygon([array])
      const extent = polygon.getExtent()
      const projection = Openlayers.proj.get(properties.projection)

      const overlayLayer = new Openlayers.layer.Image({
        source: new Openlayers.source.ImageStatic({
          url: model.get('currentOverlayUrl'),
          projection,
          imageExtent: extent,
        }),
      })

      map.addLayer(overlayLayer)
      overlays[metacardId] = overlayLayer
    },
    removeOverlay(metacardId) {
      if (overlays[metacardId]) {
        map.removeLayer(overlays[metacardId])
        delete overlays[metacardId]
      }
    },
    removeAllOverlays() {
      for (const overlay in overlays) {
        if (overlays.hasOwnProperty(overlay)) {
          map.removeLayer(overlays[overlay])
        }
      }
      overlays = {}
    },
    getCartographicCenterOfClusterInDegrees(cluster) {
      return utility.calculateCartographicCenterOfGeometriesInDegrees(
        cluster.get('results').map(function(result) {
          return result
        })
      )
    },
    getWindowLocationsOfResults(results) {
      return results.map(function(result) {
        const openlayersCenterOfGeometry = utility.calculateOpenlayersCenterOfGeometry(
          result
        )
        const center = map.getPixelFromCoordinate(openlayersCenterOfGeometry)
        if (center) {
          return center
        } else {
          return undefined
        }
      })
    },
    /*
            Adds a billboard point utilizing the passed in point and options.
            Options are a view to relate to, and an id, and a color.
        */
    addPointWithText(point, options) {
      const pointObject = convertPointCoordinate(point)
      const feature = new Openlayers.Feature({
        geometry: new Openlayers.geom.Point(pointObject),
      })
      feature.setId(options.id)

      feature.setStyle(
        new Openlayers.style.Style({
          image: new Openlayers.style.Icon({
            img: DrawingUtility.getCircleWithText({
              fillColor: options.color,
              text: options.id.length,
            }),
            imgSize: [44, 44],
          }),
        })
      )

      const vectorSource = new Openlayers.source.Vector({
        features: [feature],
      })

      const vectorLayer = new Openlayers.layer.Vector({
        source: vectorSource,
        zIndex: 1,
      })

      map.addLayer(vectorLayer)

      return vectorLayer
    },
    /*
          Adds a billboard point utilizing the passed in point and options.
          Options are a view to relate to, and an id, and a color.
        */
    addPoint(point, options) {
      const pointObject = convertPointCoordinate(point)
      const feature = new Openlayers.Feature({
        geometry: new Openlayers.geom.Point(pointObject),
        name: options.title,
      })
      feature.setId(options.id)

      let x = 39,
        y = 40
      if (options.size) {
        x = options.size.x
        y = options.size.y
      }
      feature.setStyle(
        new Openlayers.style.Style({
          image: new Openlayers.style.Icon({
            img: DrawingUtility.getPin({
              fillColor: options.color,
              icon: options.icon,
            }),
            imgSize: [x, y],
            anchor: [x / 2, 0],
            anchorOrigin: 'bottom-left',
            anchorXUnits: 'pixels',
            anchorYUnits: 'pixels',
          }),
        })
      )

      const vectorSource = new Openlayers.source.Vector({
        features: [feature],
      })

      const vectorLayer = new Openlayers.layer.Vector({
        source: vectorSource,
        zIndex: 1,
      })

      map.addLayer(vectorLayer)

      return vectorLayer
    },
    /*
          Adds a polyline utilizing the passed in line and options.
          Options are a view to relate to, and an id, and a color.
        */
    addLine(line, options) {
      const lineObject = line.map(function(coordinate) {
        return convertPointCoordinate(coordinate)
      })

      const feature = new Openlayers.Feature({
        geometry: new Openlayers.geom.LineString(lineObject),
        name: options.title,
      })
      feature.setId(options.id)

      const styles = [
        new Openlayers.style.Style({
          stroke: new Openlayers.style.Stroke({
            color: 'white',
            width: 8,
          }),
        }),
        new Openlayers.style.Style({
          stroke: new Openlayers.style.Stroke({
            color: options.color || defaultColor,
            width: 4,
          }),
        }),
      ]

      feature.setStyle(styles)

      const vectorSource = new Openlayers.source.Vector({
        features: [feature],
      })

      const vectorLayer = new Openlayers.layer.Vector({
        source: vectorSource,
      })

      map.addLayer(vectorLayer)

      return vectorLayer
    },
    /*
          Adds a polygon fill utilizing the passed in polygon and options.
          Options are a view to relate to, and an id.
        */
    addPolygon(polygon, options) {},
    /*
         Updates a passed in geometry to reflect whether or not it is selected.
         Options passed in are color and isSelected.
         */
    updateCluster(geometry, options) {
      if (geometry.constructor === Array) {
        geometry.forEach(
          function(innerGeometry) {
            this.updateCluster(innerGeometry, options)
          }.bind(this)
        )
      } else {
        const feature = geometry.getSource().getFeatures()[0]
        const geometryInstance = feature.getGeometry()
        if (geometryInstance.constructor === Openlayers.geom.Point) {
          geometry.setZIndex(options.isSelected ? 2 : 1)
          feature.setStyle(
            new Openlayers.style.Style({
              image: new Openlayers.style.Icon({
                img: DrawingUtility.getCircleWithText({
                  fillColor: options.color,
                  strokeColor: options.outline,
                  text: options.count,
                  textColor: options.textFill,
                }),
                imgSize: [44, 44],
              }),
            })
          )
        } else if (
          geometryInstance.constructor === Openlayers.geom.LineString
        ) {
          const styles = [
            new Openlayers.style.Style({
              stroke: new Openlayers.style.Stroke({
                color: 'rgba(255,255,255, .1)',
                width: 8,
              }),
            }),
            new Openlayers.style.Style({
              stroke: new Openlayers.style.Stroke({
                color: 'rgba(0,0,0, .1)',
                width: 4,
              }),
            }),
          ]
          feature.setStyle(styles)
        }
      }
    },
    /*
          Updates a passed in geometry to reflect whether or not it is selected.
          Options passed in are color and isSelected.
        */
    updateGeometry(geometry, options) {
      if (geometry.constructor === Array) {
        geometry.forEach(
          function(innerGeometry) {
            this.updateGeometry(innerGeometry, options)
          }.bind(this)
        )
      } else {
        const feature = geometry.getSource().getFeatures()[0]
        const geometryInstance = feature.getGeometry()
        if (geometryInstance.constructor === Openlayers.geom.Point) {
          let x = 39,
            y = 40
          if (options.size) {
            x = options.size.x
            y = options.size.y
          }
          geometry.setZIndex(options.isSelected ? 2 : 1)
          feature.setStyle(
            new Openlayers.style.Style({
              image: new Openlayers.style.Icon({
                img: DrawingUtility.getPin({
                  fillColor: options.color,
                  strokeColor: options.isSelected ? 'black' : 'white',
                  icon: options.icon,
                }),
                imgSize: [x, y],
                anchor: [x / 2, 0],
                anchorOrigin: 'bottom-left',
                anchorXUnits: 'pixels',
                anchorYUnits: 'pixels',
              }),
            })
          )
        } else if (
          geometryInstance.constructor === Openlayers.geom.LineString
        ) {
          const styles = [
            new Openlayers.style.Style({
              stroke: new Openlayers.style.Stroke({
                color: options.isSelected ? 'black' : 'white',
                width: 8,
              }),
            }),
            new Openlayers.style.Style({
              stroke: new Openlayers.style.Stroke({
                color: options.color || defaultColor,
                width: 4,
              }),
            }),
          ]
          feature.setStyle(styles)
        }
      }
    },
    /*
         Updates a passed in geometry to be hidden
         */
    hideGeometry(geometry) {
      geometry.setVisible(false)
    },
    /*
         Updates a passed in geometry to be shown
         */
    showGeometry(geometry) {
      geometry.setVisible(true)
    },
    removeGeometry(geometry) {
      map.removeLayer(geometry)
    },
    showPolygonShape(locationModel) {
      const polygon = new DrawPolygon.PolygonView({
        model: locationModel,
        map,
      })
      shapes.push(polygon)
    },
    showCircleShape(locationModel) {
      const circle = new DrawCircle.CircleView({
        model: locationModel,
        map,
      })
      shapes.push(circle)
    },
    showLineShape(locationModel) {
      const line = new DrawLine.LineView({
        model: locationModel,
        map,
      })
      shapes.push(line)
    },
    showMultiLineShape(locationModel) {
      let lineObject = locationModel
        .get('multiline')
        .map(line => line.map(coords => convertPointCoordinate(coords)))

      let feature = new Openlayers.Feature({
        geometry: new Openlayers.geom.MultiLineString(lineObject),
      })

      feature.setId(locationModel.cid)

      const styles = [
        new Openlayers.style.Style({
          stroke: new Openlayers.style.Stroke({
            color: locationModel.get('color') || defaultColor,
            width: 4,
          }),
        }),
      ]

      feature.setStyle(styles)

      return this.createVectorLayer(locationModel, feature)
    },
    createVectorLayer(locationModel, feature) {
      let vectorSource = new Openlayers.source.Vector({
        features: [feature],
      })

      let vectorLayer = new Openlayers.layer.Vector({
        source: vectorSource,
      })

      map.addLayer(vectorLayer)
      overlays[locationModel.cid] = vectorLayer

      return vectorLayer
    },
    destroyShape(cid) {
      const shapeIndex = shapes.findIndex(shape => cid === shape.model.cid)
      if (shapeIndex >= 0) {
        shapes[shapeIndex].destroy()
        shapes.splice(shapeIndex, 1)
      }
    },
    destroyShapes() {
      shapes.forEach(function(shape) {
        shape.destroy()
      })
      shapes = []
    },
    getOpenLayersMap() {
      return map
    },
    destroy() {
      this.destroyDrawingTools()
      unlistenToResize()
    },
  })

  return exposedMethods
}
Beispiel #14
0
var ol = require('openlayers');
var fs = require('fs');
var fastCsv = require('fast-csv');
var csvParser = require('csv-parser');
var stream = require('stream');

var sfExtent = [-122.384591, 37.703211, -122.510850, 37.808675];
var sf = ol.extent.getCenter(sfExtent);
var halfMileInMeters = 804.672;
var wgs84Sphere = new ol.Sphere(6378137);

function stringStream(string) {
  // http://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js
  var s = new stream.Readable();
  s._read = function noop() {}; // redundant? see update below
  s.push(string);
  s.push(null);
  return s;
}

function makeLayer(csvStream, color) {
  var style = new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: color,
      width: 1
    }),
    fill: new ol.style.Fill({
      color: color,
    })
  });
Beispiel #15
0
function unconvertPointCoordinate(point) {
  return Openlayers.proj.transform(point, properties.projection, 'EPSG:4326')
}

/*
  A variety of helpful functions for dealing with Openlayers
*/
module.exports = {
  /*
      Calculates the center of given a geometry (WKT)
    */
  calculateOpenlayersCenterOfGeometry(propertyModel) {
    const lineObject = propertyModel.getPoints().map(function(coordinate) {
      return convertPointCoordinate(coordinate)
    })
    const extent = Openlayers.extent.boundingExtent(lineObject)
    return Openlayers.extent.getCenter(extent)
  },
  /*
      Calculates the center of given a geometry (WKT)
    */
  calculateCartographicCenterOfGeometryInDegrees(propertyModel) {
    const openlayersCenter = this.calculateOpenlayersCenterOfGeometry(
      propertyModel
    )
    return unconvertPointCoordinate(openlayersCenter)
  },
  /*
      Calculates the center of given geometries (WKT)
    */
  calculateOpenlayersCenterOfGeometries(propertyModels) {
  willDestroyElement() {
    this.get('map').un('postcompose', this.onPostCompose, this);
  },

  onPostCompose(e) {
    this.renderMarkers(e.vectorContext);
  },

  renderMarkers(context) {
    this.renderMarker(context, this.get('startStyle'), this.get('startPoint'));
    this.renderMarker(context, this.get('endStyle'), this.get('endPoint'));
  },

  renderMarker(context, style, coordinate) {
    if (coordinate) {
      context.setStyle(style);
      context.drawGeometry(coordinate);
    }
  },

  adjustMapView() {
    let coordinates = this.get('coordinates');
    if (coordinates) {
      let map = this.get('map');
      let extent = ol.extent.boundingExtent(coordinates);
      let padding = this.getWithDefault('calculatePadding', Ember.K)();
      map.getView().fit(extent, map.getSize(), { padding });
    }
  },
});