Openlayers 3 - Line with two points

I'm trying to create a tool which enables the user to draw a linestring with only 2 points. It's surprising how long I've searched and can't find an example or someone asking the question.

I know that there is a potential maxPoints property but I don't know how to apply it. My guess is that it involves defining a geometry function on the linestring draw interaction but I'm struggling to make it work.

This is what I've got so far:

var vecSource = session.activeRoute.Layer.getSource(); // setup draw interaction session.draw = new ol.interaction.Draw({     source: vecSource,     type: geomtype,     geometryFunction: geometryFunction,     maxPoints: maxPoints });      if (geomtype === 'Line') {     maxPoints = 2;     geomtype = 'LineString';     geometryFunction = function (coords, geom) {         geom = new ol.geom.LineString();         coords = geom.getCoordinates();         if (coords.length == 2) {             finishDrawing();         }     } } 

I realise this probably doesn't make any sense but I've tried several different methods and this is the best I've come up with. A linestring has been created but length and geom = null when I test this.

Can anyone please offer any insight?

Replay

Category: openlayers 3 Time: 2016-07-28 Views: 0

Related post

  • Creating line between two points with common field? 2012-07-10

    Does anyone know how I could create a line between two points that have a common code? For example: I have the start and end point of a pipe as a lat/long for a network of pipes, each with a different ID. I want to create a line feature for each of t

  • What's the idea behind defining rectangles with two points? 2010-11-30

    It's not that this doesn't make sense, but it just works out awkward 99% of the time. Often in 2D graphics rectangles are initialized, stored and manipulated as a pair of points. In no particular language, class Rect: p1, p2: point It makes more sens

  • Drawing a line between two points 2012-03-16

    The LaTeX line requirements are too restrictive (coprime and mag < 6). Is there any package that lets me just draw a line between two points? Basically \line(a,b)(c,d) or something similar I went through all the trouble of calculating the points for

  • Drawing a line between two points in opengl android 2016-01-23

    I'm new to opengl and android I have looked up some tutorial online I want to make a Line class that draws a line between two points that the user will provide here is the code I have started with ,it's actully google example of drawing a triangle bu

  • sed command to replace a blank line with two lines of content 2011-05-24

    How do I replace the first blank line with two lines of content? I did see a question on replacing multiple blank lines with a single blank line in vim sed but don't quite see how to adapt that. So, for example, if my input file is: % abd % def % jkl

  • How to drawing a line between two points 2016-01-14

    In my app I have an UIImageView where I can draw inside of that. How to draw a lines between two points in this way: The user press inside the UIImageView and when leave the press the code create the lines between the first CGPoint and the last CGPoi

  • Creating curved lines between two points in QGIS 2016-06-08

    I am trying to create curved lines between two point in QGIS. There are a few posts that show how to create these lines (hyperlinks below). However, I am having trouble executing the code in QGIS. This article says one could use the following code: S

  • Label two equations in one line with two correct reference? 2016-07-20

    I have searched the website about this but have found nothing similar. suppose that I have two equations a=b (1) and b=c (2). I would like to be able to put both of them in one line with two different references as: a = b, b = c (1, 2) --------------

  • Select all lines between two points 2016-07-22

    I need some ideas to solve the problem selecting all "lines" between two "points" using SQL Server. I have tables: Lines (line_id, geom) and Point (point_id, geom) I want to select all Lines between two Points over point_id I tried: se

  • Line through two points with offset in TikZ 2012-03-17

    I could not find a native command in TikZ allowing to draw a line going through two specified points where an offset can be controlled. So far, I'm using the calc extension to perform what I need but there may be something better: \documentclass[12pt

  • Perpendicular line to two-points-line given the length 2012-08-16

    I have two points A and B, I call the line consisting of A and B as LAB:ax+by+c=0, I would like to draw a line segment starting from the point B perpendicular to LAB and with length len such that the line segment stays on positive side of the line LA

  • How can I create a line with three points with Python in QGIS? 2013-05-09

    I'm new to Python and I'm having some dificulties. I want to create a simple layer with a line in the console of QGIS with Python. How can I do that? --------------Solutions------------- You must first understand how PyQGIS handles geometry (Geometry

  • Create line from two points, two different feature class 2013-05-17

    I'm attempting to automate this in ModelBuilder in ArcMap. I have one feature class with one point (Start) and one feature class with multiple points (Destinations). I want to iterate through the Destinations so I create multiple lines from the Start

  • How to draw lines from two points in a CSV? 2013-06-28

    I have a CSV file where one line looks like this: Duration, user, lat-start, long-start, lat-end, long-end 298, Casual,38.9101,-77.0444,38.91554,-77.03818 Each row in the CSV has two points and I need to draw a line between those two points for each

  • Plot Continuous Line With 2 Points 2014-01-13

    Is there any way to plot a continuous line with pgfplot/tikz using only 2 points (i.e. it will extend past those points on its own) within the domain I specify? --------------Solutions------------- You can use shorten with a negative length to extend

  • Draw lines between two points in QGIS 2014-08-23

    I have an excel (Fig) which has both X & Y in projected coordinates (WGS84/UTM). Is it possible to draw lines between the X & Y in QGIS ? I've tried to create points based on X,From_y and X,To_y. I've created two points by just loading them using

  • three.js draw a contour line between two points on a mesh 2016-03-10

    I've a mesh and I can mark two points with mouse and draw a line between them but What I am trying to do is to draw a contour line between those two points how can I do that ?

  • QGIS and Python - create line with multiple points in postgis 2013-05-06

    How can I create a line, with Python functions, with many points that are records in Postgis? Thank you --------------Solutions------------- Not 100% what you are asking for, but why not creating the line in PostGIS first? SELECT gps.gps_track, ST_Ma

  • Generalize lines with specific points 2014-07-28

    It's been a while since I was here. I have this problem now. I have electricity line feature class and point feature class intersecting line features. What I need to do is simplify this line feature class but effects must not effect those vertices wh

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.438 (s). 13 q(s)