Render Shapes - Polylines
Display and style geospatial data like polylines or any GeoJSON data.
Example
Render Shapes - Polylines
// Initialize and add the map
let map: woosmap.map.Map;
function initMap() {
map = new window.woosmap.map.Map(
document.getElementById("map") as HTMLElement,
{
center: { lat: 51.505, lng: -0.118 },
zoom: 15,
},
);
//Polyline Shape
const polylinePath = [
{ lng: -0.12638568878173828, lat: 51.50099581189912 },
{ lng: -0.12201905250549315, lat: 51.500832183172456 },
{ lng: -0.11891841888427736, lat: 51.50078877137083 },
{ lng: -0.11869311332702637, lat: 51.500832183172456 },
{ lng: -0.11754512786865233, lat: 51.500752038275635 },
{ lng: -0.11698186397552489, lat: 51.50050158456475 },
{ lng: -0.11669218540191649, lat: 51.50048488760175 },
{ lng: -0.11619329452514648, lat: 51.500688590132405 },
{ lng: -0.11590898036956787, lat: 51.50086557683785 },
{ lng: -0.1160377264022827, lat: 51.50112270724184 },
{ lng: -0.11700868606567383, lat: 51.50142992608211 },
{ lng: -0.11710524559020995, lat: 51.50164364231471 },
{ lng: -0.1157534122467041, lat: 51.50321309019227 },
{ lng: -0.11474490165710448, lat: 51.50420148069069 },
{ lng: -0.11411190032958984, lat: 51.50454874793857 },
{ lng: -0.11415, lat: 51.50545363381515 },
{ lng: -0.11816740036010741, lat: 51.50991769706187 },
];
//Polyline Object with Path as an Array of LatLng
const polyline = new woosmap.map.Polyline({
path: polylinePath,
strokeColor: "#b71c1c",
strokeOpacity: 0.8,
strokeWeight: 4,
});
polyline.setMap(map);
}
window.initMap = initMap;
// Initialize and add the map
let map;
function initMap() {
map = new window.woosmap.map.Map(document.getElementById("map"), {
center: { lat: 51.505, lng: -0.118 },
zoom: 15,
});
//Polyline Shape
const polylinePath = [
{ lng: -0.12638568878173828, lat: 51.50099581189912 },
{ lng: -0.12201905250549315, lat: 51.500832183172456 },
{ lng: -0.11891841888427736, lat: 51.50078877137083 },
{ lng: -0.11869311332702637, lat: 51.500832183172456 },
{ lng: -0.11754512786865233, lat: 51.500752038275635 },
{ lng: -0.11698186397552489, lat: 51.50050158456475 },
{ lng: -0.11669218540191649, lat: 51.50048488760175 },
{ lng: -0.11619329452514648, lat: 51.500688590132405 },
{ lng: -0.11590898036956787, lat: 51.50086557683785 },
{ lng: -0.1160377264022827, lat: 51.50112270724184 },
{ lng: -0.11700868606567383, lat: 51.50142992608211 },
{ lng: -0.11710524559020995, lat: 51.50164364231471 },
{ lng: -0.1157534122467041, lat: 51.50321309019227 },
{ lng: -0.11474490165710448, lat: 51.50420148069069 },
{ lng: -0.11411190032958984, lat: 51.50454874793857 },
{ lng: -0.11415, lat: 51.50545363381515 },
{ lng: -0.11816740036010741, lat: 51.50991769706187 },
];
//Polyline Object with Path as an Array of LatLng
const polyline = new woosmap.map.Polyline({
path: polylinePath,
strokeColor: "#b71c1c",
strokeOpacity: 0.8,
strokeWeight: 4,
});
polyline.setMap(map);
}
window.initMap = initMap;
/*
* Always set the map height explicitly to define the size of the div element
* that contains the map.
*/
#map {
height: 100%;
}
/*
* Optional: Makes the sample page fill the window.
*/
html,
body {
height: 100%;
margin: 0;
padding: 0;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
}
<html>
<head>
<title>Render Shapes - Polylines</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<!--The div element for the map -->
<div id="map"></div>
<script
src="https://sdk.woosmap.com/map/map.js?key=woos-48c80350-88aa-333e-835a-07f4b658a9a4&callback=initMap"
defer
></script>
</body>
</html>
Running the Sample Locally
Before you can run this sample on your local machine, you need to have Git and Node.js installed. If they’re not already installed, follow these instructions to get them set up.
Once you have Git and Node.js installed, you can run the sample by following these steps:
-
Clone the repository and navigate to the directory of the sample.
-
Install the necessary dependencies.
-
Start running the sample.
Here are the commands you can use in your terminal to do this:
git clone -b sample/render-shapes-polylines https://github.com/woosmap/js-samples.git
cd js-samples
npm i
npm start
You can experiment with other samples by switching to any branch that starts with the pattern sample/SAMPLE_NAME
.
git checkout sample/SAMPLE_NAME
npm i
npm start
Was this article helpful?
Have more questions? Submit a request