Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSWeb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSWeb
Commits
30b3cb1f
Commit
30b3cb1f
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Starting handling feature selection
parent
feedcb28
Branches
Branches containing commit
No related tags found
2 merge requests
!13
Saddlegallmidge form idec 372
,
!12
feat: Add test page (spatial) with mapserver layer in openlayers map
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ipmd/static/ipmd/js/ipmdlib.js
+67
-1
67 additions, 1 deletion
ipmd/static/ipmd/js/ipmdlib.js
ipmd/templates/ipmd/saddlegallmidgeform.html
+36
-1
36 additions, 1 deletion
ipmd/templates/ipmd/saddlegallmidgeform.html
with
103 additions
and
2 deletions
ipmd/static/ipmd/js/ipmdlib.js
+
67
−
1
View file @
30b3cb1f
...
...
@@ -380,8 +380,10 @@ var maps = {};
* Requires OpenLayers v. 4
* @param {String} containerId
* @param {JSON} geoJson
* @param {Array} countryCodeList
* @param {Function} featureClickedCallback Callback function taking parameters ({String} id, {Array<Float>} coordinate)
*/
async
function
initDataSourceMap
(
containerId
,
geoJson
,
countryCodeList
)
async
function
initDataSourceMap
(
containerId
,
geoJson
,
countryCodeList
,
featureClickedCallback
)
{
let
map
=
maps
[
containerId
];
...
...
@@ -470,6 +472,70 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList)
extent
=
featureOverlay
.
getSource
().
getExtent
();
map
.
getView
().
fit
(
extent
,
map
.
getSize
());
}
map
.
on
(
'
singleclick
'
,
function
(
evt
)
{
var
pixel
=
map
.
getEventPixel
(
evt
.
originalEvent
);
var
coordinate
=
map
.
getEventCoordinate
(
evt
.
originalEvent
);
displayFeatureDetails
(
map
,
pixel
,
coordinate
,
featureClickedCallback
);
});
}
/**
* When a user clicks on the map, handles whatever was clicked (station, point in area, point outside any feature/area)
* @param {ol.map} map
* @param {ol.Pixel} pixel
* @param {ol.coordinate} coordinate
* @param {Function} featureClickedCallback Callback function taking parameters ({String} id, {Array<Float>} coordinate)
*/
function
displayFeatureDetails
(
map
,
pixel
,
coordinate
,
featureClickedCallback
)
{
var
features
=
[];
map
.
forEachFeatureAtPixel
(
pixel
,
function
(
feature
,
layer
){
features
.
push
(
feature
);
});
if
(
features
.
length
==
1
)
{
// A station? Select station using features[i].getId() in callback
if
(
features
[
0
].
getId
()
!==
undefined
)
{
console
.
info
(
"
Station clicked:
"
+
features
[
0
].
get
(
"
name
"
)
+
"
,id=
"
+
features
[
0
].
getId
());
featureClickedCallback
(
features
[
0
].
getId
(),
getDecimalDegrees
(
map
,
coordinate
));
}
// An area? Return the coordinate of clicked point in callback
else
{
featureClickedCallback
(
null
,
getDecimalDegrees
(
map
,
coordinate
));
console
.
info
(
"
Area clicked
"
);
}
}
// Display popup,so that user can select their station
else
if
(
features
.
length
>
1
)
{
console
.
info
(
"
Multiple stations clicked. TODO: Let user select from a popup
"
)
for
(
var
i
in
features
)
{
// A station? Select station using features[i].getId() in callback
if
(
features
[
i
].
getId
()
!==
undefined
)
{
console
.
info
(
"
Station clicked:
"
+
features
[
i
].
get
(
"
name
"
)
+
"
,id=
"
+
features
[
i
].
getId
());
}
}
}
else
{
// No feature clicked. Do anything?
}
};
/**
*
* @param {ol.Map} map
* @param {Array<Float>} coordinate
* @returns the pixel coordinate from a map converted to WGS84 Decimal degrees
*/
function
getDecimalDegrees
(
map
,
coordinate
)
{
return
ol
.
coordinate
.
toStringXY
(
ol
.
proj
.
transform
(
coordinate
,
map
.
getView
().
getProjection
().
getCode
(),
'
EPSG:4326
'
),
5
);
}
async
function
getCountryBoundaries
(
countryCodeList
)
...
...
This diff is collapsed.
Click to expand it.
ipmd/templates/ipmd/saddlegallmidgeform.html
+
36
−
1
View file @
30b3cb1f
...
...
@@ -178,7 +178,12 @@
}
// Display map
initDataSourceMap
(
"
historicDatasourceMap
"
,
JSON
.
parse
(
currentWeatherDatasource
.
spatial
.
geoJSON
),
currentWeatherDatasource
.
spatial
.
countries
);
initDataSourceMap
(
"
historicDatasourceMap
"
,
JSON
.
parse
(
currentWeatherDatasource
.
spatial
.
geoJSON
),
currentWeatherDatasource
.
spatial
.
countries
,
handleHistoricDatasourceMapClicked
);
let
sourceInfo
=
document
.
getElementById
(
"
historicSourceInfo
"
);
sourceInfo
.
innerHTML
=
currentWeatherDatasource
.
description
;
...
...
@@ -200,6 +205,36 @@
//console.info(currentWeatherDatasource);
}
function
handleHistoricDatasourceMapClicked
(
id
,
coordinate
)
{
console
.
info
(
"
Map clicked, station=
"
+
id
+
"
, coordinate=
"
+
coordinate
+
"
. TODO: select station and/or populate lat/lon fields
"
);
// id != null => station. Pull station coordinates from source list to avoid inacurracies in user's map click coordinate
if
(
id
!==
null
)
{
// Set the selected station
setSelection
(
selectList
,
id
);
handleWeatherStationSelected
(
selectList
);
// Call handleWeatherStationSelected()
}
// id == null => area. Use the provided coordinate
}
function
setSelection
(
selectList
,
optionValue
)
{
for
(
let
i
=
0
;
i
<
selectList
.
options
.
length
;
i
++
)
{
if
(
selectList
.
options
[
i
].
value
==
optionValue
)
{
selectList
.
options
[
i
].
selected
=
true
;
}
else
{
selectList
.
options
[
i
].
selected
=
false
;
}
}
}
function
handleForecastSourceSelected
(
forecastSourceSelectList
)
{
currentForecastWeatherDatasource
=
getWeatherDatasource
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment