google-map-directions
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,34 +0,63 @@ | ||
"use strict"; | ||
// Import the required types | ||
/// <reference types="@types/google.maps" /> | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loadGoogleMap = void 0; | ||
// google-map-directions.ts | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
loadGoogleMap: () => loadGoogleMap | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
function loadGoogleMap(apiKey, containerId, pointA, pointB) { | ||
const script = document.createElement('script'); | ||
script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=initMap`; | ||
script.async = true; | ||
script.defer = true; | ||
document.body.appendChild(script); | ||
window.initMap = () => { | ||
const map = new google.maps.Map(document.getElementById(containerId), { | ||
center: pointA, | ||
zoom: 10, | ||
}); | ||
const directionsService = new google.maps.DirectionsService(); | ||
const directionsRenderer = new google.maps.DirectionsRenderer(); | ||
directionsRenderer.setMap(map); | ||
const request = { | ||
origin: pointA, | ||
destination: pointB, | ||
travelMode: google.maps.TravelMode.DRIVING, | ||
}; | ||
directionsService.route(request, (result, status) => { | ||
if (status === google.maps.DirectionsStatus.OK) { | ||
directionsRenderer.setDirections(result); | ||
} | ||
}); | ||
const script = document.createElement("script"); | ||
script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=initMap`; | ||
script.id = "google-maps-script"; | ||
script.async = true; | ||
script.defer = true; | ||
document.body.appendChild(script); | ||
window.initMap = () => { | ||
const map = new google.maps.Map(document.getElementById(containerId), { | ||
center: pointA, | ||
zoom: 10 | ||
}); | ||
const directionsService = new google.maps.DirectionsService(); | ||
const directionsRenderer = new google.maps.DirectionsRenderer(); | ||
directionsRenderer.setMap(map); | ||
const request = { | ||
origin: pointA, | ||
destination: pointB, | ||
travelMode: google.maps.TravelMode.DRIVING | ||
}; | ||
directionsService.route(request, (result, status) => { | ||
if (status === google.maps.DirectionsStatus.OK) { | ||
directionsRenderer.setDirections(result); | ||
} | ||
}); | ||
const line = new google.maps.Polyline({ | ||
path: [pointA, pointB], | ||
geodesic: true, | ||
strokeColor: "#FF0000", | ||
strokeOpacity: 1, | ||
strokeWeight: 2 | ||
}); | ||
line.setMap(map); | ||
}; | ||
} | ||
exports.loadGoogleMap = loadGoogleMap; | ||
//# sourceMappingURL=index.js.map | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
loadGoogleMap | ||
}); |
{ | ||
"name": "google-map-directions", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "NPM package for Google Map directions that allows users to specify two points, draw lines between them, and display the map", | ||
@@ -8,4 +8,13 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "tsup src/index.ts --format esm,cjs", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"compilerOptions": { | ||
"types": [ | ||
"google.maps" | ||
], | ||
"typeRoots": [ | ||
"./node_modules/@types" | ||
] | ||
}, | ||
"keywords": [ | ||
@@ -40,2 +49,3 @@ "google", | ||
"@types/node": "^22.4.0", | ||
"tsup": "^8.2.4", | ||
"typescript": "^4.9.5" | ||
@@ -42,0 +52,0 @@ }, |
@@ -1,8 +0,7 @@ | ||
// Import the required types | ||
/// <reference types="@types/google.maps" /> | ||
/// <reference types="google.maps" /> | ||
// google-map-directions.ts | ||
export function loadGoogleMap(apiKey: string, containerId: string, pointA: google.maps.LatLngLiteral, pointB: google.maps.LatLngLiteral) { | ||
const script = document.createElement('script'); | ||
script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=initMap`; | ||
script.id = 'google-maps-script'; | ||
script.async = true; | ||
@@ -33,4 +32,13 @@ script.defer = true; | ||
}); | ||
// Optionally, draw a line between the two points | ||
const line = new google.maps.Polyline({ | ||
path: [pointA, pointB], | ||
geodesic: true, | ||
strokeColor: '#FF0000', | ||
strokeOpacity: 1.0, | ||
strokeWeight: 2, | ||
}); | ||
line.setMap(map); | ||
}; | ||
} | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10128
9
175
4