mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-30 23:50:32 +01:00
Improved OpenLayers support
Added support for gejson sources Fix toVectorLayer map callback (this was undefined) Improved ol css; show map controls
This commit is contained in:
parent
0555fc48ad
commit
df04064e81
3 changed files with 49 additions and 11 deletions
|
@ -2,6 +2,7 @@ import React from 'react'
|
||||||
import style from '../../libs/style.js'
|
import style from '../../libs/style.js'
|
||||||
import isEqual from 'lodash.isequal'
|
import isEqual from 'lodash.isequal'
|
||||||
import { loadJSON } from '../../libs/urlopen'
|
import { loadJSON } from '../../libs/urlopen'
|
||||||
|
import 'openlayers/dist/ol.css'
|
||||||
|
|
||||||
function suitableVectorSource(mapStyle) {
|
function suitableVectorSource(mapStyle) {
|
||||||
const sources = Object.keys(mapStyle.sources)
|
const sources = Object.keys(mapStyle.sources)
|
||||||
|
@ -11,7 +12,7 @@ function suitableVectorSource(mapStyle) {
|
||||||
source: mapStyle.sources[sourceId]
|
source: mapStyle.sources[sourceId]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(({source}) => source.type === 'vector')
|
.filter(({source}) => (source.type === 'vector' || source.type === 'geojson'))
|
||||||
return sources[0]
|
return sources[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +29,16 @@ function toVectorLayer(source, tilegrid, cb) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function newGeoJSONLayer(sourceUrl) {
|
||||||
|
const ol = require('openlayers')
|
||||||
|
return new ol.layer.Vector({
|
||||||
|
source: new ol.source.Vector({
|
||||||
|
format: new ol.format.GeoJSON(),
|
||||||
|
url: sourceUrl
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (source.type === 'vector') {
|
||||||
if(!source.tiles) {
|
if(!source.tiles) {
|
||||||
sourceFromTileJSON(source.url, tileSource => {
|
sourceFromTileJSON(source.url, tileSource => {
|
||||||
cb(newMVTLayer(tileSource.tiles[0]))
|
cb(newMVTLayer(tileSource.tiles[0]))
|
||||||
|
@ -35,6 +46,9 @@ function toVectorLayer(source, tilegrid, cb) {
|
||||||
} else {
|
} else {
|
||||||
cb(newMVTLayer(source.tiles[0]))
|
cb(newMVTLayer(source.tiles[0]))
|
||||||
}
|
}
|
||||||
|
} else if (source.type === 'geojson') {
|
||||||
|
cb(newGeoJSONLayer(source.data))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sourceFromTileJSON(url, cb) {
|
function sourceFromTileJSON(url, cb) {
|
||||||
|
@ -91,10 +105,11 @@ class OpenLayers3Map extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.layer) {
|
if(!this.layer) {
|
||||||
|
var self = this
|
||||||
toVectorLayer(newSource.source, this.tilegrid, vectorLayer => {
|
toVectorLayer(newSource.source, this.tilegrid, vectorLayer => {
|
||||||
this.layer = vectorLayer
|
self.layer = vectorLayer
|
||||||
this.map.addLayer(this.layer)
|
self.map.addLayer(self.layer)
|
||||||
setStyleFunc(this.map, this.layer)
|
setStyleFunc(self.map, self.layer)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
setStyleFunc(this.map, this.layer)
|
setStyleFunc(this.map, this.layer)
|
||||||
|
@ -140,10 +155,10 @@ class OpenLayers3Map extends React.Component {
|
||||||
ref={x => this.container = x}
|
ref={x => this.container = x}
|
||||||
style={{
|
style={{
|
||||||
position: "fixed",
|
position: "fixed",
|
||||||
top: 0,
|
top: 40,
|
||||||
right: 0,
|
right: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
height: "100%",
|
height: 'calc(100% - 40px)',
|
||||||
width: "75%",
|
width: "75%",
|
||||||
backgroundColor: '#fff',
|
backgroundColor: '#fff',
|
||||||
...this.props.style,
|
...this.props.style,
|
||||||
|
|
22
src/styles/_map.scss
Normal file
22
src/styles/_map.scss
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
//OPENLAYERS
|
||||||
|
.maputnik-layout {
|
||||||
|
.ol-zoom {
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ol-attribution.ol-logo-only {
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ol-control {
|
||||||
|
button {
|
||||||
|
background-color: rgb(28, 31, 36);
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: rgb(86, 83, 83);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,3 +35,4 @@ $toolbar-offset: 0;
|
||||||
@import 'filtereditor';
|
@import 'filtereditor';
|
||||||
@import 'zoomproperty';
|
@import 'zoomproperty';
|
||||||
@import 'popup';
|
@import 'popup';
|
||||||
|
@import 'map';
|
||||||
|
|
Loading…
Reference in a new issue