Skip to content

Commit

Permalink
Merge pull request #13 from sbruggmann/feature/map-hooks
Browse files Browse the repository at this point in the history
TASK: Added a possability to hook into the layer generation
  • Loading branch information
sbruggmann authored Sep 23, 2020
2 parents 24dafbc + 141453a commit 5f36ae8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ WebExcess:
paddingTopLeft: [100, 100]
paddingBottomRight: [100, 100]
mapOptions: []
mapHooks: []
36 changes: 35 additions & 1 deletion Resources/Private/Assets/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ function OpenStreetMap() {
scrollWheelZoom: false
};

var mapHooks = {
addMarkersLayerHook: false
};

if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
Expand Down Expand Up @@ -120,7 +124,29 @@ function OpenStreetMap() {
markers[mapElement._container.attributes.id.value].push(marker);
return marker;
}
}).addTo(mapElement);
});

if (mapHooks.addMarkersLayerHook) {
var addMarkersLayerHookResult;
try {
if (typeof(mapHooks.addMarkersLayerHook) === 'string') {
addMarkersLayerHookResult = window[mapHooks.addMarkersLayerHook](geojsonLayer);
} else if (typeof(mapHooks.addMarkersLayerHook) === 'function') {
addMarkersLayerHookResult = mapHooks.addMarkersLayerHook(geojsonLayer);
}
} catch (e) {
console.log(e);
}

if (!addMarkersLayerHookResult) {
addMarkersLayerHookResult = geojsonLayer;
}

mapElement.addLayer(addMarkersLayerHookResult);
} else {
mapElement.addLayer(geojsonLayer);
}

mapElement.fitBounds(geojsonLayer.getBounds(), {
paddingTopLeft: paddingTopLeft,
paddingBottomRight: paddingBottomRight
Expand Down Expand Up @@ -168,6 +194,14 @@ function OpenStreetMap() {
}
mapSpecificOptions = Object.assign({}, mapOptions, mapSpecificOptions);

var mapSpecificHooks = mapContainer.getAttribute('data-map-hooks');
if (mapSpecificHooks) {
mapSpecificHooks = JSON.parse(mapSpecificHooks);
} else {
mapSpecificHooks = {};
}
mapHooks = Object.assign({}, mapHooks, mapSpecificHooks);

mapIds.push(mapId);
maps[mapId] = new L.Map(mapId, mapSpecificOptions);
markers[mapId] = [];
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Fusion/Components/Map.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ prototype(WebExcess.OpenStreetMap:Map.Component) < prototype(Neos.Fusion:Compone
mapOptionsRenderer = ${Array.concat(this.defaultMapOptions, this.mapOptions)}
mapOptionsRenderer.@process.jsonStringify = ${value ? Json.stringify(value) : null}

mapHooks = Neos.Fusion:RawArray
defaultMapHooks = ${Configuration.setting('WebExcess.OpenStreetMap.mapHooks')}
mapHooksRenderer = ${Array.concat(this.defaultMapHooks, this.mapHooks)}
mapHooksRenderer.@process.jsonStringify = ${value ? Json.stringify(value) : null}

address = null
latLonRenderer = ${this.address ? Geocode.latLonFromAddress(this.address) : null}

Expand Down Expand Up @@ -79,6 +84,7 @@ prototype(WebExcess.OpenStreetMap:Map.Component) < prototype(Neos.Fusion:Compone
data-popup = ${props.popupRenderer}
data-json = ${props.jsonRenderer}
data-map-options = ${props.mapOptionsRenderer}
data-map-hooks = ${props.mapHooksRenderer}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Assets/Main.js

Large diffs are not rendered by default.

0 comments on commit 5f36ae8

Please sign in to comment.