Show polyline along with roads

558
2
09-09-2021 01:13 PM
Mohammedaz
New Contributor

Hi Guys, I am a newbie to arcGIS so please excuse my mistakes.
I am fetching lat/longs from database using .Net and returning JSON array of lat/longs along with other data. I am able to draw points and polyline on map.

My requirement is to draw the line in consideration with
road / street network [Ex: as Route is displayed on street] instead of being diagonal it should follow the street.

Many Thanks in advance !!!! 😊

Initial code snippet for reference.

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>
ArcGIS API for JavaScript Tutorials: Display a map
</title>

<style>
html,
body,
#viewDiv {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}

#infoDiv {
padding: 6px;
width: 370px;
height: 97%;
position: absolute;
top: 10px;
right: 10px;
--calcite-ui-brand: #71C96E;
--calcite-ui-brand-hover: #67B564;
}
</style>

<link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css" />

<link rel="stylesheet" type="text/css" href="jquery.datetimepicker.css" />
<script type="module"
src="https://js.arcgis.com/calcite-components/1.0.0-beta.56/calcite.esm.js"></script>
<script src="https://js.arcgis.com/calcite-components/1.0.0-beta.56/calcite.js"></script>
<link rel="stylesheet"
type="text/css"
href="https://js.arcgis.com/calcite-components/1.0.0-beta.56/calcite.css" />
<link rel="stylesheet"
href="https://js.arcgis.com/4.20/esri/themes/dark/main.css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>


<script src="https://js.arcgis.com/4.20/"></script>

<script>
var demoBaseMap;

require(["esri/config", "esri/Map", "esri/views/MapView",
"esri/geometry/SpatialReference",
"esri/Graphic",
"esri/layers/GraphicsLayer",
//"esri/layers/FeatureLayer",
"esri/geometry/Point",
"dojo/domReady!",

], function (esriConfig, Map, MapView,
SpatialReference,
Graphic, GraphicsLayer,
//FeatureLayer,
Point) {

esriConfig.apiKey = "";

demoBaseMap = new Map({
basemap: "streets-navigation-vector"
});

const view = new MapView({
map: demoBaseMap,
center: [46.763561, 24.709821],

zoom: 13, // Zoom level
container: "viewDiv", // Div element
});

var simpleMarkerSymbol = {
type: "simple-marker",
color: [46, 204, 113], // Green
outline: {
color: [255, 255, 255], // white
width: 1
}
};

var graphicsLayer = new GraphicsLayer();
demoBaseMap.add(graphicsLayer);

function DrawPolyline() {

var pointsArray = new Array();
var serverResponseLength = 3; // will be getting array of Lat/Long from server

for (i = 0; i < serverResponseLength; i++) {
var Point;
if (i == 0) {
Point = {
type: "point",
longitude: 46.680000, //temporarily hardcoded
latitude: 24.834080
};
pointsArray.push(new Array(Point.longitude, Point.latitude));
}

if (i == 1) {
Point = {
type: "point",
longitude: 46.680860,
latitude: 24.834690
};
pointsArray.push(new Array(Point.longitude, Point.latitude));
}

var pointGraphic = new Graphic({
geometry: Point,
symbol: simpleMarkerSymbol
});

graphicsLayer.add(pointGraphic);

}

const polyline = {
type: "polyline",
paths: pointsArray
};
const simpleLineSymbol = {
type: "simple-line",
color: [226, 119, 40], // Orange
width: 2
};

const polylineGraphic = new Graphic({
geometry: polyline,
symbol: simpleLineSymbol
});
graphicsLayer.add(polylineGraphic);
view.goTo(polylineGraphic.geometry);
}

document.getElementById('btn-Query').onclick = function () {
DrawPolyline();
};
});
</script>

</head>
<body>
<div id="viewDiv">
</div>
<calcite-panel id="infoDiv" class="calcite-theme-light">

<div id="content" style="padding: 5px">

<div style="width: 360px; max-width: 100%; display: flex;flex-direction: row;">
<calcite-button id="btn-Query" width="half"
appearance="solid"
alignment="center"
scale="s">
Query
</calcite-button>

</div>
<br />
</div>
</calcite-panel>
</body>
</html>

 

 

0 Kudos
2 Replies
IhabHassan
Esri Contributor

Hi @Mohammedaz 
to be able to construct a line feature that exactly follows the street, you will need to get your hands on the streets data, query the geometry, and use the geometry values to build your graphics/features.
The streets that you can see on the map are from a basemap, which is just an image, the basemap won't provide you with a vector layer for streets.

Regards
Ihab
0 Kudos
Mohammedaz
New Contributor

Hey Hi @IhabHassan 
Thanks a ton for looking into my query. I understand your point, could you please give me some pointers / links for integrating streets data and geometry.  I have .Net development experience and totally newbie to arcGIS development.

 

 

0 Kudos