Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-264] zeppelin helium plugin supports drawing geometry like linestring, polygon #801

Merged
merged 1 commit into from
Mar 18, 2023
Merged
Changes from all commits
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
29 changes: 23 additions & 6 deletions zeppelin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class LeafletMap extends Visualization {
];

this.transformation = new ColumnselectorTransformation(config, columnSpec);
this.chartInstance = L.map(this.getChartElementId());
this.chartInstance = this.createMap();
}

getTransformation() {
Expand All @@ -68,11 +68,16 @@ export default class LeafletMap extends Visualization {
super.setConfig(config);
this.transformation.setConfig(config);
if (!this.chartInstance) {
this.chartInstance = L.map(this.getChartElementId());
this.chartInstance = this.createMap();
}
return this.chartInstance;
};

createMap() {
// using canvas renderer to support drawing geometry like LineString, Polygon etc.
return L.map(this.getChartElementId(), {renderer: L.canvas()});
}

getChartElementId() {
return this.targetEl[0].id
};
Expand Down Expand Up @@ -109,21 +114,33 @@ export default class LeafletMap extends Visualization {
map.invalidateSize(true)

var imageBounds = null
const markers = chartDataModel.rows.map(
const markers = chartDataModel.rows.flatMap(
row => {
const {image, boundary, info} = row;
var markers = [];

// throw new Error(image);
var jsts = require("jsts");
// Read WKT string from Sedona
var reader = new jsts.io.WKTReader();
var obj = reader.read(boundary)
var obj = reader.read(boundary);
// Collect the centroid point of the input geometry
var centroid = obj.getCentroid()
var marker = L.marker([centroid.getY(), centroid.getX()]);
const mapMarker = marker.addTo(map);
markers.push(marker);

if (obj.getGeometryType() !== 'Point') {
var writer = new jsts.io.GeoJSONWriter();
var geojson = writer.write(obj);
marker = L.geoJSON(geojson);
marker.addTo(map);
markers.push(marker);
}

// Attach the marker information if exists
if(info){
mapMarker.bindTooltip(info)
mapMarker.bindTooltip(info);
}
// Overlay the generated image over the tile layer
if (image) {
Expand All @@ -133,7 +150,7 @@ export default class LeafletMap extends Visualization {
var imageUrl = 'data:image/png;base64,' + image;
L.imageOverlay(imageUrl, imageBounds).addTo(map);
}
return marker
return markers;
}
);
// Adjust the location of the viewport
Expand Down