Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Jan 24, 2024
1 parent 25f6d2d commit de99f37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 164 deletions.
154 changes: 1 addition & 153 deletions maplibre/srcjs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "pymaplibregl",
"version": "0.1.0",
"version": "0.1.1",
"description": "...",
"main": "index.js",
"directories": {
"example": "examples",
"test": "tests"
},
"scripts": {
"build": "esbuild srcjs/index.js --bundle --outfile=maplibre/srcjs/index.js",
"build": "esbuild srcjs/index.js --bundle --minify --outfile=maplibre/srcjs/index.js",
"build-dev": "esbuild srcjs/index.js --bundle --outfile=maplibre/srcjs/index.js",
"build-ipywidget": "esbuild srcjs/ipywidget.js --bundle --format=esm --outfile=maplibre/srcjs/ipywidget.js",
"build-rwidget": "esbuild srcjs/rwidget.js --bundle --minify --outfile=../r-maplibregl/inst/htmlwidgets/maplibre.js",
"prettier": "prettier srcjs --write",
Expand Down
21 changes: 12 additions & 9 deletions srcjs/pymaplibregl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// import { getCustomMapMethods } from "./mapmethods";

function getTextFromFeature(feature, property) {
if (property === null) {
const text = Object.keys(feature.properties)
.map((key) => `${key}: ${feature.properties[key]}`)
.join("</br>");
return text;
}

return feature.properties[property];
}

export default class PyMapLibreGL {
constructor(mapOptions) {
this._id = mapOptions.container;
Expand Down Expand Up @@ -79,15 +90,7 @@ export default class PyMapLibreGL {
const popup = new maplibregl.Popup(popupOptions);
this._map.on("mousemove", layerId, (e) => {
const feature = e.features[0];
let text;
if (property === null) {
text = Object.keys(feature.properties)
.map((key) => `${key}: ${feature.properties[key]}`)
.join("</br>");
} else {
text = feature.properties[property];
}

const text = getTextFromFeature(feature, property);
popup.setLngLat(e.lngLat).setHTML(text).addTo(this._map);
});

Expand Down

0 comments on commit de99f37

Please sign in to comment.