fit on geometry

parent bb35fe54
MAPBOX_ACCESS_TOKEN = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw'; MAPBOX_ACCESS_TOKEN = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
// create wkt polygon
const format = new ol.format.WKT();
const feature = format.readFeature(polygon, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
// Create layers // Create layers
const mapbox = new ol.layer.Tile({ const mapbox = new ol.layer.Tile({
name: 'mapbox', name: 'mapbox',
...@@ -8,13 +16,7 @@ const mapbox = new ol.layer.Tile({ ...@@ -8,13 +16,7 @@ const mapbox = new ol.layer.Tile({
}) })
}); });
// add wkt polygon const vector = new ol.layer.Vector({
const format = new ol.format.WKT();
const feature = format.readFeature(polygon, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
var vector = new ol.layer.Vector({
name: 'polygon', name: 'polygon',
source: new ol.source.Vector({ source: new ol.source.Vector({
features: [feature] features: [feature]
...@@ -32,6 +34,9 @@ const map = new ol.Map({ ...@@ -32,6 +34,9 @@ const map = new ol.Map({
}) })
}); });
// fit to polygon
map.getView().fit(feature.getGeometry());
// show first date and current date // show first date and current date
let currentDate; let currentDate;
...@@ -76,10 +81,7 @@ function addImageLayer(labelDate) { ...@@ -76,10 +81,7 @@ function addImageLayer(labelDate) {
map.addLayer(xyz); map.addLayer(xyz);
}) })
let currentZoom = map.getView().getZoom();
// fit and zoom // fit and zoom
// map.getView().fit(ol.proj.transformExtent(data.boundingBox, 'EPSG:4326', 'EPSG:3857'))
map.getView().setZoom(currentZoom);
map.getView().setMinZoom(data.zoom.min); map.getView().setMinZoom(data.zoom.min);
map.getView().setMaxZoom(data.zoom.max); map.getView().setMaxZoom(data.zoom.max);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment