Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable basemaps #351

Merged
merged 4 commits into from
Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 38 additions & 142 deletions app/state/configSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,44 @@ import utils from "app/utils/utils";
function newConfigSvc(layerOptionsSvc, appConfig) {
const svc = {};

svc.defaultBasemap = "world-dark";
const compareSources = (a,b) => a.name === b.name && a.ptype === b.ptype && a.restUrl === b.restUrl && a.url === b.url;

const createBasemaps = (layers, sources) =>
layers.map(layer => (
{
opacity: layer.opacity,
group: layer.group,
name: layer.name,
title: layer.title,
visibility: false,
selected: false,
source: String(sources.findIndex(source => compareSources(source, layer.source))),
fixed: layer.fixed
}));

const createSources = (sourcesObject, layers) => {
const sources = [];
layers.forEach(layer => {
const found = sources.find(source => compareSources(layer.source, source));
if (!found) {
sources.push(layer.source);
sourcesObject[sources.length - 1] = layer.source;
}
});
return sources;
};

const basemaps = [
{
opacity: 1.0,
group: "background",
name: "world-dark",
title: "World Dark",
visibility: false,
selected: false,
source: "1",
fixed: false
},
{
opacity: 1.0,
group: "background",
name: "natural-earth-1",
title: "Natural Earth",
visibility: false,
source: "1",
fixed: false
},
{
opacity: 1.0,
group: "background",
name: "natural-earth-2",
title: "Natural Earth 2",
visibility: false,
source: "1",
fixed: false
},
{
opacity: 1.0,
group: "background",
name: "geography-class",
title: "Geography Class",
visibility: false,
source: "1",
fixed: false
},
{
opacity: 1.0,
group: "background",
name: "control-room",
title: "MapBoxControlRoom",
visibility: false,
source: "1",
fixed: false
},
{
opacity: 1.0,
group: "background",
name: "world-light",
title: "World Light",
visibility: false,
source: "1",
fixed: false
},
{
opacity: 1.0,
group: "background",
name: "hot",
title: "Humanitarian OpenStreetMap",
args: [
"Humanitarian OpenStreetMap",
[
/* eslint-disable no-template-curly-in-string */
"//a.tile.openstreetmap.fr/hot/${z}/${x}/${y}.png",
"//b.tile.openstreetmap.fr/hot/${z}/${x}/${y}.png",
"//c.tile.openstreetmap.fr/hot/${z}/${x}/${y}.png"
/* eslint-enable no-template-curly-in-string */
],
{ tileOptions: { crossOriginKeyword: null } }
],
visibility: false,
source: "3",
fixed: true,
type: "OpenLayers.Layer.OSM"
},
{
opacity: 1.0,
group: "background",
name: "osm",
title: "OpenStreetMap",
args: ["OpenStreetMap"],
visibility: false,
source: "3",
fixed: true,
type: "OpenLayers.Layer.OSM"
},
{
opacity: 1.0,
group: "background",
name: "world-topo-map",
title: "Eri NGS",
args: [
"Worldmap",
"https://services.arcgisonline.com/arcgis/rest/services/NGS_Topo_US_2D/MapServer/",
{ layers: "basic" }
],
visibility: false,
source: "2",
fixed: true,
type: "OpenLayers.Layer"
}
];

svc.defaultBasemap = "";
const sourcesObject = {};
let sourcesArray = [];
let basemaps = [];
if (window.mapstory.composer.config.baselayersConfig) {
window.mapstory.composer.config.baselayersConfig.layers = window.mapstory.composer.config.baselayersConfig.layers.filter(layer => layer.name !== null);
sourcesArray = createSources(sourcesObject, window.mapstory.composer.config.baselayersConfig.layers);
basemaps = createBasemaps(window.mapstory.composer.config.baselayersConfig.layers, sourcesArray);
svc.defaultBasemap = window.mapstory.composer.config.baselayersConfig.defaultLayer;
}

svc.getBasemapArrayWithActiveBasemap = layers => {
let activeBasemap = null;
Expand Down Expand Up @@ -241,43 +173,7 @@ function newConfigSvc(layerOptionsSvc, appConfig) {
layers: data.layersConfig,
viewerPlaybackMode: "instant",
storyID: data.story_id || null,
sources: {
"0": {
lazy: true,
name: "local geoserver",
title: "Local Geoserver",
restUrl: "/gs/rest",
ptype: "gxp_wmscsource",
url: "https://mapstory.org/geoserver/wms",
isVirtualService: false
},
"1": { hidden: true, ptype: "gxp_mapboxsource" },
"3": { ptype: "gxp_osmsource" },
"2": {
ptype: "gxp_arcrestsource",
url:
"https://services.arcgisonline.com/arcgis/rest/services/NGS_Topo_US_2D/MapServer/",
isVirtualService: false,
alwaysAnonymous: true,
proj: "EPSG:4326"
},
"5": { ptype: "gxp_olsource" },
"4": {
lazy: true,
name: "local geoserver",
title: "Local Geoserver",
url: "https://mapstory.org/geoserver/wms",
ptype: "gxp_wmscsource",
restUrl: "/gs/rest"
},
"6": {
url:
"https://services.arcgisonline.com/arcgis/rest/services/NGS_Topo_US_2D/MapServer/",
proj: "EPSG:4326",
ptype: "gxp_arcrestsource",
alwaysAnonymous: true
}
},
sources: sourcesObject,
map: {
id: index,
center: [-11046067.8315474, 4153282.36890334],
Expand Down