1- import { latLngBounds , Map as LeafletMapInstance , Marker as LeafletMarker , TileLayer , TileLayerOptions } from "leaflet" ;
1+ import { latLngBounds , Map as LeafletMapInstance , Marker as LeafletMarker , TileLayer } 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" ;
78import { translateZoom } from "../../utils/zoom" ;
89import { CurrentLocationService } from "../services/CurrentLocation.service" ;
910import { LocationResolverService } from "../services/LocationResolver.service" ;
@@ -24,56 +25,6 @@ export class LeafletMapViewModel {
2425 return this . gate . props . mapProvider ;
2526 }
2627
27- private getTileLayerConfig (
28- mapProvider : MapProviderEnum ,
29- apiKey : string | null
30- ) : { url : string ; options : TileLayerOptions } {
31- const customUrls = {
32- openStreetMap : "https://{s}.tile.osm.org/{z}/{x}/{y}.png" ,
33- mapbox : "https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}" ,
34- hereMaps : "https://2.base.maps.cit.api.here.com/maptile/2.1/maptile/newest/normal.day/{z}/{x}/{y}/256/png8"
35- } ;
36-
37- const mapAttr = {
38- openStreetMapAttr : "© <a href='https://osm.org/copyright'>OpenStreetMap</a> contributors" ,
39- mapboxAttr :
40- "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>" ,
41- hereMapsAttr : "Map © 1987-2020 <a href='https://developer.here.com'>HERE</a>"
42- } ;
43-
44- if ( mapProvider === "mapBox" ) {
45- const token = apiKey ? `?access_token=${ apiKey } ` : "" ;
46- return {
47- url : customUrls . mapbox + token ,
48- options : {
49- attribution : mapAttr . mapboxAttr ,
50- id : "mapbox/streets-v11" ,
51- tileSize : 512 ,
52- zoomOffset : - 1
53- }
54- } ;
55- } else if ( mapProvider === "hereMaps" ) {
56- let token = "" ;
57- if ( apiKey ) {
58- if ( apiKey . indexOf ( "," ) > 0 ) {
59- const [ appId , appCode ] = apiKey . split ( "," ) ;
60- token = `?app_id=${ appId } &app_code=${ appCode } ` ;
61- } else {
62- token = `?apiKey=${ apiKey } ` ;
63- }
64- }
65- return {
66- url : customUrls . hereMaps + token ,
67- options : { attribution : mapAttr . hereMapsAttr }
68- } ;
69- } else {
70- return {
71- url : customUrls . openStreetMap ,
72- options : { attribution : mapAttr . openStreetMapAttr }
73- } ;
74- }
75- }
76-
7728 setupMap ( node : HTMLDivElement ) : ( ) => void {
7829 const {
7930 attributionControl,
@@ -98,7 +49,7 @@ export class LeafletMapViewModel {
9849
9950 this . map = map ;
10051
101- const { url, options } = this . getTileLayerConfig ( mapProvider , this . apiKeyAtom . get ( ) ) ;
52+ const { url, options } = getTileLayerConfig ( mapProvider , this . apiKeyAtom . get ( ) ) ;
10253 this . tileLayer = new TileLayer ( url , options ) ;
10354 this . tileLayer . addTo ( map ) ;
10455
0 commit comments