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

Updated Dependencies #101

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
53 changes: 53 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,56 @@ To publish a new version to PyPI follow these steps:
.. _GeoJSON: http://geojson.org/
.. _Shapefile: https://en.wikipedia.org/wiki/Shapefile
.. _ckanext-spatial: https://github.com/ckan/ckanext-spatial



* update bower, updating pins in bower.json
```
docker run -ti --rm -v `pwd`:/src node:18 bash
npm install -g bower
cd /src
bower update
cd /src/ckanext/geoview/public/js/vendor/leaflet
npm install .
npm run build
```

* OL User Spec'd View Styles:
- Default can be json only, using expressions
- Highlight has to use old school style objects, so needs to be directly convertible to ol.style.Style objects.
- Highlight is optional.
- If it's just a set of json styles, it's the default style, implying no highlight style.
```
{
"default": [
{
"filter": [
">",
[
"get",
"FIELD_NAME"
],
20
],
"style": {
"circle-fill-color": "red",
"circle-radius": 5
}
},
{
"else": true,
"style": {
"circle-fill-color": "blue",
"circle-radius": 5
}
}
],
"highlight": {
"image": {
"fill": "white",
"stroke": "red",
"radius": 10
}
}
}
```
15 changes: 6 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"name": "ckanext-geoview",
"version": "0.0.2",
"version": "0.1.1",
"dependencies": {
"ol-helpers": "pduchesne/ol-helpers#ol4",
"leaflet": "~0.7.7",
"proj4leaflet": "~0.7.2",
"proj4": "^2.3.17"
"ol-helpers": "derilinx/ol-helpers#ol9",
"leaflet": "1.9.4",
"proj4leaflet": "1.0.2",
"proj4": "^2.11.0"
},
"appPath": "ckanext/geoview/public",
"resolutions": {
"proj4": "^2.3.17"
}
"appPath": "ckanext/geoview/public"
}
3 changes: 2 additions & 1 deletion ckanext/geoview/public/js/geojson_preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global preload_resource, ckan, proj4, $, L */
// geojson preview module
ckan.module('geojsonpreview', function (jQuery, _) {
return {
Expand Down Expand Up @@ -32,7 +33,7 @@ ckan.module('geojsonpreview', function (jQuery, _) {
self.map = ckan.commonLeafletMap('map', this.options.map_config);

// hack to make leaflet use a particular location to look for images
L.Icon.Default.imagePath = this.options.site_url + 'js/vendor/leaflet/dist/images';
L.Icon.Default.imagePath = this.options.site_url + 'js/vendor/leaflet/dist/images/';

jQuery.getJSON(preload_resource['url']).done(
function(data){
Expand Down
226 changes: 114 additions & 112 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 All @@ -16,11 +17,12 @@

var esrirestExtractor = function(resource, proxyUrl, proxyServiceUrl, layerProcessor, map) {
var parsedUrl = resource.url.split('#');
var url = proxyServiceUrl || parsedUrl[0];
var url = parsedUrl[0]; // proxy urls don't work with ckan's resource proxy and the /query added on at the end.

var layerName = parsedUrl.length > 1 && parsedUrl[1];
var proxifyFn = (_url) => _url.includes('/query') ? url + _url : proxyServiceUrl + _url;

OL_HELPERS.withArcGisLayers(url, layerProcessor, layerName, parsedUrl[0]);
OL_HELPERS.withArcGisLayers('', layerProcessor, layerName, proxifyFn, map);
}

ckan.geoview.layerExtractors = {
Expand Down Expand Up @@ -93,18 +95,14 @@

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)
}
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,110 @@
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);

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 @@ -165,110 +266,11 @@
overlays.push(new OL_HELPERS.FeatureInfoOverlay({
element: $("<div class='popupContainer'><div class='popupContent'></div></div>")[0],
autoPan: false,
offset: [5,5]
offset: [5,5],
showDetails: true
}))


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 +291,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
Loading