Comments (3)
@khashashin No, you can only add one marker per input, its a builtin limitation.
But there are other ways to accomplish multiple markers by either:
- Using a stream field where you create a new Geo block per marker (https://github.com/Frojd/wagtail-geo-widget/blob/develop/example/geopage/models.py#L73)
- Or using a InlinePanel where every marker is a new model (example: https://github.com/Frojd/wagtail-geo-widget/blob/develop/example/geopage/models.py#L52)
Hope this answers you question!
from wagtail-geo-widget.
Yeah thanks that is what I done. In case if some one needed. I've did following:
#models.py
from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.core.fields import StreamField
from wagtail.core.models import Page
from wagtail.core import blocks
from django.db import models
CENTER_LTD = 47.5545913
CENTER_LGT = 7.5594406
class AddressBlock(blocks.StructBlock):
latitude = blocks.FloatBlock(blank=True, default=0)
longitude = blocks.FloatBlock(blank=True, default=0)
street = blocks.CharBlock(max_length=255, blank=True, default='')
street_number = blocks.CharBlock(max_length=20, blank=True, default='')
zip = blocks.CharBlock(max_length=20, blank=True, default='')
city = blocks.CharBlock(max_length=255, blank=True, default='')
country = blocks.CharBlock(max_length=255, blank=True, default='')
title = blocks.CharBlock(max_length=255, blank=True, default='')
description = blocks.TextBlock(blank=True, default='')
class Meta:
icon = 'site'
class MapSection(Page):
template = 'home/sections/map_section.html'
center_latitude = models.FloatField(
"Latitude", default=CENTER_LTD, help_text="Default to Basel", blank=True)
center_longitude = models.FloatField(
"Latitude", default=CENTER_LGT, help_text="Default to Basel", blank=True)
map_zoom = models.IntegerField("Map Default Zoom Setting", default=13, blank=True)
addresses = StreamField([
('address', AddressBlock())
], blank=True)
content_panels = Page.content_panels + [
StreamFieldPanel('addresses'),
]
In your template:
{% block content %}
<div class="map-content">
<div id="map">
</div>
</div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key={{ settings.home.GoogleApiSettings.google_api_key }}"></script>
<script type="text/javascript">
let addresses = [];
{% for address in self.addresses %}
addresses.push([
{{ address.value.latitude }},
{{ address.value.longitude }},
"{{ address.value.title }}",
"{{ address.value.description }}"
]);
{% endfor %}
const map = undefined;
const markers = [];
function addMarker(lat, long, title, text) {
const latLng = new google.maps.LatLng(lat, long);
const marker = new google.maps.Marker({
position: latLng,
map: map,
title: title,
desc: "<h3>" + title + "</h3>" + text
});
const popup = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function() {
popup.setContent(marker.desc);
popup.open(map,marker);
});
markers.push(marker);
}
// Initialize and add the map
function initMap() {
const center = {lat: {{ self.center_latitude }}, lng: {{ self.center_longitude }}};
const map = new google.maps.Map(document.getElementById("map"), {
zoom: {{ self.map_zoom }},
center: center,
});
addresses.forEach(function (address) {
addMarker.apply(undefined, address);
});
}
google.maps.event.addDomListener(window, 'load', initMap());
</script>
{% endblock %}
from wagtail-geo-widget.
Just to clarify to anyone who would be reading this issue, the solution above is a custom solution that do not use "wagtail-geo-widget".
from wagtail-geo-widget.
Related Issues (20)
- Fix broken documentation links on Pypi page HOT 1
- Widget not rendering in Wagtail 3.0, but works in Wagtail 2.16.2. HOT 4
- GoogleMapsPanel doesn't correctly parse the passed in address_field HOT 2
- Reverse geocoding HOT 1
- How to use it with MultiPolygonField from django.contrib.gis.db HOT 3
- Wagtail 4 compatibility: FieldPanel Permissions HOT 1
- pip installs develop branch? HOT 2
- Add required Wagtail version in setup.py to prevent silent errors when using non-supported version HOT 1
- Can wagtail-geo-widget support more complex geometry? HOT 2
- Make it possible to have an empty location field as default
- Admin Configurable Settings. HOT 3
- GEO_WIDGET_DEFAULT_LOCATION without touching the field returns None HOT 1
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- Translate strings
- Add example on how to implement GeoPanel on a regular django model used through Wagtails ModelAdmin
- Set zoom level dynamically from a GeoPanel HOT 2
- Will this awesome widget have template rendering? HOT 1
- Add documentation for LeafletPanel/LeafletBlock HOT 1
- Update the example page models to include all widget/block types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wagtail-geo-widget.