Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some new features #67

Merged
merged 7 commits into from Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
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
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
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
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
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
@@ -1,6 +1,6 @@
import ol from 'openlayers'

import GroupLayer from '../layers/GroupLayer'
import {GroupLayer} from '../layers/GroupLayer'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as example for many:) The use of spaces in brackets is very inconsistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See standard/standard#609

space-in-brackets was removed with ESLint 1.0.

import { copyDeep } from '../utilitiesObject'
import { checkFor } from '../utilities'
import Debug from '../Debug'
Expand Down
6 changes: 3 additions & 3 deletions src/configurators/LayerFactory.js
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
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
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
@@ -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
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
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
@@ -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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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_
}
}