-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #340, Draggable GetFeatureInfo
- Loading branch information
1 parent
f90a4a8
commit 1083173
Showing
31 changed files
with
621 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/** | ||
* Copyright 2015, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
var React = require('react'); | ||
var L = require('leaflet'); | ||
const {isEqual} = require('lodash'); | ||
|
||
var coordsToLatLngF = function(coords) { | ||
return new L.LatLng(coords[1], coords[0], coords[2]); | ||
}; | ||
|
||
var coordsToLatLngs = function(coords, levelsDeep, coordsToLatLng) { | ||
var latlngs = []; | ||
var len = coords.length; | ||
for (let i = 0, latlng; i < len; i++) { | ||
latlng = levelsDeep ? | ||
coordsToLatLngs(coords[i], levelsDeep - 1, coordsToLatLng) : | ||
(coordsToLatLng || this.coordsToLatLng)(coords[i]); | ||
|
||
latlngs.push(latlng); | ||
} | ||
|
||
return latlngs; | ||
}; | ||
var geometryToLayer = function(geojson, options) { | ||
|
||
var geometry = geojson.type === 'Feature' ? geojson.geometry : geojson; | ||
var coords = geometry ? geometry.coordinates : null; | ||
var layers = []; | ||
var pointToLayer = options && options.pointToLayer; | ||
var latlng; | ||
var latlngs; | ||
var i; | ||
var len; | ||
let coordsToLatLng = options && options.coordsToLatLng || coordsToLatLngF; | ||
|
||
if (!coords && !geometry) { | ||
return null; | ||
} | ||
|
||
switch (geometry.type) { | ||
case 'Point': | ||
latlng = coordsToLatLng(coords); | ||
return pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng); | ||
|
||
case 'MultiPoint': | ||
for (i = 0, len = coords.length; i < len; i++) { | ||
latlng = coordsToLatLng(coords[i]); | ||
layers.push(pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng)); | ||
} | ||
return new L.FeatureGroup(layers); | ||
|
||
case 'LineString': | ||
case 'MultiLineString': | ||
latlngs = coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, coordsToLatLng); | ||
return new L.Polyline(latlngs, options); | ||
|
||
case 'Polygon': | ||
case 'MultiPolygon': | ||
latlngs = coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, coordsToLatLng); | ||
return new L.Polygon(latlngs, options); | ||
|
||
case 'GeometryCollection': | ||
for (i = 0, len = geometry.geometries.length; i < len; i++) { | ||
let layer = this.geometryToLayer({ | ||
geometry: geometry.geometries[i], | ||
type: 'Feature', | ||
properties: geojson.properties | ||
}, options); | ||
|
||
if (layer) { | ||
layers.push(layer); | ||
} | ||
} | ||
return new L.FeatureGroup(layers); | ||
|
||
default: | ||
throw new Error('Invalid GeoJSON object.'); | ||
} | ||
}; | ||
|
||
let Feature = React.createClass({ | ||
propTypes: { | ||
type: React.PropTypes.string, | ||
styleName: React.PropTypes.string, | ||
properties: React.PropTypes.object, | ||
container: React.PropTypes.object, // TODO it must be a L.GeoJSON | ||
geometry: React.PropTypes.object // TODO check for geojson format for geometry | ||
}, | ||
componentDidMount() { | ||
if (this.props.container) { | ||
this._layer = geometryToLayer({ | ||
type: this.props.type, | ||
geometry: this.props.geometry, | ||
pointToLayer: this.props.styleName !== "marker" ? function(feature, latlng) { | ||
return L.circleMarker(latlng, { | ||
radius: 5, | ||
color: "red", | ||
weight: 1, | ||
opacity: 1, | ||
fillOpacity: 0 | ||
}); | ||
} : null} | ||
); | ||
this.props.container.addLayer(this._layer); | ||
} | ||
}, | ||
componentWillReceiveProps(newProps) { | ||
if (!isEqual(newProps.properties, this.props.properties) || !isEqual(newProps.geometry, this.props.geometry)) { | ||
this.props.container.removeLayer(this._layer); | ||
this._layer = geometryToLayer({ | ||
type: newProps.type, | ||
geometry: newProps.geometry, | ||
pointToLayer: newProps.styleName !== "marker" ? function(feature, latlng) { | ||
return L.circleMarker(latlng, { | ||
radius: 5, | ||
color: "red", | ||
weight: 1, | ||
opacity: 1, | ||
fillOpacity: 0 | ||
}); | ||
} : null} | ||
); | ||
newProps.container.addLayer(this._layer); | ||
} | ||
}, | ||
shouldComponentUpdate(nextProps) { | ||
return !isEqual(nextProps.properties, this.props.properties) || !isEqual(nextProps.geometry, this.props.geometry); | ||
}, | ||
componentWillUnmount() { | ||
if (this._layer) { | ||
this.props.container.removeLayer(this._layer); | ||
} | ||
}, | ||
render() { | ||
return null; | ||
} | ||
}); | ||
|
||
module.exports = Feature; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright 2015, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
var React = require('react'); | ||
|
||
|
||
let Feature = React.createClass({ | ||
propTypes: { | ||
type: React.PropTypes.string, | ||
container: React.PropTypes.object, // TODO it must be a L.GeoJSON | ||
geometry: React.PropTypes.object | ||
}, | ||
componentDidMount() { | ||
}, | ||
componentWillUnmount() { | ||
}, | ||
render() { | ||
return null; | ||
} | ||
}); | ||
|
||
module.exports = Feature; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright 2015, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
var Layers = require('../../../../utils/leaflet/Layers'); | ||
var L = require('leaflet'); | ||
|
||
var defaultStyle = { | ||
radius: 5, | ||
color: "red", | ||
weight: 1, | ||
opacity: 1, | ||
fillOpacity: 0 | ||
}; | ||
|
||
var createVectorLayer = function(options) { | ||
return L.geoJson([]/* options.features */, { | ||
pointToLayer: options.styleName !== "marker" ? function(feature, latlng) { | ||
return L.circleMarker(latlng, defaultStyle); | ||
} : null | ||
}); | ||
}; | ||
|
||
Layers.registerType('vector', { | ||
create: (options) => { | ||
return createVectorLayer(options); | ||
}, | ||
render: () => { | ||
return null; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.