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
ef813f76
Commit
ef813f76
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Historic datasource map works as expected
parent
30b3cb1f
No related branches found
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
+72
-32
72 additions, 32 deletions
ipmd/static/ipmd/js/ipmdlib.js
ipmd/templates/ipmd/saddlegallmidgeform.html
+14
-8
14 additions, 8 deletions
ipmd/templates/ipmd/saddlegallmidgeform.html
with
86 additions
and
40 deletions
ipmd/static/ipmd/js/ipmdlib.js
+
72
−
32
View file @
ef813f76
...
...
@@ -183,8 +183,8 @@ function getPragmaticWeatherParameterList(requestedParameters, availableParamete
{
completeList
=
completeList
.
concat
(
requestedParameters
[
i
],
fallbackParams
[
requestedParameters
[
i
]]);
}
console
.
info
(
completeList
);
console
.
info
(
availableParameters
);
//
console.info(completeList);
//
console.info(availableParameters);
return
completeList
.
filter
(
param
=>
availableParameters
.
includes
(
param
));
...
...
@@ -422,6 +422,10 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList, featureC
layers
:
[
backgroundLayer
],
renderer
:
'
canvas
'
});
maps
[
containerId
]
=
map
;
// Setting zoom and center for the map (need to do this after creating map. so that we can transform our
// center to correct map projection)
...
...
@@ -455,14 +459,17 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList, featureC
});
}
let
featureOverlay
=
undefined
;
if
(
drawnFeatures
!=
undefined
)
{
//console.info(drawnFeatures);
// Create an empty layer
var
featureOverlay
=
new
ol
.
layer
.
Vector
({
featureOverlay
=
new
ol
.
layer
.
Vector
({
source
:
new
ol
.
source
.
Vector
({
features
:
features
})
}),
style
:
styleUnselected
});
// Add the stations or area
featureOverlay
.
getSource
().
addFeatures
(
drawnFeatures
);
...
...
@@ -473,69 +480,102 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList, featureC
map
.
getView
().
fit
(
extent
,
map
.
getSize
());
}
/*
* A little bit of this and that with regards to feature selection
* to make it work as we want
* - Highlight a selected station (but only one station, multiple select is not allowed)
* - If user clicks on multiple stations, zoom in to make it easy to pick the right one
*/
let
selectInteraction
=
new
ol
.
interaction
.
Select
({
toggleCondition
:
ol
.
events
.
condition
.
never
// Only one can be selected at a time
});
map
.
addInteraction
(
selectInteraction
);
selectInteraction
.
on
(
"
select
"
,
function
(
e
){
// If it's an area (id == undefined), don't mark it as selected
if
(
e
.
target
.
getFeatures
().
getLength
()
>
0
&&
e
.
target
.
getFeatures
().
item
(
0
).
getId
()
==
undefined
)
{
e
.
target
.
getFeatures
().
clear
();
}
else
if
(
e
.
target
.
getFeatures
().
getLength
()
==
1
)
{
let
feature
=
e
.
target
.
getFeatures
().
item
(
0
);
featureClickedCallback
(
feature
.
getId
(),
undefined
);
}
});
map
.
on
(
'
singleclick
'
,
function
(
evt
)
{
var
pixel
=
map
.
getEventPixel
(
evt
.
originalEvent
);
var
coordinate
=
map
.
getEventCoordinate
(
evt
.
originalEvent
);
displayFeatureDetails
(
map
,
pixel
,
coordinate
,
featureClickedCallback
);
handleMapClicked
(
map
,
featureOverlay
,
pixel
,
coordinate
,
featureClickedCallback
);
});
}
const
styleUnselected
=
new
ol
.
style
.
Style
({
fill
:
new
ol
.
style
.
Fill
({
color
:
'
rgba(173, 173, 173, 0.5)
'
}),
stroke
:
new
ol
.
style
.
Stroke
({
color
:
'
#000000
'
,
width
:
1
}),
image
:
new
ol
.
style
.
Circle
({
radius
:
6
,
fill
:
new
ol
.
style
.
Fill
({
color
:
'
#adadad
'
}),
stroke
:
new
ol
.
style
.
Stroke
({
color
:
'
#000000
'
,
width
:
1
})
})
});
/**
* 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.layer} layer
* @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
)
{
function
handleMapClicked
(
map
,
layer
,
pixel
,
coordinate
,
featureClickedCallback
)
{
var
features
=
[];
map
.
forEachFeatureAtPixel
(
pixel
,
function
(
feature
,
layer
){
map
.
forEachFeatureAtPixel
(
pixel
,
function
(
feature
){
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
// Area
if
(
features
[
0
].
getId
()
===
undefined
)
{
featureClickedCallback
(
null
,
getDecimalDegrees
(
map
,
coordinate
));
console
.
info
(
"
Area clicked
"
);
}
// Click on a station is handled in the select interaction (see initDataSourceMap)
}
// Display popup,so that user can select their station
// The select interaction (see initDataSourceMap) highlights one and only one
// selected feature. If the clicked pixel has more than one feature,
// zoom in to let the user be able to separate the features
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
());
}
}
map
.
getView
().
setCenter
(
coordinate
);
map
.
getView
().
setZoom
(
map
.
getView
().
getZoom
()
+
2
);
}
else
{
// No feature clicked. Do anything?
}
};
/**
*
* @param {ol.Map} map
* @param {Array<Float>} coordinate
* @return
s
the pixel coordinate from a map converted to WGS84 Decimal degrees
* @return
{ol.Coordinate}
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
)
;
return
ol
.
proj
.
transform
(
coordinate
,
map
.
getView
().
getProjection
().
getCode
(),
'
EPSG:4326
'
);
}
async
function
getCountryBoundaries
(
countryCodeList
)
...
...
This diff is collapsed.
Click to expand it.
ipmd/templates/ipmd/saddlegallmidgeform.html
+
14
−
8
View file @
ef813f76
...
...
@@ -67,9 +67,7 @@
</div>
</fieldset>
</div>
<div
class=
"col-md-4"
>
<div
id=
"forecastDatasourceMap"
></div>
</div>
<div
class=
"col-md-4"
></div>
</div>
<button
class=
"btn btn-primary"
type=
"button"
onclick=
"submitData();"
>
Submit
</button>
<div
style=
"aspect-ratio: 2;"
>
...
...
@@ -208,16 +206,19 @@
function
handleHistoricDatasourceMapClicked
(
id
,
coordinate
)
{
console
.
info
(
"
Map clicked, station=
"
+
id
+
"
, coordinate=
"
+
coordinate
+
"
. TODO: select station and/or populate lat/lon fields
"
);
//
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
else
{
setLatLon
(
coordinate
);
}
}
function
setSelection
(
selectList
,
optionValue
)
...
...
@@ -258,8 +259,13 @@
let
weatherStationId
=
selectList
.
options
[
selectList
.
selectedIndex
].
value
;
let
stationCoordinate
=
getWeatherStationCoordinate
(
currentWeatherDatasource
,
weatherStationId
);
//console.info(stationCoordinate);
document
.
getElementById
(
"
longitude
"
).
value
=
stationCoordinate
[
0
];
document
.
getElementById
(
"
latitude
"
).
value
=
stationCoordinate
[
1
];
setLatLon
(
stationCoordinate
);
}
function
setLatLon
(
coordinate
)
{
document
.
getElementById
(
"
longitude
"
).
value
=
coordinate
[
0
];
document
.
getElementById
(
"
latitude
"
).
value
=
coordinate
[
1
];
}
async
function
submitData
(){
...
...
@@ -364,7 +370,7 @@
inputData
[
"
weatherData
"
]
=
weatherData
;
console
.
info
(
weatherData
);
//
console.info(weatherData);
}
// Ready to call server?
//console.info(JSON.stringify(inputData));
...
...
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