@@ -6,6 +6,7 @@ const app = require('hadron-app');
66const turfDistance = require ( 'turf-distance' ) ;
77const turfPoint = require ( 'turf-point' ) ;
88const turfDestination = require ( 'turf-destination' ) ;
9+ const mapboxgl = require ( 'mapbox-gl/dist/mapbox-gl.js' ) ;
910
1011// const metrics = require('mongodb-js-metrics')();
1112// const debug = require('debug')('mongodb-compass:minicharts:geo');
@@ -16,7 +17,9 @@ const CONTROL_COLOR = '#ed271c';
1617const TOKEN = 'pk.eyJ1IjoibW9uZ29kYi1jb21wYXNzIiwiYSI6ImNpbWUxZjNudjAwZTZ0emtrczByanZ4MzIifQ.6Mha4zoflraopcZKOLSpYQ' ;
1718
1819const MAPBOX_API_URL = 'https://compass-maps.mongodb.com/api.mapbox.com' ;
19- const MAPBOX_CLIENT_URL = MAPBOX_API_URL + '/mapbox-gl-js/v0.15.0/mapbox-gl.js' ;
20+
21+ mapboxgl . accessToken = TOKEN ;
22+ mapboxgl . config . API_URL = MAPBOX_API_URL ;
2023
2124const minicharts_d3fns_geo = function ( ) {
2225 // --- beginning chart setup ---
@@ -25,7 +28,6 @@ const minicharts_d3fns_geo = function() {
2528 let map = null ;
2629 let mousedown = false ;
2730 let circleControl ;
28- let mapboxgl ;
2931
3032 const options = {
3133 view : null
@@ -276,28 +278,6 @@ const minicharts_d3fns_geo = function() {
276278 return this ;
277279 }
278280
279- function disableMapsFeature ( ) {
280- // disable in preferences and persist
281- app . preferences . save ( 'googleMaps' , false ) ;
282- delete window . google ;
283- // options.view.parent.render();
284- }
285-
286- function loadMapBoxScript ( done ) {
287- const script = document . createElement ( 'script' ) ;
288- script . setAttribute ( 'type' , 'text/javascript' ) ;
289- script . src = MAPBOX_CLIENT_URL ;
290- script . onerror = function ( ) {
291- done ( 'Error ocurred while loading MapBox script.' ) ;
292- } ;
293- script . onload = function ( ) {
294- window . mapboxgl . config . API_URL = MAPBOX_API_URL ;
295- done ( null , window . mapboxgl ) ;
296- } ;
297- document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( script ) ;
298- }
299-
300-
301281 function selectFromQuery ( ) {
302282 // don't update from query while dragging the circle
303283 if ( mousedown ) {
@@ -321,19 +301,6 @@ const minicharts_d3fns_geo = function() {
321301 // --- end chart setup ---
322302
323303 function chart ( selection ) {
324- // load mapbox script
325- if ( ! window . mapboxgl ) {
326- loadMapBoxScript ( function ( err ) {
327- if ( err ) {
328- disableMapsFeature ( ) ;
329- } else {
330- chart . call ( this , selection ) ;
331- }
332- } ) ;
333- return ;
334- }
335- mapboxgl = window . mapboxgl ;
336-
337304 selection . each ( function ( data ) {
338305 function getLL ( d ) {
339306 if ( d instanceof mapboxgl . LngLat ) return d ;
@@ -381,20 +348,20 @@ const minicharts_d3fns_geo = function() {
381348
382349 // create the map once
383350 if ( ! map ) {
384- mapboxgl . accessToken = TOKEN ;
385351 map = new mapboxgl . Map ( {
386352 container : innerDiv [ 0 ] [ 0 ] ,
387- // not allowed to whitelabel the map without enterprise license
353+ // not allowed to whitelabel the map ever due to OpenStreetMaps license.
388354 // attributionControl: false,
389- style : 'mapbox://styles/mapbox/light-v8 ' ,
355+ style : 'mapbox://styles/mapbox/light-v9 ' ,
390356 center : bounds . getCenter ( )
391357 } ) ;
392358 map . dragPan . enable ( ) ;
393359 map . scrollZoom . enable ( ) ;
394360 map . boxZoom . disable ( ) ;
395361
396362 // Add zoom and rotation controls to the map
397- map . addControl ( new mapboxgl . Navigation ( { position : 'top-left' } ) ) ;
363+ const navControl = new mapboxgl . NavigationControl ( ) ;
364+ map . addControl ( navControl , 'top-left' ) ;
398365
399366 // Setup our svg layer that we can manipulate with d3
400367 const container = map . getCanvasContainer ( ) ;
0 commit comments