code Snippetlanguage CDNpackage_2 NPM
content_copy Copyopen_in_new Open
var svgPin = function ( color ) {
return 'data:image/svg+xml,' + encodeURIComponent ( '<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40"><path d="M15 0C6.7 0 0 6.7 0 15c0 11.3 15 25 15 25s15-13.7 15-25C30 6.7 23.3 0 15 0z" fill="' + color + '"/><circle cx="15" cy="14" r="6" fill="#fff"/></svg>' );
};
var features = [
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.1276 , 51.5074 ])), name: 'Big Ben' , color: '#e63946' }),
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.1015 , 51.5014 ])), name: 'London Eye' , color: '#2196F3' }),
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.0763 , 51.5081 ])), name: 'Tower of London' , color: '#4CAF50' })
];
var vectorLayer = new ol.layer. Vector ({
source: new ol.source. Vector ({ features: features }),
style : function ( feature ) {
return new ol.style. Style ({
image: new ol.style. Icon ({
src: svgPin (feature. get ( 'color' )),
anchor: [ 0.5 , 1 ],
scale: 1
})
});
}
});
var map = new ol. Map ({
target: 'map' ,
layers: [
new ol.layer. Tile ({ source: new ol.source. XYZ ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol. View ({ center: ol.proj. fromLonLat ([ - 0.1 , 51.505 ]), zoom: 14 })
}); content_copy Copyopen_in_new Open
<! DOCTYPE html >
< html >
< head >
< meta charset = "utf-8" />
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" />
< link rel = "stylesheet" href = "https://unpkg.com/ol@10.10.0/ol.css" />
< script src = "https://unpkg.com/ol@10.10.0/dist/ol.js" ></ script >
< style >
body { margin : 0 ; padding : 0 ; }
#map { width : 100 % ; height : 100 vh ; }
</ style >
</ head >
< body >
< div id = "map" ></ div >
< script >
var svgPin = function ( color ) {
return 'data:image/svg+xml,' + encodeURIComponent ( '<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40"><path d="M15 0C6.7 0 0 6.7 0 15c0 11.3 15 25 15 25s15-13.7 15-25C30 6.7 23.3 0 15 0z" fill="' + color + '"/><circle cx="15" cy="14" r="6" fill="#fff"/></svg>' );
};
var features = [
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.1276 , 51.5074 ])), name: 'Big Ben' , color: '#e63946' }),
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.1015 , 51.5014 ])), name: 'London Eye' , color: '#2196F3' }),
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.0763 , 51.5081 ])), name: 'Tower of London' , color: '#4CAF50' })
];
var vectorLayer = new ol.layer. Vector ({
source: new ol.source. Vector ({ features: features }),
style : function ( feature ) {
return new ol.style. Style ({
image: new ol.style. Icon ({
src: svgPin (feature. get ( 'color' )),
anchor: [ 0.5 , 1 ],
scale: 1
})
});
}
});
var map = new ol. Map ({
target: 'map' ,
layers: [
new ol.layer. Tile ({ source: new ol.source. XYZ ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol. View ({ center: ol.proj. fromLonLat ([ - 0.1 , 51.505 ]), zoom: 14 })
});
</ script >
</ body >
</ html > content_copy Copyopen_in_new Open
import Map from 'ol/Map' ;
import View from 'ol/View' ;
import TileLayer from 'ol/layer/Tile' ;
import { fromLonLat } from 'ol/proj' ;
import 'ol/ol.css' ;
var svgPin = function ( color ) {
return 'data:image/svg+xml,' + encodeURIComponent ( '<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40"><path d="M15 0C6.7 0 0 6.7 0 15c0 11.3 15 25 15 25s15-13.7 15-25C30 6.7 23.3 0 15 0z" fill="' + color + '"/><circle cx="15" cy="14" r="6" fill="#fff"/></svg>' );
};
var features = [
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.1276 , 51.5074 ])), name: 'Big Ben' , color: '#e63946' }),
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.1015 , 51.5014 ])), name: 'London Eye' , color: '#2196F3' }),
new ol. Feature ({ geometry: new ol.geom. Point (ol.proj. fromLonLat ([ - 0.0763 , 51.5081 ])), name: 'Tower of London' , color: '#4CAF50' })
];
var vectorLayer = new ol.layer. Vector ({
source: new ol.source. Vector ({ features: features }),
style : function ( feature ) {
return new ol.style. Style ({
image: new ol.style. Icon ({
src: svgPin (feature. get ( 'color' )),
anchor: [ 0.5 , 1 ],
scale: 1
})
});
}
});
var map = new ol. Map ({
target: 'map' ,
layers: [
new ol.layer. Tile ({ source: new ol.source. XYZ ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol. View ({ center: ol.proj. fromLonLat ([ - 0.1 , 51.505 ]), zoom: 14 })
});
var svgPin = function(color) {
return 'data:image/svg+xml,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40"><path d="M15 0C6.7 0 0 6.7 0 15c0 11.3 15 25 15 25s15-13.7 15-25C30 6.7 23.3 0 15 0z" fill="' + color + '"/><circle cx="15" cy="14" r="6" fill="#fff"/></svg>');
};
var features = [
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.1276, 51.5074])), name: 'Big Ben', color: '#e63946' }),
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.1015, 51.5014])), name: 'London Eye', color: '#2196F3' }),
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.0763, 51.5081])), name: 'Tower of London', color: '#4CAF50' })
];
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({ features: features }),
style: function(feature) {
return new ol.style.Style({
image: new ol.style.Icon({
src: svgPin(feature.get('color')),
anchor: [0.5, 1],
scale: 1
})
});
}
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol.View({ center: ol.proj.fromLonLat([-0.1, 51.505]), zoom: 14 })
}); <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/ol@10.10.0/ol.css" />
<script src="https://unpkg.com/ol@10.10.0/dist/ol.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { width: 100%; height: 100vh; }
</style>
</head>
<body>
<div id="map"></div>
<script>
var svgPin = function(color) {
return 'data:image/svg+xml,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40"><path d="M15 0C6.7 0 0 6.7 0 15c0 11.3 15 25 15 25s15-13.7 15-25C30 6.7 23.3 0 15 0z" fill="' + color + '"/><circle cx="15" cy="14" r="6" fill="#fff"/></svg>');
};
var features = [
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.1276, 51.5074])), name: 'Big Ben', color: '#e63946' }),
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.1015, 51.5014])), name: 'London Eye', color: '#2196F3' }),
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.0763, 51.5081])), name: 'Tower of London', color: '#4CAF50' })
];
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({ features: features }),
style: function(feature) {
return new ol.style.Style({
image: new ol.style.Icon({
src: svgPin(feature.get('color')),
anchor: [0.5, 1],
scale: 1
})
});
}
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol.View({ center: ol.proj.fromLonLat([-0.1, 51.505]), zoom: 14 })
});
</script>
</body>
</html> import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import { fromLonLat } from 'ol/proj';
import 'ol/ol.css';
var svgPin = function(color) {
return 'data:image/svg+xml,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="30" height="40" viewBox="0 0 30 40"><path d="M15 0C6.7 0 0 6.7 0 15c0 11.3 15 25 15 25s15-13.7 15-25C30 6.7 23.3 0 15 0z" fill="' + color + '"/><circle cx="15" cy="14" r="6" fill="#fff"/></svg>');
};
var features = [
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.1276, 51.5074])), name: 'Big Ben', color: '#e63946' }),
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.1015, 51.5014])), name: 'London Eye', color: '#2196F3' }),
new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([-0.0763, 51.5081])), name: 'Tower of London', color: '#4CAF50' })
];
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({ features: features }),
style: function(feature) {
return new ol.style.Style({
image: new ol.style.Icon({
src: svgPin(feature.get('color')),
anchor: [0.5, 1],
scale: 1
})
});
}
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol.View({ center: ol.proj.fromLonLat([-0.1, 51.505]), zoom: 14 })
});