-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
448 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
assets/scripts/vanilla/controllers/back_signalement_view/pick-localisation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import L from 'leaflet'; | ||
import 'leaflet.vectorgrid'; | ||
|
||
const modalLocalisation = document.getElementById('fr-modal-localisation'); | ||
const modalPickLocalisation = document.getElementById('fr-modal-pick-localisation'); | ||
const modalPickLocalisationMessage = document.getElementById('fr-modal-pick-localisation-message'); | ||
|
||
if (modalLocalisation) { | ||
modalLocalisation.addEventListener('dsfr.disclose', (e) => { | ||
if(modalLocalisation.dataset.loaded == 'false'){ | ||
modalLocalisation.dataset.loaded = 'true' | ||
const map = L.map('fr-modal-localisation-map') | ||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||
maxZoom: 19, | ||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' | ||
}).addTo(map) | ||
let lat = modalLocalisation.dataset.lat | ||
let lng = modalLocalisation.dataset.lng | ||
map.setView([lat, lng], 18) | ||
L.marker([lat, lng]).addTo(map) | ||
} | ||
}) | ||
|
||
}else if (modalPickLocalisation) { | ||
const map = L.map('fr-modal-pick-localisation-map') | ||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||
maxZoom: 19, | ||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' | ||
}).addTo(map) | ||
|
||
modalPickLocalisation.addEventListener('dsfr.disclose', (e) => { | ||
if(modalPickLocalisation.dataset.loaded == 'false'){ | ||
modalPickLocalisation.dataset.loaded = 'true' | ||
const apiAdresse = 'https://api-adresse.data.gouv.fr/search/?q=' | ||
let address = modalPickLocalisation.dataset.address | ||
let postCode = modalPickLocalisation.dataset.postcode | ||
fetch(apiAdresse + address + '&postcode=' + postCode).then(response => response.json()).then(json => { | ||
map.setView([json.features[0].geometry.coordinates[1], json.features[0].geometry.coordinates[0]], 18) | ||
modalPickLocalisationMessage.classList.add('fr-hidden') | ||
}) | ||
} | ||
}) | ||
|
||
// Patch pour rendre les couches vectorielles interactives : https://github.com/Leaflet/Leaflet.VectorGrid/issues/274#issuecomment-1371640331 | ||
L.Canvas.Tile.include({ | ||
_onClick: function (e) { | ||
var point = this._map.mouseEventToLayerPoint(e).subtract(this.getOffset()); | ||
var layer = L.Layer; | ||
var clickedLayer = L.Layer; | ||
|
||
for (var id in this._layers) { | ||
layer = this._layers[id]; | ||
if ( | ||
layer.options.interactive && | ||
layer._containsPoint(point) && | ||
!this._map._draggableMoved(layer) | ||
) { | ||
clickedLayer = layer; | ||
} | ||
} | ||
if (clickedLayer) { | ||
if (typeof clickedLayer === 'object' && clickedLayer !== null) { | ||
clickedLayer.fireEvent(e.type, undefined, true); | ||
} | ||
} | ||
}, | ||
}) | ||
// Fin du patch | ||
var clickedStyle = { | ||
radius: 5, | ||
fillColor: '#31e060', | ||
color: '#ffffff', | ||
weight: 3, | ||
fill: true, | ||
fillOpacity: 1, | ||
opacity: 1 | ||
} | ||
|
||
var initialStyle = { | ||
radius: 5, | ||
fillColor: '#1452e3', | ||
color: '#ffffff', | ||
weight: 3, | ||
fill: true, | ||
fillOpacity: 1, | ||
opacity: 1 | ||
} | ||
|
||
var vectorTileOptions = { | ||
rendererFactory: L.canvas.tile, | ||
vectorTileLayerStyles: { | ||
'default': initialStyle | ||
}, | ||
interactive: true, | ||
getFeatureId: function(f) { | ||
return f.properties.rnb_id; | ||
} | ||
} | ||
|
||
var vectorTileLayer = L.vectorGrid.protobuf('https://rnb-api.beta.gouv.fr/api/alpha/tiles/{x}/{y}/{z}.pbf', vectorTileOptions); | ||
vectorTileLayer.addTo(map); | ||
var previousId; | ||
vectorTileLayer.on('click', async function(e) { | ||
var properties = e.layer.properties; | ||
var rnb_id = properties.rnb_id; | ||
if (previousId !== undefined) { | ||
vectorTileLayer.setFeatureStyle(previousId, initialStyle); | ||
} | ||
vectorTileLayer.setFeatureStyle(rnb_id, clickedStyle); | ||
previousId = rnb_id; | ||
document.getElementById('fr-modal-pick-localisation-rnb-id').value = rnb_id | ||
document.getElementById('fr-modal-pick-localisation-submit').disabled = false | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ parameters: | |
- "https://cdn.jsdelivr.net/npm/[email protected]/" | ||
- "https://cdn.jsdelivr.net/gh/nelmio/NelmioApiDocBundle/public/swagger-ui/" | ||
- "https://cdn.jsdelivr.net/gh/nelmio/NelmioApiDocBundle/public/" | ||
- "https://cdn.jsdelivr.net/npm/leaflet.vectorgrid/dist/Leaflet.VectorGrid.bundled.min.js" | ||
style-src: | ||
- "'self'" | ||
- "'unsafe-inline'" | ||
|
@@ -34,6 +35,7 @@ parameters: | |
- "blob:" | ||
- "https://voxusagers.numerique.gouv.fr" | ||
- "https://*.tile.openstreetmap.org" | ||
- "https://tile.openstreetmap.org" | ||
- "https://cdn.jsdelivr.net" | ||
- "https://jedonnemonavis.numerique.gouv.fr" | ||
- "https://cdn.redoc.ly" | ||
|
@@ -44,6 +46,7 @@ parameters: | |
- "https://histologe.matomo.cloud" | ||
- "https://koumoul.com" | ||
- "https://sentry.incubateur.net" | ||
- "https://rnb-api.beta.gouv.fr" | ||
font-src: | ||
- "'self'" | ||
- "https://fonts.gstatic.com" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.