mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 16:21:16 +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 isEqual from 'lodash.isequal'
|
||||
import { loadJSON } from '../../libs/urlopen'
|
||||
import 'openlayers/dist/ol.css'
|
||||
|
||||
function suitableVectorSource(mapStyle) {
|
||||
const sources = Object.keys(mapStyle.sources)
|
||||
|
@ -11,7 +12,7 @@ function suitableVectorSource(mapStyle) {
|
|||
source: mapStyle.sources[sourceId]
|
||||
}
|
||||
})
|
||||
.filter(({source}) => source.type === 'vector')
|
||||
.filter(({source}) => (source.type === 'vector' || source.type === 'geojson'))
|
||||
return sources[0]
|
||||
}
|
||||
|
||||
|
@ -28,12 +29,25 @@ function toVectorLayer(source, tilegrid, cb) {
|
|||
})
|
||||
}
|
||||
|
||||
if(!source.tiles) {
|
||||
sourceFromTileJSON(source.url, tileSource => {
|
||||
cb(newMVTLayer(tileSource.tiles[0]))
|
||||
function newGeoJSONLayer(sourceUrl) {
|
||||
const ol = require('openlayers')
|
||||
return new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
format: new ol.format.GeoJSON(),
|
||||
url: sourceUrl
|
||||
})
|
||||
})
|
||||
} else {
|
||||
cb(newMVTLayer(source.tiles[0]))
|
||||
}
|
||||
if (source.type === 'vector') {
|
||||
if(!source.tiles) {
|
||||
sourceFromTileJSON(source.url, tileSource => {
|
||||
cb(newMVTLayer(tileSource.tiles[0]))
|
||||
})
|
||||
} else {
|
||||
cb(newMVTLayer(source.tiles[0]))
|
||||
}
|
||||
} else if (source.type === 'geojson') {
|
||||
cb(newGeoJSONLayer(source.data))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,10 +105,11 @@ class OpenLayers3Map extends React.Component {
|
|||
}
|
||||
|
||||
if(!this.layer) {
|
||||
var self = this
|
||||
toVectorLayer(newSource.source, this.tilegrid, vectorLayer => {
|
||||
this.layer = vectorLayer
|
||||
this.map.addLayer(this.layer)
|
||||
setStyleFunc(this.map, this.layer)
|
||||
self.layer = vectorLayer
|
||||
self.map.addLayer(self.layer)
|
||||
setStyleFunc(self.map, self.layer)
|
||||
})
|
||||
} else {
|
||||
setStyleFunc(this.map, this.layer)
|
||||
|
@ -140,10 +155,10 @@ class OpenLayers3Map extends React.Component {
|
|||
ref={x => this.container = x}
|
||||
style={{
|
||||
position: "fixed",
|
||||
top: 0,
|
||||
top: 40,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
height: "100%",
|
||||
height: 'calc(100% - 40px)',
|
||||
width: "75%",
|
||||
backgroundColor: '#fff',
|
||||
...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 'zoomproperty';
|
||||
@import 'popup';
|
||||
@import 'map';
|
||||
|
|
Loading…
Reference in a new issue