Skip to content

Commit

Permalink
Merge branch 'js-requirements'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Aug 12, 2024
2 parents 7c85f8b + 7c1a4f1 commit 28a8716
Show file tree
Hide file tree
Showing 190 changed files with 5,618 additions and 129,024 deletions.
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

20 changes: 19 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,27 @@ http://docs.ckan.org/projects/ckanext-spatial/en/latest/map-widgets.html

.. _widgets: http://docs.ckan.org/projects/ckanext-spatial/en/latest/spatial-search.html#spatial-search-widget

> [!WARNING]
> As of July 2024 the common map configuration is not working with the OpenLayers viewer. Pull requests are welcome to address the issue

-------------------------
Updating the JS libraries
-------------------------

To update a JS library to a new version:

1. Update the version number in ``package.json``
2. Run ``npm install``
3. Run ``npm run update-libs``

The following libraries are managed manually as they don't have npm packages:

* ol-helpers
* shp2geojson


-----------------------------------
Registering ckanext-geoview on PyPI
Registering ckanext-geoview on pypi
-----------------------------------

ckanext-geoview should be availabe on PyPI as
Expand Down
14 changes: 0 additions & 14 deletions bower.json

This file was deleted.

32 changes: 5 additions & 27 deletions ckanext/geoview/public/css/wmts_preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,20 @@ html, body {
height: 100%;
}

#map .table{
width: 300px;
}

#map label {
font-weight: normal;
}

#map label:after {
content: none;
}

#map input {
width: auto;
top: auto;
}

.leaflet-control-layers {
box-shadow: 0 1px 7px rgba(0,0,0,0.4);
background: #f8f8f9;
-webkit-border-radius: 5px;
border-radius: 5px;
overflow: auto;
max-height: 200px;
overflow-y: hidden;
}

.ui-opacity {
box-shadow: 0 0 8px rgba(0,0,0,0.4);
background: rgba(255, 255, 255, 0.8);
position: absolute;
left: 13px;
top: 70px;
left: 14px;
top: 80px;
height: 200px;
width: 22px;
border: 1px solid #888;
border-radius: 5px;
border: 2px solid rgba(0, 0, 0, 0.2);
border-radius: 4px;
z-index: 1000;
}

Expand Down
241 changes: 132 additions & 109 deletions ckanext/geoview/public/js/ol_preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global ckan, OL_HELPERS, ol, $, preload_resource */
// Openlayers preview module

(function() {
Expand Down Expand Up @@ -92,19 +93,16 @@
},

addLayer: function (resourceLayer) {

if (ckan.geoview && ckan.geoview.feature_style) {
var styleMapJson = JSON.parse(ckan.geoview.feature_style)
/* TODO_OL4 how is stylemap converted to OL4 ? */
//resourceLayer.styleMap = new OpenLayers.StyleMap(styleMapJson)
if (resourceLayer.setStyle) {
resourceLayer.setStyle(this.defaultStyle);
}

if (this.options.ol_config.hide_overlays &&
this.options.ol_config.hide_overlays.toLowerCase() == "true") {
resourceLayer.setVisibility(false);
}

this.map.addLayerWithExtent(resourceLayer)
this.map.addLayerWithExtent(resourceLayer);
},

_commonBaseLayer: function(mapConfig, callback, module) {
Expand All @@ -130,7 +128,132 @@
mapConfig.type = 'OSM'
}

return OL_HELPERS.createLayerFromConfig(mapConfig, true, callback);
return OL_HELPERS.createLayerFromConfig(mapConfig, true).then(callback);
},

createMapFun: function (baseMapLayerList, overlays) {

var layerSwitcher = new ol.control.HilatsLayerSwitcher();

var styleMapJson = OL_HELPERS.DEFAULT_STYLEMAP;

if (ckan.geoview && ckan.geoview.feature_style) {
styleMapJson = JSON.parse(ckan.geoview.feature_style);
// default style can be json w/ expressions, highlight style needs to be objectified
if (styleMapJson.highlight) {
// must convert highlight style to objects.
styleMapJson.highlight = OL_HELPERS.makeStyle(styleMapJson.highlight);
}
}
this.defaultStyle = styleMapJson.default || styleMapJson;
this.highlightStyle = styleMapJson.highlight || undefined;


var coordinateFormatter = function(coordinate) {
var degrees = map && map.getView() && map.getView().getProjection() && (map.getView().getProjection().getUnits() == 'degrees')
return ol.coordinate.toStringXY(coordinate, degrees ? 5:2);
};

const baseMapLayer = baseMapLayerList[0];

var options = {
target: $('.map')[0],
layers: baseMapLayerList,
controls: [
new ol.control.ZoomSlider(),
new ol.control.MousePosition( {
coordinateFormat: coordinateFormatter,
}),
layerSwitcher
],
loadingDiv: false,
loadingListener: function(isLoading) {
layerSwitcher.isLoading(isLoading);
},
overlays: overlays,
view: new ol.View({
// projection attr should be set when creating a baselayer
projection: baseMapLayer.getSource().getProjection() || OL_HELPERS.Mercator,
extent: baseMapLayer.getExtent(), /* TODO_OL4 is this equivalent to maxExtent? */
//center: [0,0],
//zoom: 4
})
};

var map = this.map = new OL_HELPERS.LoggingMap(options);
// by default stretch the map to the basemap extent or to the world
map.getView().fit(
baseMapLayer.getExtent() || ol.proj.transformExtent(OL_HELPERS.WORLD_BBOX, OL_HELPERS.EPSG4326, map.getView().getProjection()),
{constrainResolution: false}
);

map.highlightStyle = this.highlightStyle;
let selected = null;
map.on('pointermove', function (e) {
if (selected !== null) {
selected.setStyle(undefined);
selected = null;
}

map.forEachFeatureAtPixel(e.pixel, function (f) {
selected = f;
f.setStyle(map.highlightStyle);
return true;
});
});

// force a reload of all vector sources on projection change
map.getView().on('change:projection', function() {
map.getLayers().forEach(function(layer) {
if (layer instanceof ol.layer.Vector) {
layer.getSource().clear();
}
});
});
map.on('change:view', function() {
map.getLayers().forEach(function(layer) {
if (layer instanceof ol.layer.Vector) {
layer.getSource().clear();
}
});
});


var fragMap = OL_HELPERS.parseKVP((window.parent || window).location.hash && (window.parent || window).location.hash.substring(1));

var bbox = fragMap.bbox && fragMap.bbox.split(',').map(parseFloat)
var bbox = bbox && ol.proj.transformExtent(bbox, OL_HELPERS.EPSG4326, this.map.getProjection());
if (bbox) this.map.zoomToExtent(bbox);

/* Update URL with current bbox
var $map = this.map;
var mapChangeListener = function() {
var newBbox = $map.getExtent() && $map.getExtent().transform($map.getProjectionObject(), OL_HELPERS.EPSG4326).toString()
if (newBbox) {
var fragMap = OL_HELPERS.parseKVP((window.parent || window).location.hash && (window.parent || window).location.hash.substring(1));
fragMap['bbox'] = newBbox;
(window.parent || window).location.hash = OL_HELPERS.kvp2string(fragMap)
}
}
// listen to bbox changes to update URL fragment
this.map.events.register("moveend", this.map, mapChangeListener);
this.map.events.register("zoomend", this.map, mapChangeListener);
*/


var proxyUrl = this.options.proxy_url;
var proxyServiceUrl = this.options.proxy_service_url;

ckan.geoview.googleApiKey = this.options.gapi_key;


withLayers(preload_resource, proxyUrl, proxyServiceUrl, $_.bind(this.addLayer, this), this.map);
},

_onReady: function () {
Expand Down Expand Up @@ -169,106 +292,6 @@
}))


var createMapFun = function(baseMapLayer) {

var layerSwitcher = new ol.control.HilatsLayerSwitcher();

var coordinateFormatter = function(coordinate) {
var degrees = map && map.getView() && map.getView().getProjection() && (map.getView().getProjection().getUnits() == 'degrees')
return ol.coordinate.toStringXY(coordinate, degrees ? 5:2);
};

var options = {
target: $('.map')[0],
layers: [baseMapLayer],
controls: [
new ol.control.ZoomSlider(),
new ol.control.MousePosition( {
coordinateFormat: coordinateFormatter,
}),
layerSwitcher
],
loadingDiv: false,
loadingListener: function(isLoading) {
layerSwitcher.isLoading(isLoading)
},
overlays: overlays,
view: new ol.View({
// projection attr should be set when creating a baselayer
projection: baseMapLayer.getSource().getProjection() || OL_HELPERS.Mercator,
extent: baseMapLayer.getExtent(), /* TODO_OL4 is this equivalent to maxExtent? */
//center: [0,0],
//zoom: 4
})
}

var map = this.map = new OL_HELPERS.LoggingMap(options);
// by default stretch the map to the basemap extent or to the world
map.getView().fit(
baseMapLayer.getExtent() || ol.proj.transformExtent(OL_HELPERS.WORLD_BBOX, OL_HELPERS.EPSG4326, map.getView().getProjection()),
{constrainResolution: false}
);

var highlighter = new ol.interaction.Select({
toggleCondition : function(evt) {return false},
multi: true,
condition: ol.events.condition.pointerMove
});
map.addInteraction(highlighter);

// force a reload of all vector sources on projection change
map.getView().on('change:projection', function() {
map.getLayers().forEach(function(layer) {
if (layer instanceof ol.layer.Vector) {
layer.getSource().clear();
}
});
});
map.on('change:view', function() {
map.getLayers().forEach(function(layer) {
if (layer instanceof ol.layer.Vector) {
layer.getSource().clear();
}
});
});


var fragMap = OL_HELPERS.parseKVP((window.parent || window).location.hash && (window.parent || window).location.hash.substring(1));

var bbox = fragMap.bbox && fragMap.bbox.split(',').map(parseFloat)
var bbox = bbox && ol.proj.transformExtent(bbox, OL_HELPERS.EPSG4326, this.map.getProjection());
if (bbox) this.map.zoomToExtent(bbox);

/* Update URL with current bbox
var $map = this.map;
var mapChangeListener = function() {
var newBbox = $map.getExtent() && $map.getExtent().transform($map.getProjectionObject(), OL_HELPERS.EPSG4326).toString()
if (newBbox) {
var fragMap = OL_HELPERS.parseKVP((window.parent || window).location.hash && (window.parent || window).location.hash.substring(1));
fragMap['bbox'] = newBbox;
(window.parent || window).location.hash = OL_HELPERS.kvp2string(fragMap)
}
}
// listen to bbox changes to update URL fragment
this.map.events.register("moveend", this.map, mapChangeListener);
this.map.events.register("zoomend", this.map, mapChangeListener);
*/


var proxyUrl = this.options.proxy_url;
var proxyServiceUrl = this.options.proxy_service_url;

ckan.geoview.googleApiKey = this.options.gapi_key;


withLayers(preload_resource, proxyUrl, proxyServiceUrl, $_.bind(this.addLayer, this), this.map);
}

var $this = this;

Expand All @@ -289,8 +312,8 @@
this._commonBaseLayer(
baseMapsConfig[0],
function(layer) {
baseMapsConfig[0].$ol_layer = layer
$_.bind(createMapFun,$this)(layer)
baseMapsConfig[0].$ol_layer = layer;
$this.createMapFun(layer, overlays);

// add all configured basemap layers
if (baseMapsConfig.length > 1) {
Expand Down
Loading

0 comments on commit 28a8716

Please sign in to comment.