Results 1 to 6 of 6

Thread: Convert Google maps code to openlayers

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2013
    Posts
    41

    Convert Google maps code to openlayers

    hi i have this code for google maps but need to convert it for openlayers bing maps
    Code:
       var latlng = new google.maps.LatLng(LAT, LNG);
            marker = new google.maps.Marker({
                position: latlng,
                title: 'Sitename' + ' ' + SiteName + ' '
                + 'LAC' + ' ' + LAC,
                animation: google.maps.Animation.DROP,
                draggable: true,
                icon: pinSymbol('cyan'),
                id: SiteName,
                label: { text: SiteName + ' ' + '(' + LAC + ')', color: '#ff0000', strokeColor: '#ffc125' },
                labelStyle: { opacity: 0.75 },
                zoom:20,
                map: gmap
    Last edited by Shaggy Hiker; Feb 6th, 2025 at 12:32 PM.

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,735

    Re: convert Google maps code to openlayers

    First this is for html/Jscript or asp forums.
    Second you are not closing the market Json .... zoom:20,
    map: gmap }) , I guess
    Third I have no idea but I'm guessing the bing have some kind of similar layer? So I would create a class for gmaps that sprout to Json and a class for bing that sprout to Json also and try to convert the gmaps class to show the properties of the binq class and then Json it (newtonsoft Json or Json.net , I prefer the first).
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,755

    Re: convert Google maps code to openlayers

    Aside from that, Bing maps will be going away at the end of June of this year, so moving to Bing at this point seems unlikely to last. Perhaps you should be looking for Azure maps, which is what Microsoft is replacing Bing maps with.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2013
    Posts
    41

    Convert JS for Google maps to open layers with Bing maps

    Hi i posted this in the wrong area first. i have code that worked with google maps but need to convert it for open layers, probably Bing Maps (i know it is defunct from June this year) my problem is the "LAT, LNG" is picking up my variable from the database query in VB and passing it to the html but not sure how to action a marker/pushpin with the same effect for OpenLayers/Bing Maps (hopefully Azzure would be the same).


    Code:
      
    var AllMarkers= []
    function addAllMarker(Code, Name,  LAT, LNG) {
                  var localimage = {
                url: '/resources/1494357980_wifi.png', // image is 512 x 512
                scaledSize: new google.maps.Size(22, 32) }
    
        
            var latlng = new google.maps.LatLng(LAT, LNG);
            marker = new google.maps.Marker({
                position: latlng,
                title: 'Name' + ' ' + Name + ' '
                + 'LAC' + ' ' + LAC,
                animation: google.maps.Animation.DROP,
                draggable: true,
                icon: pinSymbol('cyan'),
                id: SiteName,
                label: { text: Name + ' ' + '(' + Code + ')', color: '#ff0000', strokeColor: '#ffc125' },
                labelStyle: { opacity: 0.75 },
                zoom:20,
                map: gmap
            });
            AllMarkers.push(marker);
    
           
        }
        google.maps.event.addDomListener(window, 'addAllMarker', function () {
    
        });

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,755

    Re: Convert Google maps code to openlayers

    I decided to merge the two threads into one.

    I'm hoping Azure will be the same, too, as I get to make that transition as well. However, the code I have is in VB.NET for a desktop application, which probably doesn't apply very well to a JavaScript use.
    My usual boring signature: Nothing

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    12,064

    Re: Convert Google maps code to openlayers

    I didn't test this, but ChatGPT threw out this code:
    Code:
    // Global array to hold all pushpins
    const pushpins = [];
    
    // Adds a pushpin to the Bing map.
    // Parameters:
    //   code      - The code identifier for the marker
    //   name      - The name to display
    //   lat       - Latitude
    //   lng       - Longitude
    //   lac       - (Optional) Additional information for the title
    //   siteName  - (Optional) An identifier for the site
    const addPushpin = (code, name, lat, lng, lac = '', siteName = '') => {
      // Create a location using Bing Maps API
      const location = new Microsoft.Maps.Location(lat, lng);
    
      // Configure pushpin options
      const options = {
        title: `${name} (${code})`,
        draggable: true,
        // Assumes pinSymbol('cyan') returns a valid icon configuration for Bing Maps.
        icon: pinSymbol('cyan')
      };
    
      // Create the pushpin
      const pushpin = new Microsoft.Maps.Pushpin(location, options);
    
      // Attach additional metadata if required
      pushpin.metadata = {
        fullTitle: `Name ${name} LAC ${lac}`,
        id: siteName
      };
    
      // Add the pushpin to the Bing Maps map (assumes 'gmap' is your map instance)
      gmap.entities.push(pushpin);
    
      // Store the pushpin in the global array for later reference
      pushpins.push(pushpin);
    
      // raise the custom addPushpin event
      window.dispatchEvent(new CustomEvent('addPushpin', { detail: pushpin }));
    };
    
    // Standard DOM event listener for a custom event 'addPushpin'.
    // Replace or extend the functionality as needed.
    window.addEventListener('addPushpin', e => {
      // Place any code here that should execute when the 'addPushpin' event is fired.
    });
    Looking at the documentation, it seems like it'd work:
    https://learn.microsoft.com/en-us/bi...location-class
    https://learn.microsoft.com/en-us/bi.../pushpin-class
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width