1- import { latLngBounds , Map as LeafletMapInstance , Marker as LeafletMarker , TileLayer } from "leaflet" ;
1+ import { latLngBounds , Map as LeafletMapInstance , Marker as LeafletMarker , TileLayer , TileLayerOptions } from "leaflet" ;
22import { reaction } from "mobx" ;
33import { ComputedAtom , DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/main" ;
44import { MapProviderEnum , MapsContainerProps } from "../../../typings/MapsProps" ;
55import { Marker } from "../../../typings/shared" ;
66import { createLeafletMarker } from "../../utils/leaflet-markers" ;
7- import { getTileLayerConfig } from "../../utils/tile-layer" ;
87import { translateZoom } from "../../utils/zoom" ;
98import { CurrentLocationService } from "../services/CurrentLocation.service" ;
109import { LocationResolverService } from "../services/LocationResolver.service" ;
@@ -50,7 +49,7 @@ export class LeafletMapViewModel {
5049
5150 this . map = map ;
5251
53- const { url, options } = getTileLayerConfig ( mapProvider , this . apiKeyAtom . get ( ) ) ;
52+ const { url, options } = this . getTileLayerConfig ( mapProvider ) ;
5453 this . tileLayer = new TileLayer ( url , options ) ;
5554 this . tileLayer . addTo ( map ) ;
5655
@@ -73,6 +72,45 @@ export class LeafletMapViewModel {
7372 this . map = undefined ;
7473 }
7574
75+ private getTileLayerConfig ( mapProvider : MapProviderEnum ) : { url : string ; options : TileLayerOptions } {
76+ const apiKey = this . apiKeyAtom . get ( ) ;
77+
78+ if ( mapProvider === "mapBox" ) {
79+ const token = apiKey ? `?access_token=${ apiKey } ` : "" ;
80+ return {
81+ url : `https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}${ token } ` ,
82+ options : {
83+ attribution :
84+ "Map data © <a href='https://www.openstreetmap.org/'>OpenStreetMap</a> contributors, <a href='https://creativecommons.org/licenses/by-sa/2.0/'>CC-BY-SA</a>, Imagery © <a href='https://www.mapbox.com/'>Mapbox</a>" ,
85+ id : "mapbox/streets-v11" ,
86+ tileSize : 512 ,
87+ zoomOffset : - 1
88+ }
89+ } ;
90+ }
91+
92+ if ( mapProvider === "hereMaps" ) {
93+ let token = "" ;
94+ if ( apiKey ) {
95+ if ( apiKey . indexOf ( "," ) > 0 ) {
96+ const [ appId , appCode ] = apiKey . split ( "," ) ;
97+ token = `?app_id=${ appId } &app_code=${ appCode } ` ;
98+ } else {
99+ token = `?apiKey=${ apiKey } ` ;
100+ }
101+ }
102+ return {
103+ url : `https://2.base.maps.cit.api.here.com/maptile/2.1/maptile/newest/normal.day/{z}/{x}/{y}/256/png8${ token } ` ,
104+ options : { attribution : "Map © 1987-2020 <a href='https://developer.here.com'>HERE</a>" }
105+ } ;
106+ }
107+
108+ return {
109+ url : "https://{s}.tile.osm.org/{z}/{x}/{y}.png" ,
110+ options : { attribution : "© <a href='https://osm.org/copyright'>OpenStreetMap</a> contributors" }
111+ } ;
112+ }
113+
76114 private syncMarkers ( locations : Marker [ ] , currentLocation : Marker | undefined , autoZoom : boolean ) : void {
77115 const map = this . map ;
78116 if ( ! map ) {
0 commit comments