mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 16:41:17 +01:00
Added back in experimental OpenLayers support
This commit is contained in:
parent
b7fd889fcd
commit
0973dcee8a
5 changed files with 74 additions and 83 deletions
|
@ -35,8 +35,8 @@
|
||||||
"mapbox-gl": "^0.47.0",
|
"mapbox-gl": "^0.47.0",
|
||||||
"mapbox-gl-inspect": "^1.3.1",
|
"mapbox-gl-inspect": "^1.3.1",
|
||||||
"maputnik-design": "github:maputnik/design",
|
"maputnik-design": "github:maputnik/design",
|
||||||
"ol-mapbox-style": "^2.10.1",
|
"ol-mapbox-style": "^3.0.1",
|
||||||
"ol": "^4.6.5",
|
"ol": "^5.0.0",
|
||||||
"prop-types": "^15.6.0",
|
"prop-types": "^15.6.0",
|
||||||
"react": "^16.3.2",
|
"react": "^16.3.2",
|
||||||
"react-aria-menubutton": "^5.1.1",
|
"react-aria-menubutton": "^5.1.1",
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {arrayMove} from 'react-sortable-hoc'
|
||||||
import url from 'url'
|
import url from 'url'
|
||||||
|
|
||||||
import MapboxGlMap from './map/MapboxGlMap'
|
import MapboxGlMap from './map/MapboxGlMap'
|
||||||
|
import OpenLayersMap from './map/OpenLayersMap'
|
||||||
import LayerList from './layers/LayerList'
|
import LayerList from './layers/LayerList'
|
||||||
import LayerEditor from './layers/LayerEditor'
|
import LayerEditor from './layers/LayerEditor'
|
||||||
import Toolbar from './Toolbar'
|
import Toolbar from './Toolbar'
|
||||||
|
@ -442,8 +443,10 @@ export default class App extends React.Component {
|
||||||
let mapElement;
|
let mapElement;
|
||||||
|
|
||||||
// Check if OL3 code has been loaded?
|
// Check if OL3 code has been loaded?
|
||||||
if(renderer === 'ol3') {
|
if(renderer === 'ol') {
|
||||||
mapElement = <div>TODO</div>
|
mapElement = <OpenLayersMap
|
||||||
|
{...mapProps}
|
||||||
|
/>
|
||||||
} else {
|
} else {
|
||||||
mapElement = <MapboxGlMap {...mapProps}
|
mapElement = <MapboxGlMap {...mapProps}
|
||||||
inspectModeEnabled={this.state.inspectModeEnabled}
|
inspectModeEnabled={this.state.inspectModeEnabled}
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
import React from 'react'
|
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import { loadJSON } from '../../libs/urlopen'
|
|
||||||
import 'ol/ol.css'
|
|
||||||
|
|
||||||
|
|
||||||
class OpenLayers3Map extends React.Component {
|
|
||||||
static propTypes = {
|
|
||||||
onDataChange: PropTypes.func,
|
|
||||||
mapStyle: PropTypes.object.isRequired,
|
|
||||||
accessToken: PropTypes.string,
|
|
||||||
style: PropTypes.object,
|
|
||||||
}
|
|
||||||
|
|
||||||
static defaultProps = {
|
|
||||||
onMapLoaded: () => {},
|
|
||||||
onDataChange: () => {},
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props) {
|
|
||||||
super(props)
|
|
||||||
this.map = null
|
|
||||||
}
|
|
||||||
|
|
||||||
updateStyle(newMapStyle) {
|
|
||||||
const olms = require('ol-mapbox-style');
|
|
||||||
const styleFunc = olms.apply(this.map, newMapStyle)
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate() {
|
|
||||||
require.ensure(["ol", "ol-mapbox-style"], () => {
|
|
||||||
if(!this.map) return
|
|
||||||
this.updateStyle(this.props.mapStyle)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
//Load OpenLayers dynamically once we need it
|
|
||||||
//TODO: Make this more convenient
|
|
||||||
require.ensure(["ol", "ol/map", "ol/view", "ol/control/zoom", "ol-mapbox-style"], ()=> {
|
|
||||||
console.log('Loaded OpenLayers3 renderer')
|
|
||||||
|
|
||||||
const olMap = require('ol/map').default
|
|
||||||
const olView = require('ol/view').default
|
|
||||||
const olZoom = require('ol/control/zoom').default
|
|
||||||
|
|
||||||
const map = new olMap({
|
|
||||||
target: this.container,
|
|
||||||
layers: [],
|
|
||||||
view: new olView({
|
|
||||||
zoom: 2,
|
|
||||||
center: [52.5, -78.4]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
map.addControl(new olZoom())
|
|
||||||
this.map = map
|
|
||||||
this.updateStyle(this.props.mapStyle)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return <div
|
|
||||||
ref={x => this.container = x}
|
|
||||||
style={{
|
|
||||||
position: "fixed",
|
|
||||||
top: 40,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
height: 'calc(100% - 40px)',
|
|
||||||
width: "75%",
|
|
||||||
backgroundColor: '#fff',
|
|
||||||
...this.props.style,
|
|
||||||
}}>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default OpenLayers3Map
|
|
66
src/components/map/OpenLayersMap.jsx
Normal file
66
src/components/map/OpenLayersMap.jsx
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { loadJSON } from '../../libs/urlopen'
|
||||||
|
|
||||||
|
import 'ol/ol.css'
|
||||||
|
import {apply} from 'ol-mapbox-style';
|
||||||
|
import {Map, View} from 'ol';
|
||||||
|
|
||||||
|
|
||||||
|
export default class OpenLayersMap extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
onDataChange: PropTypes.func,
|
||||||
|
mapStyle: PropTypes.object.isRequired,
|
||||||
|
accessToken: PropTypes.string,
|
||||||
|
style: PropTypes.object,
|
||||||
|
}
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
onMapLoaded: () => {},
|
||||||
|
onDataChange: () => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateStyle(newMapStyle) {
|
||||||
|
if(!this.map) return;
|
||||||
|
apply(this.map, newMapStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.updateStyle(this.props.mapStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.updateStyle(this.props.mapStyle);
|
||||||
|
|
||||||
|
const map = new Map({
|
||||||
|
target: this.container,
|
||||||
|
layers: [],
|
||||||
|
view: new View({
|
||||||
|
zoom: 2,
|
||||||
|
center: [52.5, -78.4]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <div
|
||||||
|
ref={x => this.container = x}
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
top: 40,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
height: 'calc(100% - 40px)',
|
||||||
|
width: "75%",
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
...this.props.style,
|
||||||
|
}}>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ class SettingsModal extends React.Component {
|
||||||
data-wd-key="modal-settings.maputnik:renderer"
|
data-wd-key="modal-settings.maputnik:renderer"
|
||||||
options={[
|
options={[
|
||||||
['mbgljs', 'MapboxGL JS'],
|
['mbgljs', 'MapboxGL JS'],
|
||||||
// ['ol3', 'Open Layers 3'],
|
['ol', 'Open Layers 3 (experimental)'],
|
||||||
]}
|
]}
|
||||||
value={metadata['maputnik:renderer'] || 'mbgljs'}
|
value={metadata['maputnik:renderer'] || 'mbgljs'}
|
||||||
onChange={this.changeMetadataProperty.bind(this, 'maputnik:renderer')}
|
onChange={this.changeMetadataProperty.bind(this, 'maputnik:renderer')}
|
||||||
|
|
Loading…
Reference in a new issue