Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:03:00+00:00 2026-06-01T15:03:00+00:00

I am making a region drawing tool for a web application and I am

  • 0

I am making a region drawing tool for a web application and I am using markers as anchors that the user can use to change the shape of a polygon.

This is what I have so far. http://demos.nodeline.com/leaflet_development/

the repo is at https://github.com/SpencerCooley/Leaflet_development

$(document).ready(function(){

var map, cloudmade, sanAntonio, polygonPoints  


 map = new L.Map('map');

 cloudmade = new L.TileLayer('http://{s}.tile.cloudmade.com/d4334cd6077140e3b92ccfae2b363070/997/256/{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
    maxZoom: 18
});


 sanAntonio = new L.LatLng(29.4238889, -98.4933333); // geographical point (longitude and latitude)


 map.setView(sanAntonio, 13).addLayer(cloudmade);




polygonPoints = [];

var polygon = new L.Polygon(polygonPoints);
map.addLayer(polygon);

map.on('click', function(e) {  


  var marker = new L.Marker(e.latlng, {draggable:true});
  polygonPoints.push(e.latlng);
  var markerId = polygonPoints.length -1 
  map.addLayer(marker);
  polygon.setLatLngs(polygonPoints);



  marker.on('drag', function(){
    var locationWhileDrag = marker.getLatLng();
    $('#first_marker').val(locationWhileDrag);
    polygonPoints.splice(markerId,1,locationWhileDrag);
    polygon.setLatLngs(polygonPoints);
  });      



});







});

I only want the markers to be normal size when the user is zoomed in to street level. When you zoom out the normal sized markers completely drown out the polygon. I looked through the docs but couldn’t find anything about this.

I am mainly looking for suggestions/brainstorming. I am thinking maybe there is a way to detect which zoom state you are currently in? If so, I could use an if statement to change the icon.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:03:01+00:00Added an answer on June 1, 2026 at 3:03 pm

    Ok so I found a few methods and came up with this:

    //this sets up an icon to be replaced on redraw. 
    var MyIcon = L.Icon.extend({
        iconUrl: 'marker.png',
        iconSize: new L.Point(10, 16),
        shadowSize: new L.Point(10, 16),
        iconAnchor: new L.Point(10, 16)
    });
    
    var icon = new MyIcon();
    
    //When view resets use the smaller icon if zoom level is less than 13
    map.on('viewreset', function(){
        if(map.getZoom() < 13){
            marker.setIcon(icon);
        }
    });
    

    The setIcon() method was not in the docs, I found it in a google forum and it worked.I made a smaller icon and I am basically just replacing the original icon when the zoom level is less than 13. I am going to implement different markers for different zoom levels now to give the markers ‘further away’ effect.

    Here is the revised code.

    $(document).ready(function(){
    
    var map, cloudmade, sanAntonio, polygonPoints  
    
    map = new L.Map('map');
    
    cloudmade = new L.TileLayer('http://{s}.tile.cloudmade.com/d4334cd6077140e3b92ccfae2b363070/997/256/{z}/{x}/{y}.png', {
        attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
        maxZoom: 18
    });
    
    sanAntonio = new L.LatLng(29.4238889, -98.4933333); // geographical point (longitude and latitude)
    
    map.setView(sanAntonio, 13).addLayer(cloudmade);
    
    polygonPoints = [];
    
    var polygon = new L.Polygon(polygonPoints);
    map.addLayer(polygon);
    
    map.on('click', function(e) {  
        //this sets up an icon to be replaced when redraw. 
        var MyIcon = L.Icon.extend({
            iconUrl: 'marker.png',
            iconSize: new L.Point(10, 16),
            shadowSize: new L.Point(10, 16),
            iconAnchor: new L.Point(10, 16)
        });
    
        var icon = new MyIcon(); 
        //this sets up an icon to be replaced when redraw.
    
        var marker = new L.Marker(e.latlng, {draggable:true});
        polygonPoints.push(e.latlng);
        var markerId = polygonPoints.length -1 
        map.addLayer(marker);
        polygon.setLatLngs(polygonPoints);
    
        marker.on('drag', function(){
            var locationWhileDrag = marker.getLatLng();
            $('#first_marker').val(locationWhileDrag);
            polygonPoints.splice(markerId,1,locationWhileDrag);
            polygon.setLatLngs(polygonPoints);
        });      
    
        //When view resets use the small icon if zoom level is less than 13
        map.on('viewreset', function(){
            if(map.getZoom() < 13){
                marker.setIcon(icon);
            }
        });
    });
    
    });
    

    here is the demo:
    http://demos.nodeline.com/leaflet_development/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making an adobe flex ui in which data that is calculated must use proprietary
Im making a login/logout class that logs users in, sets cookies based on user's
I'm making a drawing application with WINAPI and OpenGL. To make things more efficient
I am making an application, in that I want to move the sprite in
I need to write a simple Java GUI application that, basically, allows the user
Making UML sequence diagram in VS 2010RC I've observed that there is no activation
Making websites that appear correctly in IE is a big problem. Is there any
While making some final tests of a class-library that I'm writing for Windows Mobile
This should be so simple, but I'm making heavy weather of it. Div region
In order to use SetWindowsHookEx in a GUI application, you usually want in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.