-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"editor.formatOnSave": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,97 @@ | ||
import config from '@/config/config' | ||
import { store } from '@/store/store' | ||
export const createMap = function (loader, router, title) { | ||
const esriLoader = loader | ||
esriLoader.dojoRequire([ | ||
'esri/core/urlUtils', | ||
'esri/core/watchUtils', | ||
'esri/views/MapView', | ||
'esri/Map', | ||
'esri/layers/VectorTileLayer', | ||
'esri/layers/Layer', | ||
'esri/widgets/Expand', | ||
'esri/widgets/Legend', | ||
'esri/widgets/LayerList', | ||
'esri/widgets/Search' | ||
], (urlUtils, watchUtils, MapView, Map, VectorTileLayer, Layer, Expand, Legend, LayerList, Search) => { | ||
const urlObject = urlUtils.urlToObject(window.location.href) | ||
const center = (urlObject.query.center.split(',')).map(element => parseFloat(element)) | ||
const ids = (urlObject.query.ids.split(',')) | ||
const zoom = urlObject.query.zoom | ||
const map = new Map() | ||
const tileLyr = new VectorTileLayer({ | ||
url: config.tileLayerURL | ||
}) | ||
map.add(tileLyr) | ||
const view = new MapView({ | ||
map: map, | ||
container: 'viewDiv', | ||
zoom: zoom, | ||
center: center | ||
}) | ||
ids.forEach(function (id) { | ||
Layer.fromPortalItem({ | ||
portalItem: { | ||
id: id | ||
} | ||
}).then(function (layer) { | ||
map.add(layer) | ||
esriLoader.dojoRequire( | ||
[ | ||
'esri/core/urlUtils', | ||
'esri/core/watchUtils', | ||
'esri/views/MapView', | ||
'esri/Map', | ||
'esri/layers/VectorTileLayer', | ||
'esri/layers/Layer', | ||
'esri/widgets/Expand', | ||
'esri/widgets/Legend', | ||
'esri/widgets/LayerList', | ||
'esri/widgets/Search' | ||
], | ||
( | ||
urlUtils, | ||
watchUtils, | ||
MapView, | ||
Map, | ||
VectorTileLayer, | ||
Layer, | ||
Expand, | ||
Legend, | ||
LayerList, | ||
Search | ||
) => { | ||
const urlObject = urlUtils.urlToObject(window.location.href) | ||
const center = urlObject.query.center.split(',').map(element => parseFloat(element)) | ||
const ids = urlObject.query.ids.split(',') | ||
const zoom = urlObject.query.zoom | ||
const map = new Map({ | ||
basemap: 'topo-vector' | ||
}) | ||
}) | ||
view.then(() => { | ||
const legend = new Legend({ | ||
view: view, | ||
container: document.createElement('div') | ||
const view = new MapView({ | ||
map: map, | ||
container: 'viewDiv', | ||
zoom: zoom, | ||
center: center | ||
}) | ||
const layerList = new LayerList({ | ||
view: view, | ||
container: document.createElement('div') | ||
ids.forEach(function (id) { | ||
Layer.fromPortalItem({ | ||
portalItem: { | ||
id: id | ||
} | ||
}).then(function (layer) { | ||
map.add(layer) | ||
}) | ||
}) | ||
const legendExpand = new Expand({ | ||
view: view, | ||
content: legend.domNode, | ||
expandIconClass: 'esri-icon-collection', | ||
expandTooltip: 'Legend' | ||
view.then(() => { | ||
const legend = new Legend({ | ||
view: view, | ||
container: document.createElement('div') | ||
}) | ||
const layerList = new LayerList({ | ||
view: view, | ||
container: document.createElement('div') | ||
}) | ||
const legendExpand = new Expand({ | ||
view: view, | ||
content: legend.domNode, | ||
expandIconClass: 'esri-icon-collection', | ||
expandTooltip: 'Legend' | ||
}) | ||
const layersExpand = new Expand({ | ||
view: view, | ||
content: layerList.domNode, | ||
expandIconClass: 'esri-icon-layer-list', | ||
expandTooltip: 'Layers' | ||
}) | ||
view.ui.add(layersExpand, 'top-right') | ||
view.ui.add(legendExpand, 'top-right') | ||
}) | ||
const layersExpand = new Expand({ | ||
view: view, | ||
content: layerList.domNode, | ||
expandIconClass: 'esri-icon-layer-list', | ||
expandTooltip: 'Layers' | ||
const searchWidget = new Search({ | ||
view: view | ||
}) | ||
view.ui.add(layersExpand, 'top-right') | ||
view.ui.add(legendExpand, 'top-right') | ||
}) | ||
const searchWidget = new Search({ | ||
view: view | ||
}) | ||
view.ui.add(searchWidget, { | ||
position: 'top-left', | ||
index: 0 | ||
}) | ||
watchUtils.whenTrue(view, 'stationary', () => { | ||
let center = [view.center.longitude.toFixed(3), view.center.latitude.toFixed(3)].toString() | ||
let zoom = view.zoom | ||
router.push({name: 'map', query: {mapTitle: store.state.route.query.mapTitle, zoom: zoom, ids: ids.join(','), center: center}}) | ||
}) | ||
}) | ||
view.ui.add(searchWidget, { | ||
position: 'top-left', | ||
index: 0 | ||
}) | ||
watchUtils.whenTrue(view, 'stationary', () => { | ||
let center = [view.center.longitude.toFixed(3), view.center.latitude.toFixed(3)].toString() | ||
let zoom = view.zoom | ||
router.push({ | ||
name: 'map', | ||
query: { | ||
mapTitle: store.state.route.query.mapTitle, | ||
zoom: zoom, | ||
ids: ids.join(','), | ||
center: center | ||
} | ||
}) | ||
}) | ||
} | ||
) | ||
} |