Source: map-openstreetmap/src/main/resources/META-INF/resources/js/OpenStreetMapGeoJSON.es.js

  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. import GeoJSONBase from 'map-common/js/GeoJSONBase.es';
  15. /**
  16. * OpenStreetMapGeoJSONBase
  17. * @review
  18. */
  19. class OpenStreetMapGeoJSONBase extends GeoJSONBase {
  20. /**
  21. * Creates a new map geojson parser using OpenStreetMap's API
  22. * @param {Array} args List of arguments to be passed to State
  23. * @review
  24. */
  25. constructor(...args) {
  26. super(...args);
  27. this._handleFeatureClicked = this._handleFeatureClicked.bind(this);
  28. }
  29. /**
  30. * @inheritDoc
  31. * @review
  32. */
  33. _getNativeFeatures(geoJSONData) {
  34. const features = [];
  35. L.geoJson(geoJSONData, {
  36. onEachFeature: (feature, layer) => {
  37. layer.on('click', this._handleFeatureClicked);
  38. features.push(feature);
  39. },
  40. }).addTo(this.map);
  41. return features;
  42. }
  43. /**
  44. * @inheritDoc
  45. * @review
  46. */
  47. _wrapNativeFeature(nativeFeature) {
  48. const feature = nativeFeature.geometry
  49. ? nativeFeature
  50. : nativeFeature.target.feature;
  51. const geometry = feature.geometry;
  52. return {
  53. getGeometry() {
  54. return {
  55. get() {
  56. return L.latLng(
  57. geometry.coordinates[1],
  58. geometry.coordinates[0]
  59. );
  60. },
  61. };
  62. },
  63. getMarker() {
  64. return nativeFeature.target;
  65. },
  66. getProperty(prop) {
  67. return feature.properties[prop];
  68. },
  69. };
  70. }
  71. }
  72. export default OpenStreetMapGeoJSONBase;
  73. export {OpenStreetMapGeoJSONBase};