//draw line
var coordinates = [];
//coordinates[0] = ol.proj.transform([73.77994, 18.55966], 'EPSG:4326', 'EPSG:3857')
//coordinates[1] = ol.proj.transform([73.80095, 18.55471], 'EPSG:4326', 'EPSG:3857')
var lineFeature = new ol.Feature({
geometry: new ol.geom.LineString(coordinates)});
var lineStyle = new ol.style.Style({
stroke: new ol.style.Stroke({
color: "#ff00ff",
width: 5
})
});
lineFeature.setStyle(lineStyle);
//draw a point
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([73.9432, 18.9608], 'EPSG:4326', 'EPSG:3857')),
});
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor:[0.5, 1],
src: 'http://www.openlayers.org/dev/img/marker.png'
}))
});
iconFeature.setStyle(iconStyle);
var vectorSource = new ol.source.Vector({
features: [iconFeature, lineFeature]
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuest({
layer: 'osm'
})
}), vectorLayer],
view: new ol.View2D({
center: ol.proj.transform([73.9432, 18.9608], 'EPSG:4326', 'EPSG:3857'),
zoom: 8
})
});
//update line
var line = lineFeature.getGeometry();
line.appendCoordinate(ol.proj.transform([73.9432, 18.9608], 'EPSG:4326', 'EPSG:3857'));
line.appendCoordinate(ol.proj.transform([73.9432, 18.9808], 'EPSG:4326', 'EPSG:3857'));
//move marker
var point = iconFeature.getGeometry();
point.setCoordinates(ol.proj.transform([73.873215, 18.281518], 'EPSG:4326', 'EPSG:3857'));
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.