diff --git a/src/components/MapViewer/AreaWidget.jsx b/src/components/MapViewer/AreaWidget.jsx index eccaf128..60390ee6 100644 --- a/src/components/MapViewer/AreaWidget.jsx +++ b/src/components/MapViewer/AreaWidget.jsx @@ -1,6 +1,7 @@ import React, { createRef } from "react"; import "@arcgis/core/assets/esri/css/main.css"; import "./ArcgisMap.css"; +import { loadModules } from 'esri-loader'; var Graphic, Extent, WMSLayer, GroupLayer; diff --git a/src/components/MapViewer/LegendWidget.jsx b/src/components/MapViewer/LegendWidget.jsx index 357f0d21..36593565 100644 --- a/src/components/MapViewer/LegendWidget.jsx +++ b/src/components/MapViewer/LegendWidget.jsx @@ -1,6 +1,7 @@ import React, {createRef } from "react"; import "@arcgis/core/assets/esri/css/main.css"; import "./ArcgisMap.css"; +import { loadModules } from 'esri-loader'; var Legend; class LegendWidget extends React.Component { diff --git a/src/components/MapViewer/MapViewer.jsx b/src/components/MapViewer/MapViewer.jsx index 1821a1ad..2db0b6b7 100644 --- a/src/components/MapViewer/MapViewer.jsx +++ b/src/components/MapViewer/MapViewer.jsx @@ -1,103 +1,167 @@ -import React, { createRef } from 'react'; -import './ArcgisMap.css'; -import classNames from 'classnames'; +import React, { createRef } from "react"; +//import intl from "@arcgis/intl"; +import {setLocale} from "@arcgis/core/intl"; +import "@arcgis/core/assets/esri/css/main.css"; +import "./ArcgisMap.css"; import BasemapWidget from './BasemapWidget'; +import MeasurementWidget from './MeasurementWidget'; +import PrintWidget from './PrintWidget'; +import AreaWidget from './AreaWidget'; +import ScaleWidget from './ScaleWidget'; +import LegendWidget from './LegendWidget'; +import MenuWidget from './MenuWidget'; import { loadModules, loadCss } from 'esri-loader'; var Map, MapView, Zoom; class MapViewer extends React.Component { - /** - * This method does the creation of the main component - * @param {*} props - */ - constructor(props) { - super(props); - loadCss(); - //we create a reference to the DOM element that will - //be later mounted. We will use the reference that we - //create here to reference the DOM element from javascript - //code, for example, to create later a MapView component - //that will use the map div to show the map - this.mapdiv = createRef(); - this.mapCfg = props.cfg.Map; - this.map = null; - this.id = props.id; - this.mapClass = classNames('map-container', { - [`${props.customClass}`]: props.customClass || null, - }); - } + /** + * This method does the creation of the main component + * @param {*} props + */ + constructor(props) { + super(props); + loadCss(); + //we create a reference to the DOM element that will + //be later mounted. We will use the reference that we + //create here to reference the DOM element from javascript + //code, for example, to create later a MapView component + //that will use the map div to show the map + setLocale("en"); + this.mapdiv = createRef(); + this.mapCfg = props.cfg.Map; + this.compCfg = props.cfg.Components; + this.map = new Map({ + basemap: "topo" + }); + this.activeWidget = null; + } + + loader() { + return loadModules([ + 'esri/WebMap', + 'esri/views/MapView', + 'esri/widgets/Zoom', + ]).then(([_Map, _MapView, _Zoom]) => { + [Map, MapView, Zoom] = [_Map, _MapView, _Zoom]; + }); + } - loader() { - return loadModules([ - 'esri/WebMap', - 'esri/views/MapView', - 'esri/widgets/Zoom', - ]).then(([_Map, _MapView, _Zoom]) => { - [Map, MapView, Zoom] = [_Map, _MapView, _Zoom]; - }); - } + /** + * Once the component has been mounted in the screen, this method + * will be executed, so we can access to the DOM elements, since + * they are already mounted + */ + async componentDidMount() { + await this.loader(); + // this.mapdiv.current is the reference to the current DOM element of + // this.mapdiv after it was mounted by the render() method + setLocale("en-GB"); + this.view = new MapView({ + container: this.mapdiv.current, + map: this.map, + center: this.mapCfg.center, + zoom: this.mapCfg.zoom, + ui: { + components: ["attribution"] + } + }); + this.zoom = new Zoom({ + view: this.view + }); + this.view.ui.add(this.zoom, { + position: "top-right" + }); - /** - * Once the component has been mounted in the screen, this method - * will be executed, so we can access to the DOM elements, since - * they are already mounted - */ - async componentDidMount() { - await this.loader(); - // this.mapdiv.current is the reference to the current DOM element of - // this.mapdiv after it was mounted by the render() method - this.map = new Map({ - basemap: 'topo-vector', - }); - this.view = new MapView({ - container: this.mapdiv.current, - map: this.map, - center: this.mapCfg.center, - zoom: this.mapCfg.zoom, - ui: { - components: ['attribution'], - }, - }); - this.zoom = new Zoom({ - view: this.view, - }); - this.view.ui.add(this.zoom, { - position: 'top-right', - }); + //Once we have created the MapView, we need to ensure that the map div + //is refreshed in order to show the map on it. To do so, we need to + //trigger the renderization again, and to trigger the renderization + //we invoke the setState method, that changes the state and forces a + //react component to render itself again + this.setState({}); + } - //Once we have created the MapView, we need to ensure that the map div - //is refreshed in order to show the map on it. To do so, we need to - //trigger the renderization again, and to trigger the renderization - //we invoke the setState method, that changes the state and forces a - //react component to render itself again - this.setState({}); - } + setActiveWidget(widget){ + if(!widget){ + this.activeWidget = null; + return; + } + if(this.activeWidget === widget) return; + this.closeActiveWidget(); + this.activeWidget = widget; + } + closeActiveWidget(){ + if(this.activeWidget){ + this.activeWidget.openMenu(); + this.activeWidget = null; + } + } - /** - * This method evaluates the ability to render the basemaps widget and - * returns the jsx allowing such a render (if conditions are ok) - * @returns jsx - */ - renderBasemap() { - if (this.view) return ; - } + /** + * This method evaluates the ability to render the basemaps widget and + * returns the jsx allowing such a render (if conditions are ok) + * @returns jsx + */ + renderBasemap() { + if (this.view) + return + } - /** - * This method renders the map viewer, invoking if necessary the methods - * to render the other widgets to display - * @returns jsx - */ - render() { - // we use a reference (ref={this.mapdiv}) in order to reference a - // DOM element to be mounted (but not yet mounted) - return ( -
-
- {this.renderBasemap()} -
-
- ); - } + renderLegend(){ + if(this.view) + return + } + + renderMeasurement() { + if (this.view) + return + } + + renderPrint() { + if (this.view) + return + } + + renderArea() { + if (this.view) + return + } + + renderScale() { + if (this.view) + return + } + + renderMenu() { + if (this.view) + return //call conf + } + + + + + /** + * This method renders the map viewer, invoking if necessary the methods + * to render the other widgets to display + * @returns jsx + */ + render(){ + // we use a reference (ref={this.mapdiv}) in order to reference a + // DOM element to be mounted (but not yet mounted) + return( +
+
+ {this.renderBasemap()} + {this.renderLegend()} + {this.renderMeasurement()} + {this.renderPrint()} + {this.renderArea()} + {this.renderScale()} + {this.renderMenu()} + +
+
+ ) + } } export default MapViewer; diff --git a/src/components/MapViewer/MeasurementWidget.jsx b/src/components/MapViewer/MeasurementWidget.jsx index 779fd548..b55a2a0c 100644 --- a/src/components/MapViewer/MeasurementWidget.jsx +++ b/src/components/MapViewer/MeasurementWidget.jsx @@ -1,6 +1,7 @@ import React, { createRef } from "react"; import "@arcgis/core/assets/esri/css/main.css"; import "./ArcgisMap.css"; +import { loadModules } from 'esri-loader'; var Measurement; class MeasurementWidget extends React.Component { diff --git a/src/components/MapViewer/MenuWidget.jsx b/src/components/MapViewer/MenuWidget.jsx index 6542a815..021362b8 100644 --- a/src/components/MapViewer/MenuWidget.jsx +++ b/src/components/MapViewer/MenuWidget.jsx @@ -2,6 +2,7 @@ import React, { createRef } from "react"; import "@arcgis/core/assets/esri/css/main.css"; import "./lib/font-awesome/css/all.min.css"; import "./ArcgisMap.css"; +import { loadModules } from 'esri-loader'; var WMSLayer; class MenuWidget extends React.Component { diff --git a/src/components/MapViewer/PrintWidget.jsx b/src/components/MapViewer/PrintWidget.jsx index e85f430b..05e62d78 100644 --- a/src/components/MapViewer/PrintWidget.jsx +++ b/src/components/MapViewer/PrintWidget.jsx @@ -1,6 +1,7 @@ import React, { createRef } from "react"; import "@arcgis/core/assets/esri/css/main.css"; import "./ArcgisMap.css"; +import { loadModules } from 'esri-loader'; var Print; class PrintWidget extends React.Component { diff --git a/src/components/MapViewer/ScaleWidget.jsx b/src/components/MapViewer/ScaleWidget.jsx index a1fbee3f..581021d0 100644 --- a/src/components/MapViewer/ScaleWidget.jsx +++ b/src/components/MapViewer/ScaleWidget.jsx @@ -1,6 +1,7 @@ import React, { createRef } from "react"; import "@arcgis/core/assets/esri/css/main.css"; import "./ArcgisMap.css"; +import { loadModules } from 'esri-loader'; var ScaleBar; class ScaleWidget extends React.Component {