From 9391bff392609fb7c2efefd7fca507de4dba3f51 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Wed, 8 May 2019 09:07:40 +0200 Subject: [PATCH] Transform to goog modules ./node_modules/.bin/jscodeshift --transform=node_modules/googshift/transforms/goog_provide_to_goog_module.js --legacy true jsapi/src/ ./node_modules/.bin/jscodeshift --transform=node_modules/googshift/transforms/goog_provide_to_goog_module.js --legacy true geoportailv3/static/js/ --- geoportailv3/static/js/main.js | 252 +++++++-------- geoportailv3/static/js/maincontroller.js | 4 +- jsapi/src/index.js | 257 ++++++++-------- jsapi/src/layermanager.js | 35 +-- jsapi/src/map.js | 373 ++++++++++++----------- jsapi/src/mymap.js | 337 ++++++++++---------- jsapi/src/piwik.js | 6 +- jsapi/src/printmanager.js | 205 ++++++------- jsapi/src/statemanager.js | 35 +-- 9 files changed, 761 insertions(+), 743 deletions(-) diff --git a/geoportailv3/static/js/main.js b/geoportailv3/static/js/main.js index 1a8a6c828..875013899 100644 --- a/geoportailv3/static/js/main.js +++ b/geoportailv3/static/js/main.js @@ -7,130 +7,140 @@ * This file includes `goog.require`'s for all the components/directives used * by the HTML page. */ -goog.provide('app.main'); +goog.module('app.main'); + +goog.module.declareLegacyNamespace(); +const appAskredirectAskredirectDirective = goog.require('app.askredirect.askredirectDirective'); +const appAskredirectAskredirectController = goog.require('app.askredirect.AskredirectController'); +const appAuthenticationAuthenticationDirective = goog.require('app.authentication.authenticationDirective'); +const appAuthenticationAuthenticationController = goog.require('app.authentication.AuthenticationController'); +const appBackgroundlayerBackgroundlayerDirective = goog.require('app.backgroundlayer.backgroundlayerDirective'); +const appBackgroundlayerBackgroundlayerController = goog.require('app.backgroundlayer.BackgroundlayerController'); +const appBackgroundlayerBlankLayer = goog.require('app.backgroundlayer.BlankLayer'); +const appCatalogCatalogController = goog.require('app.catalog.CatalogController'); +const appCatalogCatalogDirective = goog.require('app.catalog.catalogDirective'); +const appImageuploadImguploadController = goog.require('app.imageupload.ImguploadController'); +const appImageuploadImguploadDirective = goog.require('app.imageupload.ImguploadDirective'); +const appDrawDrawDirective = goog.require('app.draw.drawDirective'); +const appDrawDrawController = goog.require('app.draw.DrawController'); +const appDrawDrawnFeatures = goog.require('app.draw.DrawnFeatures'); +const appDrawFeatureHash = goog.require('app.draw.FeatureHash'); +const appDrawFeaturePopup = goog.require('app.draw.FeaturePopup'); +const appDrawFeaturePopupController = goog.require('app.draw.FeaturePopupController'); +const appDrawFeaturePopupDirective = goog.require('app.draw.featurePopupDirective'); +const appDrawRouteControl = goog.require('app.draw.RouteControl'); -goog.require('app.askredirect.askredirectDirective'); -goog.require('app.askredirect.AskredirectController'); -goog.require('app.authentication.authenticationDirective'); -goog.require('app.authentication.AuthenticationController'); -goog.require('app.backgroundlayer.backgroundlayerDirective'); -goog.require('app.backgroundlayer.BackgroundlayerController'); -goog.require('app.backgroundlayer.BlankLayer'); -goog.require('app.catalog.CatalogController'); -goog.require('app.catalog.catalogDirective'); -goog.require('app.imageupload.ImguploadController'); -goog.require('app.imageupload.ImguploadDirective'); -goog.require('app.draw.drawDirective'); -goog.require('app.draw.DrawController'); -goog.require('app.draw.DrawnFeatures'); -goog.require('app.draw.FeatureHash'); -goog.require('app.draw.FeaturePopup'); -goog.require('app.draw.FeaturePopupController'); -goog.require('app.draw.featurePopupDirective'); -goog.require('app.draw.RouteControl'); //const appDrawRouteControlOptions = goog.require('app.draw.RouteControlOptions'); -goog.require('app.draw.SelectedFeaturesService'); -goog.require('app.draw.StyleEditingController'); -goog.require('app.draw.styleEditingDirective'); -goog.require('app.draw.SymbolSelectorController'); -goog.require('app.draw.symbolSelectorDirective'); -goog.require('app.ExclusionManager'); -goog.require('app.externaldata.externalDataDirective'); -goog.require('app.externaldata.ExternalDataController'); -goog.require('app.feedback.feedbackDirective'); -goog.require('app.feedback.FeedbackController'); -goog.require('app.feedbackanf.feedbackanfDirective'); -goog.require('app.feedbackanf.FeedbackanfController'); -goog.require('app.infobar.elevationDirective'); -goog.require('app.infobar.ElevationController'); -goog.require('app.infobar.InfobarController'); -goog.require('app.infobar.infobarDirective'); -goog.require('app.infobar.projectionselectorDirective'); -goog.require('app.infobar.ProjectionselectorController'); -goog.require('app.infobar.scalelineDirective'); -goog.require('app.infobar.ScalelineController'); -goog.require('app.infobar.scaleselectorDirective'); -goog.require('app.infobar.ScaleselectorController'); -goog.require('app.layerinfo.layerinfoDirective'); -goog.require('app.layerinfo.LayerinfoController'); -goog.require('app.locationinfo.LocationInfoOverlay'); -goog.require('app.layerinfo.ShowLayerinfoFactory'); -goog.require('app.layermanager.layermanagerDirective'); -goog.require('app.layermanager.LayermanagerController'); -goog.require('app.layerlegends.layerlegendsDirective'); -goog.require('app.layerlegends.LayerlegendsController'); -goog.require('app.locationinfo.locationinfoDirective'); -goog.require('app.locationinfo.LocationinfoController'); -goog.require('app.map.mapDirective'); -goog.require('app.map.MapController'); -goog.require('app.MainController'); -goog.require('app.mymaps.filereaderDirective'); -goog.require('app.measure.MeasureController'); -goog.require('app.measure.MeasureDirective'); -goog.require('app.mymaps.mymapsDirective'); -goog.require('app.mymaps.MymapsController'); -goog.require('app.NotifyFactory'); -goog.require('app.print.printDirective'); -goog.require('app.print.PrintController'); -goog.require('app.print.Printservice'); -goog.require('app.profile.profileDirective'); -goog.require('app.profile.ProfileController'); -goog.require('app.query.pagreportDirective'); -goog.require('app.query.PagreportController'); -goog.require('app.query.casiporeportDirective'); -goog.require('app.query.CasiporeportController'); -goog.require('app.query.pdsreportDirective'); -goog.require('app.query.PdsreportController'); +const appDrawSelectedFeaturesService = goog.require('app.draw.SelectedFeaturesService'); + +const appDrawStyleEditingController = goog.require('app.draw.StyleEditingController'); +const appDrawStyleEditingDirective = goog.require('app.draw.styleEditingDirective'); +const appDrawSymbolSelectorController = goog.require('app.draw.SymbolSelectorController'); +const appDrawSymbolSelectorDirective = goog.require('app.draw.symbolSelectorDirective'); +const appExclusionManager = goog.require('app.ExclusionManager'); +const appExternaldataExternalDataDirective = goog.require('app.externaldata.externalDataDirective'); +const appExternaldataExternalDataController = goog.require('app.externaldata.ExternalDataController'); +const appFeedbackFeedbackDirective = goog.require('app.feedback.feedbackDirective'); +const appFeedbackFeedbackController = goog.require('app.feedback.FeedbackController'); +const appFeedbackanfFeedbackanfDirective = goog.require('app.feedbackanf.feedbackanfDirective'); +const appFeedbackanfFeedbackanfController = goog.require('app.feedbackanf.FeedbackanfController'); +const appInfobarElevationDirective = goog.require('app.infobar.elevationDirective'); +const appInfobarElevationController = goog.require('app.infobar.ElevationController'); +const appInfobarInfobarController = goog.require('app.infobar.InfobarController'); +const appInfobarInfobarDirective = goog.require('app.infobar.infobarDirective'); +const appInfobarProjectionselectorDirective = goog.require('app.infobar.projectionselectorDirective'); +const appInfobarProjectionselectorController = goog.require('app.infobar.ProjectionselectorController'); +const appInfobarScalelineDirective = goog.require('app.infobar.scalelineDirective'); +const appInfobarScalelineController = goog.require('app.infobar.ScalelineController'); +const appInfobarScaleselectorDirective = goog.require('app.infobar.scaleselectorDirective'); +const appInfobarScaleselectorController = goog.require('app.infobar.ScaleselectorController'); +const appLayerinfoLayerinfoDirective = goog.require('app.layerinfo.layerinfoDirective'); +const appLayerinfoLayerinfoController = goog.require('app.layerinfo.LayerinfoController'); +const appLocationinfoLocationInfoOverlay = goog.require('app.locationinfo.LocationInfoOverlay'); +const appLayerinfoShowLayerinfoFactory = goog.require('app.layerinfo.ShowLayerinfoFactory'); +const appLayermanagerLayermanagerDirective = goog.require('app.layermanager.layermanagerDirective'); +const appLayermanagerLayermanagerController = goog.require('app.layermanager.LayermanagerController'); +const appLayerlegendsLayerlegendsDirective = goog.require('app.layerlegends.layerlegendsDirective'); +const appLayerlegendsLayerlegendsController = goog.require('app.layerlegends.LayerlegendsController'); +const appLocationinfoLocationinfoDirective = goog.require('app.locationinfo.locationinfoDirective'); +const appLocationinfoLocationinfoController = goog.require('app.locationinfo.LocationinfoController'); +const appMapMapDirective = goog.require('app.map.mapDirective'); +const appMapMapController = goog.require('app.map.MapController'); +const appMainController = goog.require('app.MainController'); +const appMymapsFilereaderDirective = goog.require('app.mymaps.filereaderDirective'); +const appMeasureMeasureController = goog.require('app.measure.MeasureController'); +const appMeasureMeasureDirective = goog.require('app.measure.MeasureDirective'); +const appMymapsMymapsDirective = goog.require('app.mymaps.mymapsDirective'); +const appMymapsMymapsController = goog.require('app.mymaps.MymapsController'); +const appNotifyFactory = goog.require('app.NotifyFactory'); +const appPrintPrintDirective = goog.require('app.print.printDirective'); +const appPrintPrintController = goog.require('app.print.PrintController'); +const appPrintPrintservice = goog.require('app.print.Printservice'); +const appProfileProfileDirective = goog.require('app.profile.profileDirective'); +const appProfileProfileController = goog.require('app.profile.ProfileController'); +const appQueryPagreportDirective = goog.require('app.query.pagreportDirective'); +const appQueryPagreportController = goog.require('app.query.PagreportController'); +const appQueryCasiporeportDirective = goog.require('app.query.casiporeportDirective'); +const appQueryCasiporeportController = goog.require('app.query.CasiporeportController'); +const appQueryPdsreportDirective = goog.require('app.query.pdsreportDirective'); +const appQueryPdsreportController = goog.require('app.query.PdsreportController'); + //const appQueryQueryStyles = goog.require('app.query.QueryStyles'); -goog.require('app.query.queryDirective'); -goog.require('app.query.QueryController'); -goog.require('app.resizemapDirective'); -goog.require('app.routing.RoutingController'); -goog.require('app.routing.routingDirective'); -goog.require('app.search.searchDirective'); -goog.require('app.search.SearchController'); -goog.require('app.share.ShareDirective'); -goog.require('app.share.ShareController'); -goog.require('app.share.shorturlDirective'); -goog.require('app.share.ShorturlController'); -goog.require('app.slider.SliderDirective'); -goog.require('app.slider.SliderController'); -goog.require('app.streetview.streetviewDirective'); -goog.require('app.streetview.StreetviewController'); -goog.require('app.themeswitcher.themeswitcherDirective'); -goog.require('app.themeswitcher.ThemeswitcherController'); -goog.require('app.Activetool'); -goog.require('app.CoordinateStringService'); -goog.require('app.Export'); -goog.require('app.Geocoding'); -goog.require('app.GetDevice'); -goog.require('app.GetElevationService'); -goog.require('app.GetLayerForCatalogNodeFactory'); -goog.require('app.GetProfileService'); -goog.require('app.GetShorturlService'); -goog.require('app.GetWmsLayerFactory'); -goog.require('app.GetWmtsLayerFactory'); -goog.require('app.LayerOpacityManager'); -goog.require('app.LayerPermalinkManager'); -goog.require('app.LocationControl'); +const appQueryQueryDirective = goog.require('app.query.queryDirective'); + +const appQueryQueryController = goog.require('app.query.QueryController'); +const appResizemapDirective = goog.require('app.resizemapDirective'); +const appRoutingRoutingController = goog.require('app.routing.RoutingController'); +const appRoutingRoutingDirective = goog.require('app.routing.routingDirective'); +const appSearchSearchDirective = goog.require('app.search.searchDirective'); +const appSearchSearchController = goog.require('app.search.SearchController'); +const appShareShareDirective = goog.require('app.share.ShareDirective'); +const appShareShareController = goog.require('app.share.ShareController'); +const appShareShorturlDirective = goog.require('app.share.shorturlDirective'); +const appShareShorturlController = goog.require('app.share.ShorturlController'); +const appSliderSliderDirective = goog.require('app.slider.SliderDirective'); +const appSliderSliderController = goog.require('app.slider.SliderController'); +const appStreetviewStreetviewDirective = goog.require('app.streetview.streetviewDirective'); +const appStreetviewStreetviewController = goog.require('app.streetview.StreetviewController'); +const appThemeswitcherThemeswitcherDirective = goog.require('app.themeswitcher.themeswitcherDirective'); +const appThemeswitcherThemeswitcherController = goog.require('app.themeswitcher.ThemeswitcherController'); +const appActivetool = goog.require('app.Activetool'); +const appCoordinateStringService = goog.require('app.CoordinateStringService'); +const appExport = goog.require('app.Export'); +const appGeocoding = goog.require('app.Geocoding'); +const appGetDevice = goog.require('app.GetDevice'); +const appGetElevationService = goog.require('app.GetElevationService'); +const appGetLayerForCatalogNodeFactory = goog.require('app.GetLayerForCatalogNodeFactory'); +const appGetProfileService = goog.require('app.GetProfileService'); +const appGetShorturlService = goog.require('app.GetShorturlService'); +const appGetWmsLayerFactory = goog.require('app.GetWmsLayerFactory'); +const appGetWmtsLayerFactory = goog.require('app.GetWmtsLayerFactory'); +const appLayerOpacityManager = goog.require('app.LayerOpacityManager'); +const appLayerPermalinkManager = goog.require('app.LayerPermalinkManager'); +const appLocationControl = goog.require('app.LocationControl'); + // const appLocationControlOptions = goog.require('app.LocationControlOptions'); -goog.require('app.Map'); +const appMap = goog.require('app.Map'); + //const appMapsResponse = goog.require('app.MapsResponse'); -goog.require('app.Mymaps'); -goog.require('app.MymapsOffline'); -goog.require('app.olcs.toggle3d'); -goog.require('app.olcs.Lux3DManager'); -goog.require('app.olcs.Extent'); -goog.require('app.olcs.ZoomToExtent'); -goog.require('app.projections'); -goog.require('app.Routing'); -goog.require('app.ScalesService'); -goog.require('app.StateManager'); -goog.require('app.Theme'); -goog.require('app.Themes'); +const appMymaps = goog.require('app.Mymaps'); + +const appMymapsOffline = goog.require('app.MymapsOffline'); +const appOlcsToggle3d = goog.require('app.olcs.toggle3d'); +const appOlcsLux3DManager = goog.require('app.olcs.Lux3DManager'); +const appOlcsExtent = goog.require('app.olcs.Extent'); +const appOlcsZoomToExtent = goog.require('app.olcs.ZoomToExtent'); +const appProjections = goog.require('app.projections'); +const appRouting = goog.require('app.Routing'); +const appScalesService = goog.require('app.ScalesService'); +const appStateManager = goog.require('app.StateManager'); +const appTheme = goog.require('app.Theme'); +const appThemes = goog.require('app.Themes'); + //const appThemesResponse = goog.require('app.ThemesResponse'); -goog.require('app.UserManager'); -goog.require('app.WmsHelper'); -goog.require('app.WmtsHelper'); -goog.require('app.misc.file'); -goog.require('app.LotChasse'); +const appUserManager = goog.require('app.UserManager'); + +const appWmsHelper = goog.require('app.WmsHelper'); +const appWmtsHelper = goog.require('app.WmtsHelper'); +const appMiscFile = goog.require('app.misc.file'); +const appLotChasse = goog.require('app.LotChasse'); diff --git a/geoportailv3/static/js/maincontroller.js b/geoportailv3/static/js/maincontroller.js index 65dc90840..7bdbcee92 100644 --- a/geoportailv3/static/js/maincontroller.js +++ b/geoportailv3/static/js/maincontroller.js @@ -30,8 +30,8 @@ const appOlcsZoomToExtent = goog.require('app.olcs.ZoomToExtent'); const appOlcsLux3DManager = goog.require('app.olcs.Lux3DManager'); const olProj = goog.require('ol.proj'); const olMath = goog.require('ol.math'); -goog.require('app.OfflineDownloader'); -goog.require('app.OfflineRestorer'); +const appOfflineDownloader = goog.require('app.OfflineDownloader'); +const appOfflineRestorer = goog.require('app.OfflineRestorer'); /** diff --git a/jsapi/src/index.js b/jsapi/src/index.js index 83b652bf5..d71743dae 100644 --- a/jsapi/src/index.js +++ b/jsapi/src/index.js @@ -1,57 +1,58 @@ -goog.provide('lux'); - -goog.require('ol.events'); -goog.require('ol.events.EventType'); -goog.require('ol.proj'); -goog.require('ol.layer.Tile'); -goog.require('ol.source.WMTS'); -goog.require('ol.source.WMTSRequestEncoding'); -goog.require('ol.string'); -goog.require('ol.tilegrid.WMTS'); -goog.require('ol.layer.Image'); -goog.require('ol.source.ImageWMS'); -goog.require('ol.coordinate'); +goog.module('lux'); + +goog.module.declareLegacyNamespace(); +const olEvents = goog.require('ol.events'); +const olEventsEventType = goog.require('ol.events.EventType'); +const olProj = goog.require('ol.proj'); +const olLayerTile = goog.require('ol.layer.Tile'); +const olSourceWMTS = goog.require('ol.source.WMTS'); +const olSourceWMTSRequestEncoding = goog.require('ol.source.WMTSRequestEncoding'); +const olString = goog.require('ol.string'); +const olTilegridWMTS = goog.require('ol.tilegrid.WMTS'); +const olLayerImage = goog.require('ol.layer.Image'); +const olSourceImageWMS = goog.require('ol.source.ImageWMS'); +const olCoordinate = goog.require('ol.coordinate'); /** * @type {string} */ -lux.requestScheme = 'http'; +exports.requestScheme = 'http'; /** * @type {string} */ -lux.layersUrl = 'jsapilayers'; +exports.layersUrl = 'jsapilayers'; /** * @type {string} */ -lux.searchUrl = 'fulltextsearch?'; +exports.searchUrl = 'fulltextsearch?'; /** * @type {string} */ -lux.profileUrl = 'profile.json'; +exports.profileUrl = 'profile.json'; /** * @type {string} */ -lux.exportCsvUrl = 'profile/echocsv'; +exports.exportCsvUrl = 'profile/echocsv'; /** * @type {string?} */ -lux.baseUrl = null; +exports.baseUrl = null; /** * @type {Object} * @export */ -lux.languages = {}; +exports.languages = {}; /** * @type {string?} */ -lux.wmtsCrossOrigin = 'anonymous'; +exports.wmtsCrossOrigin = 'anonymous'; /** @@ -66,76 +67,76 @@ lux.wmtsCrossOrigin = 'anonymous'; * @param {string | undefined} requestScheme The request scheme. Default is http. * @export */ -lux.setBaseUrl = function(url, requestScheme) { +exports.setBaseUrl = function(url, requestScheme) { if (requestScheme !== undefined) { - lux.requestScheme = requestScheme; + exports.requestScheme = requestScheme; } if (!url) { - lux.layersUrl = '../layers.json'; - lux.i18nUrl = '../lang_xx.json'; + exports.layersUrl = '../layers.json'; + exports.i18nUrl = '../lang_xx.json'; url = 'https://apiv3.geoportail.lu/'; } else { - lux.layersUrl = url + lux.layersUrl; - lux.i18nUrl = url + lux.i18nUrl; + exports.layersUrl = url + exports.layersUrl; + exports.i18nUrl = url + exports.i18nUrl; } - lux.searchUrl = url + lux.searchUrl; - lux.mymapsUrl = url + lux.mymapsUrl; - lux.elevationUrl = url + lux.elevationUrl; - lux.geocodeUrl = url + lux.geocodeUrl; - lux.reverseGeocodeUrl = url + lux.reverseGeocodeUrl; - lux.queryUrl = url + lux.queryUrl; - lux.profileUrl = url + lux.profileUrl; - lux.exportCsvUrl = url + lux.exportCsvUrl; - lux.printUrl = url + lux.printUrl; - lux.pagUrl = url + lux.pagUrl; - lux.baseUrl = url; + exports.searchUrl = url + exports.searchUrl; + exports.mymapsUrl = url + exports.mymapsUrl; + exports.elevationUrl = url + exports.elevationUrl; + exports.geocodeUrl = url + exports.geocodeUrl; + exports.reverseGeocodeUrl = url + exports.reverseGeocodeUrl; + exports.queryUrl = url + exports.queryUrl; + exports.profileUrl = url + exports.profileUrl; + exports.exportCsvUrl = url + exports.exportCsvUrl; + exports.printUrl = url + exports.printUrl; + exports.pagUrl = url + exports.pagUrl; + exports.baseUrl = url; }; /** * @type {string} */ -lux.pagUrl = 'pag'; +exports.pagUrl = 'pag'; /** * @type {string} */ -lux.mymapsUrl = 'mymaps'; +exports.mymapsUrl = 'mymaps'; /** * @type {string} */ -lux.elevationUrl = 'raster'; +exports.elevationUrl = 'raster'; /** * @type {string} */ -lux.queryUrl = 'getfeatureinfo?'; +exports.queryUrl = 'getfeatureinfo?'; /** * @type {string} */ -lux.geocodeUrl = 'geocode/search'; +exports.geocodeUrl = 'geocode/search'; /** * @type {string} */ -lux.reverseGeocodeUrl = 'geocode/reverse'; +exports.reverseGeocodeUrl = 'geocode/reverse'; /** * @type {string} */ -lux.printUrl = 'printproxy'; +exports.printUrl = 'printproxy'; /** * @param {string} url Url to jsapilayers service. * @export * @api */ -lux.setLayersUrl = function(url) { - lux.layersUrl = url; +exports.setLayersUrl = function(url) { + exports.layersUrl = url; }; /** @@ -143,24 +144,24 @@ lux.setLayersUrl = function(url) { * @export * @api */ -lux.setWmtsCrossOrigin = function(crossorigin) { - lux.wmtsCrossOrigin = crossorigin; +exports.setWmtsCrossOrigin = function(crossorigin) { + exports.wmtsCrossOrigin = crossorigin; }; /** * @type {string} */ -lux.i18nUrl = 'proj/api/build/locale/xx/geoportailv3.json'; +exports.i18nUrl = 'proj/api/build/locale/xx/geoportailv3.json'; /** * @type {string} */ -lux.lang = 'fr'; +exports.lang = 'fr'; /** * @type {Array?} */ -lux.popupSize = null; +exports.popupSize = null; /** @@ -169,9 +170,9 @@ lux.popupSize = null; * @return {string} The translated text. * @export */ -lux.translate = function(text) { - if (lux.lang in lux.languages) { - return lux.languages[lux.lang][text] || text; +exports.translate = function(text) { + if (exports.lang in exports.languages) { + return exports.languages[exports.lang][text] || text; } return text; }; @@ -181,8 +182,8 @@ lux.translate = function(text) { * @export * @api */ -lux.setPopupSize = function(size) { - lux.popupSize = size; +exports.setPopupSize = function(size) { + exports.popupSize = size; }; /** @@ -190,8 +191,8 @@ lux.setPopupSize = function(size) { * @export * @api */ -lux.setI18nUrl = function(url) { - lux.i18nUrl = url; +exports.setI18nUrl = function(url) { + exports.i18nUrl = url; }; /** @@ -205,7 +206,7 @@ lux.setI18nUrl = function(url) { * @return {function()} The function. * @api */ -lux.debounce = function(func, wait, opt_immediate) { +exports.debounce = function(func, wait, opt_immediate) { var timeout; return function() { var context = this; @@ -230,7 +231,7 @@ lux.debounce = function(func, wait, opt_immediate) { * @param {string} msg The message to notify. * @api */ -lux.notify = function(msg) { +exports.notify = function(msg) { alert(msg); }; @@ -245,21 +246,21 @@ lux.notify = function(msg) { * @export * @api */ -lux.buildPopupLayout = function(html, closeCallback, title) { - var container = document.createElement('DIV'); - container.classList.add('lux-popup'); - - var arrow = document.createElement('DIV'); - arrow.classList.add('lux-popup-arrow'); +exports.buildPopupLayout = function(html, closeCallback, title) { + var container = document.createElement('DIV'); + container.classList.add('lux-popup'); + + var arrow = document.createElement('DIV'); + arrow.classList.add('lux-popup-arrow'); - var elements = [arrow]; + var elements = [arrow]; - var content = document.createElement('DIV'); + var content = document.createElement('DIV'); content.classList.add('lux-popup-content'); - if (lux.popupSize) { - container.style.width = lux.popupSize[0] + 'px'; - content.style.height = lux.popupSize[1] + 'px'; + if (exports.popupSize) { + container.style.width = exports.popupSize[0] + 'px'; + content.style.height = exports.popupSize[1] + 'px'; content.style.maxHeight = 'none'; } @@ -269,27 +270,27 @@ lux.buildPopupLayout = function(html, closeCallback, title) { content.appendChild(html); } - if (closeCallback) { - var header = document.createElement('DIV'); + if (closeCallback) { + var header = document.createElement('DIV'); header.classList.add('lux-popup-header'); if (title !== undefined) { header.innerHTML = title; - } - - var closeBtn = document.createElement('BUTTON'); - closeBtn.classList.add('lux-popup-close'); + } + + var closeBtn = document.createElement('BUTTON'); + closeBtn.classList.add('lux-popup-close'); closeBtn.innerHTML = '×'; header.appendChild(closeBtn); elements.push(header); - ol.events.listen(closeBtn, ol.events.EventType.CLICK, closeCallback); + olEvents.listen(closeBtn, olEventsEventType.CLICK, closeCallback); } elements.push(content); - elements.forEach(function(element) { - container.appendChild(element); + elements.forEach(function(element) { + container.appendChild(element); }); return container; }; @@ -300,7 +301,7 @@ lux.buildPopupLayout = function(html, closeCallback, title) { * @param {string} two The second list of exclusions. * @return {boolean} Whether the array intersect or not. */ -lux.intersects = function(one, two) { +exports.intersects = function(one, two) { var arr1 = /** @type {Array} */ (JSON.parse(one)); var arr2 = /** @type {Array} */ (JSON.parse(two)); return arr1.some(function(item) { @@ -314,7 +315,7 @@ lux.intersects = function(one, two) { * @param {boolean} visible The layer's visibility. * @return {ol.layer.Tile} The layer. */ -lux.WMTSLayerFactory = function(config, opacity, visible) { +exports.WMTSLayerFactory = function(config, opacity, visible) { var format = config['imageType']; var imageExt = format.split('/')[1]; @@ -331,29 +332,29 @@ lux.WMTSLayerFactory = function(config, opacity, visible) { retinaExtension + '/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.' + imageExt; - if (lux.requestScheme === 'https') { + if (exports.requestScheme === 'https') { url = 'https://wmts{3-4}.geoportail.lu/mapproxy_4_v3/wmts/{Layer}' + retinaExtension + '/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.' + imageExt; } - var projection = ol.proj.get('EPSG:3857'); + var projection = olProj.get('EPSG:3857'); var extent = projection.getExtent(); - var layer = new ol.layer.Tile({ + var layer = new olLayerTile({ name: config['name'], id: config['id'], metadata: config['metadata'], - source: new ol.source.WMTS({ - crossOrigin: lux.wmtsCrossOrigin, + source: new olSourceWMTS({ + crossOrigin: exports.wmtsCrossOrigin, url: url, attributions: [''], tilePixelRatio: (retina ? 2 : 1), layer: config['name'], matrixSet: 'GLOBAL_WEBMERCATOR_4_V3' + (retina ? '_HD' : ''), format: format, - requestEncoding: ol.source.WMTSRequestEncoding.REST, + requestEncoding: olSourceWMTSRequestEncoding.REST, projection: projection, - tileGrid: new ol.tilegrid.WMTS({ + tileGrid: new olTilegridWMTS({ origin: [ -20037508.3428, 20037508.3428 ], @@ -387,7 +388,7 @@ lux.WMTSLayerFactory = function(config, opacity, visible) { * @param {boolean} visible The layer's visibility. * @return {ol.layer.Image} The layer. */ -lux.WMSLayerFactory = function(config, opacity, visible) { +exports.WMSLayerFactory = function(config, opacity, visible) { var url = config.url || 'https://map.geoportail.lu/main/wsgi/ogcproxywms?'; var optSource = { crossOrigin: 'anonymous', @@ -397,11 +398,11 @@ lux.WMSLayerFactory = function(config, opacity, visible) { 'LAYERS': config['layers'] } }; - var layer = new ol.layer.Image({ + var layer = new olLayerImage({ name: config['name'], id: config['id'], metadata: config['metadata'], - source: new ol.source.ImageWMS(optSource), + source: new olSourceImageWMS(optSource), opacity: opacity, visible: visible }); @@ -436,12 +437,12 @@ lux.WMSLayerFactory = function(config, opacity, visible) { * @static * @global */ -lux.geocode = function(obj, cb) { - var url = document.createElement('A'); - url.href = lux.geocodeUrl; +exports.geocode = function(obj, cb) { + var url = document.createElement('A'); + url.href = exports.geocodeUrl; goog.asserts.assertObject(obj); - Object.keys(obj).forEach(function(key) { + Object.keys(obj).forEach(function(key) { url.search = url.search + '&' + key + '=' + obj[key]; }); return /** @type {Promise.} */ (fetch(url.toString()).then(function(resp) { @@ -473,9 +474,9 @@ lux.geocode = function(obj, cb) { * @static * @global */ -lux.reverseGeocode = function(coordinate, cb) { - var url = document.createElement('A'); - url.href = lux.reverseGeocodeUrl; +exports.reverseGeocode = function(coordinate, cb) { + var url = document.createElement('A'); + url.href = exports.reverseGeocodeUrl; url.search = 'easting=' + coordinate[0] + '&northing=' + coordinate[1]; return /** @type {Promise.} */ (fetch(url.toString()).then(function(resp) { @@ -501,42 +502,42 @@ lux.reverseGeocode = function(coordinate, cb) { * @param {boolean} opt_DMm True if Degree decimal minutes. * @return {string} The coordinate string. */ -lux.coordinateString_ = function(coordinate, sourceEpsgCode, +exports.coordinateString_ = function(coordinate, sourceEpsgCode, targetEpsgCode, opt_DMS, opt_DMm) { var str = ''; if (targetEpsgCode === 'EPSG:3263*') { var lonlat = /** @type {ol.Coordinate} */ - (ol.proj.transform(coordinate, sourceEpsgCode, 'EPSG:4326')); + (olProj.transform(coordinate, sourceEpsgCode, 'EPSG:4326')); targetEpsgCode = Math.floor(lonlat[0]) >= 6 ? 'EPSG:32632' : 'EPSG:32631'; } - coordinate = ol.proj.transform(coordinate, sourceEpsgCode, targetEpsgCode); + coordinate = olProj.transform(coordinate, sourceEpsgCode, targetEpsgCode); switch (targetEpsgCode) { default: case 'EPSG:2169': - str = ol.coordinate.format(coordinate, '{x} E | {y} N', 0); + str = olCoordinate.format(coordinate, '{x} E | {y} N', 0); break; case 'EPSG:4326': if (opt_DMS) { - var hdms = lux.toStringHDMS_(coordinate); + var hdms = exports.toStringHDMS_(coordinate); var yhdms = hdms.split(' ').slice(0, 4).join(' '); var xhdms = hdms.split(' ').slice(4, 8).join(' '); str = xhdms + ' | ' + yhdms; } else if (opt_DMm) { - var hdmm = lux.toStringHDMm_(coordinate); + var hdmm = exports.toStringHDMm_(coordinate); var yhdmm = hdmm.split(' ').slice(0, 3).join(' '); var xhdmm = hdmm.split(' ').slice(3, 6).join(' '); str = xhdmm + ' | ' + yhdmm; } else { - str = ol.coordinate.format(coordinate, ' {x} E | {y} N', 5); + str = olCoordinate.format(coordinate, ' {x} E | {y} N', 5); } break; case 'EPSG:32632': - str = ol.coordinate.format(coordinate, '{x} | {y} (UTM32N)', 0); + str = olCoordinate.format(coordinate, '{x} | {y} (UTM32N)', 0); break; case 'EPSG:32631': - str = ol.coordinate.format(coordinate, '{x} | {y} (UTM31N)', 0); + str = olCoordinate.format(coordinate, '{x} | {y} (UTM31N)', 0); break; } return str; @@ -547,10 +548,10 @@ lux.coordinateString_ = function(coordinate, sourceEpsgCode, * @param {ol.Coordinate|undefined} coordinate Coordinate. * @return {string} Hemisphere, degrees, minutes and seconds. */ -lux.toStringHDMS_ = function(coordinate) { +exports.toStringHDMS_ = function(coordinate) { if (coordinate !== undefined) { - return lux.degreesToStringHDMS_(coordinate[1], 'NS') + ' ' + - lux.degreesToStringHDMS_(coordinate[0], 'EW'); + return exports.degreesToStringHDMS_(coordinate[1], 'NS') + ' ' + + exports.degreesToStringHDMS_(coordinate[0], 'EW'); } else { return ''; } @@ -561,10 +562,10 @@ lux.toStringHDMS_ = function(coordinate) { * @param {ol.Coordinate|undefined} coordinate Coordinate. * @return {string} Hemisphere, degrees, decimal minutes. */ -lux.toStringHDMm_ = function(coordinate) { +exports.toStringHDMm_ = function(coordinate) { if (coordinate !== undefined) { - return lux.degreesToStringHDMm_(coordinate[1], 'NS') + ' ' + - lux.degreesToStringHDMm_(coordinate[0], 'EW'); + return exports.degreesToStringHDMm_(coordinate[1], 'NS') + ' ' + + exports.degreesToStringHDMm_(coordinate[0], 'EW'); } else { return ''; } @@ -576,12 +577,12 @@ lux.toStringHDMm_ = function(coordinate) { * @param {string} hemispheres Hemispheres. * @return {string} String. */ -lux.degreesToStringHDMS_ = function(degrees, hemispheres) { +exports.degreesToStringHDMS_ = function(degrees, hemispheres) { var normalizedDegrees = ((degrees + 180) % 360) - 180; var x = Math.abs(3600 * normalizedDegrees); return Math.floor(x / 3600) + '\u00b0 ' + - ol.string.padNumber(Math.floor((x / 60) % 60), 2) + '\u2032 ' + - ol.string.padNumber(Math.floor(x % 60), 2) + ',' + + olString.padNumber(Math.floor((x / 60) % 60), 2) + '\u2032 ' + + olString.padNumber(Math.floor(x % 60), 2) + ',' + Math.floor((x - (x < 0 ? Math.ceil(x) : Math.floor(x))) * 10) + '\u2033 ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0); }; @@ -592,14 +593,14 @@ lux.degreesToStringHDMS_ = function(degrees, hemispheres) { * @param {string} hemispheres Hemispheres. * @return {string} String. */ -lux.degreesToStringHDMm_ = function(degrees, hemispheres) { +exports.degreesToStringHDMm_ = function(degrees, hemispheres) { var normalizedDegrees = ((degrees + 180) % 360) - 180; var x = Math.abs(3600 * normalizedDegrees); var dd = x / 3600; var m = (dd - Math.floor(dd)) * 60; var res = Math.floor(dd) + '\u00b0 ' + - ol.string.padNumber(Math.floor(m), 2) + ',' + + olString.padNumber(Math.floor(m), 2) + ',' + Math.floor((m - Math.floor(m)) * 100000) + '\u2032 ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0); return res; @@ -612,15 +613,15 @@ lux.degreesToStringHDMm_ = function(degrees, hemispheres) { * @param {boolean} eula Has user accepted the end user licence agreement?. * @export */ -lux.generatePagRepport = function(ids, mail, eula) { - var msg = lux.translate('Votre rapport est en train d\'être généré. Un email vous sera envoyé dès qu\'il sera disponible'); +exports.generatePagRepport = function(ids, mail, eula) { + var msg = exports.translate('Votre rapport est en train d\'être généré. Un email vous sera envoyé dès qu\'il sera disponible'); var re = /^\S+@\S+\.\S+$/; if (mail.length === 0 || !re.test(mail)) { - msg = lux.translate('Veuillez saisir une adresse email valide'); - lux.notify(msg); + msg = exports.translate('Veuillez saisir une adresse email valide'); + exports.notify(msg); } else if (!eula) { - msg = lux.translate('Veuillez accepter les termes du rapport'); - lux.notify(msg); + msg = exports.translate('Veuillez accepter les termes du rapport'); + exports.notify(msg); } else { /** * @type {!RequestInit} @@ -631,7 +632,7 @@ lux.generatePagRepport = function(ids, mail, eula) { 'Content-Type': 'application/x-www-form-urlencoded' }) }); - fetch(lux.pagUrl + '/report/' + ids + '.pdf?email=' + mail + '&staging=false', request); - lux.notify(msg); + fetch(exports.pagUrl + '/report/' + ids + '.pdf?email=' + mail + '&staging=false', request); + exports.notify(msg); } }; diff --git a/jsapi/src/layermanager.js b/jsapi/src/layermanager.js index ae2647abc..2a1eb0536 100644 --- a/jsapi/src/layermanager.js +++ b/jsapi/src/layermanager.js @@ -1,10 +1,11 @@ -goog.provide('lux.LayerManager'); +goog.module('lux.LayerManager'); -goog.require('lux'); -goog.require('ol'); -goog.require('ol.control.Control'); -goog.require('ol.events'); -goog.require('ol.CollectionEventType'); +goog.module.declareLegacyNamespace(); +const luxBase = goog.require('lux'); +const olBase = goog.require('ol'); +const olControlControl = goog.require('ol.control.Control'); +const olEvents = goog.require('ol.events'); +const olCollectionEventType = goog.require('ol.CollectionEventType'); /** @@ -13,30 +14,30 @@ goog.require('ol.CollectionEventType'); * @param {olx.control.ControlOptions} options Layer manager options. * @export */ -lux.LayerManager = function(options) { +exports = function(options) { var element = document.createElement('UL'); element.classList.add('lux-layer-manager'); - ol.control.Control.call(this, { + olControlControl.call(this, { element: element, target: options.target }); }; -ol.inherits(lux.LayerManager, ol.control.Control); +olBase.inherits(exports, olControlControl); /** * @inheritDoc */ -lux.LayerManager.prototype.setMap = function(map) { - ol.control.Control.prototype.setMap.call(this, map); +exports.prototype.setMap = function(map) { + olControlControl.prototype.setMap.call(this, map); if (map) { var layers = map.getLayers(); this.listenerKeys.push( - ol.events.listen(layers, ol.CollectionEventType.ADD, + olEvents.listen(layers, olCollectionEventType.ADD, this.update, this), - ol.events.listen(layers, ol.CollectionEventType.REMOVE, + olEvents.listen(layers, olCollectionEventType.REMOVE, this.update, this) ); this.update(); @@ -47,7 +48,7 @@ lux.LayerManager.prototype.setMap = function(map) { /** * Update the component adequately. */ -lux.LayerManager.prototype.update = function() { +exports.prototype.update = function() { while (this.element.firstChild) { this.element.removeChild(this.element.firstChild); } @@ -59,9 +60,9 @@ lux.LayerManager.prototype.update = function() { var label = document.createElement('label'); var name = /** @type {string} */ (layer.get('name')); - if (lux.lang in lux.languages && - lux.languages[lux.lang][name] !== undefined) { - label.innerHTML = lux.languages[lux.lang][name]; + if (luxBase.lang in luxBase.languages && + luxBase.languages[luxBase.lang][name] !== undefined) { + label.innerHTML = luxBase.languages[luxBase.lang][name]; } else { label.innerHTML = name; } diff --git a/jsapi/src/map.js b/jsapi/src/map.js index 0615c3aa0..18ea4500b 100644 --- a/jsapi/src/map.js +++ b/jsapi/src/map.js @@ -1,40 +1,41 @@ -goog.provide('lux.Map'); - -goog.require('lux'); -goog.require('lux.LayerManager'); -goog.require('lux.MyMap'); -goog.require('lux.PrintManager'); -goog.require('lux.StateManager'); -goog.require('ol'); -goog.require('ol.array'); -goog.require('ol.Map'); -goog.require('ol.Overlay'); -goog.require('ol.View'); -goog.require('ol.control.MousePosition'); -goog.require('ol.events'); -goog.require('ol.format.GPX'); -goog.require('ol.format.GeoJSON'); -goog.require('ol.format.KML'); -goog.require('ol.geom.Point'); -goog.require('ol.interaction.Select'); -goog.require('ol.layer.Tile'); -goog.require('ol.layer.Vector'); -goog.require('ol.extent'); -goog.require('ol.style.Fill'); -goog.require('ol.style.Stroke'); -goog.require('ol.style.Style'); -goog.require('ol.style.Circle'); -goog.require('ol.source.Vector'); -goog.require('ol.proj'); -goog.require('ol.Collection'); -goog.require('ol.asserts'); -goog.require('ol.control.Attribution'); -goog.require('ol.control'); -goog.require('ol.CollectionEventType'); -goog.require('ol.MapBrowserEventType'); -goog.require('ol.Feature'); -goog.require('ol.geom.Polygon'); -goog.require('ol.source.VectorEventType'); +goog.module('lux.Map'); + +goog.module.declareLegacyNamespace(); +const luxBase = goog.require('lux'); +const luxLayerManager = goog.require('lux.LayerManager'); +const luxMyMap = goog.require('lux.MyMap'); +const luxPrintManager = goog.require('lux.PrintManager'); +const luxStateManager = goog.require('lux.StateManager'); +const olBase = goog.require('ol'); +const olArray = goog.require('ol.array'); +const olMap = goog.require('ol.Map'); +const olOverlay = goog.require('ol.Overlay'); +const olView = goog.require('ol.View'); +const olControlMousePosition = goog.require('ol.control.MousePosition'); +const olEvents = goog.require('ol.events'); +const olFormatGPX = goog.require('ol.format.GPX'); +const olFormatGeoJSON = goog.require('ol.format.GeoJSON'); +const olFormatKML = goog.require('ol.format.KML'); +const olGeomPoint = goog.require('ol.geom.Point'); +const olInteractionSelect = goog.require('ol.interaction.Select'); +const olLayerTile = goog.require('ol.layer.Tile'); +const olLayerVector = goog.require('ol.layer.Vector'); +const olExtent = goog.require('ol.extent'); +const olStyleFill = goog.require('ol.style.Fill'); +const olStyleStroke = goog.require('ol.style.Stroke'); +const olStyleStyle = goog.require('ol.style.Style'); +const olStyleCircle = goog.require('ol.style.Circle'); +const olSourceVector = goog.require('ol.source.Vector'); +const olProj = goog.require('ol.proj'); +const olCollection = goog.require('ol.Collection'); +const olAsserts = goog.require('ol.asserts'); +const olControlAttribution = goog.require('ol.control.Attribution'); +const olControl = goog.require('ol.control'); +const olCollectionEventType = goog.require('ol.CollectionEventType'); +const olMapBrowserEventType = goog.require('ol.MapBrowserEventType'); +const olFeature = goog.require('ol.Feature'); +const olGeomPolygon = goog.require('ol.geom.Polygon'); +const olSourceVectorEventType = goog.require('ol.source.VectorEventType'); proj4.defs('EPSG:2169', '+proj=tmerc +lat_0=49.83333333333334 +lon_0=6.166666666666667 +k=1 +x_0=80000 +y_0=100000 +ellps=intl +towgs84=-189.681,18.3463,-42.7695,-0.33746,-3.09264,2.53861,0.4598 +units=m +no_defs'); @@ -77,7 +78,7 @@ _paq.push(['setSiteId', 22]); * @export * @api stable */ -lux.Map = function(options) { +exports = function(options) { /** * @private * @type {Array} @@ -107,7 +108,7 @@ lux.Map = function(options) { * @private * @type {ol.Extent} */ - this.featureExtent_ = ol.extent.createEmpty(); + this.featureExtent_ = olExtent.createEmpty(); /** * @private @@ -140,7 +141,7 @@ lux.Map = function(options) { */ this.showLayerInfoPopup_ = options.showLayerInfoPopup ? true : false; - this.setLanguage(lux.lang); + this.setLanguage(luxBase.lang); /** * @private @@ -148,11 +149,11 @@ lux.Map = function(options) { */ this.searchLayer_ = null; - var fillStyle = new ol.style.Fill({ + var fillStyle = new olStyleFill({ color: [255, 255, 0, 0.6] }); - var strokeStyle = new ol.style.Stroke({ + var strokeStyle = new olStyleStroke({ color: [255, 155, 55, 1], width: 3 }); @@ -161,10 +162,10 @@ lux.Map = function(options) { * @private * @type {ol.style.Style} */ - this.vectorStyle_ = new ol.style.Style({ + this.vectorStyle_ = new olStyleStyle({ fill: fillStyle, stroke: strokeStyle, - image: new ol.style.Circle({ + image: new olStyleCircle({ radius: 10, fill: fillStyle, stroke: strokeStyle @@ -175,8 +176,8 @@ lux.Map = function(options) { * @private * @type {ol.layer.Vector} */ - this.showLayer_ = new ol.layer.Vector({ - source: new ol.source.Vector() + this.showLayer_ = new olLayerVector({ + source: new olSourceVector() }); this.showLayer_.setStyle(this.vectorStyle_); @@ -185,7 +186,7 @@ lux.Map = function(options) { * @private * @type {ol.layer.Tile} */ - this.blankLayer_ = new ol.layer.Tile(); + this.blankLayer_ = new olLayerTile(); this.blankLayer_.set('name', 'blank'); /** @@ -233,7 +234,7 @@ lux.Map = function(options) { delete options.layerVisibilities; } - this.layersPromise = fetch(lux.layersUrl).then(function(resp) { + this.layersPromise = fetch(luxBase.layersUrl).then(function(resp) { return resp.json(); }).then(function(json) { this.layersConfig = /** @type {luxx.LayersOptions} */ (json); @@ -252,7 +253,7 @@ lux.Map = function(options) { var el = typeof target === 'string' ? document.getElementById(target) : target; - this.layerManagerControl_ = new lux.LayerManager({ + this.layerManagerControl_ = new luxLayerManager({ target: el }); this.addControl(this.layerManagerControl_); @@ -273,14 +274,14 @@ lux.Map = function(options) { } if (options.view === undefined) { - options.view = new ol.View(); + options.view = new olView(); } if (options.position) { var position = [parseFloat( options.position[0]), parseFloat(options.position[1])]; - options.view.setCenter(ol.proj.transform( + options.view.setCenter(olProj.transform( position, (options.positionSrs) ? 'EPSG:' + options.positionSrs.toString() : 'EPSG:2169', @@ -296,7 +297,7 @@ lux.Map = function(options) { if (options.view.getCenter() === undefined || options.view.getCenter() === null) { - options.view.setCenter(ol.proj.fromLonLat([6.215, 49.845])); + options.view.setCenter(olProj.fromLonLat([6.215, 49.845])); } if (options.view.getZoom() === undefined || options.view.getZoom() === null) { @@ -306,17 +307,17 @@ lux.Map = function(options) { var controls; if (options.controls !== undefined) { if (Array.isArray(options.controls)) { - controls = new ol.Collection(options.controls.slice()); + controls = new olCollection(options.controls.slice()); } else { - ol.asserts.assert(options.controls instanceof ol.Collection, + olAsserts.assert(options.controls instanceof olCollection, 47); // Expected `controls` to be an array or an `ol.Collection` controls = options.controls; } } else { - var attribution = new ol.control.Attribution({ + var attribution = new olControlAttribution({ collapsible: false }); - controls = ol.control.defaults({attribution: false}).extend([attribution]); + controls = olControl.defaults({attribution: false}).extend([attribution]); } var target; @@ -329,10 +330,10 @@ lux.Map = function(options) { document.getElementById(target) : target; if (el instanceof Element) { - controls.push(new ol.control.MousePosition({ + controls.push(new olControlMousePosition({ target: el, className: 'lux-mouse-position', - projection: ol.proj.get(srs), + projection: olProj.get(srs), coordinateFormat: function(coord) { var decimal = 1; if (srs == 'EPSG:4326') { @@ -359,11 +360,11 @@ lux.Map = function(options) { src: 'https://www.geoportail.lu/static/img/favicon-16x16.ico' }; - ol.Map.call(this, options); + olMap.call(this, options); this.getTargetElement().classList.add('lux-map'); - ol.events.listen(this.getLayers(), ol.CollectionEventType.ADD, + olEvents.listen(this.getLayers(), olCollectionEventType.ADD, this.checkForExclusion_, this); /** @@ -373,16 +374,16 @@ lux.Map = function(options) { this.popupTarget_ = undefined; this.setPopupTarget(options.popupTarget); - ol.events.listen(this, ol.MapBrowserEventType.SINGLECLICK, + olEvents.listen(this, olMapBrowserEventType.SINGLECLICK, this.handleSingleclickEvent_, this); - this.stateManager_ = new lux.StateManager(); + this.stateManager_ = new luxStateManager(); this.stateManager_.setMap(this); this.showLayer_.setMap(this); // change cursor on mouseover feature - ol.events.listen(this, ol.MapBrowserEventType.POINTERMOVE, function(evt) { + olEvents.listen(this, olMapBrowserEventType.POINTERMOVE, function(evt) { var pixel = this.getEventPixel(evt.originalEvent); var hit = this.hasFeatureAtPixel(pixel); var pixelHit = this.forEachLayerAtPixel(pixel, function(colors) { @@ -400,7 +401,7 @@ lux.Map = function(options) { } }; -ol.inherits(lux.Map, ol.Map); +olBase.inherits(exports, olMap); /** * Adds the given layer to the top of this map. If you want to add a layer @@ -411,9 +412,9 @@ ol.inherits(lux.Map, ol.Map); * @export * @api */ -lux.Map.prototype.addLayer = function(layer) { +exports.prototype.addLayer = function(layer) { this.layersPromise.then(function() { - ol.Map.prototype.addLayer.call(this, layer); + olMap.prototype.addLayer.call(this, layer); }.bind(this)); }; @@ -424,7 +425,7 @@ lux.Map.prototype.addLayer = function(layer) { * @export * @api */ -lux.Map.prototype.getMapReadyPromise = function() { +exports.prototype.getMapReadyPromise = function() { return Promise.all([this.i18nPromise, this.layersPromise]); }; @@ -447,11 +448,11 @@ lux.Map.prototype.getMapReadyPromise = function() { * @export * @api */ -lux.Map.prototype.print = function(name, layout, scale, firstPagesUrls, callback) { +exports.prototype.print = function(name, layout, scale, firstPagesUrls, callback) { var dpi = 127; var format = 'pdf'; - var pm = new lux.PrintManager(lux.printUrl, this); + var pm = new luxPrintManager(luxBase.printUrl, this); if (firstPagesUrls === undefined || firstPagesUrls === null) { firstPagesUrls = []; } @@ -460,7 +461,7 @@ lux.Map.prototype.print = function(name, layout, scale, firstPagesUrls, callback } var curLayout = ''; if (layout === undefined || layout === null || - lux.PrintManager.LAYOUTS.indexOf(layout) === -1) { + luxPrintManager.LAYOUTS.indexOf(layout) === -1) { var size = this.getSize(); if (size !== undefined && size[0] > size[1]) { curLayout = 'A4 landscape'; @@ -491,10 +492,10 @@ lux.Map.prototype.print = function(name, layout, scale, firstPagesUrls, callback return self.indexOf(item) == pos; }); - var disclaimer = lux.translate('www.geoportail.lu est un portail d\'accès aux informations géolocalisées, données et services qui sont mis à disposition par les administrations publiques luxembourgeoises. Responsabilité: Malgré la grande attention qu’elles portent à la justesse des informations diffusées sur ce site, les autorités ne peuvent endosser aucune responsabilité quant à la fidélité, à l’exactitude, à l’actualité, à la fiabilité et à l’intégralité de ces informations. Information dépourvue de foi publique. Droits d\'auteur: Administration du Cadastre et de la Topographie. http://g-o.lu/copyright'); - var dateText = lux.translate('Date d\'impression: '); - var scaleTitle = lux.translate('Echelle approximative 1:'); - var appTitle = lux.translate('Le géoportail national du Grand-Duché du Luxembourg'); + var disclaimer = luxBase.translate('www.geoportail.lu est un portail d\'accès aux informations géolocalisées, données et services qui sont mis à disposition par les administrations publiques luxembourgeoises. Responsabilité: Malgré la grande attention qu’elles portent à la justesse des informations diffusées sur ce site, les autorités ne peuvent endosser aucune responsabilité quant à la fidélité, à l’exactitude, à l’actualité, à la fiabilité et à l’intégralité de ces informations. Information dépourvue de foi publique. Droits d\'auteur: Administration du Cadastre et de la Topographie. http://g-o.lu/copyright'); + var dateText = luxBase.translate('Date d\'impression: '); + var scaleTitle = luxBase.translate('Echelle approximative 1:'); + var appTitle = luxBase.translate('Le géoportail national du Grand-Duché du Luxembourg'); var longUrl = this.stateManager_.getUrl(); if (longUrl.toLowerCase().indexOf('http') !== 0 && longUrl.toLowerCase().indexOf('//') === 0) { @@ -511,7 +512,7 @@ lux.Map.prototype.print = function(name, layout, scale, firstPagesUrls, callback 'scale': scale, 'name': name, 'longUrl': longUrl, - 'lang': lux.lang, + 'lang': luxBase.lang, 'legend': '', 'scalebar': {'geodetic': true}, 'dataOwner': dataOwners.join(' '), @@ -539,7 +540,7 @@ lux.Map.prototype.print = function(name, layout, scale, firstPagesUrls, callback * @param {function(string)=} callback Optional callback function. * @private */ -lux.Map.prototype.getStatus_ = function(pm, ref, callback) { +exports.prototype.getStatus_ = function(pm, ref, callback) { pm.getStatus(ref).then( function(resp) { if (resp.status === 200) { @@ -576,7 +577,7 @@ lux.Map.prototype.getStatus_ = function(pm, ref, callback) { * @api * @return {ol.layer.Vector} The show layer. */ -lux.Map.prototype.getShowLayer = function() { +exports.prototype.getShowLayer = function() { return this.showLayer_; }; @@ -585,8 +586,8 @@ lux.Map.prototype.getShowLayer = function() { * @param {Object} translations Set the new translations. * @export */ -lux.Map.prototype.addNewLanguage = function(lang, translations) { - lux.languages[lang.toLowerCase()] = translations; +exports.prototype.addNewLanguage = function(lang, translations) { + luxBase.languages[lang.toLowerCase()] = translations; }; /** @@ -594,21 +595,21 @@ lux.Map.prototype.addNewLanguage = function(lang, translations) { * @export * @api */ -lux.Map.prototype.setLanguage = function(lang) { - var previousLang = lux.lang; +exports.prototype.setLanguage = function(lang) { + var previousLang = luxBase.lang; if (lang === undefined) { - lang = lux.lang; + lang = luxBase.lang; } - lux.lang = lang.toLowerCase(); + luxBase.lang = lang.toLowerCase(); var curLang = lang.toLowerCase(); - if (curLang in lux.languages) { + if (curLang in luxBase.languages) { if (this.layerManagerControl_ !== null && this.layerManagerControl_ !== undefined) { this.layerManagerControl_.update(); } return; } - var langUrl = lux.i18nUrl.replace('xx', curLang); + var langUrl = luxBase.i18nUrl.replace('xx', curLang); this.i18nPromise = fetch(langUrl).then(function(resp) { if (resp === null || resp === undefined) { throw new Error('Invalid response'); @@ -618,14 +619,14 @@ lux.Map.prototype.setLanguage = function(lang) { } throw new Error('' + resp.status + ' ' + resp.statusText); }).then(function(json) { - lux.languages[curLang] = json[curLang]; + luxBase.languages[curLang] = json[curLang]; if (this.layerManagerControl_ !== null && this.layerManagerControl_ !== undefined) { this.layerManagerControl_.update(); } }.bind(this)).catch(function(error) { console.log(error); - lux.lang = previousLang; + luxBase.lang = previousLang; }.bind(this)); }; @@ -637,7 +638,7 @@ lux.Map.prototype.setLanguage = function(lang) { * @export * @api */ -lux.Map.prototype.setQueryableLayers = function(queryableLayers) { +exports.prototype.setQueryableLayers = function(queryableLayers) { this.queryableLayers_ = queryableLayers; }; @@ -648,7 +649,7 @@ lux.Map.prototype.setQueryableLayers = function(queryableLayers) { * @export * @api */ -lux.Map.prototype.showLayerInfoPopup = function(show) { +exports.prototype.showLayerInfoPopup = function(show) { this.showLayerInfoPopup_ = show; }; @@ -660,7 +661,7 @@ lux.Map.prototype.showLayerInfoPopup = function(show) { * @export * @api */ -lux.Map.prototype.setPopupTarget = function(optPopupTarget) { +exports.prototype.setPopupTarget = function(optPopupTarget) { this.popupTarget_ = typeof optPopupTarget === 'string' ? document.getElementById(optPopupTarget) : optPopupTarget; @@ -674,7 +675,7 @@ lux.Map.prototype.setPopupTarget = function(optPopupTarget) { * @export * @api */ -lux.Map.prototype.showMarker = function(opt_options) { +exports.prototype.showMarker = function(opt_options) { var options = opt_options || {}; var element = document.createElement('DIV'); var image = document.createElement('IMG'); @@ -704,7 +705,7 @@ lux.Map.prototype.showMarker = function(opt_options) { var position; if (options.position) { - position = ol.proj.transform( + position = olProj.transform( options.position, (options.positionSrs) ? 'EPSG:' + options.positionSrs.toString() : 'EPSG:2169', @@ -713,7 +714,7 @@ lux.Map.prototype.showMarker = function(opt_options) { } else { position = this.getView().getCenter(); } - var markerOverlay = new ol.Overlay({ + var markerOverlay = new olOverlay({ element: element, position: position, positioning: options.positioning || 'center-center' @@ -727,8 +728,8 @@ lux.Map.prototype.showMarker = function(opt_options) { if (options.html) { var popup; var showPopupEvent = options.click ? - ol.events.EventType.CLICK : ol.events.EventType.MOUSEMOVE; - ol.events.listen(element, showPopupEvent, (function(event) { + olEvents.EventType.CLICK : olEvents.EventType.MOUSEMOVE; + olEvents.listen(element, showPopupEvent, (function(event) { var curMarker = markerOverlay.getElement().firstChild; var isTransparent = false; if (options.noPopupOnTransparency === true) { @@ -759,8 +760,8 @@ lux.Map.prototype.showMarker = function(opt_options) { var cb = !options.click ? undefined : function() { this.removeOverlay(popup); }.bind(this); - var element = lux.buildPopupLayout(options.html, cb); - popup = new ol.Overlay({ + var element = luxBase.buildPopupLayout(options.html, cb); + popup = new olOverlay({ element: element, position: markerOverlay.getPosition(), positioning: 'bottom-center', @@ -774,7 +775,7 @@ lux.Map.prototype.showMarker = function(opt_options) { }).bind(this)); if (!options.click) { - ol.events.listen(element, ol.events.EventType.MOUSEOUT, function() { + olEvents.listen(element, olEvents.EventType.MOUSEOUT, function() { if (options.target) { el.innerHTML = ''; return; @@ -794,11 +795,11 @@ lux.Map.prototype.showMarker = function(opt_options) { * @export * @api */ -lux.getElevation = function(coordinate) { +luxBase.getElevation = function(coordinate) { var lonlat = /** @type {ol.Coordinate} */ - (ol.proj.transform(coordinate, + (olProj.transform(coordinate, 'EPSG:3857', 'EPSG:2169')); - var url = lux.elevationUrl; + var url = luxBase.elevationUrl; url += '?lon=' + lonlat[0] + '&lat=' + lonlat[1]; return fetch(url).then(function(resp) { @@ -811,13 +812,13 @@ lux.getElevation = function(coordinate) { * @return {Object} The layer config * @private */ -lux.Map.prototype.findLayerConf_ = function(layer) { +exports.prototype.findLayerConf_ = function(layer) { var conf = this.layersConfig; var layerConf; if (typeof layer == 'number' || !isNaN(parseInt(layer, 10))) { layerConf = conf[layer]; } else if (typeof layer == 'string') { - layerConf = lux.findLayerByName_(layer, conf); + layerConf = luxBase.findLayerByName_(layer, conf); } if (!layerConf) { console.error('Layer "' + layer + '" not present in layers list'); @@ -832,7 +833,7 @@ lux.Map.prototype.findLayerConf_ = function(layer) { * @param {Array} visibilities Array of layer visibility. * @private */ -lux.Map.prototype.addLayers_ = function(layers, opacities, visibilities) { +exports.prototype.addLayers_ = function(layers, opacities, visibilities) { var conf = this.layersConfig; if (!conf) { @@ -846,7 +847,7 @@ lux.Map.prototype.addLayers_ = function(layers, opacities, visibilities) { var layerConf = this.findLayerConf_(layer); if (layerConf !== null) { var fn = (layerConf.type.indexOf('WMS') != -1) ? - lux.WMSLayerFactory : lux.WMTSLayerFactory; + luxBase.WMSLayerFactory : luxBase.WMTSLayerFactory; var opacity = (opacities[index] !== undefined) ? opacities[index] : 1; var visible = (visibilities[index] !== undefined) ? visibilities[index] : true; this.getLayers().push(fn(layerConf, opacity, visible)); @@ -858,7 +859,7 @@ lux.Map.prototype.addLayers_ = function(layers, opacities, visibilities) { * @param {ol.CollectionEventType} event The event. * @private */ -lux.Map.prototype.checkForExclusion_ = function(event) { +exports.prototype.checkForExclusion_ = function(event) { var layer1 = event.element; if (layer1.get('metadata') === undefined) { @@ -886,7 +887,7 @@ lux.Map.prototype.checkForExclusion_ = function(event) { } exclusion2 = layer2.get('metadata')['exclusion']; - if (lux.intersects(exclusion1, exclusion2)) { + if (luxBase.intersects(exclusion1, exclusion2)) { // layer to exclude is not the current base layer if (i !== 0) { this.removeLayer(layer2); @@ -909,7 +910,7 @@ lux.Map.prototype.checkForExclusion_ = function(event) { * @export * @api */ -lux.Map.prototype.addLayerById = function(layer, opt_opacity, opt_visibility) { +exports.prototype.addLayerById = function(layer, opt_opacity, opt_visibility) { this.layersPromise.then(function() { var opacity = (opt_opacity !== undefined) ? opt_opacity : 1; var visibility = (opt_visibility === undefined) ? opt_visibility : true; @@ -923,7 +924,7 @@ lux.Map.prototype.addLayerById = function(layer, opt_opacity, opt_visibility) { * @return {luxx.LayersOptions|undefined} The layer config. * @private */ -lux.findLayerByName_ = function(name, layers) { +luxBase.findLayerByName_ = function(name, layers) { for (var i in layers) { var layer = layers[i]; if (layer.name == name) { @@ -941,7 +942,7 @@ lux.findLayerByName_ = function(name, layers) { * @export * @api */ -lux.Map.prototype.addBgSelector = function(target) { +exports.prototype.addBgSelector = function(target) { this.layersPromise.then(function() { if (!this.layersConfig) { return; @@ -969,7 +970,7 @@ lux.Map.prototype.addBgSelector = function(target) { backgrounds.forEach(function(background) { var option = document.createElement('option'); option.value = background.id; - option.innerText = lux.translate(background.name); + option.innerText = luxBase.translate(background.name); if (active == background.name) { option.setAttribute('selected', 'selected'); } @@ -979,7 +980,7 @@ lux.Map.prototype.addBgSelector = function(target) { // add blank layer var blankOption = document.createElement('option'); blankOption.value = 'blank'; - blankOption.innerText = lux.translate('blank'); + blankOption.innerText = luxBase.translate('blank'); if (active == 'blank') { blankOption.setAttribute('selected', 'selected'); } @@ -991,7 +992,7 @@ lux.Map.prototype.addBgSelector = function(target) { select.addEventListener('change', function() { if (select.value !== 'blank') { this.getLayers().setAt( - 0, lux.WMTSLayerFactory(this.layersConfig[select.value], 1, true) + 0, luxBase.WMTSLayerFactory(this.layersConfig[select.value], 1, true) ); } else { this.getLayers().setAt(0, this.blankLayer_); @@ -999,7 +1000,7 @@ lux.Map.prototype.addBgSelector = function(target) { }.bind(this)); // update the selector if blank layer is set (after exclusion) - ol.events.listen(this.getLayers(), ol.CollectionEventType.ADD, + olEvents.listen(this.getLayers(), olCollectionEventType.ADD, function(event) { var layer = this.getLayers().getArray()[0]; if (layer == this.blankLayer_) { @@ -1020,7 +1021,7 @@ lux.Map.prototype.addBgSelector = function(target) { * @export * @api */ -lux.Map.prototype.showFeatures = function(layer, ids, opt_click, opt_target, isShowMarker, maxZoom) { +exports.prototype.showFeatures = function(layer, ids, opt_click, opt_target, isShowMarker, maxZoom) { // remove any highlighted feature this.showLayer_.getSource().clear(); this.layersPromise.then(function() { @@ -1034,7 +1035,7 @@ lux.Map.prototype.showFeatures = function(layer, ids, opt_click, opt_target, isS ids = [ids]; } ids.forEach(function(id) { - var uri = lux.queryUrl + 'fid=' + lid + '_' + id + '&tooltip'; + var uri = luxBase.queryUrl + 'fid=' + lid + '_' + id + '&tooltip'; fetch(uri).then(function(resp) { return resp.json(); }).then(function(json) { @@ -1050,13 +1051,13 @@ lux.Map.prototype.showFeatures = function(layer, ids, opt_click, opt_target, isS * @return {Array} the features. * @private */ -lux.Map.prototype.readJsonFeatures_ = function(json) { +exports.prototype.readJsonFeatures_ = function(json) { var features = []; if (json.features != undefined) { json.features.forEach(function(f) { f.properties = f.attributes; }); - features = new ol.format.GeoJSON().readFeatures({ + features = new olFormatGeoJSON().readFeatures({ type: 'FeatureCollection', features: json.features }, { @@ -1076,7 +1077,7 @@ lux.Map.prototype.readJsonFeatures_ = function(json) { * @param {number | undefined} maxZoom The maxZoom to fit. * @private */ -lux.Map.prototype.addFeature_ = function(json, highlight, opt_click, opt_target, isShowMarker, maxZoom) { +exports.prototype.addFeature_ = function(json, highlight, opt_click, opt_target, isShowMarker, maxZoom) { var curMaxZoom = (maxZoom !== undefined) ? maxZoom : 17; if (json.length === 0) { @@ -1095,7 +1096,7 @@ lux.Map.prototype.addFeature_ = function(json, highlight, opt_click, opt_target, features.forEach(function(feature) { if (isShowMarker) { this.showMarker({ - position: ol.extent.getCenter(feature.getGeometry().getExtent()), + position: olExtent.getCenter(feature.getGeometry().getExtent()), positionSrs: '3857', autoCenter: true, click: opt_click, @@ -1103,7 +1104,7 @@ lux.Map.prototype.addFeature_ = function(json, highlight, opt_click, opt_target, html: tooltip }); } - this.featureExtent_ = ol.extent.extend( + this.featureExtent_ = olExtent.extend( this.featureExtent_, feature.getGeometry().getExtent() ); @@ -1129,7 +1130,7 @@ lux.Map.prototype.addFeature_ = function(json, highlight, opt_click, opt_target, * @export * @api */ -lux.Map.prototype.addSearch = function(target, dataSets, onSelect) { +exports.prototype.addSearch = function(target, dataSets, onSelect) { var layers = []; var searchCoordinates = false; if (dataSets !== undefined && dataSets.length > 0) { @@ -1161,14 +1162,14 @@ lux.Map.prototype.addSearch = function(target, dataSets, onSelect) { var coord = item.getAttribute('data-coord').split(',').map(parseFloat); var extent = item.getAttribute('data-extent').split(',').map(parseFloat); this.searchLayer_.getSource().clear(); - this.searchLayer_.getSource().addFeature(new ol.Feature( - new ol.geom.Point( - ol.proj.transform(coord, 'EPSG:4326', 'EPSG:3857') + this.searchLayer_.getSource().addFeature(new olFeature( + new olGeomPoint( + olProj.transform(coord, 'EPSG:4326', 'EPSG:3857') ) )); this.getView().fit( - ol.geom.Polygon.fromExtent( - ol.proj.transformExtent(extent, 'EPSG:4326', 'EPSG:3857') + olGeomPolygon.fromExtent( + olProj.transformExtent(extent, 'EPSG:4326', 'EPSG:3857') ), /** @type {olx.view.FitOptions} */ ({ size: /** @type {Array} */ (this.getSize()), @@ -1183,7 +1184,7 @@ lux.Map.prototype.addSearch = function(target, dataSets, onSelect) { var input = document.createElement('input'); input.classList.add('lux-search-input'); - input.setAttribute('placeholder', lux.translate('search')); + input.setAttribute('placeholder', luxBase.translate('search')); container.appendChild(input); var clear = document.createElement('button'); clear.classList.add('lux-search-clear'); @@ -1201,14 +1202,14 @@ lux.Map.prototype.addSearch = function(target, dataSets, onSelect) { clear.style.display = (input.value == '') ? '' : 'block'; }); - this.searchLayer_ = new ol.layer.Vector({ - source: new ol.source.Vector() + this.searchLayer_ = new olLayerVector({ + source: new olSourceVector() }); this.searchLayer_.setStyle(this.vectorStyle_); this.searchLayer_.setMap(this); - var format = new ol.format.GeoJSON(); + var format = new olFormatGeoJSON(); new autoComplete({ @@ -1224,7 +1225,7 @@ lux.Map.prototype.addSearch = function(target, dataSets, onSelect) { } if (layers.length > 0) { term = term.toLowerCase(); - fetch(lux.searchUrl + 'limit=5&layer=' + layers.join(',') + '&query=' + term).then(function(resp) { + fetch(luxBase.searchUrl + 'limit=5&layer=' + layers.join(',') + '&query=' + term).then(function(resp) { return resp.json(); }).then(function(json) { suggest(coordResults.concat(json.features)); @@ -1257,10 +1258,10 @@ lux.Map.prototype.addSearch = function(target, dataSets, onSelect) { * @return {Array} The result. * @private */ -lux.Map.prototype.matchCoordinate_ = function(searchString) { +exports.prototype.matchCoordinate_ = function(searchString) { searchString = searchString.replace(/,/gi, '.'); var results = []; - var format = new ol.format.GeoJSON(); + var format = new olFormatGeoJSON(); var re = { 'EPSG:2169': { regex: /(\d{4,6}[\,\.]?\d{0,3})\s*([E|N])?\W*(\d{4,6}[\,\.]?\d{0,3})\s*([E|N])?/, @@ -1301,12 +1302,12 @@ lux.Map.prototype.matchCoordinate_ = function(searchString) { var northing = undefined; if (epsgKey === 'EPSG:4326' || epsgKey === 'EPSG:2169') { if (m[2] !== undefined && m[2] !== null && m[4] !== undefined && m[4] !== null) { - if (ol.array.includes(northArray, m[2].toUpperCase()) && - ol.array.includes(eastArray, m[4].toUpperCase())) { + if (olArray.includes(northArray, m[2].toUpperCase()) && + olArray.includes(eastArray, m[4].toUpperCase())) { easting = parseFloat(m[3].replace(',', '.')); northing = parseFloat(m[1].replace(',', '.')); - } else if (ol.array.includes(northArray, m[4].toUpperCase()) && - ol.array.includes(eastArray, m[2].toUpperCase())) { + } else if (olArray.includes(northArray, m[4].toUpperCase()) && + olArray.includes(eastArray, m[2].toUpperCase())) { easting = parseFloat(m[1].replace(',', '.')); northing = parseFloat(m[3].replace(',', '.')); } @@ -1350,23 +1351,23 @@ lux.Map.prototype.matchCoordinate_ = function(searchString) { if (easting !== undefined && northing !== undefined) { var mapEpsgCode = 'EPSG:4326'; var point = /** @type {ol.geom.Point} */ - (new ol.geom.Point([easting, northing]) + (new olGeomPoint([easting, northing]) .transform(epsgCode, mapEpsgCode)); var flippedPoint = /** @type {ol.geom.Point} */ - (new ol.geom.Point([northing, easting]) + (new olGeomPoint([northing, easting]) .transform(epsgCode, mapEpsgCode)); var feature = /** @type {ol.Feature} */ (null); - if (ol.extent.containsCoordinate( + if (olExtent.containsCoordinate( this.maxExtent_, point.getCoordinates())) { - feature = new ol.Feature(point); - } else if (epsgCode === 'EPSG:4326' && ol.extent.containsCoordinate( + feature = new olFeature(point); + } else if (epsgCode === 'EPSG:4326' && olExtent.containsCoordinate( this.maxExtent_, flippedPoint.getCoordinates())) { - feature = new ol.Feature(flippedPoint); + feature = new olFeature(flippedPoint); } if (feature !== null) { var resultPoint = /** @type {ol.geom.Point} */ (feature.getGeometry()); - var resultString = lux.coordinateString_( + var resultString = luxBase.coordinateString_( resultPoint.getCoordinates(), mapEpsgCode, epsgCode, isDms, false); feature.set('label', resultString); feature.set('epsgLabel', re[epsgKey].label); @@ -1383,7 +1384,7 @@ lux.Map.prototype.matchCoordinate_ = function(searchString) { * @return {Object | undefined} Returns the coordinate. * @private */ -lux.Map.prototype.decDegFromMatch_ = function(m) { +exports.prototype.decDegFromMatch_ = function(m) { var signIndex = { '-': -1, 'N': 1, @@ -1429,7 +1430,7 @@ lux.Map.prototype.decDegFromMatch_ = function(m) { * @export * @api */ -lux.Map.prototype.addGPX = function(url, opt_options) { +exports.prototype.addGPX = function(url, opt_options) { /** @type {ol.StyleFunction | undefined}*/ var styleFunction; @@ -1437,26 +1438,26 @@ lux.Map.prototype.addGPX = function(url, opt_options) { styleFunction = opt_options.style; } else { var style = { - 'Point': new ol.style.Style({ - image: new ol.style.Circle({ - fill: new ol.style.Fill({ + 'Point': new olStyleStyle({ + image: new olStyleCircle({ + fill: new olStyleFill({ color: 'rgba(255,255,0,0.4)' }), radius: 5, - stroke: new ol.style.Stroke({ + stroke: new olStyleStroke({ color: '#ff0', width: 1 }) }) }), - 'LineString': new ol.style.Style({ - stroke: new ol.style.Stroke({ + 'LineString': new olStyleStyle({ + stroke: new olStyleStroke({ color: '#f00', width: 3 }) }), - 'MultiLineString': new ol.style.Style({ - stroke: new ol.style.Stroke({ + 'MultiLineString': new olStyleStyle({ + stroke: new olStyleStroke({ color: '#f00', width: 3 }) @@ -1467,7 +1468,7 @@ lux.Map.prototype.addGPX = function(url, opt_options) { }; } - this.addVector_(url, new ol.format.GPX(), { + this.addVector_(url, new olFormatGPX(), { style: styleFunction, reloadInterval: opt_options && opt_options.reloadInterval, click: opt_options.click, @@ -1484,8 +1485,8 @@ lux.Map.prototype.addGPX = function(url, opt_options) { * @export * @api */ -lux.Map.prototype.addKML = function(url, opt_options) { - this.addVector_(url, new ol.format.KML(), opt_options); +exports.prototype.addKML = function(url, opt_options) { + this.addVector_(url, new olFormatKML(), opt_options); }; /** @@ -1495,8 +1496,8 @@ lux.Map.prototype.addKML = function(url, opt_options) { * @export * @api */ -lux.Map.prototype.addGeoJSON = function(url, opt_options) { - this.addVector_(url, new ol.format.GeoJSON(), opt_options); +exports.prototype.addGeoJSON = function(url, opt_options) { + this.addVector_(url, new olFormatGeoJSON(), opt_options); }; /** @@ -1506,7 +1507,7 @@ lux.Map.prototype.addGeoJSON = function(url, opt_options) { * @param {luxx.VectorOptions=} opt_options Options. * @private */ -lux.Map.prototype.addVector_ = function(url, format, opt_options) { +exports.prototype.addVector_ = function(url, format, opt_options) { var popup; var vector; var el; @@ -1532,7 +1533,7 @@ lux.Map.prototype.addVector_ = function(url, format, opt_options) { if (opt_time) { uri.search = 'salt=' + (new Date).getTime(); } - vector.setSource(new ol.source.Vector({ + vector.setSource(new olSourceVector({ url: uri.toString(), format: format })); @@ -1546,7 +1547,7 @@ lux.Map.prototype.addVector_ = function(url, format, opt_options) { options.name = opt_options.name; } this.layersPromise.then(function() { - vector = new ol.layer.Vector(options); + vector = new olLayerVector(options); var interval = opt_options && opt_options.reloadInterval; if (interval) { @@ -1560,7 +1561,7 @@ lux.Map.prototype.addVector_ = function(url, format, opt_options) { this.addedKmlLayers_.push(vector); this.addedKmlOnClick_.push(opt_options.onClick); if (fit) { - ol.events.listen(vector.getSource(), ol.source.VectorEventType.ADDFEATURE, + olEvents.listen(vector.getSource(), olSourceVectorEventType.ADDFEATURE, function() { var size = this.getSize(); console.assert(size !== undefined, 'size should be defined'); @@ -1570,7 +1571,7 @@ lux.Map.prototype.addVector_ = function(url, format, opt_options) { } if (opt_options && opt_options.click) { - var interaction = new ol.interaction.Select({ + var interaction = new olInteractionSelect({ layers: this.addedKmlLayers_ }); this.addInteraction(interaction); @@ -1613,11 +1614,11 @@ lux.Map.prototype.addVector_ = function(url, format, opt_options) { el.innerHTML = html; return; } - var element = lux.buildPopupLayout(html, function() { + var element = luxBase.buildPopupLayout(html, function() { this.removeOverlay(popup); interaction.getFeatures().clear(); }.bind(this)); - popup = new ol.Overlay({ + popup = new olOverlay({ element: element, position: e.mapBrowserEvent.coordinate, positioning: 'bottom-center', @@ -1640,14 +1641,14 @@ lux.Map.prototype.addVector_ = function(url, format, opt_options) { * @export * @api */ -lux.Map.prototype.showPopup = function(position, title, content) { +exports.prototype.showPopup = function(position, title, content) { var popup; - var element = lux.buildPopupLayout(content, function() { + var element = luxBase.buildPopupLayout(content, function() { if (popup !== undefined) { this.removeOverlay(popup); } }.bind(this), title); - popup = new ol.Overlay({ + popup = new olOverlay({ element: element, position: position, positioning: 'bottom-center', @@ -1680,10 +1681,10 @@ lux.Map.prototype.showPopup = function(position, title, content) { * @export * @api */ -lux.Map.prototype.addMyMapLayer = function(options) { +exports.prototype.addMyMapLayer = function(options) { this.stateManager_.setMyMap(options.mapId); return Promise.all([this.i18nPromise, this.layersPromise]).then(function() { - var mymap = new lux.MyMap(options); + var mymap = new luxMyMap(options); mymap.setMap(this); return mymap; }.bind(this)); @@ -1693,7 +1694,7 @@ lux.Map.prototype.addMyMapLayer = function(options) { * Removes the popup or the information content. * @export */ -lux.Map.prototype.removeInfoPopup = function() { +exports.prototype.removeInfoPopup = function() { if (this.queryPopup_) { this.removeOverlay(this.queryPopup_); } @@ -1709,7 +1710,7 @@ lux.Map.prototype.removeInfoPopup = function() { * @param {function(Object)} callback The function to call. * @export */ -lux.Map.prototype.getFeatureInfoByIds = function(layer, ids, callback) { +exports.prototype.getFeatureInfoByIds = function(layer, ids, callback) { this.layersPromise.then(function() { var lid = this.findLayerConf_(layer).id; @@ -1717,7 +1718,7 @@ lux.Map.prototype.getFeatureInfoByIds = function(layer, ids, callback) { ids = [ids]; } ids.forEach(function(id) { - var uri = lux.queryUrl + 'fid=' + lid + '_' + id + '&tooltip'; + var uri = luxBase.queryUrl + 'fid=' + lid + '_' + id + '&tooltip'; fetch(uri).then(function(resp) { return resp.json(); }).then(function(json) { @@ -1732,7 +1733,7 @@ lux.Map.prototype.getFeatureInfoByIds = function(layer, ids, callback) { * @param {function(?)} callback The function to call. * @export */ -lux.Map.prototype.getFeatureInfo = function(evt, callback) { +exports.prototype.getFeatureInfo = function(evt, callback) { var layers = this.getLayers().getArray(); // collect the queryable layers @@ -1761,21 +1762,21 @@ lux.Map.prototype.getFeatureInfo = function(evt, callback) { var bigBuffer = 20; var smallBuffer = 1; - var lb = ol.proj.transform( + var lb = olProj.transform( this.getCoordinateFromPixel( [evt.pixel[0] - bigBuffer, evt.pixel[1] + bigBuffer]), this.getView().getProjection(), 'EPSG:2169'); - var rt = ol.proj.transform( + var rt = olProj.transform( this.getCoordinateFromPixel( [evt.pixel[0] + bigBuffer, evt.pixel[1] - bigBuffer]), this.getView().getProjection(), 'EPSG:2169'); var big_box = lb.concat(rt); - lb = ol.proj.transform( + lb = olProj.transform( this.getCoordinateFromPixel( [evt.pixel[0] - smallBuffer, evt.pixel[1] + smallBuffer]), this.getView().getProjection(), 'EPSG:2169'); - rt = ol.proj.transform( + rt = olProj.transform( this.getCoordinateFromPixel( [evt.pixel[0] + smallBuffer, evt.pixel[1] - smallBuffer]), this.getView().getProjection(), 'EPSG:2169'); @@ -1796,11 +1797,11 @@ lux.Map.prototype.getFeatureInfo = function(evt, callback) { 'X': evt.pixel[0], 'Y': evt.pixel[1], 'tooltip': 1, - 'lang': lux.lang, + 'lang': luxBase.lang, 'srs': 'EPSG:3857' }; var url = document.createElement('A'); - url.href = lux.queryUrl; + url.href = luxBase.queryUrl; Object.keys(params).forEach(function(key) { url.search = url.search + '&' + key + '=' + params[key]; @@ -1819,7 +1820,7 @@ lux.Map.prototype.getFeatureInfo = function(evt, callback) { * @export * @api */ -lux.Map.prototype.setShowlayerStyle = function(style) { +exports.prototype.setShowlayerStyle = function(style) { this.showLayer_.setStyle(style); }; @@ -1827,7 +1828,7 @@ lux.Map.prototype.setShowlayerStyle = function(style) { * @param {Object} evt The event. * @private */ -lux.Map.prototype.handleSingleclickEvent_ = function(evt) { +exports.prototype.handleSingleclickEvent_ = function(evt) { this.removeInfoPopup(); if (!this.showLayerInfoPopup_) { return; @@ -1853,10 +1854,10 @@ lux.Map.prototype.handleSingleclickEvent_ = function(evt) { if (this.popupTarget_) { this.popupTarget_.innerHTML = htmls.join(''); } else { - var element = lux.buildPopupLayout(htmls.join('
'), function() { + var element = luxBase.buildPopupLayout(htmls.join('
'), function() { this.removeOverlay(this.queryPopup_); }.bind(this)); - this.queryPopup_ = new ol.Overlay({ + this.queryPopup_ = new olOverlay({ element: element, position: this.getCoordinateFromPixel([evt.pixel[0], evt.pixel[1]]), positioning: 'bottom-center', diff --git a/jsapi/src/mymap.js b/jsapi/src/mymap.js index 26324b69e..1f9d82007 100644 --- a/jsapi/src/mymap.js +++ b/jsapi/src/mymap.js @@ -1,35 +1,36 @@ -goog.provide('lux.MyMap'); - -goog.require('lux'); -goog.require('ngeo.interaction.Measure'); -goog.require('ngeo.profile.d3Elevation'); -goog.require('ol.format.GeoJSON'); -goog.require('ol.interaction.Select'); -goog.require('ol.layer.Vector'); -goog.require('ol.style.Fill'); -goog.require('ol.style.Icon'); -goog.require('ol.style.RegularShape'); -goog.require('ol.style.Style'); -goog.require('ol.style.Stroke'); -goog.require('ol.style.Text'); -goog.require('ol.source.Vector'); -goog.require('ol.format.KML'); -goog.require('ol.format.GPX'); -goog.require('ol.style.Circle'); -goog.require('ol.events'); -goog.require('ol.obj'); -goog.require('ol.Overlay'); -goog.require('ol.events.EventType'); -goog.require('ol.geom.LineString'); -goog.require('ol.geom.Polygon'); -goog.require('ol.geom.MultiPoint'); -goog.require('ol.geom.Point'); -goog.require('ol.geom.GeometryType'); -goog.require('ol.MapBrowserEventType'); -goog.require('ol.geom.GeometryLayout'); -goog.require('ol.Feature'); -goog.require('ol.extent'); -goog.require('ol.geom.MultiLineString'); +goog.module('lux.MyMap'); + +goog.module.declareLegacyNamespace(); +const luxBase = goog.require('lux'); +const ngeoInteractionMeasure = goog.require('ngeo.interaction.Measure'); +const ngeoProfileD3Elevation = goog.require('ngeo.profile.d3Elevation'); +const olFormatGeoJSON = goog.require('ol.format.GeoJSON'); +const olInteractionSelect = goog.require('ol.interaction.Select'); +const olLayerVector = goog.require('ol.layer.Vector'); +const olStyleFill = goog.require('ol.style.Fill'); +const olStyleIcon = goog.require('ol.style.Icon'); +const olStyleRegularShape = goog.require('ol.style.RegularShape'); +const olStyleStyle = goog.require('ol.style.Style'); +const olStyleStroke = goog.require('ol.style.Stroke'); +const olStyleText = goog.require('ol.style.Text'); +const olSourceVector = goog.require('ol.source.Vector'); +const olFormatKML = goog.require('ol.format.KML'); +const olFormatGPX = goog.require('ol.format.GPX'); +const olStyleCircle = goog.require('ol.style.Circle'); +const olEvents = goog.require('ol.events'); +const olObj = goog.require('ol.obj'); +const olOverlay = goog.require('ol.Overlay'); +const olEventsEventType = goog.require('ol.events.EventType'); +const olGeomLineString = goog.require('ol.geom.LineString'); +const olGeomPolygon = goog.require('ol.geom.Polygon'); +const olGeomMultiPoint = goog.require('ol.geom.MultiPoint'); +const olGeomPoint = goog.require('ol.geom.Point'); +const olGeomGeometryType = goog.require('ol.geom.GeometryType'); +const olMapBrowserEventType = goog.require('ol.MapBrowserEventType'); +const olGeomGeometryLayout = goog.require('ol.geom.GeometryLayout'); +const olFeature = goog.require('ol.Feature'); +const olExtent = goog.require('ol.extent'); +const olGeomMultiLineString = goog.require('ol.geom.MultiLineString'); /** @@ -40,7 +41,7 @@ goog.require('ol.geom.MultiLineString'); * @param {luxx.MyMapOptions} options The options. * @api stable */ -lux.MyMap = function(options) { +exports = function(options) { /** * @type {string} @@ -70,7 +71,7 @@ lux.MyMap = function(options) { this.profile_ = null; - this.featureOverlay_ = new ol.source.Vector(); + this.featureOverlay_ = new olSourceVector(); /** * @type {ol.geom.LineString} @@ -112,18 +113,18 @@ lux.MyMap = function(options) { * @private * @type {ol.format.KML} */ - this.kmlFormat_ = new ol.format.KML(); + this.kmlFormat_ = new olFormatKML(); /** * @private * @type {ol.format.GPX} */ - this.gpxFormat_ = new ol.format.GPX(); + this.gpxFormat_ = new olFormatGPX(); - this.mymapsSymbolUrl_ = [lux.mymapsUrl, 'symbol/'].join('/'); - this.arrowUrl_ = [lux.mymapsUrl, 'getarrow'].join('/'); - this.exportGpxUrl_ = [lux.mymapsUrl, 'exportgpxkml'].join('/'); - this.exportCsvUrl_ = lux.exportCsvUrl; + this.mymapsSymbolUrl_ = [luxBase.mymapsUrl, 'symbol/'].join('/'); + this.arrowUrl_ = [luxBase.mymapsUrl, 'getarrow'].join('/'); + this.exportGpxUrl_ = [luxBase.mymapsUrl, 'exportgpxkml'].join('/'); + this.exportCsvUrl_ = luxBase.exportCsvUrl; /** * @private @@ -138,7 +139,7 @@ lux.MyMap = function(options) { * @export * @api */ -lux.MyMap.prototype.setMap = function(map) { +exports.prototype.setMap = function(map) { /** * @type {lux.Map} @@ -146,21 +147,21 @@ lux.MyMap.prototype.setMap = function(map) { */ this.map_ = map; - var layer = new ol.layer.Vector({ + var layer = new olLayerVector({ source: this.featureOverlay_ }); layer.setStyle([ - new ol.style.Style({ - image: new ol.style.Circle({ + new olStyleStyle({ + image: new olStyleCircle({ radius: 6, - fill: new ol.style.Fill({color: '#ff0000'}) + fill: new olStyleFill({color: '#ff0000'}) }) }), - new ol.style.Style({ - image: new ol.style.Circle({ + new olStyleStyle({ + image: new olStyleCircle({ radius: 5, - fill: new ol.style.Fill({color: '#ffffff'}) + fill: new olStyleFill({color: '#ffffff'}) }) })]); layer.setMap(this.map_); @@ -174,15 +175,15 @@ lux.MyMap.prototype.setMap = function(map) { * Load the features. * @private */ -lux.MyMap.prototype.loadFeatures_ = function() { +exports.prototype.loadFeatures_ = function() { - var url = [lux.mymapsUrl, 'features', this.id_].join('/'); + var url = [luxBase.mymapsUrl, 'features', this.id_].join('/'); fetch(url).then(function(resp) { return resp.json(); }).then(function(json) { - var format = new ol.format.GeoJSON(); - this.sourceFeatures_ = new ol.source.Vector(); - var vector = new ol.layer.Vector({ + var format = new olFormatGeoJSON(); + this.sourceFeatures_ = new olSourceVector(); + var vector = new olLayerVector({ source: this.sourceFeatures_ }); this.map_.addLayer(vector); @@ -202,11 +203,11 @@ lux.MyMap.prototype.loadFeatures_ = function() { var size = /** @type {Array} */ (this.map_.getSize()); this.map_.getView().fit(this.sourceFeatures_.getExtent(), {size: size}); - this.selectInteraction_ = new ol.interaction.Select({ + this.selectInteraction_ = new olInteractionSelect({ layers: [vector] }); this.map_.addInteraction(this.selectInteraction_); - ol.events.listen( + olEvents.listen( this.selectInteraction_, 'select', this.onFeatureSelected_, this); @@ -217,7 +218,7 @@ lux.MyMap.prototype.loadFeatures_ = function() { * @param {ol.interaction.Select.Event} event The select event. * @private */ -lux.MyMap.prototype.onFeatureSelected_ = function(event) { +exports.prototype.onFeatureSelected_ = function(event) { var features = event.selected; if (this.popup_) { @@ -242,11 +243,11 @@ lux.MyMap.prototype.onFeatureSelected_ = function(event) { } if (properties.thumbnail) { var link = document.createElement('A'); - link.setAttribute('href', lux.baseUrl + properties.image); + link.setAttribute('href', luxBase.baseUrl + properties.image); link.setAttribute('target', '_blank'); var thumb = document.createElement('IMG'); - thumb.setAttribute('src', lux.baseUrl + properties.thumbnail); + thumb.setAttribute('src', luxBase.baseUrl + properties.thumbnail); link.appendChild(thumb); content.appendChild(link); @@ -255,9 +256,9 @@ lux.MyMap.prototype.onFeatureSelected_ = function(event) { content.appendChild(element); }); - var element = lux.buildPopupLayout(content, function() {}); + var element = luxBase.buildPopupLayout(content, function() {}); - this.popup_ = new ol.Overlay({ + this.popup_ = new olOverlay({ element: element, positioning: 'bottom-center', offset: [0, -20], @@ -266,7 +267,7 @@ lux.MyMap.prototype.onFeatureSelected_ = function(event) { }); var closeBtn = element.querySelectorAll('.lux-popup-close')[0]; - ol.events.listen(closeBtn, ol.events.EventType.CLICK, function() { + olEvents.listen(closeBtn, olEventsEventType.CLICK, function() { this.map_.removeOverlay(this.popup_); this.popup_ = null; this.selectInteraction_.getFeatures().clear(); @@ -281,19 +282,19 @@ lux.MyMap.prototype.onFeatureSelected_ = function(event) { * @return {ol.FeatureStyleFunction} The Function to style. * @private */ -lux.MyMap.prototype.createStyleFunction_ = function(curMap) { +exports.prototype.createStyleFunction_ = function(curMap) { var styles = []; - var vertexStyle = new ol.style.Style({ - image: new ol.style.RegularShape({ + var vertexStyle = new olStyleStyle({ + image: new olStyleRegularShape({ radius: 6, points: 4, angle: Math.PI / 4, - fill: new ol.style.Fill({ + fill: new olStyleFill({ color: [255, 255, 255, 0.5] }), - stroke: new ol.style.Stroke({ + stroke: new olStyleStroke({ color: [0, 0, 0, 1] }) }), @@ -301,19 +302,19 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { var geom = feature.getGeometry(); var coordinates; - if (geom instanceof ol.geom.LineString) { + if (geom instanceof olGeomLineString) { coordinates = geom.getCoordinates(); - return new ol.geom.MultiPoint(coordinates); - } else if (geom instanceof ol.geom.Polygon) { + return new olGeomMultiPoint(coordinates); + } else if (geom instanceof olGeomPolygon) { coordinates = geom.getCoordinates()[0]; - return new ol.geom.MultiPoint(coordinates); + return new olGeomMultiPoint(coordinates); } else { return geom; } } }); - var fillStyle = new ol.style.Fill(); + var fillStyle = new olStyleFill(); var symbolUrl = this.mymapsSymbolUrl_; var arrowUrl = this.arrowUrl_; return function(resolution) { @@ -339,7 +340,7 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { rgbaColor.push(opacity); fillStyle.setColor(rgbaColor); - if (this.getGeometry().getType() === ol.geom.GeometryType.LINE_STRING && + if (this.getGeometry().getType() === olGeomGeometryType.LINE_STRING && this.get('showOrientation') === true) { var prevArrow, distance; var arrowColor = this.get('arrowcolor'); @@ -347,7 +348,7 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { arrowColor = color; } this.getGeometry().forEachSegment(function(start, end) { - var arrowPoint = new ol.geom.Point( + var arrowPoint = new olGeomPoint( [(start[0] + end[0]) / 2, (start[1] + end[1]) / 2]); var dx = end[0] - start[0]; var dy = end[1] - start[1]; @@ -362,9 +363,9 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { if (!prevArrow || distance > 600) { var coloredArrowUrl = arrowUrl + '?color=' + arrowColor.replace('#', ''); // arrows - styles.push(new ol.style.Style({ + styles.push(new olStyleStyle({ geometry: arrowPoint, - image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({ + image: new olStyleIcon(/** @type {olx.style.IconOptions} */ ({ rotation: Math.PI / 2 - Math.atan2(dy, dx), src: coloredArrowUrl })) @@ -393,7 +394,7 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { if (!this.get('__editable__') && this.get('__selected__')) { featureStroke = featureStroke + 3; } - stroke = new ol.style.Stroke({ + stroke = new olStyleStroke({ color: rgbColor, width: featureStroke, lineDash: lineDash @@ -406,7 +407,7 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { } var imageOptions = { fill: fillStyle, - stroke: new ol.style.Stroke({ + stroke: new olStyleStroke({ color: rgbColor, width: featureSize / 7 }), @@ -414,12 +415,12 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { }; var image = null; if (this.get('symbolId')) { - ol.obj.assign(imageOptions, { + olObj.assign(imageOptions, { src: symbolUrl + this.get('symbolId'), scale: featureSize / 100, rotation: this.get('angle') }); - image = new ol.style.Icon(imageOptions); + image = new olStyleIcon(imageOptions); } else { var shape = this.get('shape'); if (!shape) { @@ -427,62 +428,62 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { shape = 'circle'; } if (shape === 'circle') { - image = new ol.style.Circle(imageOptions); + image = new olStyleCircle(imageOptions); } else if (shape === 'square') { - ol.obj.assign(imageOptions, ({ + olObj.assign(imageOptions, ({ points: 4, angle: Math.PI / 4, rotation: this.get('angle') })); - image = new ol.style.RegularShape( + image = new olStyleRegularShape( /** @type {olx.style.RegularShapeOptions} */ (imageOptions)); } else if (shape === 'triangle') { - ol.obj.assign(imageOptions, ({ + olObj.assign(imageOptions, ({ points: 3, angle: 0, rotation: this.get('angle') })); - image = new ol.style.RegularShape( + image = new olStyleRegularShape( /** @type {olx.style.RegularShapeOptions} */ (imageOptions)); } else if (shape === 'star') { - ol.obj.assign(imageOptions, ({ + olObj.assign(imageOptions, ({ points: 5, angle: Math.PI / 4, rotation: this.get('angle'), radius2: featureSize })); - image = new ol.style.RegularShape( + image = new olStyleRegularShape( /** @type {olx.style.RegularShapeOptions} */ (imageOptions)); } else if (this.get('shape') == 'cross') { - ol.obj.assign(imageOptions, ({ + olObj.assign(imageOptions, ({ points: 4, angle: 0, rotation: this.get('angle'), radius2: 0 })); - image = new ol.style.RegularShape( + image = new olStyleRegularShape( /** @type {olx.style.RegularShapeOptions} */ (imageOptions)); } } if (this.get('isLabel')) { - return [new ol.style.Style({ - text: new ol.style.Text(/** @type {olx.style.TextOptions} */ ({ + return [new olStyleStyle({ + text: new olStyleText(/** @type {olx.style.TextOptions} */ ({ text: this.get('name'), textAlign: 'start', font: 'normal ' + featureSize + 'px Sans-serif', rotation: this.get('angle'), - fill: new ol.style.Fill({ + fill: new olStyleFill({ color: rgbColor }), - stroke: new ol.style.Stroke({ + stroke: new olStyleStroke({ color: [255, 255, 255], width: 2 }) })) })]; } else { - styles.push(new ol.style.Style({ + styles.push(new olStyleStyle({ image: image, fill: fillStyle, stroke: stroke @@ -497,37 +498,37 @@ lux.MyMap.prototype.createStyleFunction_ = function(curMap) { * @param {ol.Feature} feature The feature. * @return {Array} The formatted measure. */ -lux.MyMap.prototype.getMeasures = function(feature) { +exports.prototype.getMeasures = function(feature) { var elements = []; var geom = feature.getGeometry(); var projection = this.map_.getView().getProjection(); console.assert(projection); - if (geom.getType() === ol.geom.GeometryType.POLYGON || - geom.getType() === ol.geom.GeometryType.LINE_STRING) { + if (geom.getType() === olGeomGeometryType.POLYGON || + geom.getType() === olGeomGeometryType.LINE_STRING) { var lengthEl = document.createElement('P'); - console.assert(geom instanceof ol.geom.LineString || - geom instanceof ol.geom.Polygon); + console.assert(geom instanceof olGeomLineString || + geom instanceof olGeomPolygon); - var coordinates = (geom.getType() === ol.geom.GeometryType.POLYGON) ? + var coordinates = (geom.getType() === olGeomGeometryType.POLYGON) ? /** @type{ol.geom.Polygon}*/(geom).getCoordinates()[0] : /** @type{ol.geom.LineString}*/(geom).getCoordinates(); - var length = ngeo.interaction.Measure.getFormattedLength( - new ol.geom.LineString(coordinates), + var length = ngeoInteractionMeasure.getFormattedLength( + new olGeomLineString(coordinates), /** @type{!ol.proj.Projection} */(projection), undefined, function(measure) { return measure.toString(); } ); - lengthEl.appendChild(document.createTextNode(lux.translate('Length:') + ' ' + length)); + lengthEl.appendChild(document.createTextNode(luxBase.translate('Length:') + ' ' + length)); elements.push(lengthEl); } - if (geom.getType() === ol.geom.GeometryType.POLYGON) { + if (geom.getType() === olGeomGeometryType.POLYGON) { var areaEl = document.createElement('P'); - console.assert(geom instanceof ol.geom.Polygon); + console.assert(geom instanceof olGeomPolygon); - var area = ngeo.interaction.Measure.getFormattedArea( + var area = ngeoInteractionMeasure.getFormattedArea( /** @type{!ol.geom.Polygon} */(geom), /** @type{!ol.proj.Projection} */(projection), undefined, @@ -535,16 +536,16 @@ lux.MyMap.prototype.getMeasures = function(feature) { return measure.toString(); } ); - areaEl.appendChild(document.createTextNode(lux.translate('Area:') + ' ' + area)); + areaEl.appendChild(document.createTextNode(luxBase.translate('Area:') + ' ' + area)); elements.push(areaEl); } - if (geom.getType() === ol.geom.GeometryType.POLYGON && + if (geom.getType() === olGeomGeometryType.POLYGON && !!feature.get('isCircle')) { var radiusEl = document.createElement('P'); - console.assert(geom instanceof ol.geom.Polygon); - var center = ol.extent.getCenter(geom.getExtent()); - var line = new ol.geom.LineString([center, /** @type{ol.geom.Polygon} */(geom).getLastCoordinate()]); - var radius = ngeo.interaction.Measure.getFormattedLength( + console.assert(geom instanceof olGeomPolygon); + var center = olExtent.getCenter(geom.getExtent()); + var line = new olGeomLineString([center, /** @type{ol.geom.Polygon} */(geom).getLastCoordinate()]); + var radius = ngeoInteractionMeasure.getFormattedLength( line, /** @type{!ol.proj.Projection} */(projection), undefined, @@ -552,20 +553,20 @@ lux.MyMap.prototype.getMeasures = function(feature) { return measure.toString(); } ); - radiusEl.appendChild(document.createTextNode(lux.translate('Rayon:') + ' ' + radius)); + radiusEl.appendChild(document.createTextNode(luxBase.translate('Rayon:') + ' ' + radius)); elements.push(radiusEl); } - if (geom.getType() === ol.geom.GeometryType.POINT && + if (geom.getType() === olGeomGeometryType.POINT && !feature.get('isLabel')) { var elevationEl = document.createElement('P'); - console.assert(geom instanceof ol.geom.Point); + console.assert(geom instanceof olGeomPoint); elevationEl.appendChild(document.createTextNode('N/A')); - lux.getElevation(/** @type{!ol.geom.Point} */ (geom).getCoordinates()).then( + luxBase.getElevation(/** @type{!ol.geom.Point} */ (geom).getCoordinates()).then( function(json) { if (json['dhm'] > 0) { - elevationEl.appendChild(document.createTextNode(lux.translate('Elevation') + ': ' + + elevationEl.appendChild(document.createTextNode(luxBase.translate('Elevation') + ': ' + parseInt(json['dhm'], 0).toString() + ' m')); } } @@ -578,24 +579,24 @@ lux.MyMap.prototype.getMeasures = function(feature) { var link = document.createElement('A'); link.setAttribute('href', 'javascript:void(0);'); - link.appendChild(document.createTextNode(lux.translate('Zoom to'))); + link.appendChild(document.createTextNode(luxBase.translate('Zoom to'))); links.appendChild(link); - ol.events.listen(link, ol.events.EventType.CLICK, function() { + olEvents.listen(link, olEventsEventType.CLICK, function() { var size = /** @type {Array} */ (this.map_.getSize()); var extent = /** @type {Array} */ (geom.getExtent()); this.map_.getView().fit(extent, {size: size}); }.bind(this)); if (this.profileContainer_ && - geom.getType() === ol.geom.GeometryType.LINE_STRING) { - console.assert(geom instanceof ol.geom.LineString); + geom.getType() === olGeomGeometryType.LINE_STRING) { + console.assert(geom instanceof olGeomLineString); link = document.createElement('A'); link.setAttribute('href', 'javascript:void(0);'); - link.appendChild(document.createTextNode(lux.translate('Profile'))); + link.appendChild(document.createTextNode(luxBase.translate('Profile'))); links.appendChild(link); - ol.events.listen(link, ol.events.EventType.CLICK, function() { - console.assert(geom instanceof ol.geom.LineString); + olEvents.listen(link, olEventsEventType.CLICK, function() { + console.assert(geom instanceof olGeomLineString); console.assert(this.profileContainer_ instanceof Element); this.loadProfile( /** @type{ol.geom.LineString} */ (geom), @@ -603,7 +604,7 @@ lux.MyMap.prototype.getMeasures = function(feature) { var closeBtn = this.profileContainer_.querySelectorAll( '.lux-profile-header .lux-profile-close')[0]; closeBtn.style.display = 'block'; - ol.events.listen(closeBtn, ol.events.EventType.CLICK, function() { + olEvents.listen(closeBtn, olEventsEventType.CLICK, function() { this.hideProfile_(); }.bind(this)); }.bind(this)); @@ -612,19 +613,19 @@ lux.MyMap.prototype.getMeasures = function(feature) { link = document.createElement('A'); link.setAttribute('href', 'javascript:void(0);'); - link.appendChild(document.createTextNode(lux.translate('Exporter KMl'))); + link.appendChild(document.createTextNode(luxBase.translate('Exporter KMl'))); links.appendChild(link); - ol.events.listen(link, ol.events.EventType.CLICK, function() { + olEvents.listen(link, olEventsEventType.CLICK, function() { this.exportKml_(feature, undefined); }.bind(this)); link = document.createElement('A'); link.setAttribute('href', 'javascript:void(0);'); - link.appendChild(document.createTextNode(lux.translate('Exporter GPX'))); + link.appendChild(document.createTextNode(luxBase.translate('Exporter GPX'))); links.appendChild(link); - ol.events.listen(link, ol.events.EventType.CLICK, function() { + olEvents.listen(link, olEventsEventType.CLICK, function() { this.exportGpx_(feature, undefined); }.bind(this)); @@ -638,7 +639,7 @@ lux.MyMap.prototype.getMeasures = function(feature) { * not. * @private */ -lux.MyMap.prototype.initProfile_ = function(target, opt_addCloseBtn) { +exports.prototype.initProfile_ = function(target, opt_addCloseBtn) { while (target.firstChild) { target.removeChild(target.firstChild); } @@ -662,8 +663,8 @@ lux.MyMap.prototype.initProfile_ = function(target, opt_addCloseBtn) { header.appendChild(metadata); var exportCSV = document.createElement('BUTTON'); - exportCSV.innerHTML = lux.translate('Export csv'); - ol.events.listen(exportCSV, ol.events.EventType.CLICK, function() { + exportCSV.innerHTML = luxBase.translate('Export csv'); + olEvents.listen(exportCSV, olEventsEventType.CLICK, function() { this.exportCSV_(); }.bind(this)); header.appendChild(exportCSV); @@ -698,7 +699,7 @@ lux.MyMap.prototype.initProfile_ = function(target, opt_addCloseBtn) { return 0; }; - ol.events.listen(this.map_, ol.MapBrowserEventType.POINTERMOVE, + olEvents.listen(this.map_, olMapBrowserEventType.POINTERMOVE, /** * @param {ol.MapBrowserPointerEvent} evt Map browser event. */ @@ -717,7 +718,7 @@ lux.MyMap.prototype.initProfile_ = function(target, opt_addCloseBtn) { } }; - this.profile_ = ngeo.profile.d3Elevation({ + this.profile_ = ngeoProfileD3Elevation({ linesConfiguration: linesConfiguration, distanceExtractor: dist, hoverCallback: this.profileHoverCallback_.bind(this), @@ -732,7 +733,7 @@ lux.MyMap.prototype.initProfile_ = function(target, opt_addCloseBtn) { * Clears the data in the profile and hide it. * @private */ -lux.MyMap.prototype.hideProfile_ = function() { +exports.prototype.hideProfile_ = function() { if (!this.profileContainer_) { return; } @@ -751,14 +752,14 @@ lux.MyMap.prototype.hideProfile_ = function() { * @export * @api */ -lux.MyMap.prototype.loadProfile = function(geom, target, opt_addCloseBtn) { +exports.prototype.loadProfile = function(geom, target, opt_addCloseBtn) { if (typeof target === 'string') { target = document.getElementById(target); } this.profileContainer_ = target; this.initProfile_(target, opt_addCloseBtn); - console.assert(geom instanceof ol.geom.LineString, + console.assert(geom instanceof olGeomLineString, 'geometry should be a linestring'); target.classList.add('lux-profile-active'); @@ -768,7 +769,7 @@ lux.MyMap.prototype.loadProfile = function(geom, target, opt_addCloseBtn) { featureProjection: 'EPSG:3857' }; var params = { - 'geom': new ol.format.GeoJSON().writeGeometry(geom, encOpt), + 'geom': new olFormatGeoJSON().writeGeometry(geom, encOpt), 'nbPoints': 100, 'layer': 'dhm', 'id': null @@ -792,7 +793,7 @@ lux.MyMap.prototype.loadProfile = function(geom, target, opt_addCloseBtn) { body: body }); - fetch(lux.profileUrl, request + fetch(luxBase.profileUrl, request ).then(function(resp) { return resp.json(); }).then(function(data) { @@ -806,10 +807,10 @@ lux.MyMap.prototype.loadProfile = function(geom, target, opt_addCloseBtn) { var lastElevation; var i; var len = data.profile.length; - var lineString = new ol.geom.LineString([], ol.geom.GeometryLayout.XYM); + var lineString = new olGeomLineString([], olGeomGeometryLayout.XYM); for (i = 0; i < len; i++) { var p = data.profile[i]; - p = new ol.geom.Point([p['x'], p['y']]); + p = new olGeomPoint([p['x'], p['y']]); p.transform('EPSG:2169', this.map_.getView().getProjection()); lineString.appendCoordinate( p.getCoordinates().concat(data.profile[i]['dist'])); @@ -840,7 +841,7 @@ lux.MyMap.prototype.loadProfile = function(geom, target, opt_addCloseBtn) { /** * @private */ -lux.MyMap.prototype.exportCSV_ = function() { +exports.prototype.exportCSV_ = function() { var csv = 'dist,MNT,y,x\n'; this.selection_.datum().forEach(function(item) { csv += item['dist'] + ',' + @@ -874,11 +875,11 @@ lux.MyMap.prototype.exportCSV_ = function() { * Creates a new measure tooltip * @private */ -lux.MyMap.prototype.createMeasureTooltip_ = function() { +exports.prototype.createMeasureTooltip_ = function() { this.removeMeasureTooltip_(); this.measureTooltipElement_ = document.createElement('DIV'); this.measureTooltipElement_.classList.add('lux-tooltip', 'lux-tooltip-measure'); - this.measureTooltip_ = new ol.Overlay({ + this.measureTooltip_ = new olOverlay({ element: this.measureTooltipElement_, offset: [0, -15], positioning: 'bottom-center' @@ -890,7 +891,7 @@ lux.MyMap.prototype.createMeasureTooltip_ = function() { * Destroy the measure tooltip * @private */ -lux.MyMap.prototype.removeMeasureTooltip_ = function() { +exports.prototype.removeMeasureTooltip_ = function() { if (this.measureTooltipElement_ !== null) { this.measureTooltipElement_.parentNode.removeChild( this.measureTooltipElement_); @@ -907,11 +908,11 @@ lux.MyMap.prototype.removeMeasureTooltip_ = function() { * @param {string} yUnits The y unit. * @private */ -lux.MyMap.prototype.profileHoverCallback_ = function(point, dist, xUnits, elevation, yUnits) { +exports.prototype.profileHoverCallback_ = function(point, dist, xUnits, elevation, yUnits) { this.featureOverlay_.clear(); - var curPoint = new ol.geom.Point([point['x'], point['y']]); + var curPoint = new olGeomPoint([point['x'], point['y']]); curPoint.transform('EPSG:2169', this.map_.getView().getProjection()); - var positionFeature = new ol.Feature({ + var positionFeature = new olFeature({ geometry: curPoint }); this.featureOverlay_.addFeature(positionFeature); @@ -931,7 +932,7 @@ lux.MyMap.prototype.profileHoverCallback_ = function(point, dist, xUnits, elevat * @return {string} The formatted distance. * @private */ -lux.MyMap.prototype.formatDistance_ = function(dist, units) { +exports.prototype.formatDistance_ = function(dist, units) { return parseFloat(dist.toPrecision(3)) + ' ' + units; }; @@ -943,7 +944,7 @@ lux.MyMap.prototype.formatDistance_ = function(dist, units) { * @return {string} The elevation text. * @private */ -lux.MyMap.prototype.formatElevation_ = function(elevation, units) { +exports.prototype.formatElevation_ = function(elevation, units) { return parseFloat(elevation.toPrecision(4)) + ' ' + units; }; @@ -954,7 +955,7 @@ lux.MyMap.prototype.formatElevation_ = function(elevation, units) { * @return {string} the elevation gain text. * @private */ -lux.MyMap.prototype.formatElevationGain_ = +exports.prototype.formatElevationGain_ = function(elevation, units) { return parseFloat(parseInt(elevation, 10)) + ' ' + units; }; @@ -964,7 +965,7 @@ lux.MyMap.prototype.formatElevationGain_ = * @param {ol.geom.Geometry|undefined} geom The geometry to snap to. * @private */ -lux.MyMap.prototype.snapToGeometry_ = function(coordinate, geom) { +exports.prototype.snapToGeometry_ = function(coordinate, geom) { var closestPoint = geom.getClosestPoint(coordinate); // compute distance to line in pixels var dx = closestPoint[0] - coordinate[0]; @@ -985,7 +986,7 @@ lux.MyMap.prototype.snapToGeometry_ = function(coordinate, geom) { * @param {string | undefined} filename The filename. * @export */ -lux.MyMap.prototype.exportMymapsAsKml = function(filename) { +exports.prototype.exportMymapsAsKml = function(filename) { this.exportKml_(this.sourceFeatures_.getFeatures(), filename); }; @@ -995,9 +996,9 @@ lux.MyMap.prototype.exportMymapsAsKml = function(filename) { * @param {string | undefined} filename The filename. * @private */ -lux.MyMap.prototype.exportKml_ = function(feature, filename) { +exports.prototype.exportKml_ = function(feature, filename) { var features = feature; - if (features instanceof ol.Feature) { + if (features instanceof olFeature) { features = [feature]; } if (filename === undefined) { @@ -1016,7 +1017,7 @@ lux.MyMap.prototype.exportKml_ = function(feature, filename) { * @param {string | undefined} filename The filename. * @export */ -lux.MyMap.prototype.exportMymapsAsGpx = function(filename) { +exports.prototype.exportMymapsAsGpx = function(filename) { this.exportGpx_(this.sourceFeatures_.getFeatures(), filename); }; @@ -1026,10 +1027,10 @@ lux.MyMap.prototype.exportMymapsAsGpx = function(filename) { * @param {string | undefined} filename The filename. * @private */ -lux.MyMap.prototype.exportGpx_ = function(feature, filename) { +exports.prototype.exportGpx_ = function(feature, filename) { // LineString geometries, and tracks from MultiLineString var features = feature; - if (features instanceof ol.Feature) { + if (features instanceof olFeature) { features = [feature]; } if (filename === undefined) { @@ -1054,7 +1055,7 @@ lux.MyMap.prototype.exportGpx_ = function(feature, filename) { * @param {string} filename File name for the exported document. * @private */ -lux.MyMap.prototype.exportFeatures_ = function(doc, format, filename) { +exports.prototype.exportFeatures_ = function(doc, format, filename) { var formatInput = document.createElement('INPUT'); formatInput.type = 'hidden'; @@ -1088,7 +1089,7 @@ lux.MyMap.prototype.exportFeatures_ = function(doc, format, filename) { * @return {string} The sanitized string. * @private */ -lux.MyMap.prototype.sanitizeFilename_ = function(name) { +exports.prototype.sanitizeFilename_ = function(name) { name = name.replace(/\s+/g, '_'); // Replace white space with _. return name.replace(/[^a-z0-9\-\_]/gi, ''); // Strip any special charactere. }; @@ -1101,11 +1102,11 @@ lux.MyMap.prototype.sanitizeFilename_ = function(name) { * @return {Array.} The exploded features. * @private */ -lux.MyMap.prototype.exploseFeature_ = function(features) { +exports.prototype.exploseFeature_ = function(features) { var explodedFeatures = []; features.forEach(function(feature) { switch (feature.getGeometry().getType()) { - case ol.geom.GeometryType.GEOMETRY_COLLECTION: + case olGeomGeometryType.GEOMETRY_COLLECTION: var geomCollection = /** @type {ol.geom.GeometryCollection} */ (feature.getGeometry()); geomCollection.getGeometriesArray().forEach( @@ -1115,7 +1116,7 @@ lux.MyMap.prototype.exploseFeature_ = function(features) { explodedFeatures.push(newFeature); }); break; - case ol.geom.GeometryType.MULTI_LINE_STRING: + case olGeomGeometryType.MULTI_LINE_STRING: var multiLineString = /** @type {ol.geom.MultiLineString} */ (feature.getGeometry()); multiLineString.getLineStrings().forEach( @@ -1141,15 +1142,15 @@ lux.MyMap.prototype.exploseFeature_ = function(features) { * @return {Array.} The changed features. * @private */ -lux.MyMap.prototype.changeLineToMultiline_ = function(features) { +exports.prototype.changeLineToMultiline_ = function(features) { var changedFeatures = []; features.forEach(function(feature) { switch (feature.getGeometry().getType()) { - case ol.geom.GeometryType.LINE_STRING: + case olGeomGeometryType.LINE_STRING: var geom = /** @type {ol.geom.LineString} */ (feature.getGeometry()); var multilineFeature = feature.clone(); multilineFeature.setGeometry( - new ol.geom.MultiLineString([geom.getCoordinates()])); + new olGeomMultiLineString([geom.getCoordinates()])); changedFeatures.push(multilineFeature); break; default : @@ -1172,17 +1173,17 @@ lux.MyMap.prototype.changeLineToMultiline_ = function(features) { * @return {Array.} The sorted features. * @private */ -lux.MyMap.prototype.orderFeaturesForGpx_ = function(features) { +exports.prototype.orderFeaturesForGpx_ = function(features) { var points = []; var lines = []; var others = []; features.forEach(function(feature) { switch (feature.getGeometry().getType()) { - case ol.geom.GeometryType.POINT: + case olGeomGeometryType.POINT: points.push(feature); break; - case ol.geom.GeometryType.LINE_STRING: + case olGeomGeometryType.LINE_STRING: lines.push(feature); break; default : diff --git a/jsapi/src/piwik.js b/jsapi/src/piwik.js index 85ece03f0..6368e7496 100644 --- a/jsapi/src/piwik.js +++ b/jsapi/src/piwik.js @@ -1,6 +1,8 @@ -goog.provide('lux.Piwik'); +goog.module('lux.Piwik'); + +goog.module.declareLegacyNamespace(); /** * @typedef {{push: function(Array)}} */ -lux.Piwik; +exports; diff --git a/jsapi/src/printmanager.js b/jsapi/src/printmanager.js index 2317f9a98..841146f46 100644 --- a/jsapi/src/printmanager.js +++ b/jsapi/src/printmanager.js @@ -1,28 +1,29 @@ -goog.provide('lux.PrintManager'); - -goog.require('goog.color.alpha'); -goog.require('ol'); -goog.require('ol.color'); -goog.require('ol.format.GeoJSON'); -goog.require('ol.geom.GeometryType'); -goog.require('ol.layer.Image'); -goog.require('ol.layer.Tile'); -goog.require('ol.layer.Vector'); -goog.require('ol.math'); -goog.require('ol.size'); -goog.require('ol.source.ImageWMS'); -goog.require('ol.source.TileWMS'); -goog.require('ol.source.Vector'); -goog.require('ol.source.WMTS'); -goog.require('ol.style.Circle'); -goog.require('ol.style.RegularShape'); -goog.require('ol.style.Style'); -goog.require('ol.tilegrid.WMTS'); -goog.require('ol.obj'); -goog.require('ol.Feature'); -goog.require('ol.geom.Point'); -goog.require('ol.style.Icon'); -goog.require('ol.layer.Group'); +goog.module('lux.PrintManager'); + +goog.module.declareLegacyNamespace(); +const googColorAlpha = goog.require('goog.color.alpha'); +const olBase = goog.require('ol'); +const olColor = goog.require('ol.color'); +const olFormatGeoJSON = goog.require('ol.format.GeoJSON'); +const olGeomGeometryType = goog.require('ol.geom.GeometryType'); +const olLayerImage = goog.require('ol.layer.Image'); +const olLayerTile = goog.require('ol.layer.Tile'); +const olLayerVector = goog.require('ol.layer.Vector'); +const olMath = goog.require('ol.math'); +const olSize = goog.require('ol.size'); +const olSourceImageWMS = goog.require('ol.source.ImageWMS'); +const olSourceTileWMS = goog.require('ol.source.TileWMS'); +const olSourceVector = goog.require('ol.source.Vector'); +const olSourceWMTS = goog.require('ol.source.WMTS'); +const olStyleCircle = goog.require('ol.style.Circle'); +const olStyleRegularShape = goog.require('ol.style.RegularShape'); +const olStyleStyle = goog.require('ol.style.Style'); +const olTilegridWMTS = goog.require('ol.tilegrid.WMTS'); +const olObj = goog.require('ol.obj'); +const olFeature = goog.require('ol.Feature'); +const olGeomPoint = goog.require('ol.geom.Point'); +const olStyleIcon = goog.require('ol.style.Icon'); +const olLayerGroup = goog.require('ol.layer.Group'); /** @@ -32,7 +33,7 @@ goog.require('ol.layer.Group'); * @constructor * @export */ -lux.PrintManager = function(url, map) { +exports = function(url, map) { /** * @type {lux.Map} * @private @@ -74,29 +75,29 @@ lux.PrintStyleType = { */ lux.PrintStyleTypes_ = {}; -lux.PrintStyleTypes_[ol.geom.GeometryType.LINE_STRING] = +lux.PrintStyleTypes_[olGeomGeometryType.LINE_STRING] = lux.PrintStyleType.LINE_STRING; -lux.PrintStyleTypes_[ol.geom.GeometryType.POINT] = +lux.PrintStyleTypes_[olGeomGeometryType.POINT] = lux.PrintStyleType.POINT; -lux.PrintStyleTypes_[ol.geom.GeometryType.POLYGON] = +lux.PrintStyleTypes_[olGeomGeometryType.POLYGON] = lux.PrintStyleType.POLYGON; -lux.PrintStyleTypes_[ol.geom.GeometryType.MULTI_LINE_STRING] = +lux.PrintStyleTypes_[olGeomGeometryType.MULTI_LINE_STRING] = lux.PrintStyleType.LINE_STRING; -lux.PrintStyleTypes_[ol.geom.GeometryType.MULTI_POINT] = +lux.PrintStyleTypes_[olGeomGeometryType.MULTI_POINT] = lux.PrintStyleType.POINT; -lux.PrintStyleTypes_[ol.geom.GeometryType.MULTI_POLYGON] = +lux.PrintStyleTypes_[olGeomGeometryType.MULTI_POLYGON] = lux.PrintStyleType.POLYGON; /** * @private */ -lux.PrintManager.FEAT_STYLE_PROP_PREFIX_ = '_ngeo_style_'; +exports.FEAT_STYLE_PROP_PREFIX_ = '_ngeo_style_'; /** * @const * @type {Array.} */ -lux.PrintManager.LAYOUTS = [ +exports.LAYOUTS = [ 'A4 landscape', 'A4 portrait', 'A3 landscape', @@ -115,7 +116,7 @@ lux.PrintManager.LAYOUTS = [ * @return {Promise} HTTP promise. * @export */ -lux.PrintManager.prototype.cancel = function(ref) { +exports.prototype.cancel = function(ref) { return fetch(this.url_ + '/cancel/' + ref, { method: 'DELTE' }); @@ -131,7 +132,7 @@ lux.PrintManager.prototype.cancel = function(ref) { * @return {MapFishPrintSpec} The print spec. * @export */ -lux.PrintManager.prototype.createSpec = function( +exports.prototype.createSpec = function( scale, dpi, layout, format, customAttributes) { this.dpi_ = dpi; this.scale_ = scale; @@ -145,7 +146,7 @@ lux.PrintManager.prototype.createSpec = function( var attributes = /** @type {!MapFishPrintAttributes} */ ({ map: specMap }); - ol.obj.assign(attributes, customAttributes); + olObj.assign(attributes, customAttributes); var spec = /** @type {MapFishPrintSpec} */ ({ attributes: attributes, @@ -162,12 +163,12 @@ lux.PrintManager.prototype.createSpec = function( * @param {MapFishPrintMap} object Object. * @private */ -lux.PrintManager.prototype.encodeMap_ = function(scale, object) { +exports.prototype.encodeMap_ = function(scale, object) { var view = this.map_.getView(); var viewCenter = view.getCenter(); var viewProjection = view.getProjection(); var viewResolution = view.getResolution(); - var viewRotation = object.rotation || ol.math.toDegrees(view.getRotation()); + var viewRotation = object.rotation || olMath.toDegrees(view.getRotation()); goog.asserts.assert(viewCenter !== undefined); goog.asserts.assert(viewProjection !== undefined); @@ -207,19 +208,19 @@ lux.PrintManager.prototype.encodeMap_ = function(scale, object) { url.toLowerCase().indexOf('//') === 0) { url = 'http:' + url; } - var markerStyle = new ol.style.Style({ - image: new ol.style.Icon({ + var markerStyle = new olStyleStyle({ + image: new olStyleIcon({ anchor: [0.5, 1], src: url }) }); var position = layer.getPosition(); if (position !== undefined && position !== null) { - var geoMarker = new ol.Feature({ - geometry: new ol.geom.Point(position) + var geoMarker = new olFeature({ + geometry: new olGeomPoint(position) }); - var vectorLayer = new ol.layer.Vector({ - source: new ol.source.Vector({ + var vectorLayer = new olLayerVector({ + source: new olSourceVector({ features: [geoMarker] }), style: markerStyle @@ -239,12 +240,12 @@ lux.PrintManager.prototype.encodeMap_ = function(scale, object) { * @param {ol.layer.Base} layer Layer. * @param {number} resolution Resolution. */ -lux.PrintManager.prototype.encodeLayer = function(arr, layer, resolution) { - if (layer instanceof ol.layer.Image) { +exports.prototype.encodeLayer = function(arr, layer, resolution) { + if (layer instanceof olLayerImage) { this.encodeImageLayer_(arr, layer); - } else if (layer instanceof ol.layer.Tile) { + } else if (layer instanceof olLayerTile) { this.encodeTileLayer_(arr, layer); - } else if (layer instanceof ol.layer.Vector) { + } else if (layer instanceof olLayerVector) { this.encodeVectorLayer_(arr, layer, resolution); } }; @@ -255,10 +256,10 @@ lux.PrintManager.prototype.encodeLayer = function(arr, layer, resolution) { * @param {ol.layer.Image} layer Layer. * @private */ -lux.PrintManager.prototype.encodeImageLayer_ = function(arr, layer) { - goog.asserts.assertInstanceof(layer, ol.layer.Image); +exports.prototype.encodeImageLayer_ = function(arr, layer) { + goog.asserts.assertInstanceof(layer, olLayerImage); var source = layer.getSource(); - if (source instanceof ol.source.ImageWMS) { + if (source instanceof olSourceImageWMS) { this.encodeImageWmsLayer_(arr, layer); } }; @@ -269,11 +270,11 @@ lux.PrintManager.prototype.encodeImageLayer_ = function(arr, layer) { * @param {ol.layer.Image} layer Layer. * @private */ -lux.PrintManager.prototype.encodeImageWmsLayer_ = function(arr, layer) { +exports.prototype.encodeImageWmsLayer_ = function(arr, layer) { var source = layer.getSource(); - goog.asserts.assertInstanceof(layer, ol.layer.Image); - goog.asserts.assertInstanceof(source, ol.source.ImageWMS); + goog.asserts.assertInstanceof(layer, olLayerImage); + goog.asserts.assertInstanceof(source, olSourceImageWMS); var url = source.getUrl(); if (url !== undefined) { @@ -290,9 +291,9 @@ lux.PrintManager.prototype.encodeImageWmsLayer_ = function(arr, layer) { * @param {Object} params Url parameters * @private */ -lux.PrintManager.prototype.encodeWmsLayer_ = function(arr, opacity, url, params) { +exports.prototype.encodeWmsLayer_ = function(arr, opacity, url, params) { var customParams = {'TRANSPARENT': true, 'MAP_RESOLUTION': this.dpi_}; - ol.obj.assign(customParams, params); + olObj.assign(customParams, params); delete customParams['LAYERS']; delete customParams['FORMAT']; @@ -318,7 +319,7 @@ lux.PrintManager.prototype.encodeWmsLayer_ = function(arr, opacity, url, params) * @return {string} Absolute URL. * @private */ -lux.PrintManager.prototype.getAbsoluteUrl_ = function(url) { +exports.prototype.getAbsoluteUrl_ = function(url) { var a = document.createElement('a'); a.href = encodeURI(url); return decodeURI(a.href); @@ -330,12 +331,12 @@ lux.PrintManager.prototype.getAbsoluteUrl_ = function(url) { * @param {ol.layer.Tile} layer Layer. * @private */ -lux.PrintManager.prototype.encodeTileLayer_ = function(arr, layer) { - goog.asserts.assertInstanceof(layer, ol.layer.Tile); +exports.prototype.encodeTileLayer_ = function(arr, layer) { + goog.asserts.assertInstanceof(layer, olLayerTile); var source = layer.getSource(); - if (source instanceof ol.source.WMTS) { + if (source instanceof olSourceWMTS) { this.encodeTileWmtsLayer_(arr, layer); - } else if (source instanceof ol.source.TileWMS) { + } else if (source instanceof olSourceTileWMS) { this.encodeTileWmsLayer_(arr, layer); } }; @@ -346,13 +347,13 @@ lux.PrintManager.prototype.encodeTileLayer_ = function(arr, layer) { * @param {ol.layer.Tile} layer Layer. * @private */ -lux.PrintManager.prototype.encodeTileWmtsLayer_ = function(arr, layer) { - goog.asserts.assertInstanceof(layer, ol.layer.Tile); +exports.prototype.encodeTileWmtsLayer_ = function(arr, layer) { + goog.asserts.assertInstanceof(layer, olLayerTile); var source = layer.getSource(); - goog.asserts.assertInstanceof(source, ol.source.WMTS); + goog.asserts.assertInstanceof(source, olSourceWMTS); var projection = source.getProjection(); var tileGrid = source.getTileGrid(); - goog.asserts.assertInstanceof(tileGrid, ol.tilegrid.WMTS); + goog.asserts.assertInstanceof(tileGrid, olTilegridWMTS); var matrixIds = tileGrid.getMatrixIds(); /** @type {Array.} */ var matrices = []; @@ -369,7 +370,7 @@ lux.PrintManager.prototype.encodeTileWmtsLayer_ = function(arr, layer) { identifier: matrixIds[i], scaleDenominator: tileGrid.getResolution(i) * projection.getMetersPerUnit() / 0.28E-3, - tileSize: ol.size.toSize(tileGrid.getTileSize(i)), + tileSize: olSize.toSize(tileGrid.getTileSize(i)), topLeftCorner: tileGrid.getOrigin(i), matrixSize: matrixSize })); @@ -412,11 +413,11 @@ lux.PrintManager.prototype.encodeTileWmtsLayer_ = function(arr, layer) { * @param {ol.layer.Tile} layer Layer. * @private */ -lux.PrintManager.prototype.encodeTileWmsLayer_ = function(arr, layer) { +exports.prototype.encodeTileWmsLayer_ = function(arr, layer) { var source = layer.getSource(); - goog.asserts.assertInstanceof(layer, ol.layer.Tile); - goog.asserts.assertInstanceof(source, ol.source.TileWMS); + goog.asserts.assertInstanceof(layer, olLayerTile); + goog.asserts.assertInstanceof(source, olSourceTileWMS); this.encodeWmsLayer_( arr, layer.getOpacity(), source.getUrls()[0], source.getParams()); @@ -429,13 +430,13 @@ lux.PrintManager.prototype.encodeTileWmsLayer_ = function(arr, layer) { * @param {number} resolution Resolution. * @private */ -lux.PrintManager.prototype.encodeVectorLayer_ = function(arr, layer, resolution) { +exports.prototype.encodeVectorLayer_ = function(arr, layer, resolution) { var source = layer.getSource(); - goog.asserts.assertInstanceof(source, ol.source.Vector); + goog.asserts.assertInstanceof(source, olSourceVector); var features = source.getFeatures(); - var geojsonFormat = new ol.format.GeoJSON(); + var geojsonFormat = new olFormatGeoJSON(); var /** @type {Array.} */ geojsonFeatures = []; var mapfishStyleObject = /** @type {MapFishPrintVectorStyle} */ ({ @@ -467,7 +468,7 @@ lux.PrintManager.prototype.encodeVectorLayer_ = function(arr, layer, resolution) var isOriginalFeatureAdded = false; for (var j = 0, jj = styles.length; j < jj; ++j) { var style = styles[j]; - var styleId = ol.getUid(style).toString(); + var styleId = olBase.getUid(style).toString(); var geometry = style.getGeometry(); var geojsonFeature; if (!geometry) { @@ -496,7 +497,7 @@ lux.PrintManager.prototype.encodeVectorLayer_ = function(arr, layer, resolution) } this.replaceNullValues(geojsonFeature.properties); - var featureStyleProp = lux.PrintManager.FEAT_STYLE_PROP_PREFIX_ + j; + var featureStyleProp = exports.FEAT_STYLE_PROP_PREFIX_ + j; this.encodeVectorStyle_( mapfishStyleObject, geometryType, style, styleId, featureStyleProp); geojsonFeature.properties[featureStyleProp] = styleId; @@ -528,7 +529,7 @@ lux.PrintManager.prototype.encodeVectorLayer_ = function(arr, layer, resolution) * @param {Object} object Object to replace the null values. * @private */ -lux.PrintManager.prototype.replaceNullValues = function(object) { +exports.prototype.replaceNullValues = function(object) { // Mapfish print does not support null properties. for (var idx in object) { if (object[idx] === null) { @@ -548,7 +549,7 @@ lux.PrintManager.prototype.replaceNullValues = function(object) { * @param {string} featureStyleProp Feature style property name. * @private */ -lux.PrintManager.prototype.encodeVectorStyle_ = function(object, geometryType, style, styleId, featureStyleProp) { +exports.prototype.encodeVectorStyle_ = function(object, geometryType, style, styleId, featureStyleProp) { if (!(geometryType in lux.PrintStyleTypes_)) { // unsupported geometry type return; @@ -611,12 +612,12 @@ lux.PrintManager.prototype.encodeVectorStyle_ = function(object, geometryType, s * @param {!ol.style.Fill} fillStyle Fill style. * @private */ -lux.PrintManager.prototype.encodeVectorStyleFill_ = function(symbolizer, fillStyle) { +exports.prototype.encodeVectorStyleFill_ = function(symbolizer, fillStyle) { var fillColor = fillStyle.getColor(); if (fillColor !== null) { if (typeof (fillColor) === 'string') { - var hex = goog.color.alpha.parse(fillColor).hex; - fillColor = goog.color.alpha.hexToRgba(hex); + var hex = googColorAlpha.parse(fillColor).hex; + fillColor = googColorAlpha.hexToRgba(hex); } goog.asserts.assert(Array.isArray(fillColor), 'only supporting fill colors'); symbolizer.fillColor = this.rgbArrayToHex(fillColor); @@ -631,7 +632,7 @@ lux.PrintManager.prototype.encodeVectorStyleFill_ = function(symbolizer, fillSty * @param {!ol.style.Stroke} strokeStyle Stroke style. * @private */ -lux.PrintManager.prototype.encodeVectorStyleLine_ = function(symbolizers, strokeStyle) { +exports.prototype.encodeVectorStyleLine_ = function(symbolizers, strokeStyle) { var symbolizer = /** @type {MapFishPrintSymbolizerLine} */ ({ type: 'line' }); @@ -646,9 +647,9 @@ lux.PrintManager.prototype.encodeVectorStyleLine_ = function(symbolizers, stroke * @param {!ol.style.Image} imageStyle Image style. * @private */ -lux.PrintManager.prototype.encodeVectorStylePoint_ = function(symbolizers, imageStyle) { +exports.prototype.encodeVectorStylePoint_ = function(symbolizers, imageStyle) { var symbolizer; - if (imageStyle instanceof ol.style.Circle) { + if (imageStyle instanceof olStyleCircle) { symbolizer = /** @type {MapFishPrintSymbolizerPoint} */ ({ type: 'point' }); @@ -661,7 +662,7 @@ lux.PrintManager.prototype.encodeVectorStylePoint_ = function(symbolizers, image if (strokeStyle !== null) { this.encodeVectorStyleStroke_(symbolizer, strokeStyle); } - } else if (imageStyle instanceof ol.style.Icon) { + } else if (imageStyle instanceof olStyleIcon) { var src = imageStyle.getSrc(); if (src !== undefined) { symbolizer = /** @type {MapFishPrintSymbolizerPoint} */ ({ @@ -685,9 +686,9 @@ lux.PrintManager.prototype.encodeVectorStylePoint_ = function(symbolizers, image if (isNaN(rotation)) { rotation = 0; } - symbolizer.rotation = ol.math.toDegrees(rotation); + symbolizer.rotation = olMath.toDegrees(rotation); } - } else if (imageStyle instanceof ol.style.RegularShape) { + } else if (imageStyle instanceof olStyleRegularShape) { /** * Mapfish Print does not support image defined with ol.style.RegularShape. * As a workaround, I try to map the image on a well-known image name. @@ -713,7 +714,7 @@ lux.PrintManager.prototype.encodeVectorStylePoint_ = function(symbolizers, image } var rotationShape = imageStyle.getRotation(); if (!isNaN(rotationShape) && rotationShape !== 0) { - symbolizer.rotation = ol.math.toDegrees(rotationShape); + symbolizer.rotation = olMath.toDegrees(rotationShape); } var opacityShape = imageStyle.getOpacity(); if (opacityShape !== null) { @@ -742,7 +743,7 @@ lux.PrintManager.prototype.encodeVectorStylePoint_ = function(symbolizers, image * @param {ol.style.Stroke} strokeStyle Stroke style. * @private */ -lux.PrintManager.prototype.encodeVectorStylePolygon_ = function(symbolizers, fillStyle, strokeStyle) { +exports.prototype.encodeVectorStylePolygon_ = function(symbolizers, fillStyle, strokeStyle) { var symbolizer = /** @type {MapFishPrintSymbolizerPolygon} */ ({ type: 'polygon' }); @@ -760,11 +761,11 @@ lux.PrintManager.prototype.encodeVectorStylePolygon_ = function(symbolizers, fil * @param {!ol.style.Stroke} strokeStyle Stroke style. * @private */ -lux.PrintManager.prototype.encodeVectorStyleStroke_ = function(symbolizer, strokeStyle) { +exports.prototype.encodeVectorStyleStroke_ = function(symbolizer, strokeStyle) { var strokeColor = strokeStyle.getColor(); if (strokeColor !== null) { goog.asserts.assert(Array.isArray(strokeColor)); - var strokeColorRgba = ol.color.asArray(strokeColor); + var strokeColorRgba = olColor.asArray(strokeColor); goog.asserts.assert(Array.isArray(strokeColorRgba), 'only supporting stroke colors'); symbolizer.strokeColor = this.rgbArrayToHex(strokeColorRgba); symbolizer.strokeOpacity = strokeColorRgba[3]; @@ -786,7 +787,7 @@ lux.PrintManager.prototype.encodeVectorStyleStroke_ = function(symbolizer, strok * @param {!ol.style.Text} textStyle Text style. * @private */ -lux.PrintManager.prototype.encodeTextStyle_ = function(symbolizers, textStyle) { +exports.prototype.encodeTextStyle_ = function(symbolizers, textStyle) { var symbolizer = /** @type {MapFishPrintSymbolizerText} */ ({ type: 'Text' }); @@ -821,7 +822,7 @@ lux.PrintManager.prototype.encodeTextStyle_ = function(symbolizers, textStyle) { if (strokeStyle !== null) { var strokeColor = strokeStyle.getColor(); goog.asserts.assert(Array.isArray(strokeColor)); - var strokeColorRgba = ol.color.asArray(strokeColor); + var strokeColorRgba = olColor.asArray(strokeColor); goog.asserts.assert(Array.isArray(strokeColorRgba), 'only supporting stroke colors'); symbolizer.haloColor = this.rgbArrayToHex(strokeColorRgba); symbolizer.haloOpacity = strokeColorRgba[3]; @@ -835,7 +836,7 @@ lux.PrintManager.prototype.encodeTextStyle_ = function(symbolizers, textStyle) { if (fillStyle !== null) { var fillColor = fillStyle.getColor(); goog.asserts.assert(Array.isArray(fillColor), 'only supporting fill colors'); - var fillColorRgba = ol.color.asArray(fillColor); + var fillColorRgba = olColor.asArray(fillColor); goog.asserts.assert(Array.isArray(fillColorRgba), 'only supporting fill colors'); symbolizer.fontColor = this.rgbArrayToHex(fillColorRgba); } @@ -859,7 +860,7 @@ lux.PrintManager.prototype.encodeTextStyle_ = function(symbolizers, textStyle) { * @return {string} URL. * @private */ -lux.PrintManager.prototype.getWmtsUrl_ = function(source) { +exports.prototype.getWmtsUrl_ = function(source) { var urls = source.getUrls(); goog.asserts.assert(urls.length > 0); var url = urls[0]; @@ -879,7 +880,7 @@ lux.PrintManager.prototype.getWmtsUrl_ = function(source) { * @return {Promise} HTTP promise. * @export */ -lux.PrintManager.prototype.createReport = function(printSpec) { +exports.prototype.createReport = function(printSpec) { var format = printSpec.format || 'pdf'; var url = this.url_ + '/report.' + format; @@ -899,7 +900,7 @@ lux.PrintManager.prototype.createReport = function(printSpec) { * @return {Promise} HTTP promise. * @export */ -lux.PrintManager.prototype.getStatus = function(ref) { +exports.prototype.getStatus = function(ref) { var url = this.url_ + '/status/' + ref + '.json'; return fetch(url); }; @@ -911,7 +912,7 @@ lux.PrintManager.prototype.getStatus = function(ref) { * @return {string} The report URL for this ref. * @export */ -lux.PrintManager.prototype.getReportUrl = function(ref) { +exports.prototype.getReportUrl = function(ref) { return this.url_ + '/report/' + ref; }; @@ -922,7 +923,7 @@ lux.PrintManager.prototype.getReportUrl = function(ref) { * @return {Array.} Layers. * @export */ -lux.PrintManager.prototype.getFlatLayers = function(layer) { +exports.prototype.getFlatLayers = function(layer) { return this.getFlatLayers_(layer, []); }; @@ -935,8 +936,8 @@ lux.PrintManager.prototype.getFlatLayers = function(layer) { * @return {Array.} Layers. * @private */ -lux.PrintManager.prototype.getFlatLayers_ = function(layer, array) { - if (layer instanceof ol.layer.Group) { +exports.prototype.getFlatLayers_ = function(layer, array) { + if (layer instanceof olLayerGroup) { var sublayers = layer.getLayers(); sublayers.forEach(function(l) { this.getFlatLayers_(l, array); @@ -954,7 +955,7 @@ lux.PrintManager.prototype.getFlatLayers_ = function(layer, array) { * @param {!Array.} rgb rgb representation of the color. * @return {string} hex representation of the color. */ -lux.PrintManager.prototype.rgbArrayToHex = function(rgb) { +exports.prototype.rgbArrayToHex = function(rgb) { var r = rgb[0]; var g = rgb[1]; var b = rgb[2]; @@ -974,6 +975,6 @@ lux.PrintManager.prototype.rgbArrayToHex = function(rgb) { * @return {string} hex value prepended with zero if it was single digit, * otherwise the same value that was passed in. */ -lux.PrintManager.prototype.colorZeroPadding = function(hex) { +exports.prototype.colorZeroPadding = function(hex) { return hex.length == 1 ? '0' + hex : hex; }; diff --git a/jsapi/src/statemanager.js b/jsapi/src/statemanager.js index 9e3fca42e..a8b082bf5 100644 --- a/jsapi/src/statemanager.js +++ b/jsapi/src/statemanager.js @@ -1,16 +1,17 @@ -goog.provide('lux.StateManager'); +goog.module('lux.StateManager'); -goog.require('lux'); -goog.require('ol.CollectionEventType'); -goog.require('ol.events'); -goog.require('ol.obj'); +goog.module.declareLegacyNamespace(); +const luxBase = goog.require('lux'); +const olCollectionEventType = goog.require('ol.CollectionEventType'); +const olEvents = goog.require('ol.events'); +const olObj = goog.require('ol.obj'); /** * @classdesc * @constructor */ -lux.StateManager = function() { +exports = function() { /** * @type {lux.Map} @@ -32,7 +33,7 @@ lux.StateManager = function() { /** * @param {lux.Map} map The map. */ -lux.StateManager.prototype.setMap = function(map) { +exports.prototype.setMap = function(map) { this.map_ = map; var view = map.getView(); @@ -49,15 +50,15 @@ lux.StateManager.prototype.setMap = function(map) { // make sure the state is updated the first time onViewUpdate.call(this); - ol.events.listen(view, 'propertychange', - lux.debounce(onViewUpdate, 250).bind(this)); + olEvents.listen(view, 'propertychange', + luxBase.debounce(onViewUpdate, 250).bind(this)); var layersListenerKeys = []; function onLayersUpdate() { // remove any listener on visibility change layersListenerKeys.forEach(function(key) { - ol.events.unlistenByKey(key); + olEvents.unlistenByKey(key); }); layersListenerKeys.length = 0; @@ -71,7 +72,7 @@ lux.StateManager.prototype.setMap = function(map) { } else { layers.unshift(layer.get('id')); opacities.unshift(layer.get('visible') ? layer.getOpacity() : 0); - layersListenerKeys[layer.get('id')] = ol.events.listen( + layersListenerKeys[layer.get('id')] = olEvents.listen( layer, 'change:visible', onLayersUpdate, @@ -90,16 +91,16 @@ lux.StateManager.prototype.setMap = function(map) { this.updateState(object); } - ol.events.listen(map.getLayers(), ol.CollectionEventType.ADD, + olEvents.listen(map.getLayers(), olCollectionEventType.ADD, onLayersUpdate, this); - ol.events.listen(map.getLayers(), ol.CollectionEventType.REMOVE, + olEvents.listen(map.getLayers(), olCollectionEventType.REMOVE, onLayersUpdate, this); }; /** * @param {string} id The mymap id. */ -lux.StateManager.prototype.setMyMap = function(id) { +exports.prototype.setMyMap = function(id) { this.updateState({'map_id': id}); }; @@ -107,9 +108,9 @@ lux.StateManager.prototype.setMyMap = function(id) { * Updates the attribution logo href. * @param {luxx.State} object The params to update. */ -lux.StateManager.prototype.updateState = function(object) { +exports.prototype.updateState = function(object) { if (this.state_ !== null) { - ol.obj.assign(this.state_, object); + olObj.assign(this.state_, object); goog.asserts.assertObject(this.state_); @@ -132,6 +133,6 @@ lux.StateManager.prototype.updateState = function(object) { /** * @return {string} the url to the map */ -lux.StateManager.prototype.getUrl = function() { +exports.prototype.getUrl = function() { return this.url_; };