Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/components/main-app/ol/clip-raster.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { Vector as VectorLayer } from 'ol/layer';
import { Vector as VectorSource } from 'ol/source';
import { TopoJSON } from 'ol/format';
import { GeoJSON, TopoJSON } from 'ol/format';
import { getVectorContext } from 'ol/render';
import { Fill, Style, Stroke } from 'ol/style';

/**
* @param {*} rasterLayer = Raster layer map instance generated from OL map init
*/

function get_url_extension(url) {
return url.split(/[#?]/)[0].split('.').pop().trim();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if data comes from non-extension API?
I think some other approach is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must get that data and check whether this is a GeoJSON or TopoJSON.
And based on that you should pass the map feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


export default function clipRasterLayer({ rasterLayer, shape }) {
//Create cliping layer from topojson
const urlExtension = get_url_extension(shape);

const shapeSource = new VectorSource({
url: shape,
format: new TopoJSON(),
format: urlExtension === 'geojson' ? new GeoJSON() : new TopoJSON(),
overlaps: false,
});

Expand Down