How to get the Leaflet Map object (Mapping Module)

I use the Mapping Module and it works well that my items are displayed as points on the map. I know that I can also load WMS layers on the map. However, in my case I only have a GeoJson to draw additional polygons to the items.

My approach is to edit view/omeka/site/page/show.phtml in my theme and use JavaScript there to load the GeoJson on the leaflet map additionally.

However, I am not able to get the map object. I have already tried:

var mappingBlock = L.DomUtil.get($(".leaflet-container")[0]);

and
var mappingBlock = L.map($(".leaflet-container")[0]);

but that only led to the error:
Uncaught Error: Map container is already initialized.

How can I edit the map with JavaScript afterwards?

You could edit the JS file directly, here.

Thanks for the quick help. I had to edit this file though.
It works now.

Can I copy the file to my theme so that the next time I update the mapping module, it won’t overwrite the changes?

As a feature request it would be great if in the backend at the page there would be an input field in which GeoJSON could be entered?
Sorry for the childish mockup:

Maybe I’ll try it to program it myself and then make a pull request.

I had already some progress:

unfortunately, the form still “forgets” the entered data and does not save them. But I will get that right as well.

I finally have a first version

And the result:

Unfortunately, I have the problem that the GeoJSON is not yet fully generic.
Is my attempt in the right direction and is this feature generally desired? Since I have not yet graduated to Omeka 4 I have developed this with the Mapping Module 1.6.0. But it should also run with the latest version.

Should I make a pull request on github?

Adding a GeoJSON field is an idea we’re considering for a future release. In fact we’re currently working on a major update to the module that introduces Polygon and LineString types. You could submit a PR, but the codebase will be significantly different than the version you’re working on.

1 Like