console
var poly1 = turf.polygon([
[
[
118.544694359,
29.394588189000004
],
[
118.542326689,
29.336553810999973
],
[
118.48461473699999,
29.363640637000017
],
[
118.544694359,
29.394588189000004
]
]
]);
var poly2 = turf.polygon([
[
[
118.5070832918744,
29.382919780030406
],
[
118.58900198228223,
29.393880267726317
],
[
118.542326689,
29.336553810999973
],
[
118.5070832918744,
29.382919780030406
]
]
]);
var geojson = turf.intersect(poly1, poly2)
var polygon = new ol.geom.Polygon(geojson.geometry.coordinates);
var feature = new ol.Feature(polygon);
var vectorSource = new ol.source.Vector();
vectorSource.addFeature(feature);
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
const berlin = new ol.Feature({
geometry: new ol.geom.Point([118.544694359,29.394588189000004]),
});
berlin.setStyle(
new ol.style.Style({
text: new ol.style.Text({
// text: '北京市昌平区回龙观',
font: '14px sans-serif',
offsetX: 16,
fill: new ol.style.Fill({
color: 'black',
}),
textAlign: 'left',
padding: [2, 3, 0, 2],
backgroundFill: new ol.style.Stroke({
color: '#fff'
}),
backgroundStroke: new ol.style.Stroke({
color: 'black',
width: .5,
lineCap: 'butt',
lineJoin: 'bevel',
lineDash: [0]
})
}),
image: new ol.style.Icon({
crossOrigin: 'anonymous',
// imgSize: [20, 20],
scale: .14,
src: 'http://cdn.jsrun.top/res/kelee/crood.png',
}),
})
);
setTimeout(() => {
berlin.setStyle(
new ol.style.Style({
text: new ol.style.Text({
text: '北京市昌平区回龙观',
font: '14px sans-serif',
offsetX: 16,
fill: new ol.style.Fill({
color: 'black',
}),
textAlign: 'left',
padding: [2, 3, 0, 2],
backgroundFill: new ol.style.Stroke({
color: '#fff'
}),
backgroundStroke: new ol.style.Stroke({
color: 'black',
width: .5,
lineCap: 'butt',
lineJoin: 'bevel',
lineDash: [0]
})
}),
image: new ol.style.Icon({
crossOrigin: 'anonymous',
// imgSize: [20, 20],
scale: .14,
src: 'http://cdn.jsrun.top/res/kelee/crood.png',
}),
})
);
}, 3000)
vectorSource.addFeature(berlin);
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayer
],
view: new ol.View({
projection: 'EPSG:4326',
center: [118.542026689, 29.364503810999973],
zoom:13
})
});
<div id="map" class="map"></div>
.map {
height: 600px;
width: 100%;
}