code Snippetlanguage CDNpackage_2 NPM
content_copy Copyopen_in_new Open
var geojsonData = {
type: 'FeatureCollection' ,
features: [
{ type: 'Feature' , properties: { name: 'Louvre Museum' }, geometry: { type: 'Point' , coordinates: [ 2.3376 , 48.8606 ] } },
{ type: 'Feature' , properties: { name: 'Walking Path' }, geometry: { type: 'LineString' , coordinates: [[ 2.3376 , 48.8606 ], [ 2.3272 , 48.8600 ], [ 2.3200 , 48.8580 ]] } },
{ type: 'Feature' , properties: { name: 'Park Area' }, geometry: { type: 'Polygon' , coordinates: [[[ 2.3272 , 48.8620 ], [ 2.3340 , 48.8620 ], [ 2.3340 , 48.8590 ], [ 2.3272 , 48.8590 ], [ 2.3272 , 48.8620 ]]] } }
]
};
var vectorSource = new ol.source. Vector ({
features: new ol.format. GeoJSON (). readFeatures (geojsonData, { featureProjection: 'EPSG:3857' })
});
var vectorLayer = new ol.layer. Vector ({
source: vectorSource,
style : function ( feature ) {
var type = feature. getGeometry (). getType ();
if (type === 'Point' ) return new ol.style. Style ({ image: new ol.style. Circle ({ radius: 7 , fill: new ol.style. Fill ({ color: '#e63946' }), stroke: new ol.style. Stroke ({ color: '#fff' , width: 2 }) }) });
if (type === 'LineString' ) return new ol.style. Style ({ stroke: new ol.style. Stroke ({ color: '#457b9d' , width: 3 }) });
return new ol.style. Style ({ fill: new ol.style. Fill ({ color: 'rgba(42, 157, 143, 0.3)' }), stroke: new ol.style. Stroke ({ color: '#2a9d8f' , width: 2 }) });
}
});
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 ([ 2.328 , 48.860 ]), zoom: 15 })
}); 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 geojsonData = {
type: 'FeatureCollection' ,
features: [
{ type: 'Feature' , properties: { name: 'Louvre Museum' }, geometry: { type: 'Point' , coordinates: [ 2.3376 , 48.8606 ] } },
{ type: 'Feature' , properties: { name: 'Walking Path' }, geometry: { type: 'LineString' , coordinates: [[ 2.3376 , 48.8606 ], [ 2.3272 , 48.8600 ], [ 2.3200 , 48.8580 ]] } },
{ type: 'Feature' , properties: { name: 'Park Area' }, geometry: { type: 'Polygon' , coordinates: [[[ 2.3272 , 48.8620 ], [ 2.3340 , 48.8620 ], [ 2.3340 , 48.8590 ], [ 2.3272 , 48.8590 ], [ 2.3272 , 48.8620 ]]] } }
]
};
var vectorSource = new ol.source. Vector ({
features: new ol.format. GeoJSON (). readFeatures (geojsonData, { featureProjection: 'EPSG:3857' })
});
var vectorLayer = new ol.layer. Vector ({
source: vectorSource,
style : function ( feature ) {
var type = feature. getGeometry (). getType ();
if (type === 'Point' ) return new ol.style. Style ({ image: new ol.style. Circle ({ radius: 7 , fill: new ol.style. Fill ({ color: '#e63946' }), stroke: new ol.style. Stroke ({ color: '#fff' , width: 2 }) }) });
if (type === 'LineString' ) return new ol.style. Style ({ stroke: new ol.style. Stroke ({ color: '#457b9d' , width: 3 }) });
return new ol.style. Style ({ fill: new ol.style. Fill ({ color: 'rgba(42, 157, 143, 0.3)' }), stroke: new ol.style. Stroke ({ color: '#2a9d8f' , width: 2 }) });
}
});
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 ([ 2.328 , 48.860 ]), zoom: 15 })
});
</ 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 geojsonData = {
type: 'FeatureCollection' ,
features: [
{ type: 'Feature' , properties: { name: 'Louvre Museum' }, geometry: { type: 'Point' , coordinates: [ 2.3376 , 48.8606 ] } },
{ type: 'Feature' , properties: { name: 'Walking Path' }, geometry: { type: 'LineString' , coordinates: [[ 2.3376 , 48.8606 ], [ 2.3272 , 48.8600 ], [ 2.3200 , 48.8580 ]] } },
{ type: 'Feature' , properties: { name: 'Park Area' }, geometry: { type: 'Polygon' , coordinates: [[[ 2.3272 , 48.8620 ], [ 2.3340 , 48.8620 ], [ 2.3340 , 48.8590 ], [ 2.3272 , 48.8590 ], [ 2.3272 , 48.8620 ]]] } }
]
};
var vectorSource = new ol.source. Vector ({
features: new ol.format. GeoJSON (). readFeatures (geojsonData, { featureProjection: 'EPSG:3857' })
});
var vectorLayer = new ol.layer. Vector ({
source: vectorSource,
style : function ( feature ) {
var type = feature. getGeometry (). getType ();
if (type === 'Point' ) return new ol.style. Style ({ image: new ol.style. Circle ({ radius: 7 , fill: new ol.style. Fill ({ color: '#e63946' }), stroke: new ol.style. Stroke ({ color: '#fff' , width: 2 }) }) });
if (type === 'LineString' ) return new ol.style. Style ({ stroke: new ol.style. Stroke ({ color: '#457b9d' , width: 3 }) });
return new ol.style. Style ({ fill: new ol.style. Fill ({ color: 'rgba(42, 157, 143, 0.3)' }), stroke: new ol.style. Stroke ({ color: '#2a9d8f' , width: 2 }) });
}
});
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 ([ 2.328 , 48.860 ]), zoom: 15 })
});
var geojsonData = {
type: 'FeatureCollection',
features: [
{ type: 'Feature', properties: { name: 'Louvre Museum' }, geometry: { type: 'Point', coordinates: [2.3376, 48.8606] } },
{ type: 'Feature', properties: { name: 'Walking Path' }, geometry: { type: 'LineString', coordinates: [[2.3376, 48.8606], [2.3272, 48.8600], [2.3200, 48.8580]] } },
{ type: 'Feature', properties: { name: 'Park Area' }, geometry: { type: 'Polygon', coordinates: [[[2.3272, 48.8620], [2.3340, 48.8620], [2.3340, 48.8590], [2.3272, 48.8590], [2.3272, 48.8620]]] } }
]
};
var vectorSource = new ol.source.Vector({
features: new ol.format.GeoJSON().readFeatures(geojsonData, { featureProjection: 'EPSG:3857' })
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: function(feature) {
var type = feature.getGeometry().getType();
if (type === 'Point') return new ol.style.Style({ image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#e63946' }), stroke: new ol.style.Stroke({ color: '#fff', width: 2 }) }) });
if (type === 'LineString') return new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#457b9d', width: 3 }) });
return new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(42, 157, 143, 0.3)' }), stroke: new ol.style.Stroke({ color: '#2a9d8f', width: 2 }) });
}
});
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([2.328, 48.860]), zoom: 15 })
}); <!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 geojsonData = {
type: 'FeatureCollection',
features: [
{ type: 'Feature', properties: { name: 'Louvre Museum' }, geometry: { type: 'Point', coordinates: [2.3376, 48.8606] } },
{ type: 'Feature', properties: { name: 'Walking Path' }, geometry: { type: 'LineString', coordinates: [[2.3376, 48.8606], [2.3272, 48.8600], [2.3200, 48.8580]] } },
{ type: 'Feature', properties: { name: 'Park Area' }, geometry: { type: 'Polygon', coordinates: [[[2.3272, 48.8620], [2.3340, 48.8620], [2.3340, 48.8590], [2.3272, 48.8590], [2.3272, 48.8620]]] } }
]
};
var vectorSource = new ol.source.Vector({
features: new ol.format.GeoJSON().readFeatures(geojsonData, { featureProjection: 'EPSG:3857' })
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: function(feature) {
var type = feature.getGeometry().getType();
if (type === 'Point') return new ol.style.Style({ image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#e63946' }), stroke: new ol.style.Stroke({ color: '#fff', width: 2 }) }) });
if (type === 'LineString') return new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#457b9d', width: 3 }) });
return new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(42, 157, 143, 0.3)' }), stroke: new ol.style.Stroke({ color: '#2a9d8f', width: 2 }) });
}
});
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([2.328, 48.860]), zoom: 15 })
});
</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 geojsonData = {
type: 'FeatureCollection',
features: [
{ type: 'Feature', properties: { name: 'Louvre Museum' }, geometry: { type: 'Point', coordinates: [2.3376, 48.8606] } },
{ type: 'Feature', properties: { name: 'Walking Path' }, geometry: { type: 'LineString', coordinates: [[2.3376, 48.8606], [2.3272, 48.8600], [2.3200, 48.8580]] } },
{ type: 'Feature', properties: { name: 'Park Area' }, geometry: { type: 'Polygon', coordinates: [[[2.3272, 48.8620], [2.3340, 48.8620], [2.3340, 48.8590], [2.3272, 48.8590], [2.3272, 48.8620]]] } }
]
};
var vectorSource = new ol.source.Vector({
features: new ol.format.GeoJSON().readFeatures(geojsonData, { featureProjection: 'EPSG:3857' })
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: function(feature) {
var type = feature.getGeometry().getType();
if (type === 'Point') return new ol.style.Style({ image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#e63946' }), stroke: new ol.style.Stroke({ color: '#fff', width: 2 }) }) });
if (type === 'LineString') return new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#457b9d', width: 3 }) });
return new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(42, 157, 143, 0.3)' }), stroke: new ol.style.Stroke({ color: '#2a9d8f', width: 2 }) });
}
});
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([2.328, 48.860]), zoom: 15 })
});