providers/wikidata.js
function toGeoJSON(json, options = Options) {
  const languages = options.languages || Options.languages
  const collection = helpers.featureCollection([])
  if (json.results !== undefined) {
    if (json.results.bindings !== undefined) {
      json.results.bindings.map(result => {
        // Standard Wikidata tags
        const id = result.place.value.match(/entity\/(.+)/)[1]
        const [lng, lat] = result.location.value.match(/\(([\-\.\d]+) ([\-\.\d]+)\)/).slice(1, 3).map(n => Number(n))
        const distance = Number(result.distance.value)
        const properties = {
          id,
          distance,
        }
        if (result.placeDescription) {
          properties.description = result.placeDescription.value
        }
        // Parse languages
        languages.map(language => {
          const match = result[`name_${ language }`]
          if (match !== undefined) {
            properties[`name:${ language }`] = match.value
          }
        })

        // Create Point
        const point = helpers.point([lng, lat], properties)
        point.id = id

        // Add to GeoJSON Feature Collection
        collection.features.push(point)
      })
    }
  }

  return collection
}
function toGeoJSON(json, options = Options) {
  const languages = options.languages || Options.languages
  const collection = helpers.featureCollection([])
  if (json.results !== undefined) {
    if (json.results.bindings !== undefined) {
      json.results.bindings.map(result => {
        // Standard Wikidata tags
        const id = result.place.value.match(/entity\/(.+)/)[1]
        const [lng, lat] = result.location.value.match(/\(([\-\.\d]+) ([\-\.\d]+)\)/).slice(1, 3).map(n => Number(n))
        const distance = Number(result.distance.value)
        const properties = {
          id,
          distance,
        }
        if (result.placeDescription) {
          properties.description = result.placeDescription.value
        }
        // Parse languages
        languages.map(language => {
          const match = result[`name_${ language }`]
          if (match !== undefined) {
            properties[`name:${ language }`] = match.value
          }
        })

        // Create Point
        const point = helpers.point([lng, lat], properties)
        point.id = id

        // Add to GeoJSON Feature Collection
        collection.features.push(point)
      })
    }
  }

  return collection
}
function toGeoJSON ( json , options = Options ) { const languages = options . languages || Options . languages const collection = helpers . featureCollection ( [ ] ) if ( json . results !== undefined ) { if ( json . results . bindings !== undefined ) { json . results . bindings . map ( result => { // Standard Wikidata tags const id = result . place . value . match ( / entity\/(.+) / ) [ 1 ] const [ lng , lat ] = result . location . value . match ( / \(([\-\.\d]+) ([\-\.\d]+)\) / ) . slice ( 1 , 3 ) . map ( n => Number ( n ) ) const distance = Number ( result . distance . value ) const properties = { id , distance , } if ( result . placeDescription ) { properties . description = result . placeDescription . value } // Parse languages languages . map ( language => { const match = result [ ` ${ language } ` ] if ( match !== undefined ) { properties [ ` ${ language } ` ] = match . value } } ) // Create Point const point = helpers . point ( [ lng , lat ] , properties ) point . id = id // Add to GeoJSON Feature Collection collection . features . push ( point ) } ) } } return collection }
Convert Wikidata SPARQL results into GeoJSON
Convert Wikidata SPARQL results into GeoJSON