- ' + msg + '
')
- },
-
- _export: function (map) {
- const geoJson = this._layer.toGeoJSON()
- const blob = new window.Blob([JSON.stringify(geoJson)], { type: 'application/json' })
- FileSaver.saveAs(blob, 'export.geojson')
- },
-
- _import: function (map, file) {
- if (file.name.slice(-3) === 'zip') {
- const reader = new window.FileReader()
- reader.onload = (e) => {
- const buffer = e.target.result
- shp(buffer).then((geoJson) => {
- try {
- const shape = L.geoJson(geoJson, {
- style: this.options.polygonStyle
- })
- this._addToMap(map, shape)
- } catch (e) {
- this._showUploadError(django.gettext('The uploaded file is not a valid shapefile.'))
- }
- }, (e) => this._showUploadError(django.gettext('The uploaded file is not a valid shapefile.'))
- ).catch((e) => {
- this._showUploadError(django.gettext('The uploaded file could not be imported.'))
- })
- }
- reader.readAsArrayBuffer(file)
- } else if (file.name.slice(-4) === 'json') {
- const reader = new window.FileReader()
- reader.onload = (e) => {
- try {
- const geoJson = JSON.parse(e.target.result)
- const shape = L.geoJson(geoJson, {
- style: this.options.polygonStyle
- })
- this._addToMap(map, shape)
- } catch (e) {
- this._showUploadError(django.gettext('The uploaded file is not a valid geojson file.'))
- }
- }
- reader.readAsText(file, 'utf-8')
- } else {
- this._showUploadError(django.gettext('Invalid file format.'))
- }
- },
-
- _addToMap: function (map, shape) {
- $('#map-import-modal').modal('hide')
-
- this._layer.clearLayers()
- shape.eachLayer((layer) => {
- this._layer.addLayer(layer)
- })
- map.fitBounds(this._layer.getBounds())
- map.fire(L.Draw.Event.EDITED)
- }
- })
-
- $('[data-map="choose_polygon"]').each(function (i, e) {
- const name = e.getAttribute('data-name')
- const polygon = JSON.parse(e.getAttribute('data-polygon'))
- const bbox = JSON.parse(e.getAttribute('data-bbox'))
-
- const map = maps.createMap(L, e, {
- baseUrl: e.getAttribute('data-baseurl'),
- useVectorMap: e.getAttribute('data-usevectormap'),
- attribution: e.getAttribute('data-attribution'),
- mapboxToken: e.getAttribute('data-mapbox-token'),
- omtToken: e.getAttribute('data-omt-token'),
- dragging: true,
- scrollWheelZoom: false,
- zoomControl: true,
- minZoom: 2
- })
-
- const polygonStyle = {
- color: '#0076ae',
- weight: 2,
- opacity: 1,
- fillOpacity: 0.2
- }
-
- let drawnItems
- if (polygon) {
- drawnItems = L.geoJson(polygon, {
- style: polygonStyle
- })
- if (drawnItems.getLayers().length > 0) {
- map.fitBounds(drawnItems.getBounds())
- } else {
- map.fitBounds(getBaseBounds(L, polygon, bbox))
- }
- } else {
- drawnItems = L.featureGroup()
- map.fitBounds(getBaseBounds(L, polygon, bbox))
- }
- drawnItems.addTo(map)
-
- map.addControl(new L.Control.Draw({
- edit: {
- featureGroup: drawnItems,
- edit: {
- selectedPathOptions: {
- maintainColor: true
- }
- }
- },
- draw: {
- polygon: {
- shapeOptions: polygonStyle
- },
- rectangle: {
- shapeOptions: polygonStyle
- },
- marker: false,
- circlemarker: false,
- polyline: false,
- circle: false
- }
- }))
-
- map.addControl(new ImportControl(drawnItems,
- {
- polygonStyle: polygonStyle
- }
- ))
-
- map.on(L.Draw.Event.CREATED, function (event) {
- const layer = event.layer
- drawnItems.addLayer(layer)
- const geoJson = drawnItems.toGeoJSON()
- $('#id_' + name).val(JSON.stringify(geoJson))
- $('#id_' + name).trigger('change')
- })
-
- map.on(L.Draw.Event.EDITED, function (event) {
- const geoJson = drawnItems.toGeoJSON()
- $('#id_' + name).val(JSON.stringify(geoJson))
- $('#id_' + name).trigger('change')
- })
-
- map.on(L.Draw.Event.DELETED, function (event) {
- const geoJson = drawnItems.toGeoJSON()
- $('#id_' + name).val(JSON.stringify(geoJson))
- $('#id_' + name).trigger('change')
- })
-
- $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- map.invalidateSize().fitBounds(getBaseBounds(L, polygon, bbox))
- })
-
- $('#select_' + name).on('change', function (event) {
- const geoJson = event.target.value
- if (geoJson) {
- const shape = L.geoJson(JSON.parse(geoJson), {
- style: polygonStyle
- })
-
- const isEmpty = drawnItems.getLayers().length === 0
- const msg = django.gettext('Do you want to load this preset and delete all the existing polygons?')
- if (isEmpty || window.confirm(msg)) {
- drawnItems.clearLayers()
- shape.eachLayer(function (layer) {
- drawnItems.addLayer(layer)
- })
- map.fitBounds(drawnItems.getBounds())
- map.fire(L.Draw.Event.EDITED)
- }
- }
- })
- })
-}
-
-document.addEventListener('DOMContentLoaded', init, false)
-document.addEventListener('a4.embed.ready', init, false)
diff --git a/meinberlin/assets/js/app.js b/meinberlin/assets/js/app.js
index 55b5926d39..58733c346a 100644
--- a/meinberlin/assets/js/app.js
+++ b/meinberlin/assets/js/app.js
@@ -5,11 +5,13 @@ import 'shariff'
import 'slick-carousel'
import '../../apps/actions/assets/timestamps.js'
-import '../../apps/maps/assets/map-address.js'
import '../../apps/moderatorremark/assets/idea_remarks.js'
import '../../apps/newsletters/assets/dynamic_fields.js'
import '../../apps/dashboard/assets/init_accordeons_cookie.js'
+// map search function
+import 'adhocracy4/adhocracy4/maps/static/a4maps/a4maps_address.js'
+
// expose react components
import {
comments as ReactComments,
diff --git a/meinberlin/templates/a4maps/map_choose_point_widget.html b/meinberlin/templates/a4maps/map_choose_point_widget.html
index 8c2975e34e..796cd60165 100644
--- a/meinberlin/templates/a4maps/map_choose_point_widget.html
+++ b/meinberlin/templates/a4maps/map_choose_point_widget.html
@@ -3,7 +3,7 @@