The Map view presents a list of upcoming events and maps to show or edit the event's location or to set the location for new events.
By default, the left list of the view displays events beginning from the current date. To change such behavior, use the map_start, map_end properties.
To use Google Maps, you need to add your own google API key on your page.
To add the Map view to the scheduler, follow these steps:
1. Include the code file of the desired map on the page as follows:
<-- use your own Google API key to include Google Maps-->
<script src="//maps.google.com/maps/api/js?key=[your Google API key]&sensor=false"
type="text/javascript"></script>
You can change the map provider and its settings later on, if needed. The changes will be applied on the next rendering of the map.
2. Activate the Map view extension:
scheduler.plugins({
map_view: true
});
3. Add the view's tab to the scheduler's markup:
<div id="scheduler_here" class="dhx_cal_container" ...>
<div class="dhx_cal_navline">
...
<div class="dhx_cal_tab" data-tab="map"></div>
</div>
...
</div>
4. Set the label for the tab:
//'map_tab' is the name of our div
scheduler.locale.labels.map_tab = "Map";
5. Define an additional section in the lightbox to manage the event location:
scheduler.config.lightbox.sections=[
{name:"description", height:50,map_to:"text", type:"textarea", focus:true},
{name:"location", height:43, map_to:"event_location", type:"textarea"},
{name:"time", height:72, type:"time", map_to:"auto"}
]
6. Set a label for the section:
scheduler.locale.labels.section_location = "Location";
7. Initialize the scheduler:
//'map' is the default name of the Map view
scheduler.init('scheduler_here',new Date(2024,5,11),"map");
dhtmlxScheduler supports the following map providers: Google Maps, OpenStreetMaps и Mapbox.
To use some map provider, you need to:
1. Include the corresponding map library on the page, for example, Google Maps:
<-- use your own Google API key to include Google Maps-->
<script src="//maps.google.com/maps/api/js?key=[your Google API key]&sensor=false"
type="text/javascript"></script>
2. If necessary, specify the settings via the map_settings configuration option, e.g.:
scheduler.config.map_settings = {
initial_position: {
lat: 48.724,
lng: 8.215
}
}
...
scheduler.init('scheduler_here',new Date(2024,5,11),"map");
3. Set the name of the chosen map provider in one of the following ways:
scheduler.config.map_view_provider = "googleMap";
...
scheduler.init('scheduler_here',new Date(2024,5,11),"map");
Possible values are the following: "googleMap", "openStreetMaps", "mapbox".
scheduler.config.map_settings = {
view_provider: "googleMap"
}
...
scheduler.init('scheduler_here',new Date(2024,5,11),"map");
Starting from v7.1, other map configuration options are specified within the object of the map_settings property. The default map settings are the following:
scheduler.config.map_settings = {
initial_position: {
lat: 48.724,
lng: 8.215
},
error_position: {
lat: 15,
lng: 15
},
initial_zoom: 1,
zoom_after_resolve: 15,
info_window_max_width: 300,
resolve_user_location: true,
resolve_event_location: true,
view_provider: "googleMap"
}
...
scheduler.init('scheduler_here',new Date(2024,5,11),"map");
The configuration object contains the following properties:
You can also provide custom settings for a map inside the map_settings object, for example some tokens:
scheduler.config.map_settings.accessToken = "pk.eyJ...";
scheduler.xy.map_date_width - the width of the date column
scheduler.xy.map_description_width - the width of the description column
If the default map providers don't suit your needs, you can create a custom map adapter by adding a class that will implement the interface of your map adapter. It should contain the following methods:
interface IMapAdapter {
// initializes a map instance with the provided options
initialize(container: HTMLElement, options: IMapSettings): void;
// removes the map instance when user switches from the map view,releases resources
destroy(container: HTMLElement): void;
// adds a marker on the map based on the event details
addEventMarker(event: ICalendarEvent): void;
// removes the marker corresponding to the eventId
removeEventMarker(eventId: string): void;
// updates the marker based on the event details
updateEventMarker(event: ICalendarEvent): void;
// removes all events from the map
clearEventMarkers(): void;
// centers the Map view at the specific location
setView(latitude: number, longitude: number, zoom: number): void;
// called when an event in the scheduler is clicked
onEventClick(event: ICalendarEvent): void;
// takes a string address as an argument and must resolve
// with the {lat: number, lng: number} object with the corresponding address
resolveAddress(address: string): Promise<IMapPosition>;
}
To be correctly rendered on the Map view, data items must contain a number of additional properties. The final list of mandatory properties (that data items should have) looks as in:
Make sure that your .php file conforms to your database data.
The Map view has 4 labels defined in the locale:
The 2 first labels are commonly specified, while adding the view tab to the scheduler, but the remaining marker labels should be redefined, only if you localize the application to a language, different from English.
Starting from v7.0 you can customize the shape of markers by redefining the createMarker()
method of the Map View:
const { AdvancedMarkerElement,
PinElement } = await google.maps.importLibrary("marker");
scheduler.ext.mapView.createMarker = function(config){
const pinViewGlyph = new PinElement({
glyphColor: "white",
});
return new AdvancedMarkerElement({
...config,
content: pinViewGlyph.element,
});
};
You can find more information in the Google Maps documentation.