Skip to content

Commit

Permalink
Merge pull request #67 from KlausBenndorf/newFeatures
Browse files Browse the repository at this point in the history
Some new features
  • Loading branch information
simonseyock committed Sep 7, 2016
2 parents db7e514 + 8bfd278 commit d43f132
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 146 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"jquery": "3.1.0",
"lodash": "4.14.1",
"notifyjs-browser": "0.4.2",
"openlayers": "github:KlausBenndorf/ol3#g4u3_3.16",
"openlayers": "github:KlausBenndorf/ol3#g4u3_3.17.1",
"proj4": "2.3.14",
"strip-json-comments": "2.0.1"
},
Expand Down
17 changes: 12 additions & 5 deletions src/FeaturePopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ export default class FeaturePopup extends ol.Object {
this.map__ = null
}

/**
* @param {ol.Feature} feature
* @returns {boolean}
* @private
*/
static filter_ (feature) {
return !feature.get('disabled') && (feature.get('name') || feature.get('description'))
}

/**
* @param {G4UMap} map
*/
Expand Down Expand Up @@ -239,12 +248,10 @@ export default class FeaturePopup extends ol.Object {

this.$element_.append(this.window_.get$Element())

let filter = f => f.get('name') || f.get('description')

// feature click

map.getDefaultInteractions('singleClick')[ 0 ].on('select', e => {
let selected = e.selected.filter(filter)
let selected = e.selected.filter(FeaturePopup.filter_)
if (selected.length) {
this.onFeatureClick_(selected[ 0 ])
e.target.getFeatures().remove(selected[ 0 ]) // remove feature to be able to select feature again
Expand All @@ -255,8 +262,8 @@ export default class FeaturePopup extends ol.Object {
// feature hover

map.getDefaultInteractions('mouseMove')[ 0 ].on('select', e => {
let selected = e.selected.filter(filter)
let deselected = e.deselected.filter(filter)
let selected = e.selected.filter(FeaturePopup.filter_)
let deselected = e.deselected.filter(FeaturePopup.filter_)
if (selected.length) {
$(map.getViewport()).addClass(cssClasses.clickable)
} else if (deselected.length) {
Expand Down
7 changes: 5 additions & 2 deletions src/FeatureTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export default class FeatureTooltip {
this.$element_.parent().addClass(this.className_ + '-container')
}

static filter_ (feature) {
return !feature.get('disabled') && feature.get('name')
}

/**
* @param {G4UMap} map
*/
Expand All @@ -63,10 +67,9 @@ export default class FeatureTooltip {
if (map) {
map.addOverlay(this.overlay_)

let filter = f => f.get('name')
let interaction = map.getDefaultInteractions('mouseMove')[0]
interaction.on('select', e => {
let selected = e.selected.filter(filter)
let selected = e.selected.filter(FeatureTooltip.filter_)
if (selected.length) {
this.setFeature(selected[0])
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/G4UMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ export default class G4UMap extends ol.Map {
* @param {GroupLayer} groupLayer
*/
setLayerGroup (groupLayer) {
groupLayer.setMap(this)
groupLayer.provideMap(this)
super.setLayerGroup(groupLayer)
}

Expand Down
3 changes: 0 additions & 3 deletions src/Styling.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@ export default class Styling {
stylePrimitive = curStyles[0]
}
}
if (this.get('opacity')) {
stylePrimitive = thisRef.adjustColorOpacity(thisRef.cloneStyle(stylePrimitive), this.get('opacity'))
}
return [stylePrimitive]
}

Expand Down
2 changes: 1 addition & 1 deletion src/configurators/LayerConfigurator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ol from 'openlayers'

import GroupLayer from '../layers/GroupLayer'
import {GroupLayer} from '../layers/GroupLayer'
import { copyDeep } from '../utilitiesObject'
import { checkFor } from '../utilities'
import Debug from '../Debug'
Expand Down
6 changes: 3 additions & 3 deletions src/configurators/LayerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import ol from 'openlayers'

import {BaseLayerImage, ImageLayer} from '../layers/ImageLayer'
import {EmptyBaseLayer} from '../layers/EmptyBaseLayer'
import BaseLayerTile from '../layers/BaseLayerTile'
import GroupLayer from '../layers/GroupLayer'
import VectorLayer from '../layers/VectorLayer'
import {BaseLayerTile} from '../layers/BaseLayerTile'
import {GroupLayer} from '../layers/GroupLayer'
import {VectorLayer} from '../layers/VectorLayer'
import SourceServerVector from '../sources/SourceServerVector'
import QuerySource from '../sources/QuerySource'
import { copyDeep, take } from '../utilitiesObject'
Expand Down
2 changes: 1 addition & 1 deletion src/configurators/UIConfigurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export default class UIConfigurator {
}

this.map_.addDefaultInteraction('singleClick', new FeatureSelect({
condition: ol.events.condition.singleClick,
condition: e => ol.events.condition.singleClick(e) && $(e.originalEvent.target).is('canvas'),
style: null,
multi: true
}))
Expand Down
2 changes: 1 addition & 1 deletion src/controls/GeoLocationButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import $ from 'jquery'

import Control from './Control'
import { addTooltip } from '../html/html'
import VectorLayer from '../layers/VectorLayer'
import {VectorLayer} from '../layers/VectorLayer'
import MessageDisplay from '../MessageDisplay'
import {cssClasses} from '../globals'

Expand Down
2 changes: 1 addition & 1 deletion src/controls/LayerSelector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ from 'jquery'

import GroupLayer from '../layers/GroupLayer'
import {GroupLayer} from '../layers/GroupLayer'
import ButtonBox from '../html/ButtonBox'
import Control from './Control'
import { offset } from '../utilities'
Expand Down
2 changes: 1 addition & 1 deletion src/controls/MeasurementButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import $ from 'jquery'

import Control from './Control'
import { cssClasses, keyCodes } from '../globals'
import VectorLayer from '../layers/VectorLayer'
import {VectorLayer} from '../layers/VectorLayer'

import '../../less/measurement.less'

Expand Down
1 change: 1 addition & 0 deletions src/html/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class Window extends ol.Object {
* @private
*/
this.$element_ = $('<div>').addClass(this.className_)
.on('click', e => e.stopPropagation())

/**
* @type {jQuery}
Expand Down
4 changes: 2 additions & 2 deletions src/layers/BaseLayerMixin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import GroupLayer from './GroupLayer'
import {GroupLayer} from './GroupLayer'

/**
* @typedef {object} BaseLayerMixinOptions
Expand All @@ -8,7 +8,7 @@ import GroupLayer from './GroupLayer'
/**
* This mixin provides baselayer functionality to any layer
*/
export default class BaseLayerMixin {
export class BaseLayerMixin {
/**
* @param {BaseLayerMixinOptions} options
*/
Expand Down
30 changes: 5 additions & 25 deletions src/layers/BaseLayerTile.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
import ol from 'openlayers'

import BaseLayerMixin from './BaseLayerMixin'
import LayerLoadProcessCountMixin from './LayerLoadProcessCountMixin'
import {BaseLayerMixin} from './BaseLayerMixin'
import {LayerLoadProcessCountMixin} from './LayerLoadProcessCountMixin'
import { mixin } from '../utilities'
import {ProvideMapMixin} from './ProvideMapMixin'

export default class BaseLayerTile extends mixin(mixin(ol.layer.Tile, BaseLayerMixin), LayerLoadProcessCountMixin) {
/**
* @param {G4UMap} map
*/
setMap (map) {
/**
* WORKAROUND
* As openlayers identifies managed layers (i.e. layers that are registered via the maps addLayer function)
* by the fact that the setMap method was called and we need a reference to the map in layers contained in a
* grouplayer, we overwrite the setMap method to still have access to the map via the normal way
* @type {G4UMap}
* @private
*/
this.map__ = map
}

/**
* @returns {G4UMap}
*/
getMap () {
return this.map__
}
}
export const BaseLayerTile =
mixin(mixin(mixin(ol.layer.Tile, ProvideMapMixin), BaseLayerMixin), LayerLoadProcessCountMixin)
22 changes: 0 additions & 22 deletions src/layers/EmptyBaseLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,4 @@ export class EmptyBaseLayer extends BaseLayerImage {
})
super(options)
}

/**
* @param {G4UMap} map
*/
setMap (map) {
/**
* WORKAROUND
* As openlayers identifies managed layers (i.e. layers that are registered via the maps addLayer function)
* by the fact that the setMap method was called and we need a reference to the map in layers contained in a
* grouplayer, we overwrite the setMap method to still have access to the map via the normal way
* @type {G4UMap}
* @private
*/
this.map__ = map
}

/**
* @returns {G4UMap}
*/
getMap () {
return this.map__
}
}
31 changes: 11 additions & 20 deletions src/layers/GroupLayer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import ol from 'openlayers'
import {ProvideMapMixin} from './ProvideMapMixin'
import {mixin} from '../utilities'

/**
* This Class is a Wrap around {ol.layer.Group} providing some extra functionality. This class is normally used for a
* category of layers containing them.
*/
export default class GroupLayer extends ol.layer.Group {
export class GroupLayer extends mixin(ol.layer.Group, ProvideMapMixin) {
/**
* @param {object} [options={}]
*/
Expand All @@ -13,42 +15,31 @@ export default class GroupLayer extends ol.layer.Group {

this.getLayers().on('add', /** ol.CollectionEvent */ e => {
let layer = e.element
if (layer.setMap) {
layer.setMap(this.getMap())
if (layer.provideMap) {
layer.provideMap(this.getProvidedMap())
}
})

this.getLayers().on('remove', /** ol.CollectionEvent */ e => {
let layer = e.element
if (layer.setMap) {
layer.setMap(null)
if (layer.provideMap) {
layer.provideMap(null)
}
})
}

/**
* The setMap methods of all contained children are called recursively
* The provideMap methods of all contained children are called recursively
* @param {G4UMap} map
*/
setMap (map) {
/**
* @type {G4UMap}
* @private
*/
this.map_ = map
provideMap (map) {
super.provideMap(map)

this.getLayers().forEach(layer => {
layer.setMap(map)
if (layer.provideMap) { layer.provideMap(map) }
})
}

/**
* @returns {G4UMap}
*/
getMap () {
return this.map_
}

/**
* calls callback for every terminal, non-group Layer
* @param {Function} callback
Expand Down
34 changes: 5 additions & 29 deletions src/layers/ImageLayer.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import ol from 'openlayers'

import LayerLoadProcessCountMixin from './LayerLoadProcessCountMixin'
import BaseLayerMixin from './BaseLayerMixin'
import {LayerLoadProcessCountMixin} from './LayerLoadProcessCountMixin'
import {BaseLayerMixin} from './BaseLayerMixin'
import { mixin } from '../utilities'
import {ProvideMapMixin} from './ProvideMapMixin'

export class ImageLayer extends mixin(ol.layer.Image, LayerLoadProcessCountMixin) {
/**
* @param {G4UMap} map
*/
setMap (map) {
/**
* WORKAROUND
* As openlayers identifies managed layers (i.e. layers that are registered via the maps addLayer function)
* by the fact that the setMap method was called and we need a reference to the map in layers contained in a
* grouplayer, we overwrite the setMap method to still have access to the map via the normal way
* @type {G4UMap}
* @private
*/
this.map__ = map
}

/**
* @returns {G4UMap}
*/
getMap () {
return this.map__
}
}

export class BaseLayerImage extends mixin(ImageLayer, BaseLayerMixin) {

}
export const ImageLayer = mixin(mixin(ol.layer.Image, ProvideMapMixin), LayerLoadProcessCountMixin)

export const BaseLayerImage = mixin(ImageLayer, BaseLayerMixin)
2 changes: 1 addition & 1 deletion src/layers/LayerLoadProcessCountMixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* A mixin to keep track the amount of load processes a source is currently waiting for
*/
export default class LayerLoadProcessCountMixin {
export class LayerLoadProcessCountMixin {
initialize () {
/**
* @type {number}
Expand Down
19 changes: 19 additions & 0 deletions src/layers/ProvideMapMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export class ProvideMapMixin {
/**
* @param {G4UMap} map
*/
provideMap (map) {
/**
* @type {G4UMap|undefined}
* @private
*/
this.providedMap_ = map
}

/**
* @returns {G4UMap|undefined}
*/
getProvidedMap () {
return this.providedMap_
}
}

0 comments on commit d43f132

Please sign in to comment.